Skip to content

Commit

Permalink
use the new imgui string input popup in the uilist
Browse files Browse the repository at this point in the history
  • Loading branch information
db48x authored and mqrause committed Dec 2, 2024
1 parent 6ce41e6 commit c71df36
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 57 deletions.
63 changes: 8 additions & 55 deletions src/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "memory_fast.h"
#include "output.h"
#include "sdltiles.h"
#include "string_input_popup.h"
#include "input_popup.h"
#include "translations.h"
#include "ui_manager.h"
#include "cata_imgui.h"
Expand Down Expand Up @@ -524,41 +524,6 @@ input_context uilist::create_main_input_context() const
return ctxt;
}

input_context uilist::create_filter_input_context() const
{
input_context ctxt( input_category, keyboard_mode::keychar );
// string input popup actions
ctxt.register_action( "TEXT.LEFT" );
ctxt.register_action( "TEXT.RIGHT" );
ctxt.register_action( "TEXT.QUIT" );
ctxt.register_action( "TEXT.CONFIRM" );
ctxt.register_action( "TEXT.CLEAR" );
ctxt.register_action( "TEXT.BACKSPACE" );
ctxt.register_action( "TEXT.HOME" );
ctxt.register_action( "TEXT.END" );
ctxt.register_action( "TEXT.DELETE" );
#if defined( TILES )
ctxt.register_action( "TEXT.PASTE" );
#endif
ctxt.register_action( "TEXT.INPUT_FROM_FILE" );
ctxt.register_action( "HELP_KEYBINDINGS" );
ctxt.register_action( "ANY_INPUT" );
// uilist actions
ctxt.register_action( "UILIST.UP" );
ctxt.register_action( "UILIST.DOWN" );
ctxt.register_action( "PAGE_UP", to_translation( "Fast scroll up" ) );
ctxt.register_action( "PAGE_DOWN", to_translation( "Fast scroll down" ) );
ctxt.register_action( "HOME", to_translation( "Go to first entry" ) );
ctxt.register_action( "END", to_translation( "Go to last entry" ) );
ctxt.register_action( "SCROLL_UP" );
ctxt.register_action( "SCROLL_DOWN" );
if( allow_confirm ) {
ctxt.register_action( "SELECT" );
}
ctxt.register_action( "MOUSE_MOVE" );
return ctxt;
}

/**
* repopulate filtered entries list (fentries) and set fselected accordingly
*/
Expand Down Expand Up @@ -618,25 +583,13 @@ void uilist::filterlist()

void uilist::inputfilter()
{
input_context ctxt = create_filter_input_context();
filter_popup = std::make_unique<string_input_popup>();
filter_popup->context( ctxt ).text( filter ).max_length( 256 );
bool loop = true;
do {
ui_manager::redraw();
filter = filter_popup->query_string( false );
recalc_start = false;
if( !filter_popup->confirmed() ) {
const std::string action = ctxt.input_to_action( ctxt.get_raw_input() );
if( filter_popup->handled() ) {
filterlist();
recalc_start = true;
} else if( scrollby( scroll_amount_from_action( action ) ) ) {
recalc_start = true;
}
}
} while( loop && !filter_popup->confirmed() && !filter_popup->canceled() );

filter_popup = std::make_unique<string_input_popup_imgui>(0, filter);
filter_popup->set_max_input_length( 256 );
filter = filter_popup->query();
if( filter_popup->cancelled() ) {
filter.clear();
}
filterlist();
filter_popup.reset();
}

Expand Down
4 changes: 2 additions & 2 deletions src/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const int UILIST_TIMEOUT = -1028;
const int UILIST_ADDITIONAL = -1029;
const int MENU_AUTOASSIGN = -1;

class string_input_popup;
class string_input_popup_imgui;
class uilist_impl;

catacurses::window new_centered_win( int nlines, int ncols );
Expand Down Expand Up @@ -472,7 +472,7 @@ class uilist // NOLINT(cata-xy)

weak_ptr_fast<uilist_impl> ui;

std::unique_ptr<string_input_popup> filter_popup;
std::unique_ptr<string_input_popup_imgui> filter_popup;
std::string filter;

int max_entry_len = 0;
Expand Down

0 comments on commit c71df36

Please sign in to comment.