Обновлен и вынесен в отдельный модуль абстрактный класс базового экрана.
This commit is contained in:
parent
bea63a42f1
commit
254fa9c419
3 changed files with 109 additions and 34 deletions
108
source/ncui/engine/basescreen.d
Normal file
108
source/ncui/engine/basescreen.d
Normal 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();
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue