Обновлен и вынесен в отдельный модуль абстрактный класс базового экрана.

This commit is contained in:
Alexander Zhirov 2026-01-09 02:52:52 +03:00
parent bea63a42f1
commit 254fa9c419
Signed by: alexander
GPG key ID: C8D8BE544A27C511
3 changed files with 109 additions and 34 deletions

View file

@ -0,0 +1,108 @@
module ncui.engine.basescreen;
import ncui.core.ncwin;
import ncui.core.window;
import ncui.core.event;
import ncui.engine.screen;
import ncui.engine.action;
import ncui.widgets.container;
abstract class ScreenBase : IScreen
{
protected:
Window _window;
WidgetContainer _ui;
bool _built;
void ensureWindow(ScreenContext context);
void build(ScreenContext context, Window window, WidgetContainer ui);
void layout(ScreenContext ctx, Window w, WidgetContainer ui)
{
}
ScreenAction handleGlobal(ScreenContext context, KeyEvent event)
{
return ScreenAction.none();
}
private:
void renderAll(ScreenContext context)
{
import deimos.ncurses : doupdate;
import ncui.lib.checks;
_window.erase();
layout(context, _window, _ui);
_ui.render(_window, context);
_window.noutrefresh();
ncuiNotErr!doupdate();
}
public:
this()
{
_ui = new WidgetContainer();
}
override NCWin inputWindow()
{
return _window.handle();
}
override ScreenAction onShow(ScreenContext context)
{
if (_window !is null)
{
_window.close();
}
ensureWindow(context);
if (!_built)
{
build(context, _window, _ui);
_built = true;
}
renderAll(context);
return ScreenAction.none();
}
override ScreenAction onChildResult(ScreenContext context, ScreenResult child)
{
return ScreenAction.none();
}
override ScreenAction handle(ScreenContext context, KeyEvent event)
{
auto result = handleGlobal(context, event);
if (result.kind != ActionKind.None)
{
return result;
}
auto action = _ui.handle(context, event);
if (action.kind != ActionKind.None)
{
return action;
}
renderAll(context);
return ScreenAction.none();
}
override void close()
{
if (_window !is null)
{
_window.close();
}
_window = null;
_built = false;
_ui = new WidgetContainer();
}
}

View file

@ -56,37 +56,3 @@ interface ITaggedScreen
{
int tag();
}
abstract class ScreenBase : IScreen
{
protected:
Window _window;
public:
override NCWin inputWindow()
{
return _window.handle();
}
override ScreenAction onShow(ScreenContext context)
{
return ScreenAction.none();
}
override ScreenAction onChildResult(ScreenContext context, ScreenResult child)
{
return ScreenAction.none();
}
override ScreenAction handle(ScreenContext context, KeyEvent event)
{
return ScreenAction.none();
}
override void close()
{
if (_window !is null)
_window.close();
_window = null;
}
}

View file

@ -10,6 +10,7 @@ public import ncui.core.window;
public import ncui.engine.ncui;
public import ncui.engine.action;
public import ncui.engine.screen;
public import ncui.engine.basescreen;
// Вспомогательная библиотека
public import ncui.lib.logger;