Added support for icons/entry tooltips in drop down dialogs/comboboxes
It now works on a vector of configs, meaning it's easy to add new data to entries
This commit is contained in:
parent
adeefd7248
commit
119e095ccd
9 changed files with 105 additions and 54 deletions
|
@ -3,6 +3,9 @@
|
|||
### Definition of the window select the way to access the addon server.
|
||||
###
|
||||
|
||||
#define FORMULA_WINDOW_HEIGHT
|
||||
min(if(window_height > 0, window_height, screen_width), max(button_y, screen_height - button_h - button_y)) #enddef
|
||||
|
||||
[window]
|
||||
id = "drop_down_list"
|
||||
description="Not Empty"
|
||||
|
@ -10,15 +13,13 @@
|
|||
definition = "menu"
|
||||
maximum_width = 9999
|
||||
maximum_height = 9999
|
||||
#define FORMULA_WINDOW_HEIGHT
|
||||
min(if(window_height > 0, window_height, screen_width), max(button_y, screen_height - button_h - button_y)) #enddef
|
||||
width="(max(button_w, if(window_width > 0, window_width, screen_width)))"
|
||||
height="({FORMULA_WINDOW_HEIGHT})"
|
||||
## Show the droplist below or above the button, whereever we have enough space. Below is preffered.
|
||||
x="(min(button_x, screen_width - window_width))"
|
||||
y="(if(screen_height - button_h - button_y > {FORMULA_WINDOW_HEIGHT}, button_h + button_y, button_y - {FORMULA_WINDOW_HEIGHT}))"
|
||||
width = "(max(button_w, if(window_width > 0, window_width, screen_width)))"
|
||||
height = "({FORMULA_WINDOW_HEIGHT})"
|
||||
## Show the droplist below or above the button, wherever we have enough space. Below is prefered.
|
||||
x = "(min(button_x, screen_width - window_width))"
|
||||
y = "(if(screen_height - button_h - button_y > {FORMULA_WINDOW_HEIGHT}, button_h + button_y, button_y - {FORMULA_WINDOW_HEIGHT}))"
|
||||
automatic_placement = false
|
||||
#undef FORMULA_WINDOW_HEIGHT
|
||||
|
||||
[tooltip]
|
||||
id = "tooltip"
|
||||
[/tooltip]
|
||||
|
@ -26,6 +27,11 @@ min(if(window_height > 0, window_height, screen_width), max(button_y, screen_hei
|
|||
[helptip]
|
||||
id = "tooltip"
|
||||
[/helptip]
|
||||
|
||||
[linked_group]
|
||||
id = "icons"
|
||||
fixed_width = "true"
|
||||
[/linked_group]
|
||||
|
||||
[grid]
|
||||
|
||||
|
@ -34,8 +40,8 @@ min(if(window_height > 0, window_height, screen_width), max(button_y, screen_hei
|
|||
horizontal_grow = "true"
|
||||
vertical_grow = "true"
|
||||
|
||||
border = "all"
|
||||
border_size = 0
|
||||
#border = "all"
|
||||
#border_size = 0
|
||||
|
||||
[listbox]
|
||||
id = "list"
|
||||
|
@ -47,25 +53,39 @@ min(if(window_height > 0, window_height, screen_width), max(button_y, screen_hei
|
|||
[column]
|
||||
grow_factor = 1
|
||||
horizontal_grow = "true"
|
||||
|
||||
[toggle_panel]
|
||||
definition="default"
|
||||
definition = "default"
|
||||
[grid]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
border = "all"
|
||||
grow_factor = 0
|
||||
border = "left,top,bottom"
|
||||
border_size = 5
|
||||
horizontal_alignment = "left"
|
||||
[image]
|
||||
id = "icon"
|
||||
linked_group = "icons"
|
||||
[/image]
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_grow = "true"
|
||||
[label]
|
||||
id="label"
|
||||
id = "label"
|
||||
[/label]
|
||||
[/column]
|
||||
[/row]
|
||||
[/grid]
|
||||
[/toggle_panel]
|
||||
[/column]
|
||||
|
||||
[/toggle_panel]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
|
@ -82,3 +102,5 @@ min(if(window_height > 0, window_height, screen_width), max(button_y, screen_hei
|
|||
[/resolution]
|
||||
|
||||
[/window]
|
||||
|
||||
#undef FORMULA_WINDOW_HEIGHT
|
||||
|
|
|
@ -125,10 +125,7 @@
|
|||
|
||||
label = _ "Random Faction Matchups:"
|
||||
# TODO: assign to individual options?
|
||||
tooltip = _ "Allow for mirror matchups when random factions are chosen.
|
||||
Independent: Random factions assigned independently
|
||||
No Mirror: No two players will get the same faction
|
||||
No Ally Mirror: No two allied players will get the same faction"
|
||||
tooltip = _ "Allow for mirror matchups when random factions are chosen."
|
||||
[/label]
|
||||
[/column]
|
||||
|
||||
|
@ -148,15 +145,18 @@ No Ally Mirror: No two allied players will get the same faction"
|
|||
definition = "default"
|
||||
|
||||
[option]
|
||||
label = "Independent"
|
||||
label = _ "Independent"
|
||||
tooltip = _ "Independent: Random factions assigned independently"
|
||||
[/option]
|
||||
|
||||
[option]
|
||||
label = "No mirror"
|
||||
tooltip = _ "No Mirror: No two players will get the same faction"
|
||||
[/option]
|
||||
|
||||
[option]
|
||||
label = "No ally mirror"
|
||||
label = _ "No ally mirror"
|
||||
tooltip = _ "No Ally Mirror: No two allied players will get the same faction"
|
||||
[/option]
|
||||
[/combobox]
|
||||
|
||||
|
|
|
@ -36,13 +36,14 @@ namespace {
|
|||
if(coordinate.x < rect.x || coordinate.x > rect.x + rect.w || coordinate.y < rect.y || coordinate.y > rect.y + rect.h ) {
|
||||
halt = handled = true;
|
||||
window.set_retval(twindow::CANCEL);
|
||||
window.close();
|
||||
window.close();
|
||||
}
|
||||
}
|
||||
|
||||
void resize_callback(twindow& window)
|
||||
{
|
||||
window.set_retval(twindow::CANCEL);
|
||||
window.close();
|
||||
window.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,20 +53,38 @@ void tdrop_down_list::pre_show(twindow& window)
|
|||
window.set_variable("button_y", variant(button_pos_.y));
|
||||
window.set_variable("button_w", variant(button_pos_.w));
|
||||
window.set_variable("button_h", variant(button_pos_.h));
|
||||
|
||||
tlistbox& list = find_widget<tlistbox>(&window, "list", true);
|
||||
|
||||
std::map<std::string, string_map> data;
|
||||
t_string& label = data["label"]["label"];
|
||||
t_string& use_markup = data["label"]["use_markup"];
|
||||
for(const auto& str : items_) {
|
||||
label = str;
|
||||
use_markup = use_markup_ ? "true" : "false";
|
||||
string_map item;
|
||||
|
||||
//t_string& image = data["icon"]["label"];
|
||||
//t_string& label = data["label"]["label"];
|
||||
//t_string& tooltip = data["label"]["tooltip"];
|
||||
//t_string& use_markup = data["label"]["use_markup"];
|
||||
|
||||
for(const auto& entry : items_) {
|
||||
data.clear();
|
||||
|
||||
item["label"] = entry["icon"];
|
||||
data.emplace("icon", item);
|
||||
|
||||
item["label"] = entry["label"];
|
||||
item["tooltip"] = entry["tooltip"];
|
||||
item["use_markup"] = "true";
|
||||
data.emplace("label", item);
|
||||
|
||||
list.add_row(data);
|
||||
}
|
||||
|
||||
list.select_row(selected_item_);
|
||||
|
||||
list.set_callback_item_change(std::bind(&tdrop_down_list::item_change_callback, this, std::ref(window), _1));
|
||||
|
||||
//Dismiss on click outside the window
|
||||
window.connect_signal<event::SDL_LEFT_BUTTON_UP>(std::bind(&click_callback, std::ref(window), _3, _4, _5), event::tdispatcher::front_child);
|
||||
|
||||
//Dismiss on resize
|
||||
window.connect_signal<event::SDL_VIDEO_RESIZE>(std::bind(&resize_callback, std::ref(window)), event::tdispatcher::front_child);
|
||||
}
|
||||
|
@ -74,8 +93,9 @@ void tdrop_down_list::item_change_callback(twindow& window, size_t item)
|
|||
{
|
||||
selected_item_ = item;
|
||||
window.set_retval(twindow::OK);
|
||||
window.close();
|
||||
window.close();
|
||||
}
|
||||
|
||||
void tdrop_down_list::post_show(twindow&)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -17,13 +17,15 @@
|
|||
#include "gui/dialogs/dialog.hpp"
|
||||
#include "sdl/rect.hpp"
|
||||
|
||||
class config;
|
||||
|
||||
namespace gui2
|
||||
{
|
||||
///Used by the combobox widget.
|
||||
class tdrop_down_list : public tdialog
|
||||
{
|
||||
public:
|
||||
tdrop_down_list(SDL_Rect button_pos, const std::vector<std::string>& items, int selected_item, bool use_markup)
|
||||
tdrop_down_list(SDL_Rect button_pos, const std::vector<config>& items, int selected_item, bool use_markup)
|
||||
: button_pos_(button_pos)
|
||||
, items_(items)
|
||||
, selected_item_(selected_item)
|
||||
|
@ -36,7 +38,7 @@ private:
|
|||
/// Note: we don't adjust the location of this dialog to when resizing the window.
|
||||
/// Instead this dialog automatically closes itself on resizing.
|
||||
SDL_Rect button_pos_;
|
||||
std::vector<std::string> items_;
|
||||
std::vector<config> items_;
|
||||
int selected_item_;
|
||||
bool use_markup_;
|
||||
/** Inherited from tdialog, implemented by REGISTER_DIALOG. */
|
||||
|
|
|
@ -151,10 +151,9 @@ void tmp_create_game::pre_show(twindow& window)
|
|||
//
|
||||
// Set up game types combobox
|
||||
//
|
||||
std::vector<std::string> game_types;
|
||||
|
||||
std::vector<config> game_types;
|
||||
for(level_type_info& type_info : level_types_) {
|
||||
game_types.push_back(type_info.second);
|
||||
game_types.push_back(config_of("label", type_info.second));
|
||||
}
|
||||
|
||||
if(game_types.empty()) {
|
||||
|
@ -172,7 +171,11 @@ void tmp_create_game::pre_show(twindow& window)
|
|||
//
|
||||
tcombobox& eras_combobox = find_widget<tcombobox>(&window, "eras", false);
|
||||
|
||||
const std::vector<std::string>& era_names = create_engine_.extras_menu_item_names(ng::create_engine::ERA, false);
|
||||
std::vector<config> era_names;
|
||||
for(const auto& era : create_engine_.extras_menu_item_names(ng::create_engine::ERA, false)) {
|
||||
era_names.push_back(config_of("label", era));
|
||||
}
|
||||
|
||||
if(era_names.empty()) {
|
||||
gui2::show_transient_message(window.video(), "", _("No eras found."));
|
||||
throw config::error(_("No eras found"));
|
||||
|
@ -401,11 +404,11 @@ void tmp_create_game::display_custom_options(ttree_view& tree, std::string&& typ
|
|||
item["label"] = combobox_option["name"];
|
||||
data.emplace("combobox_label", item);
|
||||
|
||||
std::vector<std::string> combo_items;
|
||||
std::vector<config> combo_items;
|
||||
std::vector<std::string> combo_values;
|
||||
|
||||
for(const auto& item : combobox_option.child_range("item")) {
|
||||
combo_items.push_back(item["name"]);
|
||||
combo_items.push_back(item);
|
||||
combo_values.push_back(item["value"]);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
#include "gui/dialogs/preferences_dialog.hpp"
|
||||
|
||||
#include "config_assign.hpp"
|
||||
#include "game_preferences.hpp"
|
||||
#include "hotkey/hotkey_command.hpp"
|
||||
#include "hotkey/hotkey_item.hpp"
|
||||
|
@ -141,7 +142,7 @@ static void set_resolution_list(tcombobox& res_list, CVideo& video)
|
|||
{
|
||||
const std::vector<std::pair<int,int> > resolutions = video.get_available_resolutions(true);
|
||||
|
||||
std::vector<std::string> options;
|
||||
std::vector<config> options;
|
||||
for(const auto& res : resolutions)
|
||||
{
|
||||
std::ostringstream option;
|
||||
|
@ -154,7 +155,7 @@ static void set_resolution_list(tcombobox& res_list, CVideo& video)
|
|||
<< ratio[0] << ':' << ratio[1] << ")</span>";
|
||||
}
|
||||
|
||||
options.push_back(option.str());
|
||||
options.push_back(config_of("label", option.str()));
|
||||
}
|
||||
|
||||
const unsigned current_res = std::find(resolutions.begin(), resolutions.end(),
|
||||
|
@ -782,7 +783,7 @@ void tpreferences::initialize_members(twindow& window)
|
|||
|
||||
for(const config& choice : option.child_range("option"))
|
||||
{
|
||||
combo_options.first.push_back(choice["name"]);
|
||||
combo_options.first.push_back(config_of("label", choice["name"]));
|
||||
combo_options.second.push_back(choice["id"]);
|
||||
}
|
||||
|
||||
|
|
|
@ -147,7 +147,7 @@ private:
|
|||
void single_slider_callback(const tslider& widget,
|
||||
std::function<void(int)> setter);
|
||||
|
||||
typedef std::pair<std::vector<std::string>, std::vector<std::string> > combo_data;
|
||||
typedef std::pair<std::vector<config>, std::vector<std::string> > combo_data;
|
||||
|
||||
/**
|
||||
* Sets the initial state and callback for a combobox
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "gui/widgets/settings.hpp"
|
||||
#include "gui/widgets/window.hpp"
|
||||
#include "gui/dialogs/drop_down_list.hpp"
|
||||
#include "config_assign.hpp"
|
||||
#include "sound.hpp"
|
||||
|
||||
#include "utils/functional.hpp"
|
||||
|
@ -38,7 +39,7 @@ namespace gui2
|
|||
|
||||
REGISTER_WIDGET(combobox)
|
||||
|
||||
tcombobox::tcombobox()
|
||||
tcombobox::tcombobox()
|
||||
: tcontrol(COUNT)
|
||||
, tselectable_()
|
||||
, state_(ENABLED)
|
||||
|
@ -46,7 +47,7 @@ tcombobox::tcombobox()
|
|||
, values_()
|
||||
, selected_()
|
||||
{
|
||||
values_.push_back(this->label());
|
||||
values_.push_back(config_of("label", this->label()));
|
||||
|
||||
connect_signal<event::MOUSE_ENTER>(
|
||||
std::bind(&tcombobox::signal_handler_mouse_enter, this, _2, _3));
|
||||
|
@ -146,7 +147,7 @@ void tcombobox::signal_handler_left_button_click(const event::tevent event,
|
|||
|
||||
if(droplist.show(get_window()->video())) {
|
||||
selected_ = droplist.selected_item();
|
||||
this->set_label(values_[selected_]);
|
||||
this->set_label(values_[selected_]["label"]);
|
||||
if(selected_callback_) {
|
||||
selected_callback_(*this);
|
||||
}
|
||||
|
@ -162,16 +163,16 @@ void tcombobox::signal_handler_left_button_click(const event::tevent event,
|
|||
handled = true;
|
||||
}
|
||||
|
||||
void tcombobox::set_values(const std::vector<std::string>& values, int selected)
|
||||
void tcombobox::set_values(const std::vector<::config>& values, int selected)
|
||||
{
|
||||
assert(static_cast<size_t>(selected) < values.size());
|
||||
assert(static_cast<size_t>(selected_) < values_.size());
|
||||
if(values[selected] != values_[selected_]) {
|
||||
if(values[selected]["label"] != values_[selected_]["label"]) {
|
||||
set_is_dirty(true);
|
||||
}
|
||||
values_ = values;
|
||||
selected_ = selected;
|
||||
set_label(values_[selected_]);
|
||||
set_label(values_[selected_]["label"]);
|
||||
|
||||
}
|
||||
void tcombobox::set_selected(int selected)
|
||||
|
@ -182,7 +183,7 @@ void tcombobox::set_selected(int selected)
|
|||
set_is_dirty(true);
|
||||
}
|
||||
selected_ = selected;
|
||||
set_label(values_[selected_]);
|
||||
set_label(values_[selected_]["label"]);
|
||||
}
|
||||
|
||||
// }---------- DEFINITION ---------{
|
||||
|
@ -282,7 +283,7 @@ tbuilder_combobox::tbuilder_combobox(const config& cfg)
|
|||
, options_()
|
||||
{
|
||||
for(const auto& option : cfg.child_range("option")) {
|
||||
options_.push_back(option["label"]);
|
||||
options_.push_back(option);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
#include "gui/widgets/control.hpp"
|
||||
#include "gui/widgets/selectable.hpp"
|
||||
|
||||
class config;
|
||||
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
|
@ -62,9 +64,9 @@ public:
|
|||
{
|
||||
retval_ = retval;
|
||||
}
|
||||
void set_values(const std::vector<std::string>& values, int selected = 0);
|
||||
void set_values(const std::vector<::config>& values, int selected = 0);
|
||||
void set_selected(int selected);
|
||||
|
||||
|
||||
/** See tselectable_::set_callback_state_change. */
|
||||
std::function<void(twidget&)> callback_state_change_;
|
||||
|
||||
|
@ -84,7 +86,7 @@ public:
|
|||
}
|
||||
|
||||
/** Returns the value of the selected row */
|
||||
std::string get_value_string() const { return values_[selected_]; }
|
||||
std::string get_value_string() const { return values_[selected_]["label"]; }
|
||||
|
||||
private:
|
||||
/**
|
||||
|
@ -118,7 +120,7 @@ private:
|
|||
int retval_;
|
||||
/**
|
||||
*/
|
||||
std::vector<std::string> values_;
|
||||
std::vector<::config> values_;
|
||||
/**
|
||||
*/
|
||||
int selected_;
|
||||
|
@ -175,7 +177,7 @@ public:
|
|||
private:
|
||||
std::string retval_id_;
|
||||
int retval_;
|
||||
std::vector<std::string> options_;
|
||||
std::vector<::config> options_;
|
||||
};
|
||||
|
||||
} // namespace implementation
|
||||
|
|
Loading…
Add table
Reference in a new issue