mirror of https://github.com/buggins/dlangui.git
modal popups
This commit is contained in:
parent
71e3ba0f62
commit
cf75dd3496
|
@ -209,4 +209,3 @@ class DialogFrame : WindowFrame {
|
||||||
bodyWidget = _dialog;
|
bodyWidget = _dialog;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -193,6 +193,15 @@ class Window {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// returns last modal popup widget, or null if no modal popups opened
|
||||||
|
PopupWidget modalPopup() {
|
||||||
|
for (int i = cast(int)_popups.length - 1; i >= 0; i--) {
|
||||||
|
if (_popups[i].flags & PopupFlags.Modal)
|
||||||
|
return _popups[i];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/// returns true if widget is child of either main widget or one of popups
|
/// returns true if widget is child of either main widget or one of popups
|
||||||
bool isChild(Widget w) {
|
bool isChild(Widget w) {
|
||||||
if (_mainWidget !is null && _mainWidget.isChild(w))
|
if (_mainWidget !is null && _mainWidget.isChild(w))
|
||||||
|
@ -271,9 +280,17 @@ class Window {
|
||||||
long drawStart = currentTimeMillis;
|
long drawStart = currentTimeMillis;
|
||||||
// draw main widget
|
// draw main widget
|
||||||
_mainWidget.onDraw(buf);
|
_mainWidget.onDraw(buf);
|
||||||
|
|
||||||
|
PopupWidget modal = modalPopup();
|
||||||
|
|
||||||
// draw popups
|
// draw popups
|
||||||
foreach(p; _popups)
|
foreach(p; _popups) {
|
||||||
|
if (p is modal) {
|
||||||
|
// TODO: get shadow color from theme
|
||||||
|
buf.fillRect(Rect(0, 0, buf.width, buf.height), 0xD0404040);
|
||||||
|
}
|
||||||
p.onDraw(buf);
|
p.onDraw(buf);
|
||||||
|
}
|
||||||
long drawEnd = currentTimeMillis;
|
long drawEnd = currentTimeMillis;
|
||||||
debug(DebugRedraw) {
|
debug(DebugRedraw) {
|
||||||
if (drawEnd - drawStart > PERFORMANCE_LOGGING_THRESHOLD_MS)
|
if (drawEnd - drawStart > PERFORMANCE_LOGGING_THRESHOLD_MS)
|
||||||
|
@ -341,6 +358,7 @@ class Window {
|
||||||
/// dispatch keyboard event
|
/// dispatch keyboard event
|
||||||
bool dispatchKeyEvent(KeyEvent event) {
|
bool dispatchKeyEvent(KeyEvent event) {
|
||||||
bool res = false;
|
bool res = false;
|
||||||
|
PopupWidget modal = modalPopup();
|
||||||
if (event.action == KeyAction.KeyDown || event.action == KeyAction.KeyUp) {
|
if (event.action == KeyAction.KeyDown || event.action == KeyAction.KeyUp) {
|
||||||
_keyboardModifiers = event.flags;
|
_keyboardModifiers = event.flags;
|
||||||
if (event.keyCode == KeyCode.ALT || event.keyCode == KeyCode.LALT || event.keyCode == KeyCode.RALT) {
|
if (event.keyCode == KeyCode.ALT || event.keyCode == KeyCode.LALT || event.keyCode == KeyCode.RALT) {
|
||||||
|
@ -360,6 +378,7 @@ class Window {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
Widget focus = focusedWidget;
|
Widget focus = focusedWidget;
|
||||||
|
if (!modal || modal.isChild(focus)) {
|
||||||
while (focus) {
|
while (focus) {
|
||||||
if (focus.onKeyEvent(event))
|
if (focus.onKeyEvent(event))
|
||||||
return true; // processed by focused widget
|
return true; // processed by focused widget
|
||||||
|
@ -367,7 +386,12 @@ class Window {
|
||||||
break;
|
break;
|
||||||
focus = focus.parent;
|
focus = focus.parent;
|
||||||
}
|
}
|
||||||
if (_mainWidget) {
|
}
|
||||||
|
if (modal) {
|
||||||
|
if (dispatchKeyEvent(modal, event))
|
||||||
|
return res;
|
||||||
|
return modal.onKeyEvent(event) || res;
|
||||||
|
} else if (_mainWidget) {
|
||||||
if (dispatchKeyEvent(_mainWidget, event))
|
if (dispatchKeyEvent(_mainWidget, event))
|
||||||
return res;
|
return res;
|
||||||
return _mainWidget.onKeyEvent(event) || res;
|
return _mainWidget.onKeyEvent(event) || res;
|
||||||
|
@ -585,8 +609,10 @@ class Window {
|
||||||
if (_mainWidget is null)
|
if (_mainWidget is null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
PopupWidget modal = modalPopup();
|
||||||
|
|
||||||
// check if _mouseCaptureWidget and _mouseTrackingWidget still exist in child of root widget
|
// check if _mouseCaptureWidget and _mouseTrackingWidget still exist in child of root widget
|
||||||
if (_mouseCaptureWidget !is null && !isChild(_mouseCaptureWidget)) {
|
if (_mouseCaptureWidget !is null && (!isChild(_mouseCaptureWidget) || (modal && !modal.isChild(_mouseCaptureWidget)))) {
|
||||||
clearMouseCapture();
|
clearMouseCapture();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -666,6 +692,8 @@ class Window {
|
||||||
auto p = _popups[i];
|
auto p = _popups[i];
|
||||||
if (p.isPointInside(event.x, event.y))
|
if (p.isPointInside(event.x, event.y))
|
||||||
insideOneOfPopups = true;
|
insideOneOfPopups = true;
|
||||||
|
if (p is modal)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
for (int i = cast(int)_popups.length - 1; i >= 0; i--) {
|
for (int i = cast(int)_popups.length - 1; i >= 0; i--) {
|
||||||
auto p = _popups[i];
|
auto p = _popups[i];
|
||||||
|
@ -676,7 +704,10 @@ class Window {
|
||||||
if (dispatchMouseEvent(p, event, cursorIsSet))
|
if (dispatchMouseEvent(p, event, cursorIsSet))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (p is modal)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
if (!modal)
|
||||||
res = dispatchMouseEvent(_mainWidget, event, cursorIsSet);
|
res = dispatchMouseEvent(_mainWidget, event, cursorIsSet);
|
||||||
}
|
}
|
||||||
return res || processed || _mainWidget.needDraw;
|
return res || processed || _mainWidget.needDraw;
|
||||||
|
|
Loading…
Reference in New Issue