mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-29 16:39:34 +08:00
Merge dom and component focus (#978)
Instead of two levels of focus with `focus` and `selected`, use a recursive level. The components set the one "active" and hbox/vbox/dbox Co-authored-by: ArthurSonzogni <sonzogniarthur@gmail.com>
This commit is contained in:
@@ -44,12 +44,12 @@ Component Dropdown(DropdownOption option) {
|
||||
}));
|
||||
}
|
||||
|
||||
Element Render() override {
|
||||
radiobox.selected =
|
||||
Element OnRender() override {
|
||||
selected_ =
|
||||
util::clamp(radiobox.selected(), 0, int(radiobox.entries.size()) - 1);
|
||||
selected_ = util::clamp(selected_(), 0, int(radiobox.entries.size()) - 1);
|
||||
|
||||
if (selected_() >= 0) {
|
||||
if (selected_() >= 0 && selected_() < int(radiobox.entries.size())) {
|
||||
title_ = radiobox.entries[selected_()];
|
||||
}
|
||||
|
||||
@@ -70,10 +70,13 @@ Component Dropdown(DropdownOption option) {
|
||||
// Auto-close the dropdown when the user selects an item, even if the item
|
||||
// it the same as the previous one.
|
||||
if (open_old && open_()) {
|
||||
const bool should_close = (selected_() != selected_old) || //
|
||||
(event == Event::Return) || //
|
||||
(event == Event::Character(' ')) || //
|
||||
(event == Event::Escape); //
|
||||
const bool should_close =
|
||||
(selected_() != selected_old) || //
|
||||
(event == Event::Return) || //
|
||||
(event == Event::Character(' ')) || //
|
||||
(event == Event::Escape) || //
|
||||
(event.is_mouse() && event.mouse().button == Mouse::Left &&
|
||||
event.mouse().motion == Mouse::Pressed);
|
||||
|
||||
if (should_close) {
|
||||
checkbox_->TakeFocus();
|
||||
|
Reference in New Issue
Block a user