gui2/tgame_version: Switch to using a horizontal listbox

This makes for somewhat simpler event handling and allows using the
keyboard to switch between tabs. It doesn't solve the layout issues with
long tab labels, though.
This commit is contained in:
Ignacio R. Morelle 2015-08-15 21:40:20 -03:00
parent 2d0482be91
commit 305b90c9a5
3 changed files with 50 additions and 58 deletions

View file

@ -69,13 +69,8 @@
[/row]
#enddef
#
# Used to emulate a basic horizontal listbox.
# (TODO: implement a real horizontal listbox.)
#
#define _GUI_VERINFO_TAB _ID _LABEL
#define _GUI_VERINFO_TAB
[toggle_panel]
id = {_ID}
linked_group = "tabs"
[grid]
@ -90,7 +85,7 @@
border_size = 5
[label]
label = {_LABEL}
id = "tab_label"
wrap = true
[/label]
@ -509,21 +504,17 @@
border = all
border_size = 5
[grid]
[row]
[column]
{_GUI_VERINFO_TAB tab_game_paths ( _ "Paths")}
[/column]
[horizontal_listbox]
id = "tab_bar"
[column]
{_GUI_VERINFO_TAB tab_game_deps ( _ "Libraries")}
[/column]
[column]
{_GUI_VERINFO_TAB tab_game_features ( _ "Features")}
[/column]
[/row]
[/grid]
[list_definition]
[row]
[column]
{_GUI_VERINFO_TAB}
[/column]
[/row]
[/list_definition]
[/horizontal_listbox]
[/column]

View file

@ -26,7 +26,9 @@
#include "filesystem.hpp"
#include "formula_string_utils.hpp"
#include "game_config.hpp"
#include "gettext.hpp"
#include "gui/auxiliary/find_widget.tpp"
#include "gui/dialogs/helper.hpp"
#include "gui/widgets/button.hpp"
#include "gui/widgets/control.hpp"
#ifdef GUI2_EXPERIMENTAL_LISTBOX
@ -95,7 +97,6 @@ tgame_version::tgame_version()
#endif
, deps_()
, opts_(game_config::optional_features_table())
, tabs_()
, report_()
{
// NOTE: these path_map_ entries are referenced by the GUI2 WML
@ -262,37 +263,45 @@ void tgame_version::pre_show(CVideo& /*video*/, twindow& window)
= find_widget<tstacked_widget>(&window, "tabs_container", false);
pager.select_layer(0);
tabs_.push_back(&find_widget<tselectable_>(&window, "tab_game_paths", false));
tabs_.push_back(&find_widget<tselectable_>(&window, "tab_game_deps", false));
tabs_.push_back(&find_widget<tselectable_>(&window, "tab_game_features", false));
tabs_.front()->set_value(true);
tlistbox& tab_bar
= find_widget<tlistbox>(&window, "tab_bar", false);
FOREACH(const AUTO & tab, tabs_)
{
tab->set_callback_state_change(
boost::bind(&tgame_version::tab_switch_callback, this, boost::ref(*tab), boost::ref(pager)));
list_data["tab_label"]["label"] = _("Paths");
tab_bar.add_row(list_data);
list_data["tab_label"]["label"] = _("Libraries");
tab_bar.add_row(list_data);
list_data["tab_label"]["label"] = _("Features");
tab_bar.add_row(list_data);
tab_bar.select_row(0);
window.keyboard_capture(&tab_bar);
const unsigned tab_count = tab_bar.get_item_count();
VALIDATE(tab_count == pager.get_layer_count(), "Tab bar and container size mismatch");
for(unsigned k = 0; k < tab_count; ++k) {
#ifdef GUI2_EXPERIMENTAL_LISTBOX
connect_signal_notify_modified(tab_bar,
boost::bind(&tgame_version::tab_switch_callback,
*this,
boost::ref(window)));
#else
tab_bar.set_callback_value_change(
dialog_callback<tgame_version, &tgame_version::tab_switch_callback>);
#endif
}
}
void tgame_version::post_show(twindow& /*window*/)
void tgame_version::tab_switch_callback(twindow& window)
{
tabs_.clear();
}
tstacked_widget& pager
= find_widget<tstacked_widget>(&window, "tabs_container", false);
tlistbox& tab_bar
= find_widget<tlistbox>(&window, "tab_bar", false);
void tgame_version::tab_switch_callback(tselectable_& me, tstacked_widget& tab_container)
{
for(size_t k = 0; k < tabs_.size(); ++k) {
tselectable_* const current = tabs_[k];
if(!current) {
continue;
}
current->set_value(&me == current);
if(&me == current) {
tab_container.select_layer(k);
}
}
pager.select_layer(std::max<int>(0, tab_bar.get_selected_row()));
}
void tgame_version::browse_directory_callback(const std::string& path)

View file

@ -26,7 +26,7 @@
namespace gui2
{
class tselectable_;
class tlistbox;
class tstacked_widget;
class tgame_version : public tdialog
@ -63,8 +63,6 @@ private:
std::vector<game_config::optional_feature> opts_;
std::vector<tselectable_*> tabs_;
std::string report_;
void generate_plain_text_report();
@ -75,20 +73,14 @@ private:
/** Inherited from tdialog. */
void pre_show(CVideo& video, twindow& window);
/** Inherited from tdialog. */
void post_show(twindow& window);
//
// Widget event callbacks.
//
/**
* Callback function called when the tab switch widgets' state changes.
*
* @param me The widget whose state just changed.
* @param tab_container The tab pages container widget.
* Callback function called when switching tabs.
*/
void tab_switch_callback(tselectable_& me, tstacked_widget& tab_container);
void tab_switch_callback(twindow& window);
/**
* Callback function for the dialog-wide copy-to-clipboard button.