mirror of https://github.com/buggins/dlangui.git
actions state requests, part 3
This commit is contained in:
parent
bf79159d39
commit
a1ee2ba8b1
|
@ -164,7 +164,9 @@ class Action {
|
||||||
_id = a._id;
|
_id = a._id;
|
||||||
_label = a._label;
|
_label = a._label;
|
||||||
_iconId = a._iconId;
|
_iconId = a._iconId;
|
||||||
|
if (a._state)
|
||||||
_state = a._state.clone();
|
_state = a._state.clone();
|
||||||
|
if (a._defaultState)
|
||||||
_defaultState = a._defaultState.clone();
|
_defaultState = a._defaultState.clone();
|
||||||
_accelerators.length = a._accelerators.length;
|
_accelerators.length = a._accelerators.length;
|
||||||
for(int i = 0; i < _accelerators.length; i++)
|
for(int i = 0; i < _accelerators.length; i++)
|
||||||
|
|
|
@ -818,6 +818,14 @@ class Window {
|
||||||
return res || processed || _mainWidget.needDraw;
|
return res || processed || _mainWidget.needDraw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// calls update actions recursively
|
||||||
|
protected void dispatchWidgetUpdateActionStateRecursive(Widget root) {
|
||||||
|
if (root is null)
|
||||||
|
return;
|
||||||
|
root.updateActionState(true);
|
||||||
|
for (int i = 0; i < root.childCount; i++)
|
||||||
|
dispatchWidgetUpdateActionStateRecursive(root.child(i));
|
||||||
|
}
|
||||||
/// checks content widgets for necessary redraw and/or layout
|
/// checks content widgets for necessary redraw and/or layout
|
||||||
protected void checkUpdateNeeded(Widget root, ref bool needDraw, ref bool needLayout, ref bool animationActive) {
|
protected void checkUpdateNeeded(Widget root, ref bool needDraw, ref bool needLayout, ref bool animationActive) {
|
||||||
if (root is null)
|
if (root is null)
|
||||||
|
@ -842,6 +850,14 @@ class Window {
|
||||||
}
|
}
|
||||||
/// checks content widgets for necessary redraw and/or layout
|
/// checks content widgets for necessary redraw and/or layout
|
||||||
bool checkUpdateNeeded(ref bool needDraw, ref bool needLayout, ref bool animationActive) {
|
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);
|
||||||
|
_actionsUpdateRequested = false;
|
||||||
|
}
|
||||||
needDraw = needLayout = animationActive = false;
|
needDraw = needLayout = animationActive = false;
|
||||||
if (_mainWidget is null)
|
if (_mainWidget is null)
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -626,23 +626,48 @@ class Widget {
|
||||||
@property void action(const Action action) { _action = action.clone; }
|
@property void action(const Action action) { _action = action.clone; }
|
||||||
/// action to emit on click
|
/// action to emit on click
|
||||||
@property void action(Action action) { _action = action; }
|
@property void action(Action action) { _action = action; }
|
||||||
/// ask for update state of some action (unles force=true, checks window flag
|
/// ask for update state of some action (unles force=true, checks window flag actionsUpdateRequested), returns true if action state is changed
|
||||||
void updateActionState(Action a, bool force = false) {
|
bool updateActionState(Action a, bool force = false) {
|
||||||
if (Window w = window) {
|
if (Window w = window) {
|
||||||
if (!force && !w.actionsUpdateRequested())
|
if (!force && !w.actionsUpdateRequested())
|
||||||
return;
|
return false;
|
||||||
|
const ActionState oldState = a.state;
|
||||||
if (w.dispatchActionStateRequest(a, this)) {
|
if (w.dispatchActionStateRequest(a, this)) {
|
||||||
// state is updated
|
// state is updated
|
||||||
} else {
|
} else {
|
||||||
a.state = a.defaultState;
|
a.state = a.defaultState;
|
||||||
}
|
}
|
||||||
|
if (a.state != oldState)
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
/// call to update state for action (if action is assigned for widget)
|
/// call to update state for action (if action is assigned for widget)
|
||||||
void updateActionState(bool force = false) {
|
void updateActionState(bool force = false) {
|
||||||
if (!_action)
|
if (!_action)
|
||||||
return;
|
return;
|
||||||
updateActionState(_action, force);
|
if (updateActionState(_action, force))
|
||||||
|
handleActionStateChanged();
|
||||||
|
}
|
||||||
|
/// called when state of action assigned on widget is changed
|
||||||
|
void handleActionStateChanged() {
|
||||||
|
// override to update enabled state, visibility and checked state
|
||||||
|
// default processing: copy flags to this widget
|
||||||
|
updateStateFromAction(_action);
|
||||||
|
}
|
||||||
|
/// apply enabled, visibile and checked state for this widget from action's state
|
||||||
|
void updateStateFromAction(Action a) {
|
||||||
|
const ActionState s = a.state;
|
||||||
|
if (s.enabled != enabled) {
|
||||||
|
enabled = s.enabled;
|
||||||
|
}
|
||||||
|
if (s.checked != checked) {
|
||||||
|
checked = s.checked;
|
||||||
|
}
|
||||||
|
bool v = _visibility == Visibility.Visible;
|
||||||
|
if (s.visible != v) {
|
||||||
|
visibility = s.visible ? Visibility.Visible : Visibility.Gone;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected bool _focusGroup;
|
protected bool _focusGroup;
|
||||||
|
|
Loading…
Reference in New Issue