From 254fa9c41996e657c47cc3597ca13b3a1aeec020 Mon Sep 17 00:00:00 2001 From: Alexander Zhirov Date: Fri, 9 Jan 2026 02:52:52 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=B8=20=D0=B2=D1=8B=D0=BD=D0=B5=D1=81=D0=B5=D0=BD=20?= =?UTF-8?q?=D0=B2=20=D0=BE=D1=82=D0=B4=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9?= =?UTF-8?q?=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D1=8C=20=D0=B0=D0=B1=D1=81?= =?UTF-8?q?=D1=82=D1=80=D0=B0=D0=BA=D1=82=D0=BD=D1=8B=D0=B9=20=D0=BA=D0=BB?= =?UTF-8?q?=D0=B0=D1=81=D1=81=20=D0=B1=D0=B0=D0=B7=D0=BE=D0=B2=D0=BE=D0=B3?= =?UTF-8?q?=D0=BE=20=D1=8D=D0=BA=D1=80=D0=B0=D0=BD=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/ncui/engine/basescreen.d | 108 ++++++++++++++++++++++++++++++++ source/ncui/engine/screen.d | 34 ---------- source/ncui/package.d | 1 + 3 files changed, 109 insertions(+), 34 deletions(-) create mode 100644 source/ncui/engine/basescreen.d diff --git a/source/ncui/engine/basescreen.d b/source/ncui/engine/basescreen.d new file mode 100644 index 0000000..bf9b5f1 --- /dev/null +++ b/source/ncui/engine/basescreen.d @@ -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(); + } +} diff --git a/source/ncui/engine/screen.d b/source/ncui/engine/screen.d index 456941f..4663c07 100644 --- a/source/ncui/engine/screen.d +++ b/source/ncui/engine/screen.d @@ -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; - } -} diff --git a/source/ncui/package.d b/source/ncui/package.d index 80730f1..1cc91ed 100644 --- a/source/ncui/package.d +++ b/source/ncui/package.d @@ -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;