mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-13 09:47:58 -06:00
Created PrusaCollapsiblePane for CollapsiblePane view with disclosure triangles
This commit is contained in:
parent
c07f347ff6
commit
2e7d623ee4
5 changed files with 218 additions and 59 deletions
|
@ -1,5 +1,11 @@
|
|||
#include "wxExtensions.hpp"
|
||||
|
||||
#include "GUI.hpp"
|
||||
#include "../../libslic3r/Utils.hpp"
|
||||
|
||||
#include <wx/sizer.h>
|
||||
#include <wx/statline.h>
|
||||
|
||||
const unsigned int wxCheckListBoxComboPopup::DefaultWidth = 200;
|
||||
const unsigned int wxCheckListBoxComboPopup::DefaultHeight = 200;
|
||||
const unsigned int wxCheckListBoxComboPopup::DefaultItemHeight = 18;
|
||||
|
@ -166,6 +172,119 @@ void wxDataViewTreeCtrlComboPopup::OnDataViewTreeCtrlSelection(wxCommandEvent& e
|
|||
cmb->SetText(selected);
|
||||
}
|
||||
|
||||
// *** PrusaCollapsiblePane ***
|
||||
// ----------------------------------------------------------------------------
|
||||
bool PrusaCollapsiblePane::Create(wxWindow *parent, wxWindowID id, const wxString& label,
|
||||
const wxPoint& pos, const wxSize& size, long style, const wxValidator& val, const wxString& name)
|
||||
{
|
||||
if (!wxControl::Create(parent, id, pos, size, style, val, name))
|
||||
return false;
|
||||
m_pStaticLine = NULL;
|
||||
m_strLabel = label;
|
||||
|
||||
// sizer containing the expand button and possibly a static line
|
||||
m_sz = new wxBoxSizer(wxHORIZONTAL);
|
||||
|
||||
m_bmp_close.LoadFile(Slic3r::GUI::from_u8(Slic3r::var("disclosure_triangle_close.png")), wxBITMAP_TYPE_PNG);
|
||||
m_bmp_open.LoadFile(Slic3r::GUI::from_u8(Slic3r::var("disclosure_triangle_open.png")), wxBITMAP_TYPE_PNG);
|
||||
|
||||
m_pDisclosureTriangleButton = new wxButton(this, wxID_ANY, m_strLabel, wxPoint(0, 0),
|
||||
wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER);
|
||||
m_pDisclosureTriangleButton->Bind(wxEVT_BUTTON, [this](wxCommandEvent& event)
|
||||
{
|
||||
if (event.GetEventObject() != m_pDisclosureTriangleButton)
|
||||
{
|
||||
event.Skip();
|
||||
return;
|
||||
}
|
||||
|
||||
Collapse(!IsCollapsed());
|
||||
|
||||
// this change was generated by the user - send the event
|
||||
wxCollapsiblePaneEvent ev(this, GetId(), IsCollapsed());
|
||||
GetEventHandler()->ProcessEvent(ev);
|
||||
});
|
||||
|
||||
UpdateBtnBmp();
|
||||
|
||||
m_sz->Add(m_pDisclosureTriangleButton, 0, wxLEFT | wxTOP | wxBOTTOM, GetBorder());
|
||||
|
||||
// do not set sz as our sizers since we handle the pane window without using sizers
|
||||
m_pPane = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
|
||||
wxTAB_TRAVERSAL | wxNO_BORDER, wxT("wxCollapsiblePanePane"));
|
||||
|
||||
wxColour& clr = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
|
||||
m_pDisclosureTriangleButton->SetBackgroundColour(clr);
|
||||
this->SetBackgroundColour(clr);
|
||||
m_pPane->SetBackgroundColour(clr);
|
||||
|
||||
// start as collapsed:
|
||||
m_pPane->Hide();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void PrusaCollapsiblePane::UpdateBtnBmp()
|
||||
{
|
||||
IsCollapsed() ?
|
||||
m_pDisclosureTriangleButton->SetBitmap(m_bmp_close) :
|
||||
m_pDisclosureTriangleButton->SetBitmap(m_bmp_open);
|
||||
Layout();
|
||||
// m_pDisclosureTriangleButton->Refresh();
|
||||
}
|
||||
|
||||
void PrusaCollapsiblePane::Collapse(bool collapse)
|
||||
{
|
||||
// optimization
|
||||
if (IsCollapsed() == collapse)
|
||||
return;
|
||||
|
||||
InvalidateBestSize();
|
||||
|
||||
// update our state
|
||||
m_pPane->Show(!collapse);
|
||||
|
||||
// update button label
|
||||
// m_pDisclosureTriangleButton->SetLabel(m_strLabel);
|
||||
UpdateBtnBmp();
|
||||
|
||||
OnStateChange(GetBestSize());
|
||||
}
|
||||
|
||||
void PrusaCollapsiblePane::SetLabel(const wxString &label)
|
||||
{
|
||||
m_strLabel = label;
|
||||
|
||||
m_pDisclosureTriangleButton->SetLabel(m_strLabel);
|
||||
|
||||
Layout();
|
||||
}
|
||||
|
||||
bool PrusaCollapsiblePane::Layout()
|
||||
{
|
||||
if (!m_pDisclosureTriangleButton || !m_pPane || !m_sz)
|
||||
return false; // we need to complete the creation first!
|
||||
|
||||
wxSize oursz(GetSize());
|
||||
|
||||
// move & resize the button and the static line
|
||||
m_sz->SetDimension(0, 0, oursz.GetWidth(), m_sz->GetMinSize().GetHeight());
|
||||
m_sz->Layout();
|
||||
|
||||
if (IsExpanded())
|
||||
{
|
||||
// move & resize the container window
|
||||
int yoffset = m_sz->GetSize().GetHeight() + GetBorder();
|
||||
m_pPane->SetSize(0, yoffset,
|
||||
oursz.x, oursz.y - yoffset);
|
||||
|
||||
// this is very important to make the pane window layout show correctly
|
||||
m_pPane->Layout();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// ----------------------------------------------------------------------------
|
||||
// MyObjectTreeModel
|
||||
|
@ -178,17 +297,19 @@ MyObjectTreeModel::MyObjectTreeModel()
|
|||
|
||||
auto root2 = new MyObjectTreeModelNode("Object2");
|
||||
m_objects.emplace(root2);
|
||||
root2->Append(new MyObjectTreeModelNode(root2, "SubObject1"));
|
||||
root2->Append(new MyObjectTreeModelNode(root2, "SubObject2"));
|
||||
root2->Append(new MyObjectTreeModelNode(root2, "SubObject3"));
|
||||
root2->Append(new MyObjectTreeModelNode(root2, "SubObject2_1"));
|
||||
root2->Append(new MyObjectTreeModelNode(root2, "SubObject2_2"));
|
||||
root2->Append(new MyObjectTreeModelNode(root2, "SubObject2_3"));
|
||||
|
||||
auto root3 = new MyObjectTreeModelNode("Object3");
|
||||
m_objects.emplace(root3);
|
||||
auto root4 = new MyObjectTreeModelNode("Object4");
|
||||
m_objects.emplace(root4);
|
||||
root4->Append(new MyObjectTreeModelNode(root4, "SubObject1"));
|
||||
root4->Append(new MyObjectTreeModelNode(root4, "SubObject2"));
|
||||
root4->Append(new MyObjectTreeModelNode(root4, "SubObject3"));
|
||||
root4->Append(new MyObjectTreeModelNode(root4, "SubObject4_1"));
|
||||
root4->Append(new MyObjectTreeModelNode(root4, "SubObject4_2"));
|
||||
|
||||
auto root5 = new MyObjectTreeModelNode("Object5");
|
||||
m_objects.emplace(root5);
|
||||
}
|
||||
|
||||
wxString MyObjectTreeModel::GetName(const wxDataViewItem &item) const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue