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);
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"));
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
wxSizer* s = new wxBoxSizer(wxHORIZONTAL);
s->Add(preview, 0, wxRIGHT, 2);
wxSizer* s2 = new wxBoxSizer(wxVERTICAL);
s2->Add(list, 0, wxEXPAND | wxBOTTOM, 4);
s2->Add(use_for_all, 0, wxRIGHT | wxBOTTOM | wxALIGN_RIGHT, 4);
wxSizer* s3 = new wxStaticBoxSizer(wxVERTICAL, this, _LABEL_("styling options"));
s3->Add(use_custom_options, 0, wxEXPAND | wxALL, 4);
s3->Add(editor, 2, wxEXPAND, 0);
s2->Add(s3, 1, wxEXPAND | wxALL, 2);
s2->Add(list, 0, wxEXPAND | wxBOTTOM, 4);
wxSizer* s3 = new wxBoxSizer(wxHORIZONTAL);
s3->Add(stylesheet_filter, 0, wxBOTTOM | wxALIGN_LEFT, 4);
s3->AddStretchSpacer();
s3->Add(use_for_all, 0, wxBOTTOM | wxALIGN_RIGHT, 4);
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->SetSizeHints(this);
SetSizer(s);
@@ -62,7 +70,7 @@ void StylePanel::initUI(wxToolBar* tb, wxMenuBar* mb) {
}
void StylePanel::updateListSize() {
if (!isInitialized()) return;
if (!isInitialized() || list_size_already_initialized) return;
// how many columns fit?
size_t fit_columns = (size_t)((GetSize().y - 400) / 152);
// we only need enough columns to show all items
@@ -73,8 +81,11 @@ void StylePanel::updateListSize() {
if (column_count != list->column_count) {
list->column_count = column_count;
static_cast<SetWindow*>(GetParent())->fixMinWindowSize();
}
}
}
list_size_already_initialized = true;
}
bool StylePanel::Layout() {
updateListSize();
return SetWindowPanel::Layout();
@@ -125,6 +136,17 @@ void StylePanel::onAction(const Action& action, bool undone) {
use_for_all->Enable(card && card->stylesheet);
use_custom_options->Enable((bool)card);
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
@@ -186,7 +208,8 @@ void StylePanel::onUseCustom(wxCommandEvent&) {
}
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_CHECKBOX (ID_STYLE_USE_CUSTOM, StylePanel::onUseCustom)
END_EVENT_TABLE()
+72 -66
View File
@@ -1,66 +1,72 @@
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) Twan van Laarhoven and the other MSE developers |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
#pragma once
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/set/panel.hpp>
class CardViewer;
class PackageList;
class StylingEditor;
// ----------------------------------------------------------------------------- : StylePanel
/// A panel showing a list of stylesheets, and an editor for styling
class StylePanel : public SetWindowPanel {
public:
StylePanel(Window* parent, int id);
void onChangeSet() override;
void onAction(const Action&, bool undone) override;
// --------------------------------------------------- : UI
void initUI(wxToolBar*, wxMenuBar*) override;
// --------------------------------------------------- : Clipboard
bool canCut() const override;
bool canCopy() const override;
bool canPaste() const override;
bool canSelectAll() const override;
void doCut() override;
void doCopy() override;
void doPaste() override;
void doSelectAll() override;
// --------------------------------------------------- : Selection
void selectCard(const CardP& card) override;
private:
DECLARE_EVENT_TABLE();
CardViewer* preview; ///< Card preview
PackageList* list; ///< List of stylesheets
StylingEditor* editor; ///< Editor for styling information
wxButton* use_for_all;
wxCheckBox* use_custom_options;
CardP card; ///< Card we are working on
void onStyleSelect(wxCommandEvent&);
void onUseForAll(wxCommandEvent&);
void onUseCustom(wxCommandEvent&);
/// 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();
};
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) Twan van Laarhoven and the other MSE developers |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
#pragma once
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/set/panel.hpp>
#include <gui/control/filter_ctrl.hpp>
class CardViewer;
class PackageList;
class StylingEditor;
// ----------------------------------------------------------------------------- : StylePanel
/// A panel showing a list of stylesheets, and an editor for styling
class StylePanel : public SetWindowPanel {
public:
StylePanel(Window* parent, int id);
void onChangeSet() override;
void onAction(const Action&, bool undone) override;
// --------------------------------------------------- : UI
void initUI(wxToolBar*, wxMenuBar*) override;
// --------------------------------------------------- : Clipboard
bool canCut() const override;
bool canCopy() const override;
bool canPaste() const override;
bool canSelectAll() const override;
void doCut() override;
void doCopy() override;
void doPaste() override;
void doSelectAll() override;
// --------------------------------------------------- : Selection
void selectCard(const CardP& card) override;
private:
DECLARE_EVENT_TABLE();
CardViewer* preview; ///< Card preview
PackageList* list; ///< List of stylesheets
StylingEditor* editor; ///< Editor for styling information
wxButton* use_for_all;
wxCheckBox* use_custom_options;
FilterCtrl* stylesheet_filter;
String stylesheet_filter_value;
CardP card; ///< Card we are working on
bool list_size_already_initialized = false;
void onStyleSelect(wxCommandEvent&);
void onUseForAll(wxCommandEvent&);
void onUseCustom(wxCommandEvent&);
void onStylesheetFilterUpdate(wxCommandEvent&);
/// 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();
};