Commit 68f2d425 authored by twanvl's avatar twanvl

Resize list of stylesheets to fit available space

parent 75db21c2
...@@ -100,3 +100,7 @@ void PackageList::select(const String& name, bool send_event) { ...@@ -100,3 +100,7 @@ void PackageList::select(const String& name, bool send_event) {
update(); update();
return; return;
} }
int PackageList::requiredWidth() const {
return (item_size.x + SPACING) * (int)itemCount();
}
...@@ -48,11 +48,15 @@ class PackageList : public GalleryList { ...@@ -48,11 +48,15 @@ class PackageList : public GalleryList {
/// Select the package with the given name, if it is not found, selects nothing /// Select the package with the given name, if it is not found, selects nothing
void select(const String& name, bool send_event = true); void select(const String& name, bool send_event = true);
/// Required width to show all items
int requiredWidth() const;
using GalleryList::column_count;
protected: protected:
/// Return how many items there are in the list
virtual size_t itemCount() const;
/// Draw an item /// Draw an item
virtual void drawItem(DC& dc, int x, int y, size_t item); virtual void drawItem(DC& dc, int x, int y, size_t item);
/// Return how many items there are in the list
virtual size_t itemCount() const;
private: private:
// The default icon to use // The default icon to use
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <util/prec.hpp> #include <util/prec.hpp>
#include <gui/set/style_panel.hpp> #include <gui/set/style_panel.hpp>
#include <gui/set/window.hpp>
#include <gui/control/package_list.hpp> #include <gui/control/package_list.hpp>
#include <gui/control/card_viewer.hpp> #include <gui/control/card_viewer.hpp>
#include <gui/control/native_look_editor.hpp> #include <gui/control/native_look_editor.hpp>
...@@ -47,6 +48,23 @@ StylePanel::StylePanel(Window* parent, int id) ...@@ -47,6 +48,23 @@ StylePanel::StylePanel(Window* parent, int id)
s->SetSizeHints(this); s->SetSizeHints(this);
SetSizer(s); 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() { void StylePanel::onChangeSet() {
list->showData<StyleSheet>(set->game->name() + _("-*")); list->showData<StyleSheet>(set->game->name() + _("-*"));
......
...@@ -50,6 +50,10 @@ class StylePanel : public SetWindowPanel { ...@@ -50,6 +50,10 @@ class StylePanel : public SetWindowPanel {
void onStyleSelect(wxCommandEvent&); void onStyleSelect(wxCommandEvent&);
void onUseForAll(wxCommandEvent&); void onUseForAll(wxCommandEvent&);
void onUseCustom(wxCommandEvent&); void onUseCustom(wxCommandEvent&);
/// Determine the best size for the list of stylesheets based on available space
void updateListSize();
virtual bool Layout();
}; };
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment