string choice dialog allow forcing 1 column

This commit is contained in:
2025-08-25 16:11:53 -05:00
parent 72dbcd08f8
commit 2b136bccf3
2 changed files with 15 additions and 7 deletions

View File

@@ -14,6 +14,8 @@
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string/case_conv.hpp>
#include <fmt/format.h>
#include "dialogxml/widgets/field.hpp"
#include "dialogxml/dialogs/strdlog.hpp"
#include "fileio/resmgr/res_dialog.hpp"
@@ -23,14 +25,20 @@
const sf::Color HILITE_COLOUR = Colours::LIGHT_GREEN;
cStringChoice::cStringChoice(cDialog* parent, bool editable)
cStringChoice::cStringChoice(cDialog* parent, bool editable, bool force_single_column)
: editable(editable)
, per_page(editable ? 20 : 40)
, per_page((editable || force_single_column) ? 20 : 40)
, dlg(*ResMgr::dialogs.get(editable ? "choose-edit-string" : "choose-string"), parent)
{}
{
if(force_single_column){
for(int i = per_page + 1; i <= per_page * 2; ++i){
dlg[fmt::format("led{}", i)].hide();
}
}
}
cStringChoice::cStringChoice(const std::vector<std::string>& strs, std::string title, cDialog* parent, bool editable)
: cStringChoice(parent, editable)
cStringChoice::cStringChoice(const std::vector<std::string>& strs, std::string title, cDialog* parent, bool editable, bool force_single_column)
: cStringChoice(parent, editable, force_single_column)
{
setTitle(title);
strings = strs;

View File

@@ -41,13 +41,13 @@ class cStringChoice {
bool search_open = false;
cLedGroup* leds;
std::function<void(cStringChoice&,int)> select_handler;
cStringChoice(cDialog* parent, bool editable = false);
cStringChoice(cDialog* parent, bool editable = false, bool force_single_column = false);
public:
/// Initializes a dialog from a list of strings.
/// @param strs A list of all strings in the dialog.
/// @param title The title to show in the dialog.
/// @param parent Optionally, a parent dialog.
explicit cStringChoice(const std::vector<std::string>& strs, std::string title, cDialog* parent = nullptr, bool editable = false);
explicit cStringChoice(const std::vector<std::string>& strs, std::string title, cDialog* parent = nullptr, bool editable = false, bool force_single_column = false);
/// Initializes a dialog from an iterator pair.
/// @param begin An iterator to the first string in the dialog.
/// @param end An iterator to one past the last string in the dialog.