Compare commits

..

No commits in common. "c86bd1497c69da09fd1c2837e2fa660968be357c" and "d16359cf8b5e22be3a029f9f98986a0ea034849b" have entirely different histories.

8 changed files with 37 additions and 23 deletions

View File

@ -35,10 +35,6 @@ current (development)
- Bugfix: Fix cursor position in when in the last column. See #831. - Bugfix: Fix cursor position in when in the last column. See #831.
- Bugfix: Fix `ResizeableSplit` keyboard navigation. Fixed by #842. - Bugfix: Fix `ResizeableSplit` keyboard navigation. Fixed by #842.
- Bugfix: Fix `Menu` focus. See #841 - Bugfix: Fix `Menu` focus. See #841
- Feature: Add `ComponentBase::Index()`. This allows to get the index of a
component in its parent. See #932
- Feature: Add `EntryState::index`. This allows to get the index of a menu entry.
See #932
### Dom ### Dom
- Feature: Add `hscroll_indicator`. It display an horizontal indicator - Feature: Add `hscroll_indicator`. It display an horizontal indicator

View File

@ -44,7 +44,7 @@ class ComponentBase {
ComponentBase* Parent() const; ComponentBase* Parent() const;
Component& ChildAt(size_t i); Component& ChildAt(size_t i);
size_t ChildCount() const; size_t ChildCount() const;
int Index() const; int IndexOf(ComponentBase* child) const;
void Add(Component children); void Add(Component children);
void Detach(); void Detach();
void DetachAllChildren(); void DetachAllChildren();

View File

@ -48,8 +48,12 @@ class ButtonBase : public ComponentBase, public ButtonOption {
} }
auto focus_management = focused ? focus : active ? select : nothing; auto focus_management = focused ? focus : active ? select : nothing;
const EntryState state{ const EntryState state = {
*label, false, active, focused_or_hover, Index(), *label,
false,
active,
focused_or_hover,
-1,
}; };
auto element = (transform ? transform : DefaultTransform) // auto element = (transform ? transform : DefaultTransform) //

View File

@ -28,7 +28,11 @@ class CheckboxBase : public ComponentBase, public CheckboxOption {
const bool is_active = Active(); const bool is_active = Active();
auto focus_management = is_focused ? focus : is_active ? select : nothing; auto focus_management = is_focused ? focus : is_active ? select : nothing;
auto entry_state = EntryState{ auto entry_state = EntryState{
*label, *checked, is_active, is_focused || hovered_, -1, *label,
*checked,
is_active,
is_focused || hovered_,
-1,
}; };
auto element = (transform ? transform : CheckboxOption::Simple().transform)( auto element = (transform ? transform : CheckboxOption::Simple().transform)(
entry_state); entry_state);

View File

@ -51,20 +51,16 @@ size_t ComponentBase::ChildCount() const {
return children_.size(); return children_.size();
} }
/// @brief Return index of the component in its parent. -1 if no parent. /// @brief Return index of child or -1 if not found.
/// @ingroup component /// @ingroup component
int ComponentBase::Index() const { int ComponentBase::IndexOf(ComponentBase* child) const {
if (parent_ == nullptr) {
return -1;
}
int index = 0; int index = 0;
for (const Component& child : parent_->children_) { for (Component c : children_) {
if (child.get() == this) { if (&(*c) == child)
return index; return index;
}
index++; index++;
} }
return -1; // Not reached. return -1;
} }
/// @brief Add a child. /// @brief Add a child.

View File

@ -123,7 +123,11 @@ class MenuBase : public ComponentBase, public MenuOption {
const bool is_selected = (selected() == i); const bool is_selected = (selected() == i);
const EntryState state = { const EntryState state = {
entries[i], false, is_selected, is_focused, i, entries[i],
false,
is_selected,
is_focused,
i,
}; };
auto focus_management = (selected_focus_ != i) ? nothing auto focus_management = (selected_focus_ != i) ? nothing
@ -622,8 +626,12 @@ Component MenuEntry(MenuEntryOption option) {
const bool focused = Focused(); const bool focused = Focused();
UpdateAnimationTarget(); UpdateAnimationTarget();
const EntryState state{ const EntryState state = {
label(), false, hovered_, focused, Index(), label(),
false,
hovered_,
focused,
Parent()->IndexOf(this),
}; };
const Element element = const Element element =

View File

@ -266,8 +266,10 @@ TEST(MenuTest, MenuEntryIndex) {
menu->OnEvent(Event::ArrowDown); menu->OnEvent(Event::ArrowDown);
menu->OnEvent(Event::ArrowDown); menu->OnEvent(Event::ArrowDown);
menu->OnEvent(Event::Return); menu->OnEvent(Event::Return);
for (int index = 0; index < menu->ChildCount(); index++) { for(int idx = 0; idx < menu->ChildCount(); idx++)
EXPECT_EQ(menu->ChildAt(index)->Index(), index); {
auto child = menu->ChildAt(idx);
EXPECT_EQ(menu->IndexOf(&(*child)), idx);
} }
} }

View File

@ -40,7 +40,11 @@ class RadioboxBase : public ComponentBase, public RadioboxOption {
: is_menu_focused ? focus : is_menu_focused ? focus
: select; : select;
auto state = EntryState{ auto state = EntryState{
entries[i], selected() == i, is_selected, is_focused, i, entries[i],
selected() == i,
is_selected,
is_focused,
i,
}; };
auto element = auto element =
(transform ? transform : RadioboxOption::Simple().transform)(state); (transform ? transform : RadioboxOption::Simple().transform)(state);