From 055979b9e7976e7ffce6e6f4951f829632c7d097 Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Fri, 30 Jan 2015 17:55:04 +0300 Subject: [PATCH] actions update - working --- src/dlangui/core/events.d | 24 ++++++++++++++---------- src/dlangui/platforms/common/platform.d | 22 +++++++++++++++------- src/dlangui/widgets/appframe.d | 2 ++ src/dlangui/widgets/tabs.d | 12 +++++++++++- src/dlangui/widgets/widget.d | 6 ++++++ views/res/theme_default.xml | 8 ++++++-- 6 files changed, 54 insertions(+), 20 deletions(-) diff --git a/src/dlangui/core/events.d b/src/dlangui/core/events.d index 5b1603fc..74e435e3 100644 --- a/src/dlangui/core/events.d +++ b/src/dlangui/core/events.d @@ -69,14 +69,14 @@ class ActionState { } /// action is -__gshared const(ActionState) ACTION_STATE_DEFAULT_ENABLED; -__gshared const(ActionState) ACTION_STATE_DEFAULT_DISABLE; -__gshared const(ActionState) ACTION_STATE_DEFAULT_INVISIBLE; +__gshared const(ActionState) ACTION_STATE_ENABLED; +__gshared const(ActionState) ACTION_STATE_DISABLE; +__gshared const(ActionState) ACTION_STATE_INVISIBLE; __gshared static this() { - ACTION_STATE_DEFAULT_ENABLED = cast(const(ActionState))new ActionState(true, true, false); - ACTION_STATE_DEFAULT_DISABLE = cast(const(ActionState))new ActionState(false, true, false); - ACTION_STATE_DEFAULT_INVISIBLE = cast(const(ActionState))new ActionState(false, false, false); + ACTION_STATE_ENABLED = cast(const(ActionState))new ActionState(true, true, false); + ACTION_STATE_DISABLE = cast(const(ActionState))new ActionState(false, true, false); + ACTION_STATE_INVISIBLE = cast(const(ActionState))new ActionState(false, false, false); } @@ -106,21 +106,25 @@ class Action { protected ActionState _defaultState; + /// set default state to disabled, visible, not-checked + Action disableByDefault() { _defaultState = new ActionState(false, true, false); return this; } + /// set default state to disabled, invisible, not-checked + Action hideByDefault() { _defaultState = new ActionState(false, false, false); return this; } /// default state for action if action state lookup failed - @property const(ActionState) defaultState() const { return _defaultState ? _defaultState : ACTION_STATE_DEFAULT_ENABLED; } + @property const(ActionState) defaultState() const { return _defaultState ? _defaultState : ACTION_STATE_ENABLED; } /// default state for action if action state lookup failed @property Action defaultState(ActionState s) { _defaultState = s; return this; } /// action state - @property const(ActionState) state() const { return _state ? _state : (_defaultState ? _defaultState : ACTION_STATE_DEFAULT_ENABLED); } + @property const(ActionState) state() const { return _state ? _state : (_defaultState ? _defaultState : ACTION_STATE_ENABLED); } /// update action state (for non-const action) @property Action state(const ActionState s) { - if (_state != s) + if (!_state || _state != s) _state = s.clone(); return this; } /// update action state (can be changed even for const objects) @property const(Action) state(const ActionState s) const { - if (_state != s) { + if (!_state || _state != s) { // hack Action nonConstThis = cast(Action) this; nonConstThis._state = s.clone(); diff --git a/src/dlangui/platforms/common/platform.d b/src/dlangui/platforms/common/platform.d index 09b2d1a2..92be8941 100644 --- a/src/dlangui/platforms/common/platform.d +++ b/src/dlangui/platforms/common/platform.d @@ -848,14 +848,18 @@ class Window { protected void setCursorType(uint cursorType) { // override to support different mouse cursors } + /// update action states + protected void dispatchWidgetUpdateActionStateRecursive() { + if (_mainWidget !is null) + dispatchWidgetUpdateActionStateRecursive(_mainWidget); + foreach(p; _popups) + dispatchWidgetUpdateActionStateRecursive(p); + } /// checks content widgets for necessary redraw and/or layout bool checkUpdateNeeded(ref bool needDraw, ref bool needLayout, ref bool animationActive) { if (_actionsUpdateRequested) { // call update action check - as requested - if (_mainWidget !is null) - dispatchWidgetUpdateActionStateRecursive(_mainWidget); - foreach(p; _popups) - dispatchWidgetUpdateActionStateRecursive(p); + dispatchWidgetUpdateActionStateRecursive(); _actionsUpdateRequested = false; } needDraw = needLayout = animationActive = false; @@ -884,10 +888,14 @@ class Window { /// close window abstract void close(); - protected bool _actionsUpdateRequested; + protected bool _actionsUpdateRequested = true; + /// set action update request flag, will be cleared after redraw - void requestActionsUpdate() { - _actionsUpdateRequested = true; + void requestActionsUpdate(bool immediateUpdate = false) { + if (!immediateUpdate) + _actionsUpdateRequested = true; + else + dispatchWidgetUpdateActionStateRecursive(); } @property bool actionsUpdateRequested() { diff --git a/src/dlangui/widgets/appframe.d b/src/dlangui/widgets/appframe.d index ef8ae183..f1058d29 100644 --- a/src/dlangui/widgets/appframe.d +++ b/src/dlangui/widgets/appframe.d @@ -86,6 +86,7 @@ class AppFrame : VerticalLayout, MenuItemClickHandler, MenuItemActionHandler { destroy(_currentBackgroundOperation); _currentBackgroundOperation = null; _currentBackgroundOperationTimer = 0; + requestActionsUpdate(); return false; } return true; @@ -106,6 +107,7 @@ class AppFrame : VerticalLayout, MenuItemClickHandler, MenuItemActionHandler { _currentBackgroundOperation = op; if (op) _currentBackgroundOperationTimer = setTimer(op.updateInterval); + requestActionsUpdate(); } /// main menu widget diff --git a/src/dlangui/widgets/tabs.d b/src/dlangui/widgets/tabs.d index 6eda33b5..9bc77ee9 100644 --- a/src/dlangui/widgets/tabs.d +++ b/src/dlangui/widgets/tabs.d @@ -401,7 +401,7 @@ class TabControl : WidgetGroupDefaultDrawing { return true; } /// Measure widget according to desired width and height constraints. (Step 1 of two phase layout). - override void measure(int parentWidth, int parentHeight) { + override void measure(int parentWidth, int parentHeight) { //Log.d("tabControl.measure enter"); Rect m = margins; Rect p = padding; @@ -747,4 +747,14 @@ class TabWidget : VerticalLayout, TabHandler, TabCloseHandler { } return super.onKeyEvent(event); } + + @property string selectedTabId() const { + return _tabControl._selectedTabId; + } + + /// get tab content widget by id + Widget selectedTabBody() { + return _tabHost.tabBody(_tabControl._selectedTabId); + } + } diff --git a/src/dlangui/widgets/widget.d b/src/dlangui/widgets/widget.d index 76fe7cf8..aad5be0b 100644 --- a/src/dlangui/widgets/widget.d +++ b/src/dlangui/widgets/widget.d @@ -669,6 +669,12 @@ class Widget { visibility = s.visible ? Visibility.Visible : Visibility.Gone; } } + /// set action update request flag, will be cleared after redraw + void requestActionsUpdate(bool immediateUpdate = false) { + if (Window w = window) { + w.requestActionsUpdate(immediateUpdate); + } + } protected bool _focusGroup; /***************************************** diff --git a/views/res/theme_default.xml b/views/res/theme_default.xml index 23311026..cbeaf3c4 100644 --- a/views/res/theme_default.xml +++ b/views/res/theme_default.xml @@ -311,13 +311,17 @@ align="Center" margins="1,1,1,1" padding="2,2,2,2" - /> + > + +