diff --git a/data/gui/default/widget/label_default.cfg b/data/gui/default/widget/label_default.cfg index 8a47902a6ce..a4ee580a628 100644 --- a/data/gui/default/widget/label_default.cfg +++ b/data/gui/default/widget/label_default.cfg @@ -70,3 +70,64 @@ {LABEL_DEFINITION "default" "default label" 16 {FONT_COLOUR_ENABLED} "normal"} {LABEL_DEFINITION "title" "label used for titles" {FONT_SIZE_NORMAL__TITLE} {FONT_COLOUR_TITLE} "bold"} + +### +### Temporary class to avoid the redraw problem for labels in a ttoggle_panel +### This hack can be removed once the the redraw problem is fixed +### +[label_definition] + id = no_redraw + description = "temp hack to avoid redraw problems when used in a toggle panel." + + [resolution] + min_width = 0 + min_height = 0 + + default_width = 0 + default_height = 0 + + max_width = 0 + max_height = 0 + + text_font_size = 16 + + [state_enabled] + + [draw] + + [text] + x = 0 + y = {TEXT_V_CENTRE} + w = "(text_width)" + h = "(text_height)" + font_size = 16 + colour = {FONT_COLOUR_ENABLED} + text = "(text)" + [/text] + + [/draw] + + [/state_enabled] + + [state_disabled] + + [draw] + + [text] + x = 0 + y = {TEXT_V_CENTRE} + w = "(text_width)" + h = "(text_height)" + font_size = 16 + colour = {FONT_COLOUR_ENABLED} + text = "(text)" + [/text] + + [/draw] + + [/state_disabled] + + [/resolution] + +[/label_definition] + diff --git a/data/gui/default/widget/toggle_panel_default.cfg b/data/gui/default/widget/toggle_panel_default.cfg new file mode 100644 index 00000000000..851f8d97d72 --- /dev/null +++ b/data/gui/default/widget/toggle_panel_default.cfg @@ -0,0 +1,96 @@ +### +### Definition of the default toggle panel. +### + +# FIXME we should use a background image instead of a filled rect. +#define RECT BORDER_COLOUR FILL_COLOUR + [rectangle] + x = 0 + y = 0 + w = "(width)" + h = "(height)" + border_thickness = 1 + border_colour = {BORDER_COLOUR} + fill_colour = {FILL_COLOUR} + [/rectangle] +#enddef + +[toggle_panel_definition] + + id = "default" + description = "Default panel" + + [resolution] + + min_width = 0 + min_height = 0 + + default_width = 0 + default_height = 0 + + max_width = 0 + max_height = 0 + + [state_enabled] + full_redraw = "true" + + [draw] + {RECT "" "0, 0, 0, 255"} + [/draw] + + [/state_enabled] + + [state_disabled] + full_redraw = "true" + + [draw] + {RECT "" "128, 128, 128, 255"} + [/draw] + + [/state_disabled] + + [state_focussed] + full_redraw = "true" + + [draw] + {RECT "" "0, 0, 0, 255"} + [/draw] + + [/state_focussed] + +### +### Selected +### + + [state_enabled_selected] + full_redraw = "true" + + [draw] + {RECT "170, 136, 67, 255" "9, 33, 54, 255"} + [/draw] + + [/state_enabled_selected] + + [state_disabled_selected] + full_redraw = "true" + + [draw] + {RECT "170, 136, 67, 255" "128, 128, 128, 255"} + [/draw] + + [/state_disabled_selected] + + [state_focussed_selected] + full_redraw = "true" + + [draw] + {RECT "170, 136, 67, 255" "9, 33, 54, 255"} + [/draw] + + [/state_focussed_selected] + + [/resolution] + +[/toggle_panel_definition] + +#undef RECT diff --git a/data/gui/default/window/mp_server_list.cfg b/data/gui/default/window/mp_server_list.cfg index 13a127956c2..28930a33068 100644 --- a/data/gui/default/window/mp_server_list.cfg +++ b/data/gui/default/window/mp_server_list.cfg @@ -106,24 +106,54 @@ [row] [column] - grow_factor = 1 + vertical_grow = "true" horizontal_grow = "true" - [toggle_button] - id = "name" - definition = "listbox_text" - [/toggle_button] - - [/column] - - [column] - grow_factor = 1 - horizontal_grow = "true" + [toggle_panel] + definition = "default" - [toggle_button] - id = "address" - definition = "listbox_text" - [/toggle_button] + [grid] + + [row] + + [column] + grow_factor = 1 + horizontal_grow = "true" + + border = "all" + border_size = 5 + horizontal_alignment = "left" + + [label] + id = "name" + definition = "no_redraw" + + [/label] + + [/column] + + [column] + grow_factor = 1 + horizontal_grow = "true" + + border = "all" + border_size = 5 + horizontal_alignment = "left" + + + [label] + id = "address" + definition = "no_redraw" + + [/label] + + [/column] + + [/row] + + [/grid] + + [/toggle_panel] [/column] diff --git a/po/wesnoth-lib/POTFILES.in b/po/wesnoth-lib/POTFILES.in index 754645037d1..534fecdb591 100644 --- a/po/wesnoth-lib/POTFILES.in +++ b/po/wesnoth-lib/POTFILES.in @@ -25,6 +25,7 @@ src/gui/widgets/spacer.cpp src/gui/widgets/text_box.cpp src/gui/widgets/text.cpp src/gui/widgets/toggle_button.cpp +src/gui/widgets/toggle_panel.cpp src/gui/widgets/tooltip.cpp src/gui/widgets/vertical_scrollbar.cpp src/gui/widgets/widget.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4a28b7a09c6..abb26cb980c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -238,6 +238,7 @@ SET(wesnoth-main_SRC gui/widgets/text.cpp gui/widgets/text_box.cpp gui/widgets/toggle_button.cpp + gui/widgets/toggle_panel.cpp gui/widgets/tooltip.cpp gui/widgets/vertical_scrollbar.cpp gui/widgets/widget.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 7943f7c8ddf..eb8e9a41041 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -90,6 +90,7 @@ wesnoth_source = \ gui/widgets/text.cpp \ gui/widgets/text_box.cpp \ gui/widgets/toggle_button.cpp \ + gui/widgets/toggle_panel.cpp \ gui/widgets/tooltip.cpp \ gui/widgets/vertical_scrollbar.cpp \ gui/widgets/widget.cpp \ diff --git a/src/SConscript b/src/SConscript index 8fc705998b8..1c112dedfba 100644 --- a/src/SConscript +++ b/src/SConscript @@ -104,6 +104,7 @@ libwesnoth_sources = Split(""" gui/widgets/text.cpp gui/widgets/text_box.cpp gui/widgets/toggle_button.cpp + gui/widgets/toggle_panel.cpp gui/widgets/tooltip.cpp gui/widgets/vertical_scrollbar.cpp gui/widgets/widget.cpp diff --git a/src/gui/widgets/grid.cpp b/src/gui/widgets/grid.cpp index f15fd9b4887..29283f08447 100644 --- a/src/gui/widgets/grid.cpp +++ b/src/gui/widgets/grid.cpp @@ -204,10 +204,15 @@ bool tgrid::has_vertical_scrollbar() const void tgrid::draw(surface& surface) { for(iterator itor = begin(); itor != end(); ++itor) { + /** + * @todo temporary disabled until the nested drawing for + * ttoggle_panel works with this flag set. + */ +/* if(! *itor || !itor->dirty()) { continue; } - +*/ log_scope2(gui_draw, "Grid: draw child."); itor->draw(surface); diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp index 57c6a950c60..d2ce7aa08e4 100644 --- a/src/gui/widgets/listbox.cpp +++ b/src/gui/widgets/listbox.cpp @@ -20,6 +20,7 @@ #include "gui/widgets/scrollbar.hpp" #include "gui/widgets/spacer.hpp" #include "gui/widgets/toggle_button.hpp" +#include "gui/widgets/toggle_panel.hpp" #include "log.hpp" #define DBG_G LOG_STREAM_INDENT(debug, gui) @@ -515,6 +516,7 @@ void tlistbox::trow::init_in_grid(tgrid* grid, tgrid* child_grid = dynamic_cast(widget); ttoggle_button* btn = dynamic_cast(widget); + ttoggle_panel* panel = dynamic_cast(widget); if(btn) { btn->set_callback_mouse_left_click(callback_select_list_item); @@ -528,6 +530,9 @@ void tlistbox::trow::init_in_grid(tgrid* grid, if(itor != data.end()) { btn->set_members(itor->second); } + } else if(panel) { + panel->set_callback_mouse_left_click(callback_select_list_item); + panel->set_data(data); } else if(child_grid) { init_in_grid(child_grid, data); } else { diff --git a/src/gui/widgets/panel.hpp b/src/gui/widgets/panel.hpp index 81b872a1b6f..c7ec87b9cc5 100644 --- a/src/gui/widgets/panel.hpp +++ b/src/gui/widgets/panel.hpp @@ -48,7 +48,7 @@ public: * * @returns The client rect. */ - SDL_Rect get_client_rect() const; + virtual SDL_Rect get_client_rect() const; /** Inherited from tcontrol. */ void set_active(const bool /*active*/) {} diff --git a/src/gui/widgets/settings.cpp b/src/gui/widgets/settings.cpp index b231170d39e..17cdfca35cd 100644 --- a/src/gui/widgets/settings.cpp +++ b/src/gui/widgets/settings.cpp @@ -183,6 +183,8 @@ const std::string& tgui_definition::read(const config& cfg) * and selected. This is a more generic widget * which is used for eg checkboxes and * radioboxes. + * toggle_panel_definition Like a toggle button but then as panel so + * can hold multiple items in a grid. * tooltip_definition A small tooltip with help. * vertical_scrollbar_definition A vertical scrollbar. * window_definition A window. @@ -212,6 +214,7 @@ const std::string& tgui_definition::read(const config& cfg) load_definitions("spacer", cfg.get_children("spacer_definition")); load_definitions("text_box", cfg.get_children("text_box_definition")); load_definitions("toggle_button", cfg.get_children("toggle_button_definition")); + load_definitions("toggle_panel", cfg.get_children("toggle_panel_definition")); load_definitions("tooltip", cfg.get_children("tooltip_definition")); load_definitions ("vertical_scrollbar", cfg.get_children("vertical_scrollbar_definition")); @@ -717,7 +720,6 @@ ttoggle_button_definition::ttoggle_button_definition(const config& cfg) : ttoggle_button_definition::tresolution::tresolution(const config& cfg) : tresolution_definition_(cfg) - { /*WIKI * @page = GUIToolkitWML @@ -748,6 +750,50 @@ ttoggle_button_definition::tresolution::tresolution(const config& cfg) : state.push_back(tstate_definition(cfg.child("state_focussed_selected"))); } +ttoggle_panel_definition::ttoggle_panel_definition(const config& cfg) : + tcontrol_definition(cfg) +{ + DBG_G_P << "Parsing toggle panel " << id << '\n'; + + load_resolutions(cfg.get_children("resolution")); +} + +ttoggle_panel_definition::tresolution::tresolution(const config& cfg) : + tresolution_definition_(cfg), + top_border(lexical_cast_default(cfg["top_border"])), + bottom_border(lexical_cast_default(cfg["bottom_border"])), + left_border(lexical_cast_default(cfg["left_border"])), + right_border(lexical_cast_default(cfg["right_border"])) +{ +/*WIKI + * @page = GUIToolkitWML + * @order = 1_widget_toggle_panel + * + * == Toogle panel == + * + * The definition of a toggle panel. + * + * The following states exist: + * * state_enabled, the panel is enabled and not selected. + * * state_disabled, the panel is disabled and not selected. + * * state_focussed, the mouse is over the panel and not selected. + * + * * state_enabled_selected, the panel is enabled and selected. + * * state_disabled_selected, the panel is disabled and selected. + * * state_focussed_selected, the mouse is over the panel and selected. + * + */ + + // Note the order should be the same as the enum tstate is toggle_panel.hpp. + state.push_back(tstate_definition(cfg.child("state_enabled"))); + state.push_back(tstate_definition(cfg.child("state_disabled"))); + state.push_back(tstate_definition(cfg.child("state_focussed"))); + + state.push_back(tstate_definition(cfg.child("state_enabled_selected"))); + state.push_back(tstate_definition(cfg.child("state_disabled_selected"))); + state.push_back(tstate_definition(cfg.child("state_focussed_selected"))); +} + ttooltip_definition::ttooltip_definition(const config& cfg) : tcontrol_definition(cfg) { diff --git a/src/gui/widgets/settings.hpp b/src/gui/widgets/settings.hpp index 7742e403c7f..2949885f6d9 100644 --- a/src/gui/widgets/settings.hpp +++ b/src/gui/widgets/settings.hpp @@ -201,6 +201,22 @@ struct ttoggle_button_definition : public tcontrol_definition }; }; +struct ttoggle_panel_definition : public tcontrol_definition +{ + ttoggle_panel_definition(const config& cfg); + + struct tresolution : public tresolution_definition_ + { + tresolution(const config& cfg); + + unsigned top_border; + unsigned bottom_border; + + unsigned left_border; + unsigned right_border; + }; +}; + struct ttooltip_definition : public tcontrol_definition { ttooltip_definition(const config& cfg); diff --git a/src/gui/widgets/toggle_panel.cpp b/src/gui/widgets/toggle_panel.cpp new file mode 100644 index 00000000000..71d2faf16c2 --- /dev/null +++ b/src/gui/widgets/toggle_panel.cpp @@ -0,0 +1,157 @@ +/* $Id$ */ +/* + copyright (C) 2008 by mark de wever + part of the battle for wesnoth project http://www.wesnoth.org/ + + this program is free software; you can redistribute it and/or modify + it under the terms of the gnu general public license version 2 + or at your option any later version. + this program is distributed in the hope that it will be useful, + but without any warranty. + + see the copying file for more details. +*/ + +#include "gui/widgets/toggle_panel.hpp" + +#include "foreach.hpp" +#include "log.hpp" + +#define DBG_G LOG_STREAM_INDENT(debug, gui) +#define LOG_G LOG_STREAM_INDENT(info, gui) +#define WRN_G LOG_STREAM_INDENT(warn, gui) +#define ERR_G LOG_STREAM_INDENT(err, gui) + +#define DBG_G_D LOG_STREAM_INDENT(debug, gui_draw) +#define LOG_G_D LOG_STREAM_INDENT(info, gui_draw) +#define WRN_G_D LOG_STREAM_INDENT(warn, gui_draw) +#define ERR_G_D LOG_STREAM_INDENT(err, gui_draw) + +#define DBG_G_E LOG_STREAM_INDENT(debug, gui_event) +#define LOG_G_E LOG_STREAM_INDENT(info, gui_event) +#define WRN_G_E LOG_STREAM_INDENT(warn, gui_event) +#define ERR_G_E LOG_STREAM_INDENT(err, gui_event) + +#define DBG_G_P LOG_STREAM_INDENT(debug, gui_parse) +#define LOG_G_P LOG_STREAM_INDENT(info, gui_parse) +#define WRN_G_P LOG_STREAM_INDENT(warn, gui_parse) +#define ERR_G_P LOG_STREAM_INDENT(err, gui_parse) + +namespace gui2 { + +void ttoggle_panel::set_data(const std::map >& data) +{ + // typedef boost problem work around. + typedef std::pair > hack ; + foreach(const hack& item, data) { + tcontrol* widget = dynamic_cast(find_widget(item.first, false)); + if(widget) { + widget->set_members(item.second); + } + } +} + +void ttoggle_panel::mouse_enter(tevent_handler&) +{ + DBG_G_E << "Toggle panel: mouse enter.\n"; + + if(is_selected()) { + set_state(FOCUSSED_SELECTED); + } else { + set_state(FOCUSSED); + } +} + +void ttoggle_panel::mouse_leave(tevent_handler&) +{ + DBG_G_E << "Toggle panel: mouse leave.\n"; + + if(is_selected()) { + set_state(ENABLED_SELECTED); + } else { + set_state(ENABLED); + } +} + +void ttoggle_panel::mouse_left_button_click(tevent_handler&) +{ + DBG_G_E << "Toggle panel: left mouse button click.\n"; + + if(is_selected()) { + set_state(ENABLED); + } else { + set_state(ENABLED_SELECTED); + } + + if(callback_mouse_left_click_) { + callback_mouse_left_click_(this); + } +} + +void ttoggle_panel::set_active(const bool active) +{ + if(active) { + if(is_selected()) { + set_state(ENABLED_SELECTED); + } else { + set_state(ENABLED); + } + } else { + if(is_selected()) { + set_state(DISABLED_SELECTED); + } else { + set_state(DISABLED); + } + } +} + +SDL_Rect ttoggle_panel::get_client_rect() const +{ + const ttoggle_panel_definition::tresolution* conf = + dynamic_cast(config()); + assert(conf); + + SDL_Rect result = get_rect(); + result.x += conf->left_border; + result.y += conf->top_border; + result.w -= conf->left_border + conf->right_border; + result.h -= conf->top_border + conf->bottom_border; + + return result; +} + +tpoint ttoggle_panel::border_space() const +{ + const ttoggle_panel_definition::tresolution* conf = + dynamic_cast(config()); + assert(conf); + + return tpoint(conf->left_border + conf->right_border, + conf->top_border + conf->bottom_border); +} + +void ttoggle_panel::set_selected(const bool selected) +{ + if(selected == is_selected()) { + return; + } + + if(selected) { + set_state(static_cast(state_ + ENABLED_SELECTED)); + } else { + set_state(static_cast(state_ - ENABLED_SELECTED)); + } +} + +void ttoggle_panel::set_state(tstate state) +{ + if(state != state_) { + state_ = state; + set_dirty(true); + } +} + +} // namespace gui2 + + diff --git a/src/gui/widgets/toggle_panel.hpp b/src/gui/widgets/toggle_panel.hpp new file mode 100644 index 00000000000..4849330373e --- /dev/null +++ b/src/gui/widgets/toggle_panel.hpp @@ -0,0 +1,160 @@ +/* $Id$ */ +/* + copyright (C) 2008 by mark de wever + part of the battle for wesnoth project http://www.wesnoth.org/ + + this program is free software; you can redistribute it and/or modify + it under the terms of the gnu general public license version 2 + or at your option any later version. + this program is distributed in the hope that it will be useful, + but without any warranty. + + see the copying file for more details. +*/ + +#ifndef GUI_WIDGETS_TOGGLE_PANEL_HPP_INCLUDED +#define GUI_WIDGETS_TOGGLE_PANEL_HPP_INCLUDED + +#include "gui/widgets/panel.hpp" + +namespace gui2 { + +/** + * Class for a toggle button. + * + * Quite some code looks like ttoggle_button maybe we should inherit from that but let's test first. + * the problem is that the toggle_button has an icon we don't want, but maybe look at refactoring later. + * but maybe we should also ditch the icon, not sure however since it's handy for checkboxes... + */ +class ttoggle_panel : public tpanel, public tselectable_ +{ +public: + ttoggle_panel() : + tpanel(COUNT), + state_(ENABLED), + callback_mouse_left_click_(0) + { + } + + void set_data(const std::map >& data); + + /***** ***** ***** ***** Inherited ***** ***** ***** *****/ + + /** Inherted from tevent_executor. */ + void mouse_enter(tevent_handler&); + + /** Inherted from tevent_executor. */ + void mouse_leave(tevent_handler&); + + /** Inherted from tevent_executor. */ + void mouse_left_button_click(tevent_handler&); + + /** Inherited from tcontainer_ */ + twidget* find_widget(const tpoint& coordinate, const bool must_be_active) + { + /** + * @todo since there is no mouse event nesting (or event nesting at all) + * we need to capture all events. This means items on the panel will + * never receive an event, which gives problems with for example the + * intended button on the addon panel. So we need to chain mouse events + * as well and also add a handled flag for them. + */ +// twidget* result = tcontainer_::find_widget(coordinate, must_be_active); + return /*result ? result :*/ tcontrol::find_widget(coordinate, must_be_active); + } + + /** Inherited from tcontainer_ */ + const twidget* find_widget(const tpoint& coordinate, const bool must_be_active) const + { +// const twidget* result = tcontainer_::find_widget(coordinate, must_be_active); + return /*result ? result :*/ tcontrol::find_widget(coordinate, must_be_active); + } + + // Needed to import the find_widget(const tpoint&, const bool) and it's const version + // inheriting from panel eventhought they are the same as tcontainer_ but it might be + // panel reimplements it. + using tpanel::find_widget; + + /** Inherited from tpanel. */ + void set_active(const bool active); + + /** Inherited from tpanel. */ + bool get_active() const + { return state_ != DISABLED && state_ != DISABLED_SELECTED; } + + /** Inherited from tpanel. */ + unsigned get_state() const { return state_; } + + /** Inherited from tpanel. */ + void draw(surface& surface) { tcontainer_::draw(surface); } + + /** + * Inherited from tpanel. + * + * @todo only due to the fact our definition is slightly different from + * tpanel_defintion we need to override this function and do about the same, + * look at a way to 'fix' that. + */ + SDL_Rect get_client_rect() const; + + /** + * Inherited from tpanel. + * + * @todo only due to the fact our definition is slightly different from + * tpanel_defintion we need to override this function and do about the same, + * look at a way to 'fix' that. + */ + tpoint border_space() const; + + /** Inherited from tselectable_ */ + bool is_selected() const { return state_ >= ENABLED_SELECTED; } + + /** Inherited from tselectable_ */ + void set_selected(const bool selected = true); + + /***** ***** ***** setters / getters for members ***** ****** *****/ + + void set_callback_mouse_left_click(void (*callback) (twidget*)) + { callback_mouse_left_click_ = callback; } + +private: + + /** + * Possible states of the widget. + * + * Note the order of the states must be the same as defined in settings.hpp. + * Also note the internals do assume the order for 'up' and 'down' to be the + * same and also that 'up' is before 'down'. 'up' has no suffix, 'down' has + * the SELECTED suffix. + */ + enum tstate { + ENABLED, DISABLED, FOCUSSED, + ENABLED_SELECTED, DISABLED_SELECTED, FOCUSSED_SELECTED, + COUNT}; + + void set_state(tstate state); + + /** + * Current state of the widget. + * + * The state of the widget determines what to render and how the widget + * reacts to certain 'events'. + */ + tstate state_; + + /** This callback is used when the control gets a left click. */ + void (*callback_mouse_left_click_) (twidget*); + + /** Inherited from tpanel. */ + const std::string& get_control_type() const + { static const std::string type = "toggle_panel"; return type; } + +}; + +} // namespace gui2 + +#endif + + + diff --git a/src/gui/widgets/window_builder.cpp b/src/gui/widgets/window_builder.cpp index 8838062a364..d8bf62580b1 100644 --- a/src/gui/widgets/window_builder.cpp +++ b/src/gui/widgets/window_builder.cpp @@ -23,6 +23,7 @@ #include "gui/widgets/spacer.hpp" #include "gui/widgets/text_box.hpp" #include "gui/widgets/toggle_button.hpp" +#include "gui/widgets/toggle_panel.hpp" #include "gui/widgets/vertical_scrollbar.hpp" #include "gui/widgets/widget.hpp" #include "gui/widgets/window.hpp" @@ -238,6 +239,19 @@ private: std::string icon_name_; }; +struct tbuilder_toggle_panel : public tbuilder_control +{ + +private: + tbuilder_toggle_panel(); +public: + tbuilder_toggle_panel(const config& cfg); + + twidget* build () const; + + tbuilder_grid* grid; +}; + struct tbuilder_vertical_scrollbar : public tbuilder_control { private: @@ -587,6 +601,8 @@ tbuilder_grid::tbuilder_grid(const config& cfg) : widgets.push_back(new tbuilder_text_box(*((**col_itor).child("text_box")))); } else if((**col_itor).child("toggle_button")) { widgets.push_back(new tbuilder_toggle_button(*((**col_itor).child("toggle_button")))); + } else if((**col_itor).child("toggle_panel")) { + widgets.push_back(new tbuilder_toggle_panel(*((**col_itor).child("toggle_panel")))); } else if((**col_itor).child("vertical_scrollbar")) { widgets.push_back( new tbuilder_vertical_scrollbar(*((**col_itor).child("vertical_scrollbar")))); @@ -1003,6 +1019,64 @@ twidget* tbuilder_toggle_button::build() const return toggle_button; } +tbuilder_toggle_panel::tbuilder_toggle_panel(const config& cfg) : + tbuilder_control(cfg), + grid(0) +{ +/*WIKI + * @page = GUIToolkitWML + * @order = 3_widget_panel + * + * == Panel == + * + * A panel is an item which can hold other items. The difference between a grid + * and a panel is that it's possible to define how a panel looks. A grid in an + * invisible container to just hold the items. + * + * @start_table = config + * grid (section) Defines the grid with the widgets to + * place on the panel. + * @end_table + * + */ + VALIDATE(cfg.child("grid"), _("No grid defined.")); + + grid = new tbuilder_grid(*(cfg.child("grid"))); +} + +twidget* tbuilder_toggle_panel::build() const +{ + ttoggle_panel* toggle_panel = new ttoggle_panel(); + + init_control(toggle_panel); + + DBG_G << "Window builder: placed toggle panel '" << id << "' with defintion '" + << definition << "'.\n"; + + + log_scope2(gui, "Window builder: building grid for toggle panel."); + + const unsigned rows = grid->rows; + const unsigned cols = grid->cols; + + toggle_panel->set_rows_cols(rows, cols); + + for(unsigned x = 0; x < rows; ++x) { + toggle_panel->set_row_grow_factor(x, grid->row_grow_factor[x]); + for(unsigned y = 0; y < cols; ++y) { + + if(x == 0) { + toggle_panel->set_col_grow_factor(y, grid->col_grow_factor[y]); + } + + twidget* widget = grid->widgets[x * cols + y]->build(); + toggle_panel->set_child(widget, x, y, grid->flags[x * cols + y], grid->border_size[x * cols + y]); + } + } + + return toggle_panel; +} + twidget* tbuilder_text_box::build() const { ttext_box* text_box = new ttext_box();