mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-24 11:40:34 +08:00
Compare commits
2 Commits
d16359cf8b
...
c86bd1497c
Author | SHA1 | Date | |
---|---|---|---|
|
c86bd1497c | ||
|
4aa8592d7d |
@ -35,6 +35,10 @@ current (development)
|
||||
- Bugfix: Fix cursor position in when in the last column. See #831.
|
||||
- Bugfix: Fix `ResizeableSplit` keyboard navigation. Fixed by #842.
|
||||
- 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
|
||||
- Feature: Add `hscroll_indicator`. It display an horizontal indicator
|
||||
|
@ -44,7 +44,7 @@ class ComponentBase {
|
||||
ComponentBase* Parent() const;
|
||||
Component& ChildAt(size_t i);
|
||||
size_t ChildCount() const;
|
||||
int IndexOf(ComponentBase* child) const;
|
||||
int Index() const;
|
||||
void Add(Component children);
|
||||
void Detach();
|
||||
void DetachAllChildren();
|
||||
|
@ -48,12 +48,8 @@ class ButtonBase : public ComponentBase, public ButtonOption {
|
||||
}
|
||||
|
||||
auto focus_management = focused ? focus : active ? select : nothing;
|
||||
const EntryState state = {
|
||||
*label,
|
||||
false,
|
||||
active,
|
||||
focused_or_hover,
|
||||
-1,
|
||||
const EntryState state{
|
||||
*label, false, active, focused_or_hover, Index(),
|
||||
};
|
||||
|
||||
auto element = (transform ? transform : DefaultTransform) //
|
||||
|
@ -28,11 +28,7 @@ class CheckboxBase : public ComponentBase, public CheckboxOption {
|
||||
const bool is_active = Active();
|
||||
auto focus_management = is_focused ? focus : is_active ? select : nothing;
|
||||
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)(
|
||||
entry_state);
|
||||
|
@ -51,16 +51,20 @@ size_t ComponentBase::ChildCount() const {
|
||||
return children_.size();
|
||||
}
|
||||
|
||||
/// @brief Return index of child or -1 if not found.
|
||||
/// @brief Return index of the component in its parent. -1 if no parent.
|
||||
/// @ingroup component
|
||||
int ComponentBase::IndexOf(ComponentBase* child) const {
|
||||
int ComponentBase::Index() const {
|
||||
if (parent_ == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
int index = 0;
|
||||
for (Component c : children_) {
|
||||
if (&(*c) == child)
|
||||
for (const Component& child : parent_->children_) {
|
||||
if (child.get() == this) {
|
||||
return index;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
return -1;
|
||||
return -1; // Not reached.
|
||||
}
|
||||
|
||||
/// @brief Add a child.
|
||||
|
@ -123,11 +123,7 @@ class MenuBase : public ComponentBase, public MenuOption {
|
||||
const bool is_selected = (selected() == i);
|
||||
|
||||
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
|
||||
@ -626,12 +622,8 @@ Component MenuEntry(MenuEntryOption option) {
|
||||
const bool focused = Focused();
|
||||
UpdateAnimationTarget();
|
||||
|
||||
const EntryState state = {
|
||||
label(),
|
||||
false,
|
||||
hovered_,
|
||||
focused,
|
||||
Parent()->IndexOf(this),
|
||||
const EntryState state{
|
||||
label(), false, hovered_, focused, Index(),
|
||||
};
|
||||
|
||||
const Element element =
|
||||
|
@ -266,10 +266,8 @@ TEST(MenuTest, MenuEntryIndex) {
|
||||
menu->OnEvent(Event::ArrowDown);
|
||||
menu->OnEvent(Event::ArrowDown);
|
||||
menu->OnEvent(Event::Return);
|
||||
for(int idx = 0; idx < menu->ChildCount(); idx++)
|
||||
{
|
||||
auto child = menu->ChildAt(idx);
|
||||
EXPECT_EQ(menu->IndexOf(&(*child)), idx);
|
||||
for (int index = 0; index < menu->ChildCount(); index++) {
|
||||
EXPECT_EQ(menu->ChildAt(index)->Index(), index);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,11 +40,7 @@ class RadioboxBase : public ComponentBase, public RadioboxOption {
|
||||
: is_menu_focused ? focus
|
||||
: select;
|
||||
auto state = EntryState{
|
||||
entries[i],
|
||||
selected() == i,
|
||||
is_selected,
|
||||
is_focused,
|
||||
i,
|
||||
entries[i], selected() == i, is_selected, is_focused, i,
|
||||
};
|
||||
auto element =
|
||||
(transform ? transform : RadioboxOption::Simple().transform)(state);
|
||||
|
Loading…
Reference in New Issue
Block a user