mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-24 11:40:34 +08:00
Compare commits
1 Commits
0469c00e8c
...
697d11c380
Author | SHA1 | Date | |
---|---|---|---|
|
697d11c380 |
@ -35,10 +35,6 @@ 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,6 @@ class ComponentBase {
|
||||
ComponentBase* Parent() const;
|
||||
Component& ChildAt(size_t i);
|
||||
size_t ChildCount() const;
|
||||
int Index() const;
|
||||
void Add(Component children);
|
||||
void Detach();
|
||||
void DetachAllChildren();
|
||||
|
@ -25,7 +25,6 @@ struct EntryState {
|
||||
bool state; ///< The state of the button/checkbox/radiobox
|
||||
bool active; ///< Whether the entry is the active one.
|
||||
bool focused; ///< Whether the entry is one focused by the user.
|
||||
int index; ///< Index of the entry when applicable or -1.
|
||||
};
|
||||
|
||||
struct UnderlineOption {
|
||||
|
@ -48,8 +48,11 @@ class ButtonBase : public ComponentBase, public ButtonOption {
|
||||
}
|
||||
|
||||
auto focus_management = focused ? focus : active ? select : nothing;
|
||||
const EntryState state{
|
||||
*label, false, active, focused_or_hover, Index(),
|
||||
const EntryState state = {
|
||||
*label,
|
||||
false,
|
||||
active,
|
||||
focused_or_hover,
|
||||
};
|
||||
|
||||
auto element = (transform ? transform : DefaultTransform) //
|
||||
|
@ -28,7 +28,10 @@ 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_,
|
||||
};
|
||||
auto element = (transform ? transform : CheckboxOption::Simple().transform)(
|
||||
entry_state);
|
||||
|
@ -51,22 +51,6 @@ size_t ComponentBase::ChildCount() const {
|
||||
return children_.size();
|
||||
}
|
||||
|
||||
/// @brief Return index of the component in its parent. -1 if no parent.
|
||||
/// @ingroup component
|
||||
int ComponentBase::Index() const {
|
||||
if (parent_ == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
int index = 0;
|
||||
for (const Component& child : parent_->children_) {
|
||||
if (child.get() == this) {
|
||||
return index;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
return -1; // Not reached.
|
||||
}
|
||||
|
||||
/// @brief Add a child.
|
||||
/// @@param child The child to be attached.
|
||||
/// @ingroup component
|
||||
|
@ -123,7 +123,10 @@ 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,
|
||||
};
|
||||
|
||||
auto focus_management = (selected_focus_ != i) ? nothing
|
||||
@ -622,8 +625,11 @@ Component MenuEntry(MenuEntryOption option) {
|
||||
const bool focused = Focused();
|
||||
UpdateAnimationTarget();
|
||||
|
||||
const EntryState state{
|
||||
label(), false, hovered_, focused, Index(),
|
||||
const EntryState state = {
|
||||
label(),
|
||||
false,
|
||||
hovered_,
|
||||
focused,
|
||||
};
|
||||
|
||||
const Element element =
|
||||
|
@ -226,50 +226,5 @@ TEST(MenuTest, AnimationsVertical) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST(MenuTest, EntryIndex) {
|
||||
int selected = 0;
|
||||
std::vector<std::string> entries = {"0", "1", "2"};
|
||||
|
||||
auto option = MenuOption::Vertical();
|
||||
option.entries = &entries;
|
||||
option.selected = &selected;
|
||||
option.entries_option.transform = [&](const EntryState& state) {
|
||||
int curidx = std::stoi(state.label);
|
||||
EXPECT_EQ(state.index, curidx);
|
||||
return text(state.label);
|
||||
};
|
||||
auto menu = Menu(option);
|
||||
menu->OnEvent(Event::ArrowDown);
|
||||
menu->OnEvent(Event::ArrowDown);
|
||||
menu->OnEvent(Event::Return);
|
||||
entries.resize(2);
|
||||
(void)menu->Render();
|
||||
}
|
||||
|
||||
TEST(MenuTest, MenuEntryIndex) {
|
||||
int selected = 0;
|
||||
|
||||
MenuEntryOption option;
|
||||
option.transform = [&](const EntryState& state) {
|
||||
int curidx = std::stoi(state.label);
|
||||
EXPECT_EQ(state.index, curidx);
|
||||
return text(state.label);
|
||||
};
|
||||
auto menu = Container::Vertical(
|
||||
{
|
||||
MenuEntry("0", option),
|
||||
MenuEntry("1", option),
|
||||
MenuEntry("2", option),
|
||||
},
|
||||
&selected);
|
||||
|
||||
menu->OnEvent(Event::ArrowDown);
|
||||
menu->OnEvent(Event::ArrowDown);
|
||||
menu->OnEvent(Event::Return);
|
||||
for (int index = 0; index < menu->ChildCount(); index++) {
|
||||
EXPECT_EQ(menu->ChildAt(index)->Index(), index);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ftxui
|
||||
// NOLINTEND
|
||||
|
@ -40,7 +40,10 @@ 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,
|
||||
};
|
||||
auto element =
|
||||
(transform ? transform : RadioboxOption::Simple().transform)(state);
|
||||
|
Loading…
Reference in New Issue
Block a user