From 7895e417d966eefdc4f8373d5526545e6f2f264e Mon Sep 17 00:00:00 2001 From: Grim Maple Date: Sat, 26 Nov 2022 13:47:06 +0300 Subject: [PATCH] Add main widget change signal to window --- src/dlangui/platforms/common/platform.d | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/dlangui/platforms/common/platform.d b/src/dlangui/platforms/common/platform.d index 7b036187..cdc82ef8 100644 --- a/src/dlangui/platforms/common/platform.d +++ b/src/dlangui/platforms/common/platform.d @@ -129,6 +129,12 @@ interface OnWindowActivityHandler { bool onWindowActivityChange(Window window, bool isWindowActive); } +/// Window main widget changing signal listener +interface OnMainWidgetChange +{ + void onMainWidgetChange(Window window, Widget previous, Widget newWidget); +} + /// protected event list /// references to posted messages can be stored here at least to keep live reference and avoid GC /// as well, on some platforms it's easy to send id to message queue, but not pointer @@ -264,8 +270,11 @@ class Window : CustomEventTarget { @property int height() const { return _dy; } @property uint keyboardModifiers() const { return _keyboardModifiers; } @property inout(Widget) mainWidget() inout { return _mainWidget; } - @property void mainWidget(Widget widget) { - if (_mainWidget !is null) { + @property void mainWidget(Widget widget) + { + mainWidgetChange(this, _mainWidget, widget); + if (_mainWidget !is null) + { _mainWidget.window = null; destroy(_mainWidget); } @@ -274,6 +283,8 @@ class Window : CustomEventTarget { _mainWidget.window = this; } + Signal!OnMainWidgetChange mainWidgetChange; + /// save window state to setting object void saveWindowState(Setting setting) { if (!setting)