Skip to content

Class for RadioGroup & LabeledStaticBox and improvements for Calibration Dialogs, Windows with wxStaticBoxSizer #9797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jun 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions resources/images/radio_disabled.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions resources/images/radio_off_hover.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions resources/images/radio_on_hover.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/slic3r/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ set(SLIC3R_GUI_SOURCES
GUI/Widgets/Scrollbar.hpp
GUI/Widgets/ScrolledWindow.cpp
GUI/Widgets/ScrolledWindow.hpp
GUI/Widgets/LabeledStaticBox.cpp
GUI/Widgets/LabeledStaticBox.hpp
GUI/Widgets/StaticBox.cpp
GUI/Widgets/StaticBox.hpp
GUI/Widgets/ImageSwitchButton.cpp
Expand Down Expand Up @@ -70,6 +72,8 @@ set(SLIC3R_GUI_SOURCES
GUI/Widgets/StepCtrl.hpp
GUI/Widgets/ProgressBar.cpp
GUI/Widgets/ProgressBar.hpp
GUI/Widgets/RadioGroup.cpp
GUI/Widgets/RadioGroup.hpp
GUI/Widgets/SideTools.cpp
GUI/Widgets/SideTools.hpp
GUI/Widgets/WebView.cpp
Expand Down
7 changes: 4 additions & 3 deletions src/slic3r/GUI/BedShapeDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "libslic3r/Model.hpp"
#include "libslic3r/Polygon.hpp"

#include "Widgets/LabeledStaticBox.hpp"
#include "Widgets/DialogButtons.hpp"

#include <boost/algorithm/string/predicate.hpp>
Expand Down Expand Up @@ -189,9 +190,9 @@ void BedShapePanel::build_panel(const Pointfs& default_pt, const std::string& cu
m_custom_texture = custom_texture.empty() ? NONE : custom_texture;
m_custom_model = custom_model.empty() ? NONE : custom_model;

auto sbsizer = new wxStaticBoxSizer(wxVERTICAL, this, _L("Shape"));
sbsizer->GetStaticBox()->SetFont(wxGetApp().bold_font());
wxGetApp().UpdateDarkUI(sbsizer->GetStaticBox());
// ORCA match style of wxStaticBox between platforms
LabeledStaticBox* stb = new LabeledStaticBox(this, _L("Shape"));
auto sbsizer = new wxStaticBoxSizer(stb, wxVERTICAL);

// shape options
m_shape_options_book = new wxSimplebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize);
Expand Down
2 changes: 2 additions & 0 deletions src/slic3r/GUI/GUI_Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <wx/debug.h>
#include <wx/settings.h>
#include <wx/dataview.h>
#include <wx/statbox.h>

#include <chrono>

Expand Down Expand Up @@ -496,6 +497,7 @@ int get_dpi_for_window(const wxWindow *window);

#ifdef __WXOSX__
void dataview_remove_insets(wxDataViewCtrl* dv);
void staticbox_remove_margin(wxStaticBox* sb);
#endif

/// <summary>
Expand Down
6 changes: 6 additions & 0 deletions src/slic3r/GUI/GUI_UtilsMac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ void dataview_remove_insets(wxDataViewCtrl* dv) {
}
}

void staticbox_remove_margin(wxStaticBox* sb) {
NSBox* nativeBox = (NSBox*)sb->GetHandle();
[nativeBox setBoxType:NSBoxCustom];
[nativeBox setBorderWidth:0];
}

}
}

12 changes: 5 additions & 7 deletions src/slic3r/GUI/OptionsGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "MsgDialog.hpp"
#include "format.hpp"
#include "Widgets/StaticLine.hpp"
#include "Widgets/LabeledStaticBox.hpp"

#include <utility>
#include <wx/bookctrl.h>
Expand Down Expand Up @@ -470,14 +471,11 @@ bool OptionsGroup::activate(std::function<void()> throw_if_canceled/* = [](){}*/

try {
if (staticbox) {
wxStaticBox * stb = new wxStaticBox(m_parent, wxID_ANY, _(title));
if (!wxOSX) stb->SetBackgroundStyle(wxBG_STYLE_PAINT);
stb->SetBackgroundColour(m_parent->GetBackgroundColour());
stb->SetFont(wxOSX ? wxGetApp().normal_font() : wxGetApp().bold_font());
wxGetApp().UpdateDarkUI(stb);
// BBS: new layout
sizer = new wxStaticBoxSizer(stb, wxVERTICAL);
// ORCA match style of wxStaticBox between platforms
LabeledStaticBox * stb = new LabeledStaticBox(m_parent, _(title));
//wxGetApp().UpdateDarkUI(stb);
this->stb = stb;
sizer = new wxStaticBoxSizer(stb, wxVERTICAL);
}
else {
// BBS: new layout
Expand Down
181 changes: 181 additions & 0 deletions src/slic3r/GUI/Widgets/LabeledStaticBox.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
#include "LabeledStaticBox.hpp"
#include "libslic3r/Utils.hpp"
#include "../GUI.hpp"
#include "../GUI_Utils.hpp"
#include "Label.hpp"

/*
Fix label overflowing to inner frame
Fix use elypsis if text too long
setmin size
*/

LabeledStaticBox::LabeledStaticBox()
: state_handler(this)
{
m_radius = 3;
m_border_width = 1;
m_font = Label::Head_14;
text_color = StateColor(
std::make_pair(0x363636, (int) StateColor::Normal),
std::make_pair(0x6B6B6B, (int) StateColor::Disabled)
);
background_color = StateColor(
std::make_pair(0xFFFFFF, (int) StateColor::Normal),
std::make_pair(0xF0F0F1, (int) StateColor::Disabled)
);
border_color = StateColor(
std::make_pair(0xDBDBDB, (int) StateColor::Normal),
std::make_pair(0xDBDBDB, (int) StateColor::Disabled)
);

}

LabeledStaticBox::LabeledStaticBox(
wxWindow* parent,
const wxString& label,
const wxPoint& pos,
const wxSize& size,
long style
)
: LabeledStaticBox()
{
Create(parent, label, pos, size, style);
}

bool LabeledStaticBox::Create(
wxWindow* parent,
const wxString& label,
const wxPoint& pos,
const wxSize& size,
long style
)
{
if (style & wxBORDER_NONE)
m_border_width = 0;
wxStaticBox::Create(parent, wxID_ANY, label, pos, size, style);
#ifdef __WXOSX__
Slic3r::GUI::staticbox_remove_margin(this);
#endif

m_label = label;
m_scale = FromDIP(100) / 100.f;
m_pos = this->GetPosition();

int tW,tH,descent,externalLeading;
GetTextExtent("Yy", &tW, &tH, &descent, &externalLeading, &m_font);
m_label_height = tH - externalLeading;

GetTextExtent(m_label, &tW, &tH, &descent, &externalLeading, &m_font);
m_label_width = tW;

Bind(wxEVT_PAINT,([this](wxPaintEvent e) {
wxPaintDC dc(this);
PickDC(dc);
}));

state_handler.attach({&text_color, &background_color, &border_color});
state_handler.update_binds();
#ifndef __WXOSX__
SetBackgroundStyle(wxBG_STYLE_PAINT);
#endif
SetBackgroundColour(background_color.colorForStates(state_handler.states()));
SetForegroundColour( text_color.colorForStates(state_handler.states()));
SetBorderColor( border_color.colorForStates(state_handler.states()));
SetCanFocus(false);
return true;
}

void LabeledStaticBox::SetCornerRadius(int radius)
{
this->m_radius = radius;
Refresh();
}

void LabeledStaticBox::SetBorderWidth(int width)
{
this->m_border_width = width;
Refresh();
}

void LabeledStaticBox::SetBorderColor(StateColor const &color)
{
border_color = color;
state_handler.update_binds();
Refresh();
}

void LabeledStaticBox::SetFont(wxFont set_font)
{
m_font = set_font;
Refresh();
}

bool LabeledStaticBox::Enable(bool enable)
{
bool result = this->wxStaticBox::Enable(enable);
if (result) {
wxCommandEvent e(EVT_ENABLE_CHANGED);
e.SetEventObject(this);
GetEventHandler()->ProcessEvent(e);
this->SetForegroundColour( text_color.colorForStates(state_handler.states()));
this->SetBorderColor( border_color.colorForStates(state_handler.states()));
}
return result;
}

void LabeledStaticBox::PickDC(wxDC& dc)
{
#ifdef __WXMSW__
wxSize size = GetSize();
if (size.x <= 0 || size.y <= 0)
return;
wxMemoryDC memdc(&dc);
if (!memdc.IsOk()) {
DrawBorderAndLabel(dc);
return;
}
wxBitmap bmp(size.x, size.y);
memdc.SelectObject(bmp);
memdc.SetBackground(wxBrush(GetBackgroundColour()));
memdc.Clear();
{
wxGCDC dc2(memdc);
DrawBorderAndLabel(dc2);
}

memdc.SelectObject(wxNullBitmap);
dc.DrawBitmap(bmp, 0, 0);
#else
DrawBorderAndLabel(dc);
#endif
}

void LabeledStaticBox::DrawBorderAndLabel(wxDC& dc)
{
// fill full background
dc.SetBackground(wxBrush(background_color.colorForStates(0)));
dc.Clear();

wxSize wSz = GetSize();

dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.SetPen(wxPen(border_color.colorForStates(state_handler.states()), m_border_width, wxSOLID));
dc.DrawRoundedRectangle( // Border
std::max(0, m_pos.x),
std::max(0, m_pos.y) + m_label_height * .5,
wSz.GetWidth(),
wSz.GetHeight() - m_label_height * .5,
m_radius * m_scale
);

if (!m_label.IsEmpty()) {
dc.SetFont(m_font);
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(wxBrush(background_color.colorForStates(0)));
dc.DrawRectangle(wxRect(7 * m_scale,0 , m_label_width + 7 * m_scale, m_label_height)); // text background
// NEEDFIX if text lenght > client size
dc.SetTextForeground(text_color.colorForStates(state_handler.states()));
dc.DrawText(m_label, wxPoint(10 * m_scale, 0));
}
}
68 changes: 68 additions & 0 deletions src/slic3r/GUI/Widgets/LabeledStaticBox.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#ifndef slic3r_GUI_LabeledStaticBox_hpp_
#define slic3r_GUI_LabeledStaticBox_hpp_

#include <wx/window.h>
#include <wx/dc.h>
#include <wx/dcgraph.h>
#include <wx/dcclient.h>
#include <wx/dcbuffer.h>
#include <wx/settings.h>
#include <wx/statbox.h>
#include <wx/pen.h>

#include "libslic3r/Utils.hpp"

#include "slic3r/GUI/wxExtensions.hpp"
#include "slic3r/GUI/Widgets/StateHandler.hpp"

class LabeledStaticBox : public wxStaticBox
{
public:
LabeledStaticBox();

LabeledStaticBox(
wxWindow* parent,
const wxString& label = wxEmptyString,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0
);

bool Create(
wxWindow* parent,
const wxString& label = wxEmptyString,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0
);

void SetCornerRadius(int radius);

void SetBorderWidth(int width);

void SetBorderColor(StateColor const &color);

void SetFont(wxFont set_font);

bool Enable(bool enable) override;

private:
void PickDC(wxDC& dc);
virtual void DrawBorderAndLabel(wxDC& dc);

protected:
StateHandler state_handler;
StateColor text_color;
StateColor border_color;
StateColor background_color;
int m_border_width;
int m_radius;
wxFont m_font;
wxString m_label;
int m_label_height;
int m_label_width;
float m_scale;
wxPoint m_pos;
};

#endif // !slic3r_GUI_LabeledStaticBox_hpp_
Loading