Unify Modern dropdown menus with Gold layout and safe keyboard selection (by Codex)
This commit is contained in:
1 parent
e81ecf95f2
commit
fff2cc2f0b
18 files changed
+1361
-17
No files matched your search
@@ -188,7 +188,7 @@ bool App::widget_event(Rml::Event &event) {
|
||||
return widget_change(target);
|
||||
}
|
||||
}
|
||||
if (type != "keydown" || scene_ != "desktop")
|
||||
if (type != "keydown" || (scene_ != "desktop" && menu_ != "quit"))
|
||||
return false;
|
||||
const auto key =
|
||||
Rml::Input::KeyIdentifier(event.GetParameter<int>("key_identifier", 0));
|
||||
@@ -233,6 +233,22 @@ bool App::widget_event(Rml::Event &event) {
|
||||
event.StopImmediatePropagation();
|
||||
return true;
|
||||
}
|
||||
if (key == Rml::Input::KI_TAB && menu_ == "quit") {
|
||||
Rml::ElementList buttons;
|
||||
if (auto *modal = doc_->QuerySelector(".desktop-modal-layer"))
|
||||
modal->QuerySelectorAll(buttons, "button");
|
||||
std::erase_if(buttons, [](auto *button) {
|
||||
return !button->IsVisible(true) || button->HasAttribute("disabled");
|
||||
});
|
||||
if (!buttons.empty()) {
|
||||
const auto found = std::find(buttons.begin(), buttons.end(), context_->GetFocusElement());
|
||||
const int count = int(buttons.size());
|
||||
const int old = found == buttons.end() ? (shift ? 0 : -1) : int(found - buttons.begin());
|
||||
buttons[size_t((old + (shift ? -1 : 1) + count) % count)]->Focus(true);
|
||||
}
|
||||
event.StopImmediatePropagation();
|
||||
return true;
|
||||
}
|
||||
if (key == Rml::Input::KI_ESCAPE && menu_ == "quit") {
|
||||
widget_action("desktop-quit-cancel", nullptr);
|
||||
event.StopImmediatePropagation();
|
||||
|
||||
Reference in new issue
Block a user