GUI2: cleaned up widget resolution config cast fetch code
Also made all the conf variables const since they should never be modified.
This commit is contained in:
parent
5364c50ee8
commit
79ab196daa
21 changed files with 57 additions and 112 deletions
|
@ -106,9 +106,7 @@ window* build(CVideo& video, const builder_window::window_resolution* definition
|
|||
|
||||
win->set_click_dismiss(definition->click_dismiss);
|
||||
|
||||
std::shared_ptr<const window_definition::resolution>
|
||||
conf = std::static_pointer_cast<const window_definition::resolution>(
|
||||
win->config());
|
||||
const auto conf = win->cast_config_to<window_definition>();
|
||||
assert(conf);
|
||||
|
||||
if(conf->grid) {
|
||||
|
|
|
@ -446,7 +446,7 @@ widget* builder_addon_list::build() const
|
|||
DBG_GUI_G << "Window builder: placed add-on list '" << id <<
|
||||
"' with definition '" << definition << "'.\n";
|
||||
|
||||
auto conf = std::static_pointer_cast<const addon_list_definition::resolution>(widget->config());
|
||||
const auto conf = widget->cast_config_to<addon_list_definition>();
|
||||
assert(conf != nullptr);
|
||||
|
||||
widget->init_grid(conf->grid);
|
||||
|
|
|
@ -765,10 +765,7 @@ widget* builder_chatbox::build() const
|
|||
DBG_GUI_G << "Window builder: placed unit preview pane '" << id
|
||||
<< "' with definition '" << definition << "'.\n";
|
||||
|
||||
std::shared_ptr<const chatbox_definition::resolution> conf
|
||||
= std::static_pointer_cast<
|
||||
const chatbox_definition::resolution>(widget->config());
|
||||
|
||||
const auto conf = widget->cast_config_to<chatbox_definition>();
|
||||
assert(conf);
|
||||
|
||||
widget->init_grid(conf->grid);
|
||||
|
|
|
@ -35,39 +35,31 @@ REGISTER_WIDGET(horizontal_scrollbar)
|
|||
|
||||
unsigned horizontal_scrollbar::minimum_positioner_length() const
|
||||
{
|
||||
std::shared_ptr<const horizontal_scrollbar_definition::resolution>
|
||||
conf = std::static_pointer_cast<const horizontal_scrollbar_definition::
|
||||
resolution>(config());
|
||||
|
||||
const auto conf = cast_config_to<horizontal_scrollbar_definition>();
|
||||
assert(conf);
|
||||
|
||||
return conf->minimum_positioner_length;
|
||||
}
|
||||
|
||||
unsigned horizontal_scrollbar::maximum_positioner_length() const
|
||||
{
|
||||
std::shared_ptr<const horizontal_scrollbar_definition::resolution>
|
||||
conf = std::static_pointer_cast<const horizontal_scrollbar_definition::
|
||||
resolution>(config());
|
||||
|
||||
const auto conf = cast_config_to<horizontal_scrollbar_definition>();
|
||||
assert(conf);
|
||||
|
||||
return conf->maximum_positioner_length;
|
||||
}
|
||||
|
||||
unsigned horizontal_scrollbar::offset_before() const
|
||||
{
|
||||
std::shared_ptr<const horizontal_scrollbar_definition::resolution>
|
||||
conf = std::static_pointer_cast<const horizontal_scrollbar_definition::
|
||||
resolution>(config());
|
||||
|
||||
const auto conf = cast_config_to<horizontal_scrollbar_definition>();
|
||||
assert(conf);
|
||||
|
||||
return conf->left_offset;
|
||||
}
|
||||
|
||||
unsigned horizontal_scrollbar::offset_after() const
|
||||
{
|
||||
std::shared_ptr<const horizontal_scrollbar_definition::resolution>
|
||||
conf = std::static_pointer_cast<const horizontal_scrollbar_definition::
|
||||
resolution>(config());
|
||||
const auto conf = cast_config_to<horizontal_scrollbar_definition>();
|
||||
assert(conf);
|
||||
|
||||
return conf->right_offset;
|
||||
|
|
|
@ -151,10 +151,7 @@ void label::load_config_extra()
|
|||
{
|
||||
assert(config());
|
||||
|
||||
std::shared_ptr<const label_definition::resolution>
|
||||
conf = std::static_pointer_cast<const label_definition::resolution>(
|
||||
config());
|
||||
|
||||
const auto conf = cast_config_to<label_definition>();
|
||||
assert(conf);
|
||||
|
||||
set_link_aware(conf->link_aware);
|
||||
|
|
|
@ -991,9 +991,7 @@ widget* builder_listbox::build() const
|
|||
DBG_GUI_G << "Window builder: placed listbox '" << id
|
||||
<< "' with definition '" << definition << "'.\n";
|
||||
|
||||
std::shared_ptr<const listbox_definition::resolution>
|
||||
conf = std::static_pointer_cast<const listbox_definition::resolution>(
|
||||
widget->config());
|
||||
const auto conf = widget->cast_config_to<listbox_definition>();
|
||||
assert(conf);
|
||||
|
||||
widget->init_grid(conf->grid);
|
||||
|
@ -1116,9 +1114,7 @@ widget* builder_horizontal_listbox::build() const
|
|||
DBG_GUI_G << "Window builder: placed listbox '" << id
|
||||
<< "' with definition '" << definition << "'.\n";
|
||||
|
||||
std::shared_ptr<const listbox_definition::resolution>
|
||||
conf = std::static_pointer_cast<const listbox_definition::resolution>(
|
||||
widget->config());
|
||||
const auto conf = widget->cast_config_to<listbox_definition>();
|
||||
assert(conf);
|
||||
|
||||
widget->init_grid(conf->grid);
|
||||
|
@ -1241,9 +1237,7 @@ widget* builder_grid_listbox::build() const
|
|||
DBG_GUI_G << "Window builder: placed listbox '" << id
|
||||
<< "' with definition '" << definition << "'.\n";
|
||||
|
||||
std::shared_ptr<const listbox_definition::resolution>
|
||||
conf = std::static_pointer_cast<const listbox_definition::resolution>(
|
||||
widget->config());
|
||||
const auto conf = widget->cast_config_to<listbox_definition>();
|
||||
assert(conf);
|
||||
|
||||
widget->init_grid(conf->grid);
|
||||
|
|
|
@ -60,9 +60,7 @@ unsigned state_default::get_state() const
|
|||
matrix::matrix(const implementation::builder_matrix& builder)
|
||||
: tbase(builder, "matrix"), content_(), pane_(nullptr)
|
||||
{
|
||||
std::shared_ptr<const matrix_definition::resolution>
|
||||
cfg = std::static_pointer_cast<const matrix_definition::resolution>(
|
||||
config());
|
||||
const auto cfg = cast_config_to<matrix_definition>();
|
||||
|
||||
builder_widget::replacements_map replacements;
|
||||
replacements.emplace("_main", builder.builder_main);
|
||||
|
|
|
@ -301,9 +301,7 @@ widget* builder_multi_page::build() const
|
|||
DBG_GUI_G << "Window builder: placed multi_page '" << id
|
||||
<< "' with definition '" << definition << "'.\n";
|
||||
|
||||
std::shared_ptr<const multi_page_definition::resolution>
|
||||
conf = std::static_pointer_cast<const multi_page_definition::resolution>(
|
||||
widget->config());
|
||||
const auto conf = widget->cast_config_to<multi_page_definition>();
|
||||
assert(conf);
|
||||
|
||||
widget->init_grid(conf->grid);
|
||||
|
|
|
@ -37,9 +37,7 @@ REGISTER_WIDGET(panel)
|
|||
|
||||
SDL_Rect panel::get_client_rect() const
|
||||
{
|
||||
std::shared_ptr<const panel_definition::resolution> conf
|
||||
= std::static_pointer_cast<const panel_definition::resolution>(
|
||||
config());
|
||||
const auto conf = cast_config_to<panel_definition>();
|
||||
assert(conf);
|
||||
|
||||
SDL_Rect result = get_rectangle();
|
||||
|
@ -79,9 +77,7 @@ void panel::impl_draw_foreground(surface& frame_buffer, int x_offset, int y_offs
|
|||
|
||||
point panel::border_space() const
|
||||
{
|
||||
std::shared_ptr<const panel_definition::resolution> conf
|
||||
= std::static_pointer_cast<const panel_definition::resolution>(
|
||||
config());
|
||||
const auto conf = cast_config_to<panel_definition>();
|
||||
assert(conf);
|
||||
|
||||
return point(conf->left_border + conf->right_border, conf->top_border + conf->bottom_border);
|
||||
|
|
|
@ -284,8 +284,7 @@ widget* builder_scroll_label::build() const
|
|||
widget->set_vertical_scrollbar_mode(vertical_scrollbar_mode);
|
||||
widget->set_horizontal_scrollbar_mode(horizontal_scrollbar_mode);
|
||||
|
||||
std::shared_ptr<const scroll_label_definition::resolution>
|
||||
conf = std::static_pointer_cast<const scroll_label_definition::resolution>(widget->config());
|
||||
const auto conf = widget->cast_config_to<scroll_label_definition>();
|
||||
assert(conf);
|
||||
|
||||
widget->init_grid(conf->grid);
|
||||
|
|
|
@ -162,9 +162,7 @@ widget* builder_scrollbar_panel::build() const
|
|||
DBG_GUI_G << "Window builder: placed scrollbar_panel '" << id
|
||||
<< "' with definition '" << definition << "'.\n";
|
||||
|
||||
std::shared_ptr<const scrollbar_panel_definition::resolution> conf
|
||||
= std::static_pointer_cast<const scrollbar_panel_definition::resolution>(
|
||||
panel->config());
|
||||
const auto conf = panel->cast_config_to<scrollbar_panel_definition>();
|
||||
assert(conf);
|
||||
|
||||
panel->init_grid(conf->grid);
|
||||
|
|
|
@ -144,7 +144,7 @@ widget* builder_size_lock::build() const
|
|||
DBG_GUI_G << "Window builder: placed fixed size widget '" << id <<
|
||||
"' with definition '" << definition << "'.\n";
|
||||
|
||||
auto conf = std::static_pointer_cast<const size_lock_definition::resolution>(widget->config());
|
||||
const auto conf = widget->cast_config_to<size_lock_definition>();
|
||||
assert(conf != nullptr);
|
||||
|
||||
widget->init_grid(conf->grid);
|
||||
|
|
|
@ -63,10 +63,7 @@ point slider::calculate_best_size() const
|
|||
if(best_slider_length_ != 0) {
|
||||
|
||||
// Override length.
|
||||
std::shared_ptr<const slider_definition::resolution> conf
|
||||
= std::static_pointer_cast<const slider_definition::
|
||||
resolution>(config());
|
||||
|
||||
const auto conf = cast_config_to<slider_definition>();
|
||||
assert(conf);
|
||||
|
||||
result.x = conf->left_offset + best_slider_length_ + conf->right_offset;
|
||||
|
@ -158,36 +155,28 @@ void slider::child_callback_positioner_moved()
|
|||
|
||||
unsigned slider::minimum_positioner_length() const
|
||||
{
|
||||
std::shared_ptr<const slider_definition::resolution>
|
||||
conf = std::static_pointer_cast<const slider_definition::resolution>(
|
||||
config());
|
||||
const auto conf = cast_config_to<slider_definition>();
|
||||
assert(conf);
|
||||
return conf->minimum_positioner_length;
|
||||
}
|
||||
|
||||
unsigned slider::maximum_positioner_length() const
|
||||
{
|
||||
std::shared_ptr<const slider_definition::resolution>
|
||||
conf = std::static_pointer_cast<const slider_definition::resolution>(
|
||||
config());
|
||||
const auto conf = cast_config_to<slider_definition>();
|
||||
assert(conf);
|
||||
return conf->maximum_positioner_length;
|
||||
}
|
||||
|
||||
unsigned slider::offset_before() const
|
||||
{
|
||||
std::shared_ptr<const slider_definition::resolution>
|
||||
conf = std::static_pointer_cast<const slider_definition::resolution>(
|
||||
config());
|
||||
const auto conf = cast_config_to<slider_definition>();
|
||||
assert(conf);
|
||||
return conf->left_offset;
|
||||
}
|
||||
|
||||
unsigned slider::offset_after() const
|
||||
{
|
||||
std::shared_ptr<const slider_definition::resolution>
|
||||
conf = std::static_pointer_cast<const slider_definition::resolution>(
|
||||
config());
|
||||
const auto conf = cast_config_to<slider_definition>();
|
||||
assert(conf);
|
||||
return conf->right_offset;
|
||||
}
|
||||
|
|
|
@ -257,9 +257,7 @@ widget* builder_stacked_widget::build() const
|
|||
DBG_GUI_G << "Window builder: placed stacked widget '" << id
|
||||
<< "' with definition '" << definition << "'.\n";
|
||||
|
||||
std::shared_ptr<const stacked_widget_definition::resolution>
|
||||
conf = std::static_pointer_cast<const stacked_widget_definition::resolution>(
|
||||
widget->config());
|
||||
const auto conf = widget->cast_config_to<stacked_widget_definition>();
|
||||
assert(conf);
|
||||
|
||||
widget->init_grid(conf->grid);
|
||||
|
|
|
@ -321,6 +321,24 @@ protected:
|
|||
return config_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Casts the current resolution definition config to the respective type of a
|
||||
* derived widget.
|
||||
*
|
||||
* @tparam T The definition type to cast to. Should have a `resolution`
|
||||
* subclass or struct derived from resolution_definition.
|
||||
*
|
||||
* @returns A shared_ptr with the newly cast config.
|
||||
*/
|
||||
template<typename T>
|
||||
std::shared_ptr<const typename T::resolution> cast_config_to() const
|
||||
{
|
||||
static_assert(std::is_base_of<resolution_definition, typename T::resolution>::value,
|
||||
"Given type's resolution object does not derive from resolution_definition.");
|
||||
|
||||
return std::static_pointer_cast<const typename T::resolution>(config());
|
||||
}
|
||||
|
||||
void set_config(resolution_definition_ptr config)
|
||||
{
|
||||
config_ = config;
|
||||
|
|
|
@ -264,10 +264,7 @@ void text_box::update_offsets()
|
|||
{
|
||||
assert(config());
|
||||
|
||||
std::shared_ptr<const text_box_definition::resolution>
|
||||
conf = std::static_pointer_cast<const text_box_definition::resolution>(
|
||||
config());
|
||||
|
||||
const auto conf = cast_config_to<text_box_definition>();
|
||||
assert(conf);
|
||||
|
||||
// FIXME: This should use pango-cairo code path instead of sdl_ttf code path
|
||||
|
@ -340,10 +337,7 @@ void text_box::load_config_extra()
|
|||
{
|
||||
assert(config());
|
||||
|
||||
std::shared_ptr<const text_box_definition::resolution>
|
||||
conf = std::static_pointer_cast<const text_box_definition::resolution>(
|
||||
config());
|
||||
|
||||
const auto conf = cast_config_to<text_box_definition>();
|
||||
assert(conf);
|
||||
|
||||
set_font_size(conf->text_font_size);
|
||||
|
|
|
@ -141,9 +141,7 @@ unsigned toggle_panel::get_state() const
|
|||
|
||||
SDL_Rect toggle_panel::get_client_rect() const
|
||||
{
|
||||
std::shared_ptr<const toggle_panel_definition::resolution> conf
|
||||
= std::static_pointer_cast<const toggle_panel_definition::
|
||||
resolution>(config());
|
||||
const auto conf = cast_config_to<toggle_panel_definition>();
|
||||
assert(conf);
|
||||
|
||||
SDL_Rect result = get_rectangle();
|
||||
|
@ -157,9 +155,7 @@ SDL_Rect toggle_panel::get_client_rect() const
|
|||
|
||||
point toggle_panel::border_space() const
|
||||
{
|
||||
std::shared_ptr<const toggle_panel_definition::resolution> conf
|
||||
= std::static_pointer_cast<const toggle_panel_definition::
|
||||
resolution>(config());
|
||||
const auto conf = cast_config_to<toggle_panel_definition>();
|
||||
assert(conf);
|
||||
|
||||
return point(conf->left_border + conf->right_border, conf->top_border + conf->bottom_border);
|
||||
|
@ -188,9 +184,7 @@ void toggle_panel::set_state(const state_t state)
|
|||
state_ = state;
|
||||
set_is_dirty(true);
|
||||
|
||||
std::shared_ptr<const toggle_panel_definition::resolution> conf
|
||||
= std::static_pointer_cast<const toggle_panel_definition::
|
||||
resolution>(config());
|
||||
const auto conf = cast_config_to<toggle_panel_definition>();
|
||||
assert(conf);
|
||||
}
|
||||
|
||||
|
|
|
@ -410,9 +410,7 @@ widget* builder_tree_view::build() const
|
|||
DBG_GUI_G << "Window builder: placed tree_view '" << id
|
||||
<< "' with definition '" << definition << "'.\n";
|
||||
|
||||
std::shared_ptr<const tree_view_definition::resolution>
|
||||
conf = std::static_pointer_cast<const tree_view_definition::resolution>(
|
||||
widget->config());
|
||||
const auto conf = widget->cast_config_to<tree_view_definition>();
|
||||
assert(conf);
|
||||
|
||||
widget->init_grid(conf->grid);
|
||||
|
|
|
@ -595,10 +595,7 @@ widget* builder_unit_preview_pane::build() const
|
|||
DBG_GUI_G << "Window builder: placed unit preview pane '" << id
|
||||
<< "' with definition '" << definition << "'.\n";
|
||||
|
||||
std::shared_ptr<const unit_preview_pane_definition::resolution> conf
|
||||
= std::static_pointer_cast<
|
||||
const unit_preview_pane_definition::resolution>(widget->config());
|
||||
|
||||
const auto conf = widget->cast_config_to<unit_preview_pane_definition>();
|
||||
assert(conf);
|
||||
|
||||
widget->init_grid(conf->grid);
|
||||
|
|
|
@ -30,36 +30,28 @@ REGISTER_WIDGET(vertical_scrollbar)
|
|||
|
||||
unsigned vertical_scrollbar::minimum_positioner_length() const
|
||||
{
|
||||
std::shared_ptr<const vertical_scrollbar_definition::resolution> conf
|
||||
= std::static_pointer_cast<const vertical_scrollbar_definition::
|
||||
resolution>(config());
|
||||
const auto conf = cast_config_to<vertical_scrollbar_definition>();
|
||||
assert(conf);
|
||||
return conf->minimum_positioner_length;
|
||||
}
|
||||
|
||||
unsigned vertical_scrollbar::maximum_positioner_length() const
|
||||
{
|
||||
std::shared_ptr<const vertical_scrollbar_definition::resolution> conf
|
||||
= std::static_pointer_cast<const vertical_scrollbar_definition::
|
||||
resolution>(config());
|
||||
const auto conf = cast_config_to<vertical_scrollbar_definition>();
|
||||
assert(conf);
|
||||
return conf->maximum_positioner_length;
|
||||
}
|
||||
|
||||
unsigned vertical_scrollbar::offset_before() const
|
||||
{
|
||||
std::shared_ptr<const vertical_scrollbar_definition::resolution> conf
|
||||
= std::static_pointer_cast<const vertical_scrollbar_definition::
|
||||
resolution>(config());
|
||||
const auto conf = cast_config_to<vertical_scrollbar_definition>();
|
||||
assert(conf);
|
||||
return conf->top_offset;
|
||||
}
|
||||
|
||||
unsigned vertical_scrollbar::offset_after() const
|
||||
{
|
||||
std::shared_ptr<const vertical_scrollbar_definition::resolution> conf
|
||||
= std::static_pointer_cast<const vertical_scrollbar_definition::
|
||||
resolution>(config());
|
||||
const auto conf = cast_config_to<vertical_scrollbar_definition>();
|
||||
assert(conf);
|
||||
return conf->bottom_offset;
|
||||
}
|
||||
|
|
|
@ -957,9 +957,7 @@ void window::layout()
|
|||
{
|
||||
/***** Initialize. *****/
|
||||
|
||||
std::shared_ptr<const window_definition::resolution>
|
||||
conf = std::static_pointer_cast<const window_definition::resolution>(
|
||||
config());
|
||||
const auto conf = cast_config_to<window_definition>();
|
||||
assert(conf);
|
||||
|
||||
log_scope2(log_gui_layout, LOG_SCOPE_HEADER);
|
||||
|
|
Loading…
Add table
Reference in a new issue