Resize list of stylesheets to fit available space

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1138 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2008-08-11 13:23:29 +00:00
parent 5fddaa3715
commit 520b472483
4 changed files with 32 additions and 2 deletions
+18
View File
@@ -8,6 +8,7 @@
#include <util/prec.hpp>
#include <gui/set/style_panel.hpp>
#include <gui/set/window.hpp>
#include <gui/control/package_list.hpp>
#include <gui/control/card_viewer.hpp>
#include <gui/control/native_look_editor.hpp>
@@ -47,6 +48,23 @@ StylePanel::StylePanel(Window* parent, int id)
s->SetSizeHints(this);
SetSizer(s);
}
void StylePanel::updateListSize() {
// how many columns fit?
size_t fit_columns = (size_t)((GetSize().y - 400) / 152);
// we only need enough columns to show all items
int x_room = GetSize().x - editor->GetBestSize().x - 6;
size_t need_columns = (size_t)ceil(list->requiredWidth() / (double)x_room);
size_t column_count = max(1u, min(fit_columns, need_columns));
// change count
if (column_count != list->column_count) {
list->column_count = column_count;
static_cast<SetWindow*>(GetParent())->fixMinWindowSize();
}
}
bool StylePanel::Layout() {
updateListSize();
return SetWindowPanel::Layout();
}
void StylePanel::onChangeSet() {
list->showData<StyleSheet>(set->game->name() + _("-*"));
+4
View File
@@ -50,6 +50,10 @@ class StylePanel : public SetWindowPanel {
void onStyleSelect(wxCommandEvent&);
void onUseForAll(wxCommandEvent&);
void onUseCustom(wxCommandEvent&);
/// Determine the best size for the list of stylesheets based on available space
void updateListSize();
virtual bool Layout();
};
// ----------------------------------------------------------------------------- : EOF