Skip to content

Commit

Permalink
mouse input actually works correctly in uilists
Browse files Browse the repository at this point in the history
The selected menu item is now updated on hover, and the correct menu
item now is activated on click. Really all that was missing was that
parent.selected was not being updated.
  • Loading branch information
db48x committed Jun 6, 2024
1 parent 1601240 commit 17661fb
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,10 @@ void uilist_impl::draw_controls()
ImGui::PushID( i );
auto flags = !entry.enabled ? ImGuiSelectableFlags_Disabled : ImGuiSelectableFlags_None;
bool is_selected = static_cast<int>( i ) == parent.fselected;
if( ImGui::Selectable( "", is_selected, flags | ImGuiSelectableFlags_AllowItemOverlap ) ) {
parent.fselected = i;
}
if( ImGui::IsItemHovered( ) ) {
if( ImGui::Selectable( "", is_selected, flags | ImGuiSelectableFlags_AllowItemOverlap ) ||
ImGui::IsItemHovered() ) {
parent.fselected = i;
parent.selected = parent.fentries[parent.fselected];
}
ImGui::SameLine( 0, 0 );
if( is_selected ) {
Expand Down Expand Up @@ -998,8 +997,6 @@ void uilist::query( bool loop, int timeout, bool allow_unfiltered_hotkeys )

shared_ptr_fast<uilist_impl> ui = create_or_get_ui();

ui_manager::redraw();

#if defined(__ANDROID__)
for( const auto &entry : entries ) {
if( entry.enabled && entry.hotkey.has_value()
Expand All @@ -1010,6 +1007,8 @@ void uilist::query( bool loop, int timeout, bool allow_unfiltered_hotkeys )
#endif

do {
ui_manager::redraw();

ret_act = ctxt.handle_input( timeout );
const input_event event = ctxt.get_raw_input();
ret_evt = event;
Expand Down Expand Up @@ -1075,8 +1074,6 @@ void uilist::query( bool loop, int timeout, bool allow_unfiltered_hotkeys )
}
}
}

ui_manager::redraw();
} while( loop && ret == UILIST_WAIT_INPUT );
}

Expand Down

0 comments on commit 17661fb

Please sign in to comment.