From 22722f28ceb540d87007da6c3d391fe42bebee5d Mon Sep 17 00:00:00 2001 From: twanvl Date: Sat, 9 Aug 2008 21:38:53 +0000 Subject: [PATCH] Put card notes below the card editor if they fit there (dynamically) git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1127 0fc631ac-6414-0410-93d0-97cfa31319b6 --- src/gui/set/cards_panel.cpp | 52 +++++++++++++++++++++++++++++-------- src/gui/set/cards_panel.hpp | 9 +++++++ src/gui/set/window.hpp | 3 ++- 3 files changed, 52 insertions(+), 12 deletions(-) diff --git a/src/gui/set/cards_panel.cpp b/src/gui/set/cards_panel.cpp index e690fbf5..ea73f360 100644 --- a/src/gui/set/cards_panel.cpp +++ b/src/gui/set/cards_panel.cpp @@ -31,31 +31,33 @@ CardsPanel::CardsPanel(Window* parent, int id) : SetWindowPanel(parent, id) { // init controls - wxPanel* notesP; - editor = new CardEditor(this, ID_EDITOR); - splitter = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); - card_list = new ImageCardList(splitter, ID_CARD_LIST); - notesP = new Panel(splitter, wxID_ANY); - notes = new TextCtrl(notesP, ID_NOTES, true); - collapse_notes = new HoverButton(notesP, ID_COLLAPSE_NOTES, _("btn_collapse"), wxNullColour, false); + editor = new CardEditor(this, ID_EDITOR); + splitter = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); + card_list = new ImageCardList(splitter, ID_CARD_LIST); + nodes_panel = new Panel(splitter, wxID_ANY); + notes = new TextCtrl(nodes_panel, ID_NOTES, true); + collapse_notes = new HoverButton(nodes_panel, ID_COLLAPSE_NOTES, _("btn_collapse"), wxNullColour, false); collapse_notes->SetExtraStyle(wxWS_EX_PROCESS_UI_UPDATES); filter = nullptr; editor->next_in_tab_order = card_list; // init sizer for notes panel wxSizer* sn = new wxBoxSizer(wxVERTICAL); wxSizer* sc = new wxBoxSizer(wxHORIZONTAL); - sc->Add(new wxStaticText(notesP, wxID_ANY, _LABEL_("card notes")), 1, wxEXPAND); + sc->Add(new wxStaticText(nodes_panel, wxID_ANY, _LABEL_("card notes")), 1, wxEXPAND); sc->Add(collapse_notes, 0, wxALIGN_CENTER | wxRIGHT, 2); sn->Add(sc, 0, wxEXPAND, 2); sn->Add(notes, 1, wxEXPAND | wxTOP, 2); - notesP->SetSizer(sn); + nodes_panel->SetSizer(sn); // init splitter splitter->SetMinimumPaneSize(15); splitter->SetSashGravity(1.0); - splitter->SplitHorizontally(card_list, notesP, -40); + splitter->SplitHorizontally(card_list, nodes_panel, -40); + notes_below_editor = false; // init sizer wxSizer* s = new wxBoxSizer(wxHORIZONTAL); - s->Add(editor, 0, wxRIGHT, 2); + s_left = new wxBoxSizer(wxVERTICAL); + s_left->Add(editor); + s->Add(s_left, 0, wxEXPAND | wxRIGHT, 2); s->Add(splitter, 1, wxEXPAND); s->SetSizeHints(this); SetSizer(s); @@ -92,6 +94,33 @@ CardsPanel::CardsPanel(Window* parent, int id) menuFormat->Append(insertSymbolMenu); } +void CardsPanel::updateNotesPosition() { + wxSize editor_size = editor->GetBestSize(); + int room_below_editor = GetSize().y - editor_size.y; + bool should_be_below = room_below_editor > 100; + // move? + if (should_be_below && !notes_below_editor) { + notes_below_editor = true; + // move the notes_panel to below the editor, it gets this as its parent + splitter->Unsplit(nodes_panel); + nodes_panel->Reparent(this); + s_left->Add(nodes_panel, 1, wxEXPAND | wxTOP, 2); + collapse_notes->Hide(); + nodes_panel->Show(); + } else if (!should_be_below && notes_below_editor) { + notes_below_editor = false; + // move the notes_panel back to below the card list + s_left->Detach(nodes_panel); + nodes_panel->Reparent(splitter); + collapse_notes->Show(); + splitter->SplitHorizontally(card_list, nodes_panel, -80); + } +} +bool CardsPanel::Layout() { + updateNotesPosition(); + return SetWindowPanel::Layout(); +} + CardsPanel::~CardsPanel() { // settings.card_notes_height = splitter->GetSashPosition(); // we don't own the submenu @@ -352,6 +381,7 @@ void CardsPanel::selectCard(const CardP& card) { editor->setCard(card); notes->setValue(card ? &card->notes : nullptr); Layout(); + updateNotesPosition(); } void CardsPanel::selectFirstCard() { diff --git a/src/gui/set/cards_panel.hpp b/src/gui/set/cards_panel.hpp index 5522aff8..2ef476b2 100644 --- a/src/gui/set/cards_panel.hpp +++ b/src/gui/set/cards_panel.hpp @@ -72,12 +72,21 @@ class CardsPanel : public SetWindowPanel { private: // --------------------------------------------------- : Controls + wxSizer* s_left; wxSplitterWindow* splitter; DataEditor* editor; ImageCardList* card_list; + Panel* nodes_panel; TextCtrl* notes; HoverButton* collapse_notes; wxTextCtrl* filter; + bool notes_below_editor; + + /// Move the notes panel below the editor or below the card list + void updateNotesPosition(); + // before Layout, call updateNotesPosition. + // NOTE: docs say this function returns void, but the code says bool + virtual bool Layout(); // --------------------------------------------------- : Menus & tools IconMenu* menuCard, *menuFormat; diff --git a/src/gui/set/window.hpp b/src/gui/set/window.hpp index f1f4c37a..3d4606d2 100644 --- a/src/gui/set/window.hpp +++ b/src/gui/set/window.hpp @@ -86,10 +86,11 @@ class SetWindow : public wxFrame, public SetView { /// Actions that change the set virtual void onAction(const Action&, bool undone); - private: + public: // minSize = mainSizer->getMinWindowSize(this) // but wx made that private void fixMinWindowSize(); + private: /// Update the window title based on the set name void updateTitle();