feat: apply filtering to style list on "style" panel

This commit is contained in:
Brendan Hagan
2022-06-20 20:46:06 -04:00
parent 6893ec3503
commit 31c2cbd54f
2 changed files with 106 additions and 77 deletions
+34 -11
View File
@@ -35,17 +35,25 @@ void StylePanel::initControls() {
list = new PackageList (this, wxID_ANY); list = new PackageList (this, wxID_ANY);
use_for_all = new wxButton (this, ID_STYLE_USE_FOR_ALL, _BUTTON_("use for all cards")); use_for_all = new wxButton (this, ID_STYLE_USE_FOR_ALL, _BUTTON_("use for all cards"));
use_custom_options = new wxCheckBox(this, ID_STYLE_USE_CUSTOM, _BUTTON_("use custom styling options")); use_custom_options = new wxCheckBox(this, ID_STYLE_USE_CUSTOM, _BUTTON_("use custom styling options"));
editor = new StylingEditor(this, ID_EDITOR, wxNO_BORDER); editor = new StylingEditor(this, ID_EDITOR, wxNO_BORDER);
stylesheet_filter = new FilterCtrl(this, ID_STYLESHEET_FILTER, _LABEL_("search stylesheet list"), _HELP_("search stylesheet list control"));
stylesheet_filter->setFilter(stylesheet_filter_value);
// init sizer // init sizer
wxSizer* s = new wxBoxSizer(wxHORIZONTAL); wxSizer* s = new wxBoxSizer(wxHORIZONTAL);
s->Add(preview, 0, wxRIGHT, 2); s->Add(preview, 0, wxRIGHT, 2);
wxSizer* s2 = new wxBoxSizer(wxVERTICAL); wxSizer* s2 = new wxBoxSizer(wxVERTICAL);
s2->Add(list, 0, wxEXPAND | wxBOTTOM, 4); s2->Add(list, 0, wxEXPAND | wxBOTTOM, 4);
s2->Add(use_for_all, 0, wxRIGHT | wxBOTTOM | wxALIGN_RIGHT, 4); wxSizer* s3 = new wxBoxSizer(wxHORIZONTAL);
wxSizer* s3 = new wxStaticBoxSizer(wxVERTICAL, this, _LABEL_("styling options")); s3->Add(stylesheet_filter, 0, wxBOTTOM | wxALIGN_LEFT, 4);
s3->Add(use_custom_options, 0, wxEXPAND | wxALL, 4); s3->AddStretchSpacer();
s3->Add(editor, 2, wxEXPAND, 0); s3->Add(use_for_all, 0, wxBOTTOM | wxALIGN_RIGHT, 4);
s2->Add(s3, 1, wxEXPAND | wxALL, 2); s2->Add(s3, wxSizerFlags().Expand().Border(wxALL, 6));
wxSizer* s4 = new wxStaticBoxSizer(wxVERTICAL, this, _LABEL_("styling options"));
s4->Add(use_custom_options, 0, wxEXPAND | wxALL, 4);
s4->Add(editor, 2, wxEXPAND, 0);
s2->Add(s4, 1, wxEXPAND | wxALL, 2);
s->Add(s2, 1, wxEXPAND, 8); s->Add(s2, 1, wxEXPAND, 8);
s->SetSizeHints(this); s->SetSizeHints(this);
SetSizer(s); SetSizer(s);
@@ -62,7 +70,7 @@ void StylePanel::initUI(wxToolBar* tb, wxMenuBar* mb) {
} }
void StylePanel::updateListSize() { void StylePanel::updateListSize() {
if (!isInitialized()) return; if (!isInitialized() || list_size_already_initialized) return;
// how many columns fit? // how many columns fit?
size_t fit_columns = (size_t)((GetSize().y - 400) / 152); size_t fit_columns = (size_t)((GetSize().y - 400) / 152);
// we only need enough columns to show all items // we only need enough columns to show all items
@@ -73,8 +81,11 @@ void StylePanel::updateListSize() {
if (column_count != list->column_count) { if (column_count != list->column_count) {
list->column_count = column_count; list->column_count = column_count;
static_cast<SetWindow*>(GetParent())->fixMinWindowSize(); static_cast<SetWindow*>(GetParent())->fixMinWindowSize();
} }
}
list_size_already_initialized = true;
}
bool StylePanel::Layout() { bool StylePanel::Layout() {
updateListSize(); updateListSize();
return SetWindowPanel::Layout(); return SetWindowPanel::Layout();
@@ -125,6 +136,17 @@ void StylePanel::onAction(const Action& action, bool undone) {
use_for_all->Enable(card && card->stylesheet); use_for_all->Enable(card && card->stylesheet);
use_custom_options->Enable((bool)card); use_custom_options->Enable((bool)card);
use_custom_options->SetValue(card ? card->has_styling : false); use_custom_options->SetValue(card ? card->has_styling : false);
}
void StylePanel::onStylesheetFilterUpdate(wxCommandEvent&) {
if (list->hasSelection()) {
StyleSheetP existingStylesheetSelection = list->getSelection<StyleSheet>(false);
list->setFilter(stylesheet_filter->getFilter<PackageData>());
list->select(existingStylesheetSelection->name());
}
else {
list->setFilter(stylesheet_filter->getFilter<PackageData>());
}
} }
// ----------------------------------------------------------------------------- : Selection // ----------------------------------------------------------------------------- : Selection
@@ -186,7 +208,8 @@ void StylePanel::onUseCustom(wxCommandEvent&) {
} }
BEGIN_EVENT_TABLE(StylePanel, wxPanel) BEGIN_EVENT_TABLE(StylePanel, wxPanel)
EVT_GALLERY_SELECT(wxID_ANY, StylePanel::onStyleSelect) EVT_GALLERY_SELECT(wxID_ANY, StylePanel::onStyleSelect)
EVT_COMMAND_RANGE(ID_STYLESHEET_FILTER, ID_STYLESHEET_FILTER, wxEVT_COMMAND_TEXT_UPDATED, StylePanel::onStylesheetFilterUpdate)
EVT_BUTTON (ID_STYLE_USE_FOR_ALL, StylePanel::onUseForAll) EVT_BUTTON (ID_STYLE_USE_FOR_ALL, StylePanel::onUseForAll)
EVT_CHECKBOX (ID_STYLE_USE_CUSTOM, StylePanel::onUseCustom) EVT_CHECKBOX (ID_STYLE_USE_CUSTOM, StylePanel::onUseCustom)
END_EVENT_TABLE() END_EVENT_TABLE()
+72 -66
View File
@@ -1,66 +1,72 @@
//+----------------------------------------------------------------------------+ //+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards | //| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) Twan van Laarhoven and the other MSE developers | //| Copyright: (C) Twan van Laarhoven and the other MSE developers |
//| License: GNU General Public License 2 or later (see file COPYING) | //| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+ //+----------------------------------------------------------------------------+
#pragma once #pragma once
// ----------------------------------------------------------------------------- : Includes // ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp> #include <util/prec.hpp>
#include <gui/set/panel.hpp> #include <gui/set/panel.hpp>
#include <gui/control/filter_ctrl.hpp>
class CardViewer;
class PackageList; class CardViewer;
class StylingEditor; class PackageList;
class StylingEditor;
// ----------------------------------------------------------------------------- : StylePanel
// ----------------------------------------------------------------------------- : StylePanel
/// A panel showing a list of stylesheets, and an editor for styling
class StylePanel : public SetWindowPanel { /// A panel showing a list of stylesheets, and an editor for styling
public: class StylePanel : public SetWindowPanel {
StylePanel(Window* parent, int id); public:
StylePanel(Window* parent, int id);
void onChangeSet() override;
void onAction(const Action&, bool undone) override; void onChangeSet() override;
void onAction(const Action&, bool undone) override;
// --------------------------------------------------- : UI
// --------------------------------------------------- : UI
void initUI(wxToolBar*, wxMenuBar*) override;
void initUI(wxToolBar*, wxMenuBar*) override;
// --------------------------------------------------- : Clipboard
bool canCut() const override; // --------------------------------------------------- : Clipboard
bool canCopy() const override; bool canCut() const override;
bool canPaste() const override; bool canCopy() const override;
bool canSelectAll() const override; bool canPaste() const override;
void doCut() override; bool canSelectAll() const override;
void doCopy() override; void doCut() override;
void doPaste() override; void doCopy() override;
void doSelectAll() override; void doPaste() override;
void doSelectAll() override;
// --------------------------------------------------- : Selection
void selectCard(const CardP& card) override; // --------------------------------------------------- : Selection
void selectCard(const CardP& card) override;
private:
DECLARE_EVENT_TABLE(); private:
DECLARE_EVENT_TABLE();
CardViewer* preview; ///< Card preview
PackageList* list; ///< List of stylesheets CardViewer* preview; ///< Card preview
StylingEditor* editor; ///< Editor for styling information PackageList* list; ///< List of stylesheets
wxButton* use_for_all; StylingEditor* editor; ///< Editor for styling information
wxCheckBox* use_custom_options; wxButton* use_for_all;
CardP card; ///< Card we are working on wxCheckBox* use_custom_options;
FilterCtrl* stylesheet_filter;
void onStyleSelect(wxCommandEvent&); String stylesheet_filter_value;
void onUseForAll(wxCommandEvent&); CardP card; ///< Card we are working on
void onUseCustom(wxCommandEvent&); bool list_size_already_initialized = false;
/// Determine the best size for the list of stylesheets based on available space void onStyleSelect(wxCommandEvent&);
void updateListSize(); void onUseForAll(wxCommandEvent&);
bool Layout() override; void onUseCustom(wxCommandEvent&);
/// Actual intialization of the controls void onStylesheetFilterUpdate(wxCommandEvent&);
void initControls();
}; /// Determine the best size for the list of stylesheets based on available space
void updateListSize();
bool Layout() override;
/// Actual intialization of the controls
void initControls();
};