Commit 0ec81401 authored by twanvl's avatar twanvl

Put card notes below the card editor if they fit there (dynamically)

parent 5e5aa565
...@@ -31,31 +31,33 @@ CardsPanel::CardsPanel(Window* parent, int id) ...@@ -31,31 +31,33 @@ CardsPanel::CardsPanel(Window* parent, int id)
: SetWindowPanel(parent, id) : SetWindowPanel(parent, id)
{ {
// init controls // init controls
wxPanel* notesP; editor = new CardEditor(this, ID_EDITOR);
editor = new CardEditor(this, ID_EDITOR); splitter = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
splitter = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); card_list = new ImageCardList(splitter, ID_CARD_LIST);
card_list = new ImageCardList(splitter, ID_CARD_LIST); nodes_panel = new Panel(splitter, wxID_ANY);
notesP = new Panel(splitter, wxID_ANY); notes = new TextCtrl(nodes_panel, ID_NOTES, true);
notes = new TextCtrl(notesP, ID_NOTES, true); collapse_notes = new HoverButton(nodes_panel, ID_COLLAPSE_NOTES, _("btn_collapse"), wxNullColour, false);
collapse_notes = new HoverButton(notesP, ID_COLLAPSE_NOTES, _("btn_collapse"), wxNullColour, false);
collapse_notes->SetExtraStyle(wxWS_EX_PROCESS_UI_UPDATES); collapse_notes->SetExtraStyle(wxWS_EX_PROCESS_UI_UPDATES);
filter = nullptr; filter = nullptr;
editor->next_in_tab_order = card_list; editor->next_in_tab_order = card_list;
// init sizer for notes panel // init sizer for notes panel
wxSizer* sn = new wxBoxSizer(wxVERTICAL); wxSizer* sn = new wxBoxSizer(wxVERTICAL);
wxSizer* sc = new wxBoxSizer(wxHORIZONTAL); 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); sc->Add(collapse_notes, 0, wxALIGN_CENTER | wxRIGHT, 2);
sn->Add(sc, 0, wxEXPAND, 2); sn->Add(sc, 0, wxEXPAND, 2);
sn->Add(notes, 1, wxEXPAND | wxTOP, 2); sn->Add(notes, 1, wxEXPAND | wxTOP, 2);
notesP->SetSizer(sn); nodes_panel->SetSizer(sn);
// init splitter // init splitter
splitter->SetMinimumPaneSize(15); splitter->SetMinimumPaneSize(15);
splitter->SetSashGravity(1.0); splitter->SetSashGravity(1.0);
splitter->SplitHorizontally(card_list, notesP, -40); splitter->SplitHorizontally(card_list, nodes_panel, -40);
notes_below_editor = false;
// init sizer // init sizer
wxSizer* s = new wxBoxSizer(wxHORIZONTAL); 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->Add(splitter, 1, wxEXPAND);
s->SetSizeHints(this); s->SetSizeHints(this);
SetSizer(s); SetSizer(s);
...@@ -92,6 +94,33 @@ CardsPanel::CardsPanel(Window* parent, int id) ...@@ -92,6 +94,33 @@ CardsPanel::CardsPanel(Window* parent, int id)
menuFormat->Append(insertSymbolMenu); 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() { CardsPanel::~CardsPanel() {
// settings.card_notes_height = splitter->GetSashPosition(); // settings.card_notes_height = splitter->GetSashPosition();
// we don't own the submenu // we don't own the submenu
...@@ -352,6 +381,7 @@ void CardsPanel::selectCard(const CardP& card) { ...@@ -352,6 +381,7 @@ void CardsPanel::selectCard(const CardP& card) {
editor->setCard(card); editor->setCard(card);
notes->setValue(card ? &card->notes : nullptr); notes->setValue(card ? &card->notes : nullptr);
Layout(); Layout();
updateNotesPosition();
} }
void CardsPanel::selectFirstCard() { void CardsPanel::selectFirstCard() {
......
...@@ -72,12 +72,21 @@ class CardsPanel : public SetWindowPanel { ...@@ -72,12 +72,21 @@ class CardsPanel : public SetWindowPanel {
private: private:
// --------------------------------------------------- : Controls // --------------------------------------------------- : Controls
wxSizer* s_left;
wxSplitterWindow* splitter; wxSplitterWindow* splitter;
DataEditor* editor; DataEditor* editor;
ImageCardList* card_list; ImageCardList* card_list;
Panel* nodes_panel;
TextCtrl* notes; TextCtrl* notes;
HoverButton* collapse_notes; HoverButton* collapse_notes;
wxTextCtrl* filter; 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 // --------------------------------------------------- : Menus & tools
IconMenu* menuCard, *menuFormat; IconMenu* menuCard, *menuFormat;
......
...@@ -86,10 +86,11 @@ class SetWindow : public wxFrame, public SetView { ...@@ -86,10 +86,11 @@ class SetWindow : public wxFrame, public SetView {
/// Actions that change the set /// Actions that change the set
virtual void onAction(const Action&, bool undone); virtual void onAction(const Action&, bool undone);
private: public:
// minSize = mainSizer->getMinWindowSize(this) // minSize = mainSizer->getMinWindowSize(this)
// but wx made that private // but wx made that private
void fixMinWindowSize(); void fixMinWindowSize();
private:
/// Update the window title based on the set name /// Update the window title based on the set name
void updateTitle(); void updateTitle();
......
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