Skip to content

Commit 6a79f38

Browse files
committed
fix the off-by-one invlets by adjusting the order of operations
We want to avoid assigning invlets to rows that are not visible to the user, so we use ImGui::IsItemVisible() to test whether we are on a visible row of the table. However, IsItemVisible() only tests the visibility of the most recent item, not the item you are about to create. When we call it for the first key binding it is telling us that the header row of the table is hidden, which is not what we wanted to know. The fix is to draw the other columns first, then go back and decide on the invlet and draw the first column. Note in particular that we cannot draw the first column after the second column, because the second column only conditionally creates an item. It would have been fine to do it after the third column, but I did it after the fourth and final column so that all the normal stuff is done first before we get to the tricky one.
1 parent fa74674 commit 6a79f38

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

src/input_context.cpp

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -700,8 +700,8 @@ void keybindings_ui::draw_controls()
700700
float keys_col_width = str_width_to_pixels( width ) - str_width_to_pixels( TERMX >= 100 ? 62 : 52 );
701701
ImGui::TableSetupColumn( "Assigned Key(s)",
702702
ImGuiTableColumnFlags_WidthFixed | ImGuiTableColumnFlags_NoSort, keys_col_width );
703-
//ImGui::TableHeadersRow();
704703
for( size_t i = 0; i < filtered_registered_actions.size(); i++ ) {
704+
ImGui::TableNextRow();
705705
const std::string &action_id = filtered_registered_actions[i];
706706
ImGui::PushID( action_id.c_str() );
707707

@@ -714,7 +714,37 @@ void keybindings_ui::draw_controls()
714714
bool customized_keybinding = overwrite_default != basic_overwrite_default
715715
|| attributes.input_events != basic_attributes.input_events;
716716

717-
ImGui::TableNextColumn();
717+
ImGui::TableSetColumnIndex( 1 );
718+
if( customized_keybinding ) {
719+
ImGui::TextUnformatted( "*" );
720+
}
721+
722+
ImGui::TableSetColumnIndex( 2 );
723+
nc_color col;
724+
if( attributes.input_events.empty() ) {
725+
col = i == size_t( highlight_row_index ) ? h_unbound_key : unbound_key;
726+
} else if( overwrite_default ) {
727+
col = i == size_t( highlight_row_index ) ? h_local_key : local_key;
728+
} else {
729+
col = i == size_t( highlight_row_index ) ? h_global_key : global_key;
730+
}
731+
bool is_selected = false;
732+
bool is_hovered = false;
733+
cataimgui::draw_colored_text( ctxt->get_action_name( action_id ),
734+
col, 0.0f,
735+
status == kb_menu_status::show ? nullptr : &is_selected,
736+
nullptr, &is_hovered );
737+
738+
ImGui::TableSetColumnIndex( 3 );
739+
ImGui::Text( "%s", ctxt->get_desc( action_id ).c_str() );
740+
741+
// handle the first column last because
742+
// ImGui::IsItemVisble() tells you the status of the most
743+
// recent item, not the item you’re about to create. If we
744+
// did this column first, then when we call it for the
745+
// first row it would tell us that the headers were
746+
// hidden, which is not what we want to know.
747+
ImGui::TableSetColumnIndex( 0 );
718748
char invlet = ' ';
719749
if( ImGui::IsItemVisible() ) {
720750
if( scroll_offset == SIZE_MAX ) {
@@ -737,44 +767,14 @@ void keybindings_ui::draw_controls()
737767
ImGui::TextColored( c_white, "%c", invlet );
738768
}
739769

740-
ImGui::TableNextColumn();
741-
if( customized_keybinding ) {
742-
ImGui::TextUnformatted( "*" );
743-
}
744-
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 );
760770
if( ( is_selected || is_hovered ) && invlet != ' ' ) {
761771
highlight_row_index = i;
762772
}
763-
764-
ImGui::TableNextColumn();
765-
ImGui::Text( "%s", ctxt->get_desc( action_id ).c_str() );
766-
767773
ImGui::PopID();
768774
}
769775
ImGui::EndTable();
770776
}
771777
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();
778778
}
779779

780780
void keybindings_ui::init()

0 commit comments

Comments
 (0)