@@ -61,7 +61,7 @@ class keybindings_ui : public cataimgui::window
61
61
std::vector<std::string> filtered_registered_actions;
62
62
std::string hotkeys;
63
63
int highlight_row_index = -1 ;
64
- size_t scroll_offset = 0 ;
64
+ int scroll_offset = 0 ;
65
65
// std::string filter_text;
66
66
keybindings_ui ( bool permit_execute_action, input_context *parent );
67
67
void init ();
@@ -663,7 +663,7 @@ cataimgui::bounds keybindings_ui::get_bounds()
663
663
664
664
void keybindings_ui::draw_controls ()
665
665
{
666
- scroll_offset = SIZE_MAX ;
666
+ scroll_offset = INT_MAX ;
667
667
size_t legend_idx = 0 ;
668
668
for ( ; legend_idx < 4 ; legend_idx++ ) {
669
669
cataimgui::draw_colored_text ( legend[legend_idx], c_white );
@@ -700,81 +700,86 @@ void keybindings_ui::draw_controls()
700
700
float keys_col_width = str_width_to_pixels ( width ) - str_width_to_pixels ( TERMX >= 100 ? 62 : 52 );
701
701
ImGui::TableSetupColumn ( " Assigned Key(s)" ,
702
702
ImGuiTableColumnFlags_WidthFixed | ImGuiTableColumnFlags_NoSort, keys_col_width );
703
- // ImGui::TableHeadersRow();
704
- for ( size_t i = 0 ; i < filtered_registered_actions.size (); i++ ) {
705
- const std::string &action_id = filtered_registered_actions[i];
706
- ImGui::PushID ( action_id.c_str () );
707
-
708
- bool overwrite_default;
709
- const action_attributes &attributes = inp_mngr.get_action_attributes ( action_id, ctxt->category ,
710
- &overwrite_default );
711
- bool basic_overwrite_default;
712
- const action_attributes &basic_attributes = inp_mngr.get_action_attributes ( action_id,
713
- ctxt->category , &basic_overwrite_default, true );
714
- bool customized_keybinding = overwrite_default != basic_overwrite_default
715
- || attributes.input_events != basic_attributes.input_events ;
716
-
717
- ImGui::TableNextColumn ();
718
- char invlet = ' ' ;
719
- if ( ImGui::IsItemVisible () ) {
720
- if ( scroll_offset == SIZE_MAX ) {
721
- scroll_offset = i;
703
+ float row_height = ImGui::GetTextLineHeightWithSpacing ();
704
+ ImGuiListClipper clipper;
705
+ clipper.Begin ( filtered_registered_actions.size (), row_height );
706
+ while ( clipper.Step () ) {
707
+ for ( int i = clipper.DisplayStart ; i < clipper.DisplayEnd ; i++ ) {
708
+ ImGui::TableNextRow ();
709
+ const std::string &action_id = filtered_registered_actions[i];
710
+ ImGui::PushID ( action_id.c_str () );
711
+
712
+ bool overwrite_default;
713
+ const action_attributes &attributes = inp_mngr.get_action_attributes ( action_id, ctxt->category ,
714
+ &overwrite_default );
715
+ bool basic_overwrite_default;
716
+ const action_attributes &basic_attributes = inp_mngr.get_action_attributes ( action_id,
717
+ ctxt->category , &basic_overwrite_default, true );
718
+ bool customized_keybinding = overwrite_default != basic_overwrite_default
719
+ || attributes.input_events != basic_attributes.input_events ;
720
+
721
+ ImGui::TableSetColumnIndex ( 1 );
722
+ if ( customized_keybinding ) {
723
+ ImGui::TextUnformatted ( " *" );
722
724
}
723
- if ( i >= scroll_offset && ( i - scroll_offset ) < hotkeys.size () ) {
724
- invlet = hotkeys[i - scroll_offset];
725
- }
726
- }
727
- if ( ( status == kb_menu_status::add_global && overwrite_default )
728
- || ( status == kb_menu_status::reset && !customized_keybinding )
729
- ) {
730
- // We're trying to add a global, but this action has a local
731
- // defined, so gray out the invlet.
732
- ImGui::TextColored ( c_dark_gray, " %c" , invlet );
733
- } else if ( status == kb_menu_status::add || status == kb_menu_status::add_global ||
734
- status == kb_menu_status::remove || status == kb_menu_status::reset ) {
735
- ImGui::TextColored ( c_light_blue, " %c" , invlet );
736
- } else if ( status == kb_menu_status::execute ) {
737
- ImGui::TextColored ( c_white, " %c" , invlet );
738
- }
739
725
740
- ImGui::TableNextColumn ();
741
- if ( customized_keybinding ) {
742
- ImGui::TextUnformatted ( " *" );
743
- }
726
+ ImGui::TableSetColumnIndex ( 2 );
727
+ nc_color col;
728
+ if ( attributes.input_events .empty () ) {
729
+ col = i == highlight_row_index ? h_unbound_key : unbound_key;
730
+ } else if ( overwrite_default ) {
731
+ col = i == highlight_row_index ? h_local_key : local_key;
732
+ } else {
733
+ col = i == highlight_row_index ? h_global_key : global_key;
734
+ }
735
+ bool is_selected = false ;
736
+ bool is_hovered = false ;
737
+ cataimgui::draw_colored_text ( ctxt->get_action_name ( action_id ),
738
+ col, 0 .0f ,
739
+ status == kb_menu_status::show ? nullptr : &is_selected,
740
+ nullptr , &is_hovered );
741
+
742
+ ImGui::TableSetColumnIndex ( 3 );
743
+ ImGui::Text ( " %s" , ctxt->get_desc ( action_id ).c_str () );
744
+
745
+ // handle the first column last because
746
+ // ImGui::IsItemVisble() tells you the status of the most
747
+ // recent item, not the item you’re about to create. If we
748
+ // did this column first, then when we call it for the
749
+ // first row it would tell us that the headers were
750
+ // hidden, which is not what we want to know.
751
+ ImGui::TableSetColumnIndex ( 0 );
752
+ char invlet = ' ' ;
753
+ if ( ImGui::IsItemVisible () ) {
754
+ if ( scroll_offset == INT_MAX ) {
755
+ scroll_offset = i;
756
+ }
757
+ if ( i >= scroll_offset && size_t ( i - scroll_offset ) < hotkeys.size () ) {
758
+ invlet = hotkeys[i - scroll_offset];
759
+ }
760
+ }
761
+ if ( ( status == kb_menu_status::add_global && overwrite_default )
762
+ || ( status == kb_menu_status::reset && !customized_keybinding )
763
+ ) {
764
+ // We're trying to add a global, but this action has a local
765
+ // defined, so gray out the invlet.
766
+ ImGui::TextColored ( c_dark_gray, " %c" , invlet );
767
+ } else if ( status == kb_menu_status::add || status == kb_menu_status::add_global ||
768
+ status == kb_menu_status::remove || status == kb_menu_status::reset ) {
769
+ ImGui::TextColored ( c_light_blue, " %c" , invlet );
770
+ } else if ( status == kb_menu_status::execute ) {
771
+ ImGui::TextColored ( c_white, " %c" , invlet );
772
+ }
744
773
745
- ImGui::TableNextColumn ();
746
- nc_color col;
747
- if ( attributes.input_events .empty () ) {
748
- col = i == size_t ( highlight_row_index ) ? h_unbound_key : unbound_key;
749
- } else if ( overwrite_default ) {
750
- col = i == size_t ( highlight_row_index ) ? h_local_key : local_key;
751
- } else {
752
- col = i == size_t ( highlight_row_index ) ? h_global_key : global_key;
753
- }
754
- bool is_selected = false ;
755
- bool is_hovered = false ;
756
- cataimgui::draw_colored_text ( ctxt->get_action_name ( action_id ),
757
- col, 0 .0f ,
758
- status == kb_menu_status::show ? nullptr : &is_selected,
759
- nullptr , &is_hovered );
760
- if ( ( is_selected || is_hovered ) && invlet != ' ' ) {
761
- highlight_row_index = i;
774
+ if ( ( is_selected || is_hovered ) && invlet != ' ' ) {
775
+ highlight_row_index = i;
776
+ }
777
+ ImGui::PopID ();
762
778
}
763
-
764
- ImGui::TableNextColumn ();
765
- ImGui::Text ( " %s" , ctxt->get_desc ( action_id ).c_str () );
766
-
767
- ImGui::PopID ();
768
779
}
769
780
ImGui::EndTable ();
770
781
}
771
782
last_status = status;
772
-
773
- // spopup.query_string() will call wnoutrefresh( w_help )
774
- // spopup.text(filter_phrase);
775
- // spopup.query_string(false, true);
776
- // Record cursor immediately after spopup drawing
777
- // ui.record_term_cursor();
778
783
}
779
784
780
785
void keybindings_ui::init ()
0 commit comments