mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-12 05:36:59 -04:00
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:
@@ -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 {
|
|||||||
/// 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 @@
|
|||||||
|
|
||||||
#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)
|
|||||||
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 {
|
|||||||
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
|
||||||
|
|||||||
Reference in New Issue
Block a user