mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-06-08 19:49:32 -04:00
Pane: Focus selected child first
This commit is contained in:
@@ -29,7 +29,7 @@ void Button::set_text(const Rml::String& text) {
|
||||
|
||||
void Button::set_selected(bool selected) {
|
||||
if (mProps.selected != selected) {
|
||||
mRoot->SetClass("selected", selected);
|
||||
mRoot->SetPseudoClass("selected", selected);
|
||||
mProps.selected = selected;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ public:
|
||||
}
|
||||
|
||||
Rml::Element* root() const { return mRoot; }
|
||||
bool selected() const { return mRoot->IsPseudoClassSet("selected"); }
|
||||
|
||||
protected:
|
||||
static Rml::Element* append(Rml::Element* parent, const Rml::String& tag);
|
||||
|
||||
@@ -57,6 +57,12 @@ void Pane::update() {
|
||||
}
|
||||
|
||||
bool Pane::focus() {
|
||||
// If there's a selected child, focus that
|
||||
for (const auto& child : mChildren) {
|
||||
if (child->selected() && child->focus()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (const auto& child : mChildren) {
|
||||
if (child->focus()) {
|
||||
return true;
|
||||
|
||||
@@ -47,7 +47,7 @@ bool SelectButton::focus() {
|
||||
|
||||
void SelectButton::set_selected(bool selected) {
|
||||
if (mProps.selected != selected) {
|
||||
mRoot->SetClass("selected", selected);
|
||||
mRoot->SetPseudoClass("selected", selected);
|
||||
mProps.selected = selected;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user