diff --git a/.claude/skills/orca-wxwidgets/SKILL.md b/.claude/skills/orca-wxwidgets/SKILL.md index 0e39ce9d24..9bd352039e 100644 --- a/.claude/skills/orca-wxwidgets/SKILL.md +++ b/.claude/skills/orca-wxwidgets/SKILL.md @@ -56,11 +56,12 @@ the source is what runs — the references mark such facts **[source]**. Orca-si ## Golden rules -1. **Interactive controls are Orca widgets** (`Button` + `SetStyle(...)`, `::CheckBox`, `::ComboBox`, - `::TextInput`, `SpinInput`, `SwitchButton`, `RadioGroup`, `TabCtrl`); the bottom row of every dialog is - `DialogButtons`. Never `wxButton`, `wxSpinCtrl`, `wxCheckBox`, `wxChoice` or a single-line `wxTextCtrl` - in new code; multi-line text is a raw `wxTextCtrl`. Inside `Slic3r::GUI` write `::CheckBox` etc. — - `Field.hpp` has classes with the same names. → `orca-widgets.md` +1. **Interactive controls are Orca widgets** (`Button` + `SetStyle(...)`, `::CheckBox`, `LabeledCheckBox`, + `::ComboBox`, `::TextInput`, `SpinInput`, `SwitchButton`, `RadioGroup`, `TabCtrl`); the bottom row of every + dialog is `DialogButtons`. Never `wxButton`, `wxSpinCtrl`, `wxCheckBox`, `wxChoice` or a single-line + `wxTextCtrl` in new code; multi-line text is a raw `wxTextCtrl`. When the label is on the right side of the + check box and belongs to it, use a `LabeledCheckBox`, not a `::CheckBox` paired with a label by hand. Inside + `Slic3r::GUI` write `::CheckBox` etc. — `Field.hpp` has classes with the same names. → `orca-widgets.md` 2. **DPI.** Layout pixel values go through `FromDIP(n)` (or `n * em_unit()`); `wxBitmap` constructor sizes, image-list sizes and GL viewports are physical and are not `FromDIP`'d (icon heights passed to `create_scaled_bitmap`/`ScalableBitmap`/`Button` are DIP). Top-level windows are `DPIDialog`/ @@ -171,7 +172,8 @@ if (dlg.ShowModal() == wxID_OK) { /* read results */ } | Orca widget (`src/slic3r/GUI/Widgets/`) | Instead of | Must know | |---|---|---| | `Button` | `wxButton` | ctor `(parent, text, icon_name, style, iconSize, id)` — id is last; style with `SetStyle(ButtonStyle::…, ButtonType::…)`; emits `wxEVT_BUTTON`; not a `wxButton` (no dialog default/escape emulation) | -| `::CheckBox` | `wxCheckBox` | no label parameter — pair with a `wxStaticText`/`Label`; emits `wxEVT_TOGGLEBUTTON` (never `wxEVT_CHECKBOX`), and a handler bound on it must `Skip()` or the bitmap is not refreshed | +| `::CheckBox` | `wxCheckBox` without a label | no label parameter — when the label is on the right side of the check box and belongs to it, use `LabeledCheckBox`; emits `wxEVT_TOGGLEBUTTON` (never `wxEVT_CHECKBOX`), and a handler bound on it must `Skip()` or the bitmap is not refreshed | +| `LabeledCheckBox` | `wxCheckBox` with a label, a `::CheckBox` hand-paired with its own label on the right side | ctor `(parent, label, id)`; a click on the check or the label sends `wxEVT_CHECKBOX` **and** `wxEVT_TOGGLEBUTTON` from the control — bind one; `SetValue` silent; label, font, `Wrap(width)`/`AutoWrap()` and `Enable()` go through the control, not its children | | `::ComboBox` (+ `DropDown`) | `wxComboBox`/`wxChoice` | `wxCB_READONLY` for choices; `SelectAndNotify(n)` fires the event; ignores the ctor id; `void*` client data only | | `::TextInput` | single-line `wxTextCtrl` | text via `GetTextCtrl()`; bind `wxEVT_TEXT_ENTER`/`wxEVT_KILL_FOCUS` on the widget, never on a parent | | `SpinInput` | `wxSpinCtrl` | non-negative integers only (`-` cannot be typed); commits on Enter, kill-focus and arrow steps with `wxEVT_SPINCTRL`, a plain `wxCommandEvent` — bind a `wxCommandEvent&` handler and read `GetValue()` | diff --git a/.claude/skills/orca-wxwidgets/references/controls-dataview.md b/.claude/skills/orca-wxwidgets/references/controls-dataview.md index 3671e05991..a6721f5237 100644 --- a/.claude/skills/orca-wxwidgets/references/controls-dataview.md +++ b/.claude/skills/orca-wxwidgets/references/controls-dataview.md @@ -73,6 +73,7 @@ Contents: [Rules](#rules) · [Native vs generic](#native-vs-generic-and-silent-a constructor, so bind on the combo (or `SetId()` after construction if an id filter is unavoidable). → [Orca widgets](#orca-replacement-widgets-event-contracts) 26. `::CheckBox`/`SwitchButton` emit `wxEVT_TOGGLEBUTTON`, and a handler bound on the widget itself must `Skip()`; + `LabeledCheckBox` sends `wxEVT_CHECKBOX` and `wxEVT_TOGGLEBUTTON` from itself — bind one; `RadioGroup::SetSelection` always emits; `SpinInput`'s `wxEVT_SPINCTRL` is a plain `wxCommandEvent`. → [Orca widgets](#orca-replacement-widgets-event-contracts) 27. Expect Orca's colours on every generic data view and `RenderText` on MSW: `ObjectList` installs a @@ -300,8 +301,8 @@ Contract: - `wxRadioBox::SetSelection(n)` needs a valid `n`, never `wxNOT_FOUND` (`interface/wx/radiobox.h:292-295`), and sends no event. -OrcaSlicer: interactive check boxes are `::CheckBox`/`SwitchButton`, radio rows are `::RadioGroup`; their event -contracts differ from these ([below](#checkbox-and-switchbutton)). +OrcaSlicer: interactive check boxes are `::CheckBox`/`LabeledCheckBox`/`SwitchButton`, radio rows are +`::RadioGroup`; their event contracts differ from these ([below](#checkbox-and-switchbutton)). Pitfalls: - **Rule:** Put `wxRB_GROUP` on the first button of *every* group. @@ -751,6 +752,7 @@ Bind column means an ancestor bound by event type; binding an ancestor by the wi | `::ComboBox` | `wxComboBox`/`wxChoice` | `wxEVT_COMBOBOX` (int = index, string = text); DROPDOWN/CLOSEUP | COMBOBOX: combo's auto-generated id (the ctor `id` is ignored) and object; DROPDOWN/CLOSEUP: id 0, no object | `SetSelection`/`SetValue` → `wxEVT_TEXT` when the text ctrl is shown or `CB_NO_TEXT`; `SelectAndNotify` → `wxEVT_COMBOBOX` | COMBOBOX on the combo (or an ancestor); DROPDOWN/CLOSEUP on the combo without id | | `::SpinInput` | `wxSpinCtrl` | `wxEVT_SPINCTRL` (a `wxCommandEvent`); `EVT_SPINCTRL_TEXT` per parsable keystroke; inner `wxEVT_TEXT` | SPINCTRL / SPINCTRL_TEXT: spinner id/object | `SetValue(int)` → `EVT_SPINCTRL_TEXT` + `wxEVT_TEXT`, no `wxEVT_SPINCTRL` | SPINCTRL on the spinner or an ancestor, handler takes `wxCommandEvent&` | | `::CheckBox`, `SwitchButton` | `wxCheckBox` | `wxEVT_TOGGLEBUTTON` | native | `SetValue` silent | on the widget (with `Skip()`) or an ancestor; never `wxEVT_CHECKBOX` | +| `LabeledCheckBox` | `wxCheckBox` with its own label on the right side | `wxEVT_CHECKBOX`, then `wxEVT_TOGGLEBUTTON` | control id/object | `SetValue` silent | on the control or an ancestor, **one** of the two | | `::RadioGroup` | `wxRadioBox` | `wxEVT_COMMAND_RADIOBOX_SELECTED` | group id, no object | **every** `SetSelection` emits | on the group or an ancestor | | `::TabCtrl` | tab bar | `wxEVT_TAB_SEL_CHANGING` then `wxEVT_TAB_SEL_CHANGED` (plain `wxCommandEvent`) | tab ctrl id/object; CHANGING carries the old index | `SelectItem(i)` emits both when `i` changes | on the ctrl or an ancestor; cannot veto | | `Button` | `wxButton` | `wxEVT_BUTTON` | button id/object | — | on the button or an ancestor | @@ -815,9 +817,10 @@ two arrow `Button`s with key-repeat; `SetValue/GetValue/SetRange/SetStep`. ### CheckBox and SwitchButton -`::CheckBox` (ctor `CheckBox(parent, id = wxID_ANY)`, no label — pair it with a `wxStaticText`/`Label`, as -`CloneDialog` does) and `SwitchButton` are `wxBitmapToggleButton`s. They emit `wxEVT_TOGGLEBUTTON`, never -`wxEVT_CHECKBOX`; `SetValue` sends nothing. The half state is drawn only (`SetHalfChecked`/`IsHalfChecked`); any click +`::CheckBox` (ctor `CheckBox(parent, id = wxID_ANY)`, no label — when the label is on the right side of the check +box and belongs to it, use `LabeledCheckBox`, `references/orca-widgets.md §LabeledCheckBox`) and `SwitchButton` are +`wxBitmapToggleButton`s. They emit `wxEVT_TOGGLEBUTTON`, never `wxEVT_CHECKBOX`; `SetValue` sends nothing. The half +state is drawn only (`SetHalfChecked`/`IsHalfChecked`); any click clears it via the widget's own `wxEVT_TOGGLEBUTTON` handler (bound in the constructor), which also swaps the on/off bitmap. Handlers bound later on the same widget run first, so they must `Skip()`, or the bitmap keeps showing the old state and the half state is never cleared (`PreferencesDialog::create_item_bambu_cloud` marks this with "let diff --git a/.claude/skills/orca-wxwidgets/references/events.md b/.claude/skills/orca-wxwidgets/references/events.md index 98944c9646..f98c21220e 100644 --- a/.claude/skills/orca-wxwidgets/references/events.md +++ b/.claude/skills/orca-wxwidgets/references/events.md @@ -941,6 +941,10 @@ The per-widget table (event types, ids and event objects, which setters emit, wh constructor (clears the half state, refreshes the bitmap, Skips); `TextInput`'s handlers on the inner control run `OnEdit` and the re-dispatch. A user handler bound on the widget (or on `GetTextCtrl()`) for those events must `Skip()`. Capture-lost handling: `references/mouse-keyboard-focus.md`. +- **`LabeledCheckBox` re-emits.** It consumes its inner check's `wxEVT_TOGGLEBUTTON` and sends `wxEVT_CHECKBOX`, then + `wxEVT_TOGGLEBUTTON`, from itself (own id and object), for label clicks too. It has no handler of its own for the + two, so a handler bound on it needs no `Skip()` — but one bound to both runs twice + (`references/orca-widgets.md §LabeledCheckBox`). - **`EVT_ENABLE_CHANGED`** (`StateHandler.hpp`, a `wxCommandEvent` with id 0) comes from the `Enable` overrides of `Button`, `SpinInput`, `RadioGroup` and the other `StateHandler` widgets. `StateHandler` Skips it, so it propagates to ancestors like any command event. diff --git a/.claude/skills/orca-wxwidgets/references/orca-widgets.md b/.claude/skills/orca-wxwidgets/references/orca-widgets.md index 0efc91fb0a..b52cf90a3d 100644 --- a/.claude/skills/orca-wxwidgets/references/orca-widgets.md +++ b/.claude/skills/orca-wxwidgets/references/orca-widgets.md @@ -12,7 +12,8 @@ Contents: [Rules](#rules) · [Why the library exists](#why-the-library-exists) [Namespaces](#namespaces-and-the-checkbox-clash) · [Catalog](#catalog) · [Event semantics](#event-semantics) · [Custom vs raw](#custom-vs-raw) · [Shared lifecycle rules](#shared-lifecycle-rules) · [Button](#button) · [DialogButtons](#dialogbuttons) · [Label and HyperLink](#label-and-hyperlink) · [CheckBox](#checkbox-and-radiobox) · -[SwitchButton family](#switchbutton-family) · [RadioGroup](#radiogroup) · [TextInput](#textinput) · +[LabeledCheckBox](#labeledcheckbox) · [SwitchButton family](#switchbutton-family) · [RadioGroup](#radiogroup) · +[TextInput](#textinput) · [ComboBox and DropDown](#combobox-and-dropdown) · [SpinInput](#spininput-and-tempinput) · [Tab systems](#tab-systems) · [StaticBox, LabeledStaticBox, StaticLine](#staticbox-labeledstaticbox-staticline) · [ProgressBar](#progressbar) · [ScrolledWindow](#scrolledwindow) · [PopupWindow](#popupwindow) · @@ -21,9 +22,9 @@ Contents: [Rules](#rules) · [Why the library exists](#why-the-library-exists) ## Rules -1. Interactive controls in new or modified UI are Orca widgets (`Button`, `::CheckBox`, `::ComboBox`, `::TextInput`, - `SpinInput`, `SwitchButton`, `RadioGroup`, `TabCtrl`); never `wxButton`, `wxSpinCtrl`, `wxCheckBox`, `wxChoice` or - a single-line `wxTextCtrl` in new code. → §Custom vs raw +1. Interactive controls in new or modified UI are Orca widgets (`Button`, `::CheckBox`, `LabeledCheckBox`, + `::ComboBox`, `::TextInput`, `SpinInput`, `SwitchButton`, `RadioGroup`, `TabCtrl`); never `wxButton`, `wxSpinCtrl`, + `wxCheckBox`, `wxChoice` or a single-line `wxTextCtrl` in new code. → §Custom vs raw 2. Every dialog's bottom button row is `DialogButtons`. → §DialogButtons 3. Inside `namespace Slic3r::GUI` write `::CheckBox`, `::TextInput`, `::ComboBox` (also in `dynamic_cast` and forward declarations, which go at global scope). → §Namespaces @@ -38,7 +39,8 @@ Contents: [Rules](#rules) · [Why the library exists](#why-the-library-exists) 7. Know which setters emit: `RadioGroup::SetSelection`, `MultiSwitchButton::SetSelection`, `TabCtrl::SelectItem`, `Notebook::SetSelection`, an editable `ComboBox::SetSelection` (as `wxEVT_TEXT`) and `SpinInput::SetValue` (as `wxEVT_TEXT` + `EVT_SPINCTRL_TEXT`) do. → §Event semantics -8. `::CheckBox` and `SwitchButton` emit `wxEVT_TOGGLEBUTTON`, never `wxEVT_CHECKBOX`. → §CheckBox and RadioBox +8. `::CheckBox` and `SwitchButton` emit `wxEVT_TOGGLEBUTTON`, never `wxEVT_CHECKBOX`; `LabeledCheckBox` sends both + from itself. → §CheckBox and RadioBox, §LabeledCheckBox 9. Set a container's background colour before creating widgets in it. → §Shared lifecycle rules 10. Enable/disable custom widgets individually; disabling an ancestor leaves them painted enabled (`::CheckBox`, a native button, greys with it). → §Shared lifecycle rules @@ -61,6 +63,9 @@ Contents: [Rules](#rules) · [Why the library exists](#why-the-library-exists) → §StaticBox, LabeledStaticBox, StaticLine 21. Links are `HyperLink`, or a `Label` given `LB_HYPERLINK` through `SetWindowStyleFlag` (the constructor ignores it). → §Label and HyperLink +22. When the label is on the right side of the check box and belongs to it, use a `LabeledCheckBox`, not a + `::CheckBox` paired with a label by hand. Bind **one** of its two events; change its label, font and wrap through + the control; read its enabled state through a `LabeledCheckBox*`. → §LabeledCheckBox ## Why the library exists @@ -134,6 +139,7 @@ class, which is not a `wxWindow`. `TextCtrl` also names the MSW `wxTextCtrl` sub | `Label` | `wxStaticText` | `wxStaticText` | `Label(parent, text = "", style = 0, size)` (font `Body_14`), `Label(parent, font, text, style, size)` | `LB_AUTO_WRAP`, `LB_PROPAGATE_MOUSE_EVENT`, `LB_HYPERLINK` (via `SetWindowStyleFlag`); hosts the font table. §Label | | `HyperLink` (`Slic3r::GUI`) | `wxHyperlinkCtrl` | `wxStaticText` | `HyperLink(parent, label = "", url = "", style = 0)` | opens `url` with `wxLaunchDefaultBrowser` on left-down. §Label | | `::CheckBox` | `wxCheckBox` | `wxBitmapToggleButton` | `CheckBox(parent, id = wxID_ANY)` — **no label** | emits `wxEVT_TOGGLEBUTTON`; `SetHalfChecked`; `Rescale()`. §CheckBox | +| `LabeledCheckBox` | `wxCheckBox` with a label, a `::CheckBox` paired with its own label on the right side | `wxPanel` | `LabeledCheckBox(parent, label = "", id = wxID_ANY)` | clickable label with focus frame; emits `wxEVT_CHECKBOX` **and** `wxEVT_TOGGLEBUTTON`; `Wrap(width)`/`AutoWrap()`; `GetLabelCtrl()`; `Rescale()`. §LabeledCheckBox | | `SwitchButton` | on/off `wxCheckBox`, `wxToggleButton` | `wxBitmapToggleButton` | `SwitchButton(parent = nullptr, id = wxID_ANY)` | `SetLabels(on, off)`; track/thumb/text `StateColor`s; emits `wxEVT_TOGGLEBUTTON`. §SwitchButton family | | `MultiSwitchButton` | segmented `wxRadioBox` | `StaticBox` | `MultiSwitchButton(parent, id, pos, size, style)` | emits `wxCUSTOMEVT_MULTISWITCH_SELECTION`, also from `SetSelection`. §SwitchButton family | | `RadioGroup` | `wxRadioBox`, `wxRadioButton` rows | `wxPanel` | `RadioGroup(parent, std::vector labels, wxHORIZONTAL/wxVERTICAL, row_col_limit = -1)` | emits `wxEVT_RADIOBOX` from **every** `SetSelection`. §RadioGroup | @@ -164,6 +170,7 @@ Field classes (`Field.cpp`) build their editors from these widgets (`TextCtrl` |---|---|---|---|---| | `Button` | `wxEVT_BUTTON` (on release inside, Space/Enter) | button id / button | `SetValue(bool)` (Checked look) silent | on the button (Rule 6) | | `::CheckBox`, `SwitchButton` | `wxEVT_TOGGLEBUTTON` | native id / widget | `SetValue`, `SetHalfChecked` silent (`interface/wx/tglbtn.h:98`) | on the widget; never `wxEVT_CHECKBOX` | +| `LabeledCheckBox` | `wxEVT_CHECKBOX`, then `wxEVT_TOGGLEBUTTON` (int = new value), also from a label click | control id / control | `SetValue`, `SetHalfChecked` silent | on the control, **one** of the two; no `Skip()` needed for the bitmap | | `::ComboBox` | `wxEVT_COMBOBOX` (int = index, string = text) from popup pick, arrow keys (read-only combo), `SelectAndNotify`; `wxEVT_COMBOBOX_DROPDOWN`/`_CLOSEUP` | COMBOBOX: combo's auto id / combo; DROPDOWN/CLOSEUP: **id 0, no object** | `SetSelection`, `SetValue` silent for COMBOBOX; editable or `CB_NO_TEXT`: they send `wxEVT_TEXT` | on the combo | | `::TextInput` | inner `wxEVT_TEXT` (propagates); `wxEVT_TEXT_ENTER`, `wxEVT_KILL_FOCUS` re-sent to the wrapper only | TEXT: **inner** id/object; ENTER/KILL_FOCUS: wrapper id, inner object | `GetTextCtrl()->SetValue` sends `wxEVT_TEXT`; `ChangeValue` silent | TEXT: wrapper, inner, or ancestor by type; ENTER/KILL_FOCUS: wrapper or inner | | `SpinInput` | `wxEVT_SPINCTRL` (a plain `wxCommandEvent`, no int) on commit; `EVT_SPINCTRL_TEXT` (int + string) per parseable keystroke; inner `wxEVT_TEXT` | spinner id / spinner | `SetValue` sends `EVT_SPINCTRL_TEXT` + `wxEVT_TEXT`, no `wxEVT_SPINCTRL` | on the spinner; handler takes `wxCommandEvent&` | @@ -221,7 +228,9 @@ No Orca replacement exists — use raw wx (`references/controls-dataview.md`) fo **Background snapshot.** `StaticBox::Create`, `Label`, `SwitchButton` (through `StaticBox::GetParentBackgroundColor`: a parent `StaticBox`'s default fill — the midpoint for a gradient — else `parent->GetBackgroundColour()`), and -`::CheckBox`, `RadioGroup` (`parent->GetBackgroundColour()`) copy the parent's background colour at construction; +`::CheckBox`, `RadioGroup` (`parent->GetBackgroundColour()`) copy the parent's background colour at construction, and +so does `LabeledCheckBox` (`GetParentBackground` in `LabeledCheckBox.cpp`: the parent's colour, or under a scrolled +window the colour of that window's child on the parent chain); wx itself never inherits a background colour ([source] `src/common/wincmn.cpp:1543-1552`). - **Rule:** Set the container's background before creating widgets in it. ```cpp @@ -242,7 +251,8 @@ its disabled bitmap (`src/msw/window.cpp:576-593`, `src/msw/anybutton.cpp:846-87 button image draws a greyed copy of the current bitmap while `!IsEnabled()` (`src/gtk/image_gtk.cpp:37-42`), though the disabled bitmap itself needs `IsThisEnabled()` false (`src/gtk/anybutton.cpp:140-146`); macOS sends `setEnabled:NO` (`src/osx/cocoa/window.mm:3784-3791`) and AppKit dims the image (`NSButtonCell` -`imageDimsWhenDisabled`, default YES). +`imageDimsWhenDisabled`, default YES). A `LabeledCheckBox` is half of each: its inner check greys with the parent, its +label keeps the enabled colour, which only `LabeledCheckBox::Enable` changes. - **Rule:** Enable/disable each custom widget directly (`RadioGroup::Enable` does this for its own buttons). ```cpp m_options_panel->Enable(on); // Wrong: widgets keep the enabled look @@ -251,8 +261,8 @@ the disabled bitmap itself needs `IsThisEnabled()` false (`src/gtk/anybutton.cpp ``` **DPI.** Widgets size themselves from `FromDIP` values and cached bitmaps; after a DPI change the owning -`DPIDialog::on_dpi_changed` must call `Rescale()` on each (`Button`, `::CheckBox`, `::TextInput`, `::ComboBox` -(also rescales its `DropDown`), `SpinInput`, `SwitchButton`, `MultiSwitchButton`, `TabCtrl`, `StaticLine`, +`DPIDialog::on_dpi_changed` must call `Rescale()` on each (`Button`, `::CheckBox`, `LabeledCheckBox`, `::TextInput`, +`::ComboBox` (also rescales its `DropDown`), `SpinInput`, `SwitchButton`, `MultiSwitchButton`, `TabCtrl`, `StaticLine`, `ModeSwitchButton`). Exceptions: `RadioGroup`, `Label`, `HyperLink` and `LabeledStaticBox` (its scale is fixed in `Create()`) have no `Rescale()`; `ProgressBar::Rescale()` is empty; `DialogButtons` rescales itself. Pass sizes through `FromDIP` (`references/dpi-bitmaps-fonts.md`). @@ -276,7 +286,8 @@ it re-reads colours, e.g. `SwitchButton`), and keep `UpdateDlgDarkUI(this)` as t a label, font, icon, style or DPI changes, and the bitmap toggles (`::CheckBox`, `SwitchButton`) size themselves to their bitmap in `Rescale()`. Nothing re-lays out the parent: call `Layout()` on the container after changing a widget's content at runtime -(`references/sizers-layout.md`). +(`references/sizers-layout.md`). `LabeledCheckBox` is the exception: its setters re-fit it and send the parent a size +event (§LabeledCheckBox). **Mouse capture.** `Button`, `DropDown`, `SpinInput`'s arrows, `ModeSwitchButton`, `MyScrollbar`, `StepCtrl` and the device-page `SideButton`, `ImageSwitchButton` and `AxisCtrlButton` capture the mouse while pressed; a capture leak @@ -461,8 +472,10 @@ Pitfalls: ## CheckBox and RadioBox `::CheckBox` (`Widgets/CheckBox.cpp`) is a `wxBitmapToggleButton` (`wxBORDER_NONE`) showing 18 px SVGs -`check_{on,half,off}`, `…_disabled`, `…_focused`. It has **no label**: pair it with a `wxStaticText`/`Label` -(as `CloneDialog::CloneDialog` does). `GetValue()` is a 2-state `bool`. +`check_{on,half,off}`, `…_disabled`, `…_focused`. It has **no label**: when the label is on the right side of the +check box and belongs to it, use a `LabeledCheckBox` (§LabeledCheckBox); pair a bare `::CheckBox` with a +`wxStaticText`/`Label` only where the label sits elsewhere, such as on the left side in the label column of a form +row (as `CloneDialog::CloneDialog` does). `GetValue()` is a 2-state `bool`. - Emits `wxEVT_TOGGLEBUTTON` on click (native). `SetValue` emits nothing (`interface/wx/tglbtn.h:98`). - `SetHalfChecked(true)` is a drawn-only third state (`IsHalfChecked()` exists for the inspector only); the widget's own toggle handler clears it on any click. `SetValue` does **not** clear it — call `SetHalfChecked(false)` before showing a definite @@ -488,6 +501,94 @@ Pitfalls: cb->Bind(wxEVT_TOGGLEBUTTON, [this](wxCommandEvent& e) { e.Skip(); apply(); }); // Right ``` +## LabeledCheckBox + +`LabeledCheckBox` (`Widgets/LabeledCheckBox.cpp`, global namespace) is the check box with its own label on the +right side: a `wxPanel` holding a `::CheckBox` and, to its right, a `StaticBox` frame around a `Label`. The label +must belong to the check box, that is, name the option the box switches. Other text that only shares the row (a +value, a unit, a link, the label of the next control) is not its label, however close it sits, and stays a separate +window. The control has no other label position: a label on the left side or in a separate column stays a +`::CheckBox` paired with a label (§CheckBox and RadioBox). Constructor +`LabeledCheckBox(parent, label = "", id = wxID_ANY)`; font `Body_14`, label colour `#363636` (dark-mapped at +construction). An empty label hides the frame and leaves the bare check. + +- **Value.** `SetValue(bool)`, `GetValue()`/`IsChecked()`, `SetHalfChecked(bool = true)`. The half state is + `::CheckBox`'s: drawn only, cleared by any user toggle, not by `SetValue`. No setter emits. +- **Events.** A user toggle — a click on the check, Space on the focused check, a left click on the label or its + frame — sends `wxEVT_CHECKBOX` and then `wxEVT_TOGGLEBUTTON` from the control (`LabeledCheckBox::OnToggled`): the + control's current id (so `SetId()` after construction works), the control as event object, `IsChecked()`/`GetInt()` + = the new value. A double click on the label toggles twice (its second click arrives as `wxEVT_LEFT_DCLICK`). The + inner check's own `wxEVT_TOGGLEBUTTON` is consumed, so an ancestor bound by type gets one event of each type per + toggle. The control has no handler of its own for the two events: a handler bound on it needs no `Skip()` to keep + the bitmap right; `Skip()` only lets ancestors see the event. For a label click both events are sent from inside + the label's `wxEVT_LEFT_DOWN` handler, so a handler that opens a modal dialog defers it with `CallAfter` + (`references/windows-dialogs.md` rule 19). +- **Focus.** The inner check holds the keyboard focus; frame and label never take it, and a label click moves the + focus to the check. `HasFocus()` reports the check's focus. The frame's border is the focus indicator + (`LabeledCheckBox::ShowFocus`): `#009688` when focused, the background colour otherwise. +- **Hover.** While the pointer is on the label or its frame, the check shows its hover bitmap + (`LabeledCheckBox::ShowHover`). +- **Enable.** `Enable(bool)` disables the inner check and greys the label (`#6B6A6A`, dark-mapped); the panel itself + stays enabled. `IsEnabled()` is a non-virtual shadow that returns the check's state. A disabled control ignores + label clicks. +- **Setters go through the control.** `SetLabel`, `SetFont`, `Wrap`, `AutoWrap` and `Rescale` update the label, + re-fit the control (`Fit()`) and send the parent a size event (`LabeledCheckBox::Relayout`), so a sizer-managed + parent lays out again; a top-level window is not re-fitted. `SetForegroundColour` sets the enabled label colour, + `SetBackgroundColour` reaches check, frame and label, and a tooltip set on the control is copied to all three + (`DoSetToolTip`). `GetLabelCtrl()` returns the inner `Label`. +- **Wrapping** is `Label::Wrap` on the stored text. `Wrap(width)` wraps the text to `width` px minus the check and + the padding, so the whole control fits `width`; `width <= 0` unwraps. `AutoWrap(true)` re-wraps to the width the + control is given on every `wxEVT_SIZE`, so it needs a sizer item that gives it a width (`wxEXPAND` in a vertical + sizer, or a proportion) inside a container whose width comes from elsewhere: until the first layout the control + reports its unwrapped width. Each of the two calls cancels the other mode. With a wrapped label the check stays + centred on the first text line. +- **Metrics.** The padding around the text is `FromDIP(wxSize(5, 2))`, the padding of `RadioGroup`'s label buttons + (`RadioGroup::Create`), and both icons are 18 px: a `LabeledCheckBox` and a `RadioGroup` added with the same left + border line up icon under icon and text under text. Unlike `RadioGroup`, which puts `FromDIP(4)` above and below + each row, the control adds no outer margin; row spacing is the sizer's. +- **DPI.** `Rescale()` rescales the check and re-fits; call it from `on_dpi_changed`. +- **[source] Bitmap states on MSW.** Setting the normal bitmap of a bitmap button (`SetBitmapLabel`) deletes the + button's image data, so the bitmaps set for the other states are gone and their getters (`GetBitmapCurrent()`, …) + return a null bitmap until they are set again (`src/msw/anybutton.cpp:770-783`, `:785-796`); a null normal bitmap + then removes the image without a refresh (`:797-812`). wxGTK keeps one bitmap per state + (`src/gtk/anybutton.cpp:198-201`, `:391`). `LabeledCheckBox::ShowHover` shows the hover art by copying the check's + hover bitmap into its normal state, and therefore lets `::CheckBox` set all its bitmaps again first. + +Pitfalls: +- **Rule:** When the label is on the right side of the check box and belongs to it, use one `LabeledCheckBox`; + don't pair a `::CheckBox` with a `wxStaticText`/`Label` and forward the label's clicks by hand. + **Why:** the hand-made pair needs its own sizer, label styling, click and double-click forwarding, disabled + colour and tooltip on both windows, and still shows no focus frame on the label. + ```cpp + auto* cb = new ::CheckBox(this); // Wrong: two windows wired by hand + auto* lbl = new wxStaticText(this, wxID_ANY, _L("Don't show again")); + lbl->Bind(wxEVT_LEFT_DOWN, [cb](wxMouseEvent&) { cb->SetValue(!cb->GetValue()); /* + send the event */ }); + auto* cb = new LabeledCheckBox(this, _L("Don't show again")); // Right + ``` +- **Rule:** Bind **one** of the two events. + **Why:** both are sent for every toggle, so that a handler written for a `wxCheckBox` (`wxEVT_CHECKBOX`) or for a + `::CheckBox` (`wxEVT_TOGGLEBUTTON`) keeps working when the control replaces either; a handler bound to both runs + twice. + ```cpp + cb->Bind(wxEVT_CHECKBOX, h); cb->Bind(wxEVT_TOGGLEBUTTON, h); // Wrong: h runs twice + cb->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent& e) { apply(e.IsChecked()); e.Skip(); }); // Right + ``` +- **Rule:** Change the label, font and wrap through the control, not through `GetLabelCtrl()`. + **Why:** only the control's own setters re-wrap, re-fit and notify the parent. + ```cpp + cb->GetLabelCtrl()->SetLabel(text); // Wrong: the control keeps its old size and wrap + cb->SetLabel(text); // Right + ``` +- **Rule:** Read the enabled state through a `LabeledCheckBox*`. + **Why:** `Enable()` is virtual and works through any pointer, but `IsEnabled()` is not: through a `wxWindow*` it + reports the panel, which stays enabled (`src/common/wincmn.cpp:1142-1145`). The rule of §Shared lifecycle rules + holds too: disabling an ancestor greys the inner check but not the label — call the control's `Enable()`. + ```cpp + wxWindow* w = cb; cb->Enable(false); + if (w->IsEnabled()) { /* Wrong: still true */ } + if (cb->IsEnabled()) { /* Right: false */ } + ``` + ## SwitchButton family All in `Widgets/SwitchButton.hpp/.cpp`: diff --git a/.claude/skills/orca-wxwidgets/references/sizers-layout.md b/.claude/skills/orca-wxwidgets/references/sizers-layout.md index 8f58cac3c8..16b68a3ddf 100644 --- a/.claude/skills/orca-wxwidgets/references/sizers-layout.md +++ b/.claude/skills/orca-wxwidgets/references/sizers-layout.md @@ -636,7 +636,9 @@ single-line `wxST_ELLIPSIZE_END` labels; other modes are generic (`src/msw/statt - the label needs a real width: a ctor size `wxSize(FromDIP(w), -1)`, min = max width, or `wxEXPAND` in a vertical sizer whose container width is fixed; - `Label::split_lines(dc, width, text, out, max_count)` exposes the same wrapper for owner-drawn text. -Orca's wrapping is preferred over `wxST_WRAP` for CJK text. +Orca's wrapping is preferred over `wxST_WRAP` for CJK text. A check box label wraps through +`LabeledCheckBox::Wrap(width)`/`AutoWrap()`, which also re-fit the control (`references/orca-widgets.md +§LabeledCheckBox`). **Pitfalls** - **Rule:** Re-wrapping after `SetLabel` must defeat the wrap cache. diff --git a/src/slic3r/CMakeLists.txt b/src/slic3r/CMakeLists.txt index 268b48c664..ef017ffb41 100644 --- a/src/slic3r/CMakeLists.txt +++ b/src/slic3r/CMakeLists.txt @@ -628,9 +628,11 @@ set(SLIC3R_GUI_SOURCES GUI/Widgets/ImageSwitchButton.cpp GUI/Widgets/ImageSwitchButton.hpp GUI/Widgets/Label.cpp + GUI/Widgets/Label.hpp GUI/Widgets/LabeledStaticBox.cpp GUI/Widgets/LabeledStaticBox.hpp - GUI/Widgets/Label.hpp + GUI/Widgets/LabeledCheckBox.cpp + GUI/Widgets/LabeledCheckBox.hpp GUI/Widgets/PopupWindow.cpp GUI/Widgets/PopupWindow.hpp GUI/Widgets/ProgressBar.cpp diff --git a/src/slic3r/GUI/GeometryImportDialog.cpp b/src/slic3r/GUI/GeometryImportDialog.cpp index 0f276e7028..01be417d51 100644 --- a/src/slic3r/GUI/GeometryImportDialog.cpp +++ b/src/slic3r/GUI/GeometryImportDialog.cpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include @@ -30,9 +29,9 @@ #include "MsgDialog.hpp" #include "slic3r/GUI/format.hpp" #include "Widgets/Button.hpp" -#include "Widgets/CheckBox.hpp" #include "Widgets/DialogButtons.hpp" #include "Widgets/Label.hpp" +#include "Widgets/LabeledCheckBox.hpp" #include "Widgets/RadioGroup.hpp" #include "Widgets/RoundedRectangle.hpp" #include "Widgets/StateColor.hpp" @@ -95,7 +94,7 @@ void add_tip(DPIDialog& dialog, wxBoxSizer& sizer, const wxString& text, int wra sizer.Add(frame, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, dialog.FromDIP(12)); } -ImportCheckBox add_checkbox(DPIDialog& dialog, wxBoxSizer& sizer, const wxString& label, bool value) +LabeledCheckBox* add_checkbox(DPIDialog& dialog, wxBoxSizer& sizer, const wxString& label, bool value) { return add_import_checkbox(&dialog, sizer, label, value, wxLEFT | wxRIGHT | wxTOP, dialog.FromDIP(12)); } @@ -221,55 +220,20 @@ GeometryImportNamePolicy geometry_import_name_policy(const AppConfig& config) return policy; } -bool ImportCheckBox::GetValue() const { return box->GetValue(); } - -void ImportCheckBox::SetValue(bool value) const { box->SetValue(value); } - -void ImportCheckBox::Enable(bool enable) const +LabeledCheckBox* add_import_checkbox(wxWindow* parent, wxSizer& sizer, const wxString& text, bool value, int flags, int border) { - box->Enable(enable); - label->Enable(enable); - // Same disabled text color as RadioGroup. - label->SetForegroundColour(enable ? StateColor::darkModeColorFor(wxColour("#363636")) : wxColour("#6B6A6A")); - label->Refresh(); -} - -void ImportCheckBox::SetToolTip(const wxString& tip) const -{ - box->SetToolTip(tip); - label->SetToolTip(tip); -} - -ImportCheckBox add_import_checkbox(wxWindow* parent, wxSizer& sizer, const wxString& text, bool value, int flags, int border) -{ - ImportCheckBox checkbox{new ::CheckBox(parent), new wxStaticText(parent, wxID_ANY, text)}; - apply_label_style(checkbox.label); - checkbox.box->SetValue(value); - ::CheckBox* box = checkbox.box; - auto toggle = [box]() { - if (!box->IsEnabled()) - return; - box->SetValue(!box->GetValue()); - wxCommandEvent event(wxEVT_TOGGLEBUTTON, box->GetId()); - event.SetEventObject(box); - box->GetEventHandler()->ProcessEvent(event); - }; - // A double click arrives as one down and one double-click event, so each toggles once. - checkbox.label->Bind(wxEVT_LEFT_DOWN, [toggle](wxMouseEvent&) { toggle(); }); - checkbox.label->Bind(wxEVT_LEFT_DCLICK, [toggle](wxMouseEvent&) { toggle(); }); - auto* row = new wxBoxSizer(wxHORIZONTAL); - row->Add(checkbox.box, 0, wxALIGN_CENTER_VERTICAL); - row->Add(checkbox.label, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, parent->FromDIP(5)); - sizer.Add(row, 0, flags, border); + auto* checkbox = new LabeledCheckBox(parent, text); + checkbox->SetValue(value); + sizer.Add(checkbox, 0, flags, border); return checkbox; } // Sorting only makes sense for original names; while Keep is off it is disabled but keeps its remembered value. -void link_sort_to_keep(const ImportCheckBox& keep, const ImportCheckBox& sort) +void link_sort_to_keep(LabeledCheckBox* keep, LabeledCheckBox* sort) { - sort.Enable(keep.GetValue()); - keep.box->Bind(wxEVT_TOGGLEBUTTON, [keep, sort](wxCommandEvent& event) { - sort.Enable(keep.GetValue()); + sort->Enable(keep->GetValue()); + keep->Bind(wxEVT_CHECKBOX, [keep, sort](wxCommandEvent& event) { + sort->Enable(keep->GetValue()); event.Skip(); }); } @@ -300,15 +264,15 @@ bool show_geometry_import_options(wxWindow* parent, const std::string& format, G load_mode->SetRadioTooltip(2, _L("The original bodies and names are kept inside the object. Use Split to parts to show them as separate parts.")); sizer->Add(load_mode, 0, wxLEFT | wxRIGHT | wxTOP, dialog.FromDIP(12)); } - const auto keep = add_checkbox(dialog, *sizer, _L("Keep original names"), options.keep_names); - keep.SetToolTip(_L("Use the body names stored in the file, when there are any. When disabled, the usual OrcaSlicer names are used; existing project names are kept.")); - const auto sort = add_checkbox(dialog, *sizer, _L("Sort parts by name"), options.sort_names); - sort.SetToolTip(_L("Sort the parts inside each imported assembly in the object list. This does not change the order used for slicing. Available when Keep original names is on.")); + auto* keep = add_checkbox(dialog, *sizer, _L("Keep original names"), options.keep_names); + keep->SetToolTip(_L("Use the body names stored in the file, when there are any. When disabled, the usual OrcaSlicer names are used; existing project names are kept.")); + auto* sort = add_checkbox(dialog, *sizer, _L("Sort parts by name"), options.sort_names); + sort->SetToolTip(_L("Sort the parts inside each imported assembly in the object list. This does not change the order used for slicing. Available when Keep original names is on.")); link_sort_to_keep(keep, sort); - const auto remember = add_checkbox(dialog, *sizer, _L("Remember my choice"), false); - remember.SetToolTip(_L("Use these choices as defaults next time. The dialog still opens.")); - const auto dont_ask = add_checkbox(dialog, *sizer, _L("Don't ask again"), false); - dont_ask.SetToolTip(_L("Save these choices and apply them without asking next time. You can show this dialog again in Preferences.")); + auto* remember = add_checkbox(dialog, *sizer, _L("Remember my choice"), false); + remember->SetToolTip(_L("Use these choices as defaults next time. The dialog still opens.")); + auto* dont_ask = add_checkbox(dialog, *sizer, _L("Don't ask again"), false); + dont_ask->SetToolTip(_L("Save these choices and apply them without asking next time. You can show this dialog again in Preferences.")); auto* buttons = new DialogButtons(&dialog, {"OK", "Cancel"}); buttons->GetOK()->Bind(wxEVT_BUTTON, [&](wxCommandEvent&) { dialog.EndModal(wxID_OK); }); @@ -321,16 +285,16 @@ bool show_geometry_import_options(wxWindow* parent, const std::string& format, G if (dialog.ShowModal() != wxID_OK) return false; - options.keep_names = keep.GetValue(); - options.sort_names = sort.GetValue(); + options.keep_names = keep->GetValue(); + options.sort_names = sort->GetValue(); if (load_mode != nullptr) { options.separate_objects = load_mode->GetSelection() == 0; // Separate objects leave the remembered assembly choice as it was. if (!options.separate_objects) options.load_as_assembly = load_mode->GetSelection() == 1; } - options.remember = remember.GetValue(); - options.dont_ask = dont_ask.GetValue(); + options.remember = remember->GetValue(); + options.dont_ask = dont_ask->GetValue(); return true; } @@ -375,10 +339,10 @@ bool prepare_geometry_import_names(wxWindow* parent, const std::vector& wxTE_MULTILINE | wxTE_READONLY | wxTE_DONTWRAP); apply_label_style(preview); sizer->Add(preview, 1, wxEXPAND | wxALL, dialog.FromDIP(12)); - const auto remember = add_checkbox(dialog, *sizer, _L("Remember my choice"), false); - remember.SetToolTip(_L("Use this rule as the default next time. The dialog still opens.")); - const auto dont_ask = add_checkbox(dialog, *sizer, _L("Don't ask again"), false); - dont_ask.SetToolTip(_L("Save this rule and apply it without asking next time. You can show this dialog again in Preferences.")); + auto* remember = add_checkbox(dialog, *sizer, _L("Remember my choice"), false); + remember->SetToolTip(_L("Use this rule as the default next time. The dialog still opens.")); + auto* dont_ask = add_checkbox(dialog, *sizer, _L("Don't ask again"), false); + dont_ask->SetToolTip(_L("Save this rule and apply it without asking next time. You can show this dialog again in Preferences.")); auto* buttons = new DialogButtons(&dialog, {"OK", "Cancel"}); auto update_preview = [&]() { @@ -415,8 +379,8 @@ bool prepare_geometry_import_names(wxWindow* parent, const std::vector& return false; policy.remove = rule->GetSelection() == 0; policy.replacement = into_u8(replacement->GetTextCtrl()->GetValue()); - policy.remember = remember.GetValue(); - policy.dont_ask = dont_ask.GetValue(); + policy.remember = remember->GetValue(); + policy.dont_ask = dont_ask->GetValue(); } const auto results = cleaned_groups(groups, policy.remove ? std::string() : policy.replacement); diff --git a/src/slic3r/GUI/GeometryImportDialog.hpp b/src/slic3r/GUI/GeometryImportDialog.hpp index 7623e7e981..be0d96b713 100644 --- a/src/slic3r/GUI/GeometryImportDialog.hpp +++ b/src/slic3r/GUI/GeometryImportDialog.hpp @@ -3,9 +3,8 @@ #include #include -class CheckBox; +class LabeledCheckBox; class wxSizer; -class wxStaticText; class wxString; class wxWindow; @@ -49,20 +48,10 @@ bool is_geometry_only_3mf(const std::string& path); GeometryImportOptions geometry_import_options(const AppConfig& config, const std::string& format); GeometryImportNamePolicy geometry_import_name_policy(const AppConfig& config); bool show_geometry_import_options(wxWindow* parent, const std::string& format, GeometryImportOptions& options); -// App-styled check box with its label, shared by the import dialogs. -struct ImportCheckBox { - ::CheckBox* box = nullptr; - wxStaticText* label = nullptr; - bool GetValue() const; - void SetValue(bool value) const; - // Greys the label too and stops it toggling the box. - void Enable(bool enable) const; - void SetToolTip(const wxString& tip) const; -}; -// A click on the label toggles the box and sends its wxEVT_TOGGLEBUTTON, as a click on the box does. -ImportCheckBox add_import_checkbox(wxWindow* parent, wxSizer& sizer, const wxString& text, bool value, int flags, int border); +// Check box with its label, shared by the import dialogs. +LabeledCheckBox* add_import_checkbox(wxWindow* parent, wxSizer& sizer, const wxString& text, bool value, int flags, int border); // Sorting is offered only together with Keep original names; shared by the STEP dialog. -void link_sort_to_keep(const ImportCheckBox& keep, const ImportCheckBox& sort); +void link_sort_to_keep(LabeledCheckBox* keep, LabeledCheckBox* sort); bool prepare_geometry_import_names(wxWindow* parent, const std::vector& models, GeometryImportNamePolicy& policy); void save_geometry_import_options(AppConfig& config, const std::string& format, const GeometryImportOptions& options); void save_geometry_import_name_policy(AppConfig& config, const GeometryImportNamePolicy& policy); diff --git a/src/slic3r/GUI/MixedFilamentDialog.cpp b/src/slic3r/GUI/MixedFilamentDialog.cpp index d15d14c74d..eb0421ad5e 100644 --- a/src/slic3r/GUI/MixedFilamentDialog.cpp +++ b/src/slic3r/GUI/MixedFilamentDialog.cpp @@ -32,7 +32,6 @@ #include #include #include -#include #include #include @@ -45,7 +44,7 @@ #include "FilamentBitmapUtils.hpp" #include "wxExtensions.hpp" #include "Widgets/Button.hpp" -#include "Widgets/CheckBox.hpp" +#include "Widgets/LabeledCheckBox.hpp" #include "Widgets/ComboBox.hpp" #include "Widgets/DropDown.hpp" #include "Widgets/Label.hpp" @@ -1070,14 +1069,10 @@ wxBoxSizer* MixedFilamentDialog::create_gradient_section() { m_gradient_sizer = new wxBoxSizer(wxHORIZONTAL); - m_chk_gradient = new ::CheckBox(this); + m_chk_gradient = new LabeledCheckBox(this, _L("Gradient Effect")); m_chk_gradient->SetValue(m_result.gradient_enabled); - m_chk_gradient->Bind(wxEVT_TOGGLEBUTTON, [this](wxCommandEvent& e) { e.Skip(); on_gradient_toggled(); }); - m_gradient_sizer->Add(m_chk_gradient, 0, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM, FromDIP(4)); - - m_label_gradient = new wxStaticText(this, wxID_ANY, _L("Gradient Effect")); - m_label_gradient->SetFont(::Label::Body_13); - m_gradient_sizer->Add(m_label_gradient, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, FromDIP(8)); + m_chk_gradient->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent& e) { e.Skip(); on_gradient_toggled(); }); + m_gradient_sizer->Add(m_chk_gradient, 0, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM, FromDIP(2)); m_combo_gradient_dir = new ComboBox(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(FromDIP(152), FromDIP(24)), 0, nullptr, wxCB_READONLY); @@ -1111,17 +1106,12 @@ wxBoxSizer* MixedFilamentDialog::create_gradient_section() // Per-part gradient toggle sits BELOW the curve editor. m_per_part_gradient_sizer = new wxBoxSizer(wxHORIZONTAL); - m_chk_per_part_gradient = new ::CheckBox(this); + m_chk_per_part_gradient = new LabeledCheckBox(this, _L("Enable per-part gradient effect")); m_chk_per_part_gradient->SetValue(m_result.per_part_gradient); - m_chk_per_part_gradient->Bind(wxEVT_TOGGLEBUTTON, + m_chk_per_part_gradient->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent& e) { e.Skip(); on_per_part_gradient_toggled(); }); m_per_part_gradient_sizer->Add(m_chk_per_part_gradient, 0, - wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM, FromDIP(4)); - - m_label_per_part_gradient = new wxStaticText(this, wxID_ANY, _L("Enable per-part gradient effect")); - m_label_per_part_gradient->SetFont(::Label::Body_13); - m_per_part_gradient_sizer->Add(m_label_per_part_gradient, 0, - wxALIGN_CENTER_VERTICAL | wxLEFT, FromDIP(8)); + wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM, FromDIP(2)); outer->Add(m_per_part_gradient_sizer, 0, wxEXPAND | wxTOP, FromDIP(2)); m_per_part_gradient_sizer->ShowItems(m_result.gradient_enabled); @@ -1803,7 +1793,6 @@ void MixedFilamentDialog::update_component_count_ui() if (m_gradient_sizer) { bool show_gradient = is_two; m_chk_gradient->Show(show_gradient); - if (m_label_gradient) m_label_gradient->Show(show_gradient); m_combo_gradient_dir->Show(show_gradient && m_result.gradient_enabled); if (m_per_part_gradient_sizer) m_per_part_gradient_sizer->ShowItems(show_gradient && m_result.gradient_enabled); diff --git a/src/slic3r/GUI/MixedFilamentDialog.hpp b/src/slic3r/GUI/MixedFilamentDialog.hpp index 7d275a5c74..1e60b7c663 100644 --- a/src/slic3r/GUI/MixedFilamentDialog.hpp +++ b/src/slic3r/GUI/MixedFilamentDialog.hpp @@ -20,7 +20,7 @@ #include "libslic3r/FilamentMixer.hpp" class Button; -class CheckBox; +class LabeledCheckBox; class ComboBox; class wxMouseEvent; class wxScrolledWindow; @@ -142,14 +142,12 @@ private: RatioLabelPanel* m_label_ratio_b{nullptr}; wxPanel* m_ratio_editor_panel{nullptr}; wxTextCtrl* m_ratio_editor{nullptr}; - CheckBox* m_chk_gradient{nullptr}; - wxStaticText* m_label_gradient{nullptr}; + LabeledCheckBox* m_chk_gradient{nullptr}; ComboBox* m_combo_gradient_dir{nullptr}; wxBoxSizer* m_gradient_sizer{nullptr}; GradientCurveEditor* m_curve_editor{nullptr}; wxBoxSizer* m_curve_sizer{nullptr}; - CheckBox* m_chk_per_part_gradient{nullptr}; - wxStaticText* m_label_per_part_gradient{nullptr}; + LabeledCheckBox* m_chk_per_part_gradient{nullptr}; wxBoxSizer* m_per_part_gradient_sizer{nullptr}; Button* m_btn_add_material{nullptr}; Button* m_btn_remove_material{nullptr}; diff --git a/src/slic3r/GUI/MsgDialog.cpp b/src/slic3r/GUI/MsgDialog.cpp index db41c7adec..34e0983402 100644 --- a/src/slic3r/GUI/MsgDialog.cpp +++ b/src/slic3r/GUI/MsgDialog.cpp @@ -5,7 +5,7 @@ #include #include #include -#include "slic3r/GUI/Widgets/CheckBox.hpp" +#include "slic3r/GUI/Widgets/LabeledCheckBox.hpp" #include "slic3r/GUI/ReleaseNote.hpp" #include "slic3r/GUI/Widgets/StateColor.hpp" #include "slic3r/GUI/Widgets/Button.hpp" @@ -40,7 +40,6 @@ #include #include #include -#include #include #include @@ -110,30 +109,18 @@ MsgDialog::MsgDialog(wxWindow *parent, const wxString &title, const wxString &he void MsgDialog::show_dsa_button(wxString const &title) { - m_checkbox_dsa = new CheckBox(this); - m_dsa_sizer->Add(m_checkbox_dsa, 0, wxALIGN_CENTER); - m_checkbox_dsa->Bind(wxEVT_TOGGLEBUTTON, [this](wxCommandEvent& e) { + m_checkbox_dsa = new LabeledCheckBox(this, title.IsEmpty() ? _L("Don't show again") : title); + m_checkbox_dsa->SetFont(::Label::Body_13); + m_checkbox_dsa->SetForegroundColour(StateColor::darkModeColorFor(wxColour("#323A3D"))); + m_checkbox_dsa->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent& e) { auto event = wxCommandEvent(EVT_CHECKBOX_CHANGE); - event.SetInt(m_checkbox_dsa->GetValue()?1:0); + event.SetInt(e.IsChecked() ? 1 : 0); event.SetEventObject(this); wxPostEvent(this, event); e.Skip(); }); - - auto m_text_dsa = new wxStaticText(this, wxID_ANY, title.IsEmpty() ? _L("Don't show again") : title, wxDefaultPosition, wxDefaultSize, 0); - auto on_toggle = [this]() { - m_checkbox_dsa->SetValue(!m_checkbox_dsa->GetValue()); - wxCommandEvent ev(wxEVT_TOGGLEBUTTON, m_checkbox_dsa->GetId()); - ev.SetEventObject(m_checkbox_dsa); - m_checkbox_dsa->GetEventHandler()->ProcessEvent(ev); - }; - m_text_dsa->Bind(wxEVT_LEFT_DOWN, [on_toggle](wxMouseEvent& e) {if(!e.LeftDClick()) on_toggle();}); - m_text_dsa->Bind(wxEVT_LEFT_DCLICK, [on_toggle](wxMouseEvent& e) {on_toggle();}); - - m_dsa_sizer->Add(m_text_dsa, 0, wxALL | wxALIGN_CENTER, FromDIP(2)); + m_dsa_sizer->Add(m_checkbox_dsa, 0, wxALIGN_CENTER); m_dsa_sizer->AddSpacer(FromDIP(10)); // spacing after checkbox - m_text_dsa->SetFont(::Label::Body_13); - m_text_dsa->SetForegroundColour(StateColor::darkModeColorFor(wxColour("#323A3D"))); btn_sizer->Layout(); Fit(); } @@ -830,17 +817,9 @@ NetworkErrorDialog::NetworkErrorDialog(wxWindow* parent) wxBoxSizer* sizer_button = new wxBoxSizer(wxHORIZONTAL); /*dont show again*/ - auto checkbox = new ::CheckBox(this); - checkbox->SetValue(false); - - - auto checkbox_title = new Label(this, _L("Don't show this dialog again")); - checkbox_title->SetForegroundColour(0x323A3C); - checkbox_title->SetFont(::Label::Body_14); - checkbox_title->Wrap(-1); - - checkbox->Bind(wxEVT_TOGGLEBUTTON, [this, checkbox](wxCommandEvent &e) { - m_show_again = checkbox->GetValue(); + auto checkbox = new LabeledCheckBox(this, _L("Don't show this dialog again")); + checkbox->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent &e) { + m_show_again = e.IsChecked(); e.Skip(); }); @@ -848,8 +827,7 @@ NetworkErrorDialog::NetworkErrorDialog(wxWindow* parent) m_button_confirm->SetStyle(ButtonStyle::Confirm, ButtonType::Choice); m_button_confirm->Bind(wxEVT_LEFT_DOWN, [this](auto& e) {EndModal(wxCLOSE);}); - sizer_button->Add(checkbox, 0, wxALL, 5); - sizer_button->Add(checkbox_title, 0, wxALL, 5); + sizer_button->Add(checkbox, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5); sizer_button->Add(0, 0, 1, wxEXPAND, 5); sizer_button->Add(m_button_confirm, 0, wxALL, FromDIP(ButtonProps::ChoiceButtonGap())); diff --git a/src/slic3r/GUI/MsgDialog.hpp b/src/slic3r/GUI/MsgDialog.hpp index 21ad283d0a..63c08ad2de 100644 --- a/src/slic3r/GUI/MsgDialog.hpp +++ b/src/slic3r/GUI/MsgDialog.hpp @@ -21,7 +21,7 @@ #include #include #include "Widgets/Button.hpp" -#include "Widgets/CheckBox.hpp" +#include "Widgets/LabeledCheckBox.hpp" #include "Widgets/TextInput.hpp" #include "Widgets/HyperLink.hpp" #include "BBLStatusBar.hpp" @@ -106,7 +106,7 @@ protected: wxBoxSizer *m_dsa_sizer; wxStaticBitmap *logo; MsgButtonsHash m_buttons; - CheckBox* m_checkbox_dsa{nullptr}; + LabeledCheckBox* m_checkbox_dsa{nullptr}; wxString m_forward_str; }; diff --git a/src/slic3r/GUI/PrimitiveSizeDialog.cpp b/src/slic3r/GUI/PrimitiveSizeDialog.cpp index fbd19cc81d..0827fd7d15 100644 --- a/src/slic3r/GUI/PrimitiveSizeDialog.cpp +++ b/src/slic3r/GUI/PrimitiveSizeDialog.cpp @@ -7,9 +7,9 @@ #include "MainFrame.hpp" #include "MsgDialog.hpp" #include "Widgets/Button.hpp" -#include "Widgets/CheckBox.hpp" #include "Widgets/DialogButtons.hpp" #include "Widgets/Label.hpp" +#include "Widgets/LabeledCheckBox.hpp" #include "Widgets/TextInput.hpp" #include "libslic3r/LocalesUtils.hpp" @@ -99,20 +99,11 @@ bool PrimitiveSizeDialog::save_as_default() const { return m_save_default->GetVa bool PrimitiveSizeDialog::dont_show_again() const { return m_dont_show->GetValue(); } -::CheckBox* PrimitiveSizeDialog::add_checkbox(wxSizer* sizer, const wxString& label, const wxString& tooltip) +LabeledCheckBox* PrimitiveSizeDialog::add_checkbox(wxSizer* sizer, const wxString& label, const wxString& tooltip) { - auto checkbox = new ::CheckBox(this); - auto text = new wxStaticText(this, wxID_ANY, label); + auto checkbox = new LabeledCheckBox(this, label); checkbox->SetToolTip(tooltip); - text->SetToolTip(tooltip); - auto toggle = [checkbox](wxMouseEvent&) { checkbox->SetValue(!checkbox->GetValue()); }; - text->Bind(wxEVT_LEFT_DOWN, toggle); - text->Bind(wxEVT_LEFT_DCLICK, toggle); - - auto row = new wxBoxSizer(wxHORIZONTAL); - row->Add(checkbox, 0, wxALIGN_CENTER_VERTICAL); - row->Add(text, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, FromDIP(5)); - sizer->Add(row, 0, wxLEFT | wxRIGHT | wxBOTTOM, FromDIP(10)); + sizer->Add(checkbox, 0, wxLEFT | wxRIGHT | wxBOTTOM, FromDIP(10)); return checkbox; } diff --git a/src/slic3r/GUI/PrimitiveSizeDialog.hpp b/src/slic3r/GUI/PrimitiveSizeDialog.hpp index 8d41a80e4a..a685f5decb 100644 --- a/src/slic3r/GUI/PrimitiveSizeDialog.hpp +++ b/src/slic3r/GUI/PrimitiveSizeDialog.hpp @@ -7,7 +7,7 @@ #include #include -class CheckBox; +class LabeledCheckBox; class TextInput; class wxSizer; class wxWindow; @@ -34,16 +34,16 @@ protected: void on_dpi_changed(const wxRect& suggested_rect) override; private: - ::CheckBox* add_checkbox(wxSizer* sizer, const wxString& label, const wxString& tooltip); + LabeledCheckBox* add_checkbox(wxSizer* sizer, const wxString& label, const wxString& tooltip); void on_input_changed(size_t idx); bool read_values(); std::vector<::TextInput*> m_inputs; // The last valid value of each input, which uniform scaling multiplies. std::vector m_last_values; - ::CheckBox* m_uniform_scale{nullptr}; - ::CheckBox* m_save_default{nullptr}; - ::CheckBox* m_dont_show{nullptr}; + LabeledCheckBox* m_uniform_scale{nullptr}; + LabeledCheckBox* m_save_default{nullptr}; + LabeledCheckBox* m_dont_show{nullptr}; std::vector m_values; }; diff --git a/src/slic3r/GUI/ReleaseNote.cpp b/src/slic3r/GUI/ReleaseNote.cpp index f8845443a2..98ed958a26 100644 --- a/src/slic3r/GUI/ReleaseNote.cpp +++ b/src/slic3r/GUI/ReleaseNote.cpp @@ -23,7 +23,7 @@ #include #include #include "slic3r/GUI/Widgets/HyperLink.hpp" -#include "slic3r/GUI/Widgets/CheckBox.hpp" +#include "slic3r/GUI/Widgets/LabeledCheckBox.hpp" #include #include #include @@ -54,7 +54,6 @@ #include #include #include -#include #include #include #include "Plater.hpp" @@ -382,16 +381,14 @@ UpdateVersionDialog::UpdateVersionDialog(wxWindow *parent) EndModal(wxID_NO); }); - m_cb_stable_only = new CheckBox(this); + m_cb_stable_only = new LabeledCheckBox(this, _L("Check for stable updates only")); + m_cb_stable_only->SetFont(Label::Body_12); m_cb_stable_only->SetValue(wxGetApp().app_config->get_bool("check_stable_update_only")); - m_cb_stable_only->Bind(wxEVT_TOGGLEBUTTON, [this](wxCommandEvent& e) { + m_cb_stable_only->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent& e) { wxGetApp().app_config->set_bool("check_stable_update_only", m_cb_stable_only->GetValue()); e.Skip(); }); - auto stable_only_label = new Label(this, _L("Check for stable updates only")); - stable_only_label->SetFont(Label::Body_12); - m_button_cancel = new Button(this, _L("Cancel")); m_button_cancel->SetStyle(ButtonStyle::Regular, ButtonType::Choice); @@ -402,7 +399,6 @@ UpdateVersionDialog::UpdateVersionDialog(wxWindow *parent) //sizer_button->Add(m_remind_choice, 0, wxALL | wxEXPAND, FromDIP(5)); sizer_button->Add(m_cb_stable_only , 0, wxALIGN_CENTER); - sizer_button->Add(stable_only_label , 0, wxALIGN_CENTER | wxLEFT, FromDIP(5)); sizer_button->AddStretchSpacer(); sizer_button->Add(m_button_download , 0, wxLEFT, FromDIP(10)); sizer_button->Add(m_button_skip_version, 0, wxLEFT, FromDIP(10)); @@ -600,8 +596,8 @@ SecondaryCheckDialog::SecondaryCheckDialog(wxWindow* parent, wxWindowID id, cons if (not_show_again_check) { auto checkbox_sizer = new wxBoxSizer(wxHORIZONTAL); - m_show_again_checkbox = new wxCheckBox(this, wxID_ANY, _L("Don't show again"), wxDefaultPosition, wxDefaultSize, 0); - m_show_again_checkbox->Bind(wxEVT_COMMAND_CHECKBOX_CLICKED, [this](wxCommandEvent& e) { + m_show_again_checkbox = new LabeledCheckBox(this, _L("Don't show again")); + m_show_again_checkbox->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent& e) { not_show_again = !not_show_again; m_show_again_checkbox->SetValue(not_show_again); }); @@ -1184,8 +1180,8 @@ ConfirmBeforeSendDialog::ConfirmBeforeSendDialog(wxWindow* parent, wxWindowID id if (not_show_again_check) { auto checkbox_sizer = new wxBoxSizer(wxHORIZONTAL); - m_show_again_checkbox = new wxCheckBox(this, wxID_ANY, _L("Don't show again"), wxDefaultPosition, wxDefaultSize, 0); - m_show_again_checkbox->Bind(wxEVT_COMMAND_CHECKBOX_CLICKED, [this](wxCommandEvent& e) { + m_show_again_checkbox = new LabeledCheckBox(this, _L("Don't show again")); + m_show_again_checkbox->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent& e) { not_show_again = !not_show_again; m_show_again_checkbox->SetValue(not_show_again); }); diff --git a/src/slic3r/GUI/ReleaseNote.hpp b/src/slic3r/GUI/ReleaseNote.hpp index 71159feada..f78bcc274a 100644 --- a/src/slic3r/GUI/ReleaseNote.hpp +++ b/src/slic3r/GUI/ReleaseNote.hpp @@ -41,7 +41,7 @@ #include "DeviceManager.hpp" #include "Widgets/Label.hpp" #include "Widgets/Button.hpp" -#include "Widgets/CheckBox.hpp" +#include "Widgets/LabeledCheckBox.hpp" #include "Widgets/ComboBox.hpp" #include "Widgets/ScrolledWindow.hpp" #include "Widgets/HyperLink.hpp" @@ -113,7 +113,7 @@ public: Label * m_staticText_release_note{nullptr}; wxStaticBitmap* m_bitmap_open_in_browser; Button* m_button_skip_version; - CheckBox* m_cb_stable_only; + LabeledCheckBox* m_cb_stable_only; Button* m_button_download; Button* m_button_cancel; std::string url_line; @@ -166,7 +166,7 @@ public: Button* m_button_cancel { nullptr }; Button* m_button_fn { nullptr }; Button* m_button_resume { nullptr }; - wxCheckBox* m_show_again_checkbox; + LabeledCheckBox* m_show_again_checkbox; VisibleButtons m_button_style; // ORCA VisibleButtons instead ButtonStyle bool not_show_again = false; std::string show_again_config_text = ""; @@ -291,7 +291,7 @@ protected: Button* m_button_ok; Button* m_button_cancel; Button* m_button_update_nozzle; - wxCheckBox* m_show_again_checkbox; + LabeledCheckBox* m_show_again_checkbox; bool not_show_again = false; std::string show_again_config_text = ""; }; diff --git a/src/slic3r/GUI/SavePresetDialog.cpp b/src/slic3r/GUI/SavePresetDialog.cpp index 46d7088749..cf36428b66 100644 --- a/src/slic3r/GUI/SavePresetDialog.cpp +++ b/src/slic3r/GUI/SavePresetDialog.cpp @@ -11,7 +11,7 @@ #include #include "slic3r/GUI/Widgets/RadioGroup.hpp" #include "libslic3r/Config.hpp" -#include "slic3r/GUI/Widgets/CheckBox.hpp" +#include "slic3r/GUI/Widgets/LabeledCheckBox.hpp" #include #include "slic3r/GUI/wxExtensions.hpp" #include "slic3r/GUI/GUI_Utils.hpp" @@ -143,21 +143,9 @@ SavePresetDialog::Item::Item(Preset::Type type, const std::string &suffix, wxBox const std::string parent_name = sel_preset.is_system ? sel_preset.name : sel_preset.inherits(); const bool has_parent = !parent_name.empty(); - wxBoxSizer *detach_sizer = new wxBoxSizer(wxHORIZONTAL); - - auto detach_tooltip = _L("Copies all inherited values from the parent into this preset and removes the parent relationship. Presets compatible only with the parent may become unsupported."); - - auto detach_checkbox = new ::CheckBox(parent); - detach_checkbox->SetToolTip(detach_tooltip); - - auto detach_label = new wxStaticText(parent, wxID_ANY, has_parent ? _L("Detach from parent") : _L("Save without parent")); - detach_label->SetFont(::Label::Body_14); - detach_label->SetForegroundColour(wxColour("#363636")); - detach_label->SetToolTip(detach_tooltip); - - detach_sizer->Add(detach_checkbox, 0, wxALIGN_LEFT | wxLEFT, BORDER_W); - detach_sizer->Add(detach_label , 0, wxALIGN_CENTRE_VERTICAL | wxLEFT, FromDIP(5)); - sizer->Add(detach_sizer, 0, wxEXPAND | wxTOP, BORDER_W); + auto detach_checkbox = new LabeledCheckBox(parent, has_parent ? _L("Detach from parent") : _L("Save without parent")); + detach_checkbox->SetToolTip(_L("Copies all inherited values from the parent into this preset and removes the parent relationship. Presets compatible only with the parent may become unsupported.")); + sizer->Add(detach_checkbox, 0, wxTOP | wxLEFT, BORDER_W); sizer->AddSpacer(FromDIP(5)); const wxString parent_text = has_parent ? from_u8(parent_name) : _L("Unique preset"); @@ -172,19 +160,10 @@ SavePresetDialog::Item::Item(Preset::Type type, const std::string &suffix, wxBox // Set initial state (unchecked by default) detach_checkbox->SetValue(m_detach); // Bind the checkbox event to update the detach state for this item - detach_checkbox->Bind(wxEVT_TOGGLEBUTTON, [this, detach_checkbox](wxCommandEvent& event) { - m_detach = detach_checkbox->GetValue(); - event.Skip(); // Let CheckBox update its bitmap for the new state. + detach_checkbox->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent& event) { + m_detach = event.IsChecked(); + event.Skip(); }); - - auto on_toggle = [detach_checkbox]() { - detach_checkbox->SetValue(!detach_checkbox->GetValue()); - wxCommandEvent ev(wxEVT_TOGGLEBUTTON, detach_checkbox->GetId()); - ev.SetEventObject(detach_checkbox); - detach_checkbox->GetEventHandler()->ProcessEvent(ev); - }; - detach_label->Bind(wxEVT_LEFT_DOWN, [on_toggle](wxMouseEvent& e) {if(!e.LeftDClick()) on_toggle();}); - detach_label->Bind(wxEVT_LEFT_DCLICK, [on_toggle](wxMouseEvent& e) {on_toggle();}); } m_radio_group->Bind(wxEVT_COMMAND_RADIOBOX_SELECTED, [this](wxCommandEvent &e) { diff --git a/src/slic3r/GUI/StepMeshDialog.cpp b/src/slic3r/GUI/StepMeshDialog.cpp index 0841777a43..109bdbb4db 100644 --- a/src/slic3r/GUI/StepMeshDialog.cpp +++ b/src/slic3r/GUI/StepMeshDialog.cpp @@ -15,7 +15,6 @@ #include #include #include -#include #include #include "GUI_App.hpp" #include "I18N.hpp" @@ -259,33 +258,33 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file, double line bSizer->Add(angle_sizer, 0, wxEXPAND | wxLEFT | wxRIGHT, LEFT_RIGHT_PADING); - // App-styled check boxes, the same as in the AMF and 3MF import dialogs. + // Same check boxes as in the AMF and 3MF import dialogs. m_split_compound_checkbox = add_import_checkbox(this, *bSizer, _L("Split compound and compsolid into multiple objects"), wxGetApp().app_config->get_bool("is_split_compound"), wxLEFT | wxRIGHT | wxTOP, LEFT_RIGHT_PADING); if (m_import_options != nullptr) { - m_split_compound_checkbox.SetToolTip(_L("Loads each body of a multi-body part separately. Needed to keep the bodies' original names.")); - m_split_compound_checkbox.SetValue(m_import_options->split_compound); + m_split_compound_checkbox->SetToolTip(_L("Loads each body of a multi-body part separately. Needed to keep the bodies' original names.")); + m_split_compound_checkbox->SetValue(m_import_options->split_compound); m_load_mode = new RadioGroup(this, {_L("Load as an assembly"), _L("Load as a single object (can be split later)")}, wxVERTICAL); m_load_mode->SetSelection(m_import_options->load_as_assembly ? 0 : 1); m_load_mode->SetRadioTooltip(1, _L("The original bodies and names are kept inside the object. Use Split to parts to show them as separate parts.")); bSizer->Add(m_load_mode, 0, wxLEFT | wxRIGHT | wxTOP, LEFT_RIGHT_PADING); m_keep_names_checkbox = add_import_checkbox(this, *bSizer, _L("Keep original names"), m_import_options->keep_names, wxLEFT | wxRIGHT | wxTOP, LEFT_RIGHT_PADING); - m_keep_names_checkbox.SetToolTip(_L("Use the body names stored in the file, when there are any. Needs Split compound for parts with several bodies.")); + m_keep_names_checkbox->SetToolTip(_L("Use the body names stored in the file, when there are any. Needs Split compound for parts with several bodies.")); m_sort_names_checkbox = add_import_checkbox(this, *bSizer, _L("Sort parts by name"), m_import_options->sort_names, wxLEFT | wxRIGHT | wxTOP, LEFT_RIGHT_PADING); - m_sort_names_checkbox.SetToolTip(_L("Sort the parts inside each imported assembly in the object list. This does not change the order used for slicing. Available when Keep original names is on.")); + m_sort_names_checkbox->SetToolTip(_L("Sort the parts inside each imported assembly in the object list. This does not change the order used for slicing. Available when Keep original names is on.")); // The dialog opens with the remembered values; only the user's clicks move the linked option. - m_keep_names_checkbox.box->Bind(wxEVT_TOGGLEBUTTON, [this](wxCommandEvent& e) { + m_keep_names_checkbox->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent& e) { // Body names of a multi-body part exist only after splitting it. - if (m_keep_names_checkbox.GetValue()) - m_split_compound_checkbox.SetValue(true); + if (m_keep_names_checkbox->GetValue()) + m_split_compound_checkbox->SetValue(true); e.Skip(); }); - m_split_compound_checkbox.box->Bind(wxEVT_TOGGLEBUTTON, [this](wxCommandEvent& e) { - if (!m_split_compound_checkbox.GetValue() && m_keep_names_checkbox.GetValue()) { - m_keep_names_checkbox.SetValue(false); - m_sort_names_checkbox.Enable(false); + m_split_compound_checkbox->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent& e) { + if (!m_split_compound_checkbox->GetValue() && m_keep_names_checkbox->GetValue()) { + m_keep_names_checkbox->SetValue(false); + m_sort_names_checkbox->Enable(false); } e.Skip(); }); @@ -307,14 +306,14 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file, double line m_save_default_checkbox = add_import_checkbox(this, *bSizer, m_import_options ? _L("Remember my choice") : _L("Save these settings as default"), false, wxLEFT | wxRIGHT, LEFT_RIGHT_PADING); - m_save_default_checkbox.SetToolTip(_L("If enabled, the values above are stored as the defaults used for future STEP imports (and shown in Preferences).")); + m_save_default_checkbox->SetToolTip(_L("If enabled, the values above are stored as the defaults used for future STEP imports (and shown in Preferences).")); bSizer->AddSpacer(FromDIP(10)); m_checkbox = add_import_checkbox(this, *bSizer, m_import_options ? _L("Don't ask again") : _L("Don't show again"), false, wxLEFT, LEFT_RIGHT_PADING); if (m_import_options != nullptr) - m_checkbox.SetToolTip(_L("Save these choices and apply them without asking next time. You can show this dialog again in Preferences.")); + m_checkbox->SetToolTip(_L("Save these choices and apply them without asking next time. You can show this dialog again in Preferences.")); wxBoxSizer* bSizer_button = new wxBoxSizer(wxHORIZONTAL); @@ -339,21 +338,21 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file, double line validate_number_range(linear_input->GetTextCtrl()->GetValue(), 0.001, 0.1)) { if (m_import_options != nullptr) { // The callback uses these values now; AppConfig is updated only after batch success. - m_import_options->keep_names = m_keep_names_checkbox.GetValue(); - m_import_options->split_compound = m_split_compound_checkbox.GetValue(); - m_import_options->sort_names = m_sort_names_checkbox.GetValue(); + m_import_options->keep_names = m_keep_names_checkbox->GetValue(); + m_import_options->split_compound = m_split_compound_checkbox->GetValue(); + m_import_options->sort_names = m_sort_names_checkbox->GetValue(); m_import_options->load_as_assembly = m_load_mode->GetSelection() == 0; - m_import_options->remember = m_save_default_checkbox.GetValue(); - m_import_options->dont_ask = m_checkbox.GetValue(); + m_import_options->remember = m_save_default_checkbox->GetValue(); + m_import_options->dont_ask = m_checkbox->GetValue(); m_import_options->linear_deflection = get_linear_deflection(); m_import_options->angle_deflection = get_angle_deflection(); m_import_options->chosen = true; } else { - if (m_checkbox.GetValue()) { + if (m_checkbox->GetValue()) { wxGetApp().app_config->set_bool("enable_step_mesh_setting", false); } - if (m_save_default_checkbox.GetValue()) { - wxGetApp().app_config->set_bool("is_split_compound", m_split_compound_checkbox.GetValue()); + if (m_save_default_checkbox->GetValue()) { + wxGetApp().app_config->set_bool("is_split_compound", m_split_compound_checkbox->GetValue()); wxGetApp().app_config->set("linear_deflection", float_to_string_decimal_point(get_linear_deflection(), 3)); wxGetApp().app_config->set("angle_deflection", float_to_string_decimal_point(get_angle_deflection(), 2)); } diff --git a/src/slic3r/GUI/StepMeshDialog.hpp b/src/slic3r/GUI/StepMeshDialog.hpp index ce5b95f022..2cb7ae0108 100644 --- a/src/slic3r/GUI/StepMeshDialog.hpp +++ b/src/slic3r/GUI/StepMeshDialog.hpp @@ -7,6 +7,7 @@ #include "GUI_Utils.hpp" #include "libslic3r/Format/STEP.hpp" #include "Widgets/Button.hpp" +#include "Widgets/LabeledCheckBox.hpp" #include "GeometryImportDialog.hpp" class Button; class RadioGroup; @@ -35,19 +36,19 @@ public: } } inline bool get_split_compound_value() { - return m_split_compound_checkbox.GetValue(); + return m_split_compound_checkbox->GetValue(); } private: // A non-null context defers all preference writes until the whole import is ready. Slic3r::GUI::GeometryImportOptions* m_import_options = nullptr; - Slic3r::GUI::ImportCheckBox m_keep_names_checkbox; - Slic3r::GUI::ImportCheckBox m_sort_names_checkbox; + LabeledCheckBox* m_keep_names_checkbox = nullptr; + LabeledCheckBox* m_sort_names_checkbox = nullptr; // Item 0 loads as an assembly, item 1 as a single object. RadioGroup* m_load_mode = nullptr; Slic3r::Step& m_file; - Slic3r::GUI::ImportCheckBox m_checkbox; - Slic3r::GUI::ImportCheckBox m_split_compound_checkbox; - Slic3r::GUI::ImportCheckBox m_save_default_checkbox; + LabeledCheckBox* m_checkbox = nullptr; + LabeledCheckBox* m_split_compound_checkbox = nullptr; + LabeledCheckBox* m_save_default_checkbox = nullptr; wxString m_linear_last; wxString m_angle_last; wxStaticText* mesh_face_number_text; diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 95d5c886b2..f08efd85f8 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -8591,14 +8591,9 @@ static void toggle_compatible_condition(Tab& tab, const std::string& key, bool e // Return a callback to create a Tab widget to mark the preferences as compatible / incompatible to the current printer. wxSizer* Tab::compatible_widget_create(wxWindow* parent, PresetDependencies &deps) { - deps.checkbox = new ::CheckBox(parent, wxID_ANY); + deps.checkbox = new LabeledCheckBox(parent, _L("All")); wxGetApp().UpdateDarkUI(deps.checkbox, false, true); - deps.checkbox_title = new wxStaticText(parent, wxID_ANY, _L("All")); - deps.checkbox_title->SetFont(Label::Body_14); - deps.checkbox_title->SetForegroundColour(wxColour("#363636")); - wxGetApp().UpdateDarkUI(deps.checkbox_title, false, true); - // ORCA modernize button style Button* btn = new Button(parent, _(L("Set")) + " " + dots); btn->SetStyle(ButtonStyle::Regular, ButtonType::Parameter); @@ -8606,11 +8601,11 @@ wxSizer* Tab::compatible_widget_create(wxWindow* parent, PresetDependencies &dep auto sizer = new wxBoxSizer(wxHORIZONTAL); sizer->Add((deps.checkbox), 0, wxALIGN_CENTER_VERTICAL); - sizer->Add((deps.checkbox_title), 0, wxALIGN_CENTER_VERTICAL); sizer->Add(new wxStaticText(parent, wxID_ANY, " ")); // weirdly didnt apply AddSpacer or wxRIGHT border sizer->Add((deps.btn), 0, wxALIGN_CENTER_VERTICAL); - auto on_toggle = [this, &deps](const bool &state){ + deps.checkbox->Bind(wxEVT_CHECKBOX, ([this, &deps](wxCommandEvent& e) { + bool state = e.IsChecked(); deps.checkbox->SetValue(state); deps.btn->Enable(!state); // All printers have been made compatible with this preset. @@ -8618,21 +8613,6 @@ wxSizer* Tab::compatible_widget_create(wxWindow* parent, PresetDependencies &dep this->load_key_value(deps.key_list, std::vector {}); toggle_compatible_condition(*this, deps.key_condition, state); this->update_changed_ui(); - }; - - deps.checkbox_title->Bind(wxEVT_LEFT_DOWN,([&deps, on_toggle](wxMouseEvent& e) { - if (e.GetEventType() == wxEVT_LEFT_DCLICK) return; - on_toggle(!deps.checkbox->GetValue()); - e.Skip(); - })); - - deps.checkbox_title->Bind(wxEVT_LEFT_DCLICK,([&deps, on_toggle](wxMouseEvent& e) { - on_toggle(!deps.checkbox->GetValue()); - e.Skip(); - })); - - deps.checkbox->Bind(wxEVT_TOGGLEBUTTON, ([on_toggle](wxCommandEvent& e) { - on_toggle(e.IsChecked()); e.Skip(); }), deps.checkbox->GetId()); diff --git a/src/slic3r/GUI/Tab.hpp b/src/slic3r/GUI/Tab.hpp index c698b7dff0..330d0d1618 100644 --- a/src/slic3r/GUI/Tab.hpp +++ b/src/slic3r/GUI/Tab.hpp @@ -51,6 +51,7 @@ #include "ParamsPanel.hpp" #include "Widgets/TextInput.hpp" #include "Widgets/CheckBox.hpp" // ORCA +#include "Widgets/LabeledCheckBox.hpp" // ORCA #include "Widgets/ComboBox.hpp" class TabCtrl; @@ -188,8 +189,7 @@ protected: struct PresetDependencies { Preset::Type type = Preset::TYPE_INVALID; - ::CheckBox* checkbox = nullptr; - wxStaticText* checkbox_title = nullptr; + LabeledCheckBox* checkbox = nullptr; Button *btn = nullptr; std::string key_list; // "compatible_printers" std::string key_condition; diff --git a/src/slic3r/GUI/TextureImportDialog.cpp b/src/slic3r/GUI/TextureImportDialog.cpp index cee0b5fe5b..4bb4791760 100644 --- a/src/slic3r/GUI/TextureImportDialog.cpp +++ b/src/slic3r/GUI/TextureImportDialog.cpp @@ -34,6 +34,7 @@ #include "slic3r/GUI/Widgets/SpinInput.hpp" #include #include +#include #include "libslic3r/TriangleMesh.hpp" #include #include @@ -2195,10 +2196,8 @@ void TextureImportDialog::build_mapping_panel(wxWindow* parent, wxSizer* sizer) sizer->Add(header_sizer, 0, wxEXPAND | wxBOTTOM, FromDIP(4)); wxBoxSizer* merge_sizer = new wxBoxSizer(wxHORIZONTAL); - m_auto_merge_cb = new wxCheckBox(parent, wxID_ANY, _L("Auto-merge same filament")); - m_auto_merge_cb->SetFont(Label::Body_14); + m_auto_merge_cb = new LabeledCheckBox(parent, _L("Auto-merge same filament")); m_auto_merge_cb->SetToolTip(_L("Automatically merge identical filaments into existing filaments in the project")); - m_auto_merge_cb->SetForegroundColour(secondary_fg); m_auto_merge_cb->SetValue(true); m_auto_merge_cb->Bind(wxEVT_CHECKBOX, &TextureImportDialog::on_auto_merge_toggled, this); merge_sizer->Add(m_auto_merge_cb, 0, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM, FromDIP(5)); diff --git a/src/slic3r/GUI/TextureImportDialog.hpp b/src/slic3r/GUI/TextureImportDialog.hpp index b1a2449fca..8dc6fe968d 100644 --- a/src/slic3r/GUI/TextureImportDialog.hpp +++ b/src/slic3r/GUI/TextureImportDialog.hpp @@ -14,7 +14,7 @@ #include #include #include "Widgets/SpinInput.hpp" -#include +#include "Widgets/LabeledCheckBox.hpp" #include #include "Widgets/Button.hpp" #include @@ -365,7 +365,7 @@ private: SpinInput* m_smooth_spin = nullptr; Button* m_btn_apply = nullptr; - wxCheckBox* m_auto_merge_cb = nullptr; + LabeledCheckBox* m_auto_merge_cb = nullptr; Button* m_btn_auto_mix = nullptr; Button* m_btn_mix_reset = nullptr; bool m_auto_mix_applied = false; diff --git a/src/slic3r/GUI/UVEditorCanvas.cpp b/src/slic3r/GUI/UVEditorCanvas.cpp index 502a1cd912..e535ea7262 100644 --- a/src/slic3r/GUI/UVEditorCanvas.cpp +++ b/src/slic3r/GUI/UVEditorCanvas.cpp @@ -32,7 +32,6 @@ #include #include #include -#include #include "3DScene.hpp" #include "BitmapCache.hpp" @@ -43,7 +42,7 @@ #include "OpenGLManager.hpp" #include "Plater.hpp" #include "wxExtensions.hpp" -#include "Widgets/CheckBox.hpp" +#include "Widgets/LabeledCheckBox.hpp" #include "Widgets/SpinInput.hpp" #include "libslic3r/AppConfig.hpp" @@ -2036,18 +2035,16 @@ UVEditorPanel::UVEditorPanel(wxWindow *parent) : wxPanel(parent, wxID_ANY) "texture not running continuously across the cut. Takes effect at the next Unwrap."); seam_label->SetToolTip(seam_tip); m_seam_angle->SetToolTip(seam_tip); - m_connect = new ::CheckBox(this); - auto *connect_label = text(_L("Connect islands"), c.ink); - const wxString connect_tip = _L("Lay the unwrap out as a connected net: pieces that share an edge are unfolded next to each " - "other (a cube becomes a joined net rather than six loose squares). They stay separate " - "islands, so you can still move any of them by hand afterwards."); - m_connect->SetToolTip(connect_tip); - connect_label->SetToolTip(connect_tip); + m_connect = new LabeledCheckBox(this, _L("Connect islands")); + m_connect->SetFont(GetFont()); // same as the other texts of the pane + m_connect->SetForegroundColour(c.ink); + m_connect->SetToolTip(_L("Lay the unwrap out as a connected net: pieces that share an edge are unfolded next to each " + "other (a cube becomes a joined net rather than six loose squares). They stay separate " + "islands, so you can still move any of them by hand afterwards.")); settings->Add(seam_label, 0, wxALIGN_CENTER_VERTICAL); settings->Add(m_seam_angle, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, gap); settings->AddStretchSpacer(); settings->Add(m_connect, 0, wxALIGN_CENTER_VERTICAL); - settings->Add(connect_label, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, FromDIP(4)); // ---- tool strip ---- auto *strip = new wxBoxSizer(wxVERTICAL); @@ -2134,20 +2131,11 @@ UVEditorPanel::UVEditorPanel(wxWindow *parent) : wxPanel(parent, wxID_ANY) if (value != int(std::lround(m_canvas->pane_state().seam_angle_deg))) m_canvas->run_command(UVEditorCanvas::Command::SetSeamAngle, float(value)); }); - const auto send_connect = [this]() { + m_connect->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent &e) { if (m_connect->GetValue() != m_canvas->pane_state().connect_islands) m_canvas->run_command(UVEditorCanvas::Command::SetConnectIslands, m_connect->GetValue() ? 1.f : 0.f); - }; - m_connect->Bind(wxEVT_TOGGLEBUTTON, [send_connect](wxCommandEvent &e) { - send_connect(); e.Skip(); }); - connect_label->Bind(wxEVT_LEFT_DOWN, [this, send_connect](wxMouseEvent &) { - if (!m_connect->IsEnabled()) - return; - m_connect->SetValue(!m_connect->GetValue()); - send_connect(); - }); m_canvas->set_status_callback([this](const wxString &label) { if (m_status != nullptr && m_status->GetLabel() != label) { diff --git a/src/slic3r/GUI/UVEditorCanvas.hpp b/src/slic3r/GUI/UVEditorCanvas.hpp index a01d058983..0f005005e0 100644 --- a/src/slic3r/GUI/UVEditorCanvas.hpp +++ b/src/slic3r/GUI/UVEditorCanvas.hpp @@ -30,7 +30,7 @@ // Orca's own widgets (slic3r/GUI/Widgets), declared at global scope. class SpinInput; -class CheckBox; +class LabeledCheckBox; namespace Slic3r::GUI { @@ -437,7 +437,7 @@ private: UVToolButton *m_unwrap = nullptr; ::SpinInput *m_seam_angle = nullptr; - ::CheckBox *m_connect = nullptr; + LabeledCheckBox *m_connect = nullptr; UVToolButton *m_select[3]{}; UVToolButton *m_mark_seams = nullptr; diff --git a/src/slic3r/GUI/UnsavedChangesDialog.cpp b/src/slic3r/GUI/UnsavedChangesDialog.cpp index 322826ed0b..a3108cd088 100644 --- a/src/slic3r/GUI/UnsavedChangesDialog.cpp +++ b/src/slic3r/GUI/UnsavedChangesDialog.cpp @@ -68,7 +68,6 @@ #include "MsgDialog.hpp" #include "PresetComboBoxes.hpp" -#include "Widgets/CheckBox.hpp" #include "Widgets/DialogButtons.hpp" #ifdef __linux__ @@ -930,7 +929,7 @@ inline int UnsavedChangesDialog::ShowModal() } } int r = DPIDialog::ShowModal(); - if (r != wxID_CANCEL && dynamic_cast<::CheckBox*>(FindWindowById(wxID_APPLY))->GetValue()) { + if (r != wxID_CANCEL && dynamic_cast<::LabeledCheckBox*>(FindWindowById(wxID_APPLY))->GetValue()) { wxGetApp().app_config->set(choise_key, std::to_string(int(m_exit_action))); } return r; @@ -1117,16 +1116,11 @@ void UnsavedChangesDialog::build(Preset::Type type, PresetCollection *dependent_ wxBoxSizer *m_sizer_button = new wxBoxSizer(wxHORIZONTAL); - auto checkbox_sizer = new wxBoxSizer(wxHORIZONTAL); - auto checkbox = new ::CheckBox(this, wxID_APPLY); - checkbox_sizer->Add(checkbox, 0, wxALL | wxALIGN_CENTER, FromDIP(2)); + auto checkbox = new LabeledCheckBox(this, _L("Remember my choice.")); + checkbox->SetId(wxID_APPLY); - auto checkbox_text = new wxStaticText(this, wxID_ANY, _L("Remember my choice."), wxDefaultPosition, wxDefaultSize, 0); - checkbox_sizer->Add(checkbox_text, 0, wxALL | wxALIGN_CENTER, FromDIP(2)); - checkbox_text->SetFont(::Label::Body_13); - checkbox_text->SetForegroundColour(StateColor::darkModeColorFor(wxColour("#323A3D"))); - m_sizer_button->Add(checkbox_sizer, 0, wxLEFT, FromDIP(22)); - checkbox_sizer->Show(bool(m_buttons & REMEMBER_CHOISE)); + m_sizer_button->Add(checkbox, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, FromDIP(22)); + checkbox->Show(bool(m_buttons & REMEMBER_CHOISE)); if (dependent_presets != nullptr) { auto wiki_btn = new Button(this, "", "toolbar_wiki", 0, 15); @@ -2200,7 +2194,7 @@ void DiffPresetDialog::create_presets_sizer() void DiffPresetDialog::create_show_all_presets_chb() { - m_show_all_presets = new wxCheckBox(this, wxID_ANY, _L("Show all presets (including incompatible)")); + m_show_all_presets = new LabeledCheckBox(this, _L("Show all presets (including incompatible)")); m_show_all_presets->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent&) { bool show_all = m_show_all_presets->GetValue(); for (auto preset_combos : m_preset_combos) { @@ -2305,7 +2299,7 @@ void DiffPresetDialog::create_buttons() void DiffPresetDialog::create_edit_sizer() { // Add check box for the edit mode - m_use_for_transfer = new wxCheckBox(this, wxID_ANY, _L("Transfer values from left to right")); + m_use_for_transfer = new LabeledCheckBox(this, _L("Transfer values from left to right")); m_use_for_transfer->SetToolTip(_L("If enabled, this dialog can be used for transfer selected values from left to right preset.")); m_use_for_transfer->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent&) { bool use = m_use_for_transfer->GetValue(); diff --git a/src/slic3r/GUI/UnsavedChangesDialog.hpp b/src/slic3r/GUI/UnsavedChangesDialog.hpp index be65c28cfd..4308d83664 100644 --- a/src/slic3r/GUI/UnsavedChangesDialog.hpp +++ b/src/slic3r/GUI/UnsavedChangesDialog.hpp @@ -27,6 +27,7 @@ #include "wxExtensions.hpp" #include "libslic3r/PresetBundle.hpp" #include "Widgets/Button.hpp" +#include "Widgets/LabeledCheckBox.hpp" #include "Widgets/ScrolledWindow.hpp" #include "Lazy.hpp" @@ -453,8 +454,8 @@ class DiffPresetDialog : public DPIDialog, public LazyInstance wxBoxSizer* m_presets_sizer { nullptr }; wxStaticText* m_top_info_line { nullptr }; wxStaticText* m_bottom_info_line { nullptr }; - wxCheckBox* m_show_all_presets { nullptr }; - wxCheckBox* m_use_for_transfer { nullptr }; + LabeledCheckBox* m_show_all_presets { nullptr }; + LabeledCheckBox* m_use_for_transfer { nullptr }; wxBoxSizer* m_buttons { nullptr }; wxBoxSizer* m_edit_sizer { nullptr }; diff --git a/src/slic3r/GUI/Widgets/LabeledCheckBox.cpp b/src/slic3r/GUI/Widgets/LabeledCheckBox.cpp new file mode 100644 index 0000000000..168a707b61 --- /dev/null +++ b/src/slic3r/GUI/Widgets/LabeledCheckBox.cpp @@ -0,0 +1,307 @@ +#include "LabeledCheckBox.hpp" + +#include "CheckBox.hpp" +#include "Label.hpp" +#include "StateColor.hpp" +#include "StaticBox.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // wxEVT_TOGGLEBUTTON +#include +#include +#include +#include + +#include +#include + +static wxColour GetParentBackground(wxWindow* parent) +{ + wxWindow* child = parent; + for (wxWindow* win = parent; win; child = win, win = win->GetParent()) + if (dynamic_cast(win)) + return child->GetBackgroundColour(); + return parent->GetBackgroundColour(); +} + +LabeledCheckBox::LabeledCheckBox(wxWindow* parent, const wxString& label, wxWindowID id) + : wxPanel(parent, id) +{ + m_check = new CheckBox(this); + + m_text_box = new StaticBox(this); + m_text_box->SetCornerRadius(0); + + // Hidden while creation. wxGTK measures label itself and GTK reports size for a new font too late + m_text_box->Hide(); + m_text = new Label(m_text_box, Label::Body_14, label); + m_text_box->Show(!label.empty()); + UpdateFocusTarget(); + + // Two sizers, as horizontal and vertical padding differ + wxBoxSizer* text_sizer = new wxBoxSizer(wxHORIZONTAL); + text_sizer->Add(m_text, 0, wxLEFT | wxRIGHT); + wxBoxSizer* box_sizer = new wxBoxSizer(wxVERTICAL); + box_sizer->Add(text_sizer, 0, wxTOP | wxBOTTOM); + m_text_box->SetSizer(box_sizer); + + wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL); + sizer->Add(m_check, 0, wxTOP); + sizer->Add(m_text_box); + SetSizer(sizer); + + wxPanel::SetLabel(label); + wxPanel::SetFont(Label::Body_14); + SetBackgroundColour(GetParentBackground(parent)); + SetForegroundColour(StateColor::darkModeColorFor(wxColour("#363636"))); + UpdateMetrics(); + Fit(); + + m_check->Bind(wxEVT_TOGGLEBUTTON, [this](wxCommandEvent&) { + // Focus to frame once the click is over. Pressed button cancels its click on MSW. A click does not focus it at all on macOS + CallAfter([this] { TakeFocus(); }); + OnToggled(); + }); + m_check->Bind(wxEVT_SET_FOCUS, [this](wxFocusEvent& e) { ShowFocus(true); e.Skip(); }); + m_check->Bind(wxEVT_KILL_FOCUS, [this](wxFocusEvent& e) { ShowFocus(false); e.Skip(); }); + m_text_box->Bind(wxEVT_SET_FOCUS, [this](wxFocusEvent& e) { ShowFocus(true); e.Skip(); }); + m_text_box->Bind(wxEVT_KILL_FOCUS, [this](wxFocusEvent& e) { ShowFocus(false); e.Skip(); }); + m_text_box->Bind(wxEVT_KEY_DOWN, &LabeledCheckBox::OnKeyDown, this); + for (wxWindow* win : std::initializer_list{m_text_box, m_text}) { + win->Bind(wxEVT_LEFT_DOWN, &LabeledCheckBox::OnLabelClick, this); + win->Bind(wxEVT_LEFT_DCLICK, &LabeledCheckBox::OnLabelClick, this); // 2nd click of a double click + win->Bind(wxEVT_ENTER_WINDOW, &LabeledCheckBox::OnLabelHover, this); + win->Bind(wxEVT_LEAVE_WINDOW, &LabeledCheckBox::OnLabelHover, this); + } + Bind(wxEVT_SIZE, &LabeledCheckBox::OnSize, this); +} + +void LabeledCheckBox::SetValue(bool value) +{ + m_check->SetValue(value); + ShowHover(); +} + +void LabeledCheckBox::SetHalfChecked(bool half) +{ + m_check->SetHalfChecked(half); + ShowHover(); +} + +void LabeledCheckBox::Wrap(int width) +{ + m_auto_wrap = false; + m_wrap_width = width; + Relayout(); +} + +void LabeledCheckBox::AutoWrap(bool enable) +{ + m_auto_wrap = enable; + m_wrap_width = -1; // wrapped again on the next resize + Relayout(); +} + +void LabeledCheckBox::OnSize(wxSizeEvent& e) +{ + e.Skip(); + // Never wrap below the min width, and not for our own best width: it already fits + const int width = std::max(GetClientSize().x, GetMinSize().x); + const wxSize best = GetBestSize(); + if (!m_auto_wrap || width == m_wrap_width || width == best.x) + return; + + m_wrap_width = width; + UpdateMetrics(); + if (GetBestSize() != best) // Height changed, let the parent lay out again + CallAfter([this]() { SendSizeEventToParent(); }); +} + +void LabeledCheckBox::OnToggled() +{ + m_check->SetHalfChecked(false); // also refreshes the bitmap + ShowHover(); + + // A handler may destroy us + const wxWeakRef self(this); + const wxWindowID id = GetId(); + const bool value = GetValue(); + for (wxEventType type : {wxEVT_CHECKBOX, wxEVT_TOGGLEBUTTON}) { + wxCommandEvent evt(type, id); + evt.SetEventObject(this); + evt.SetInt(value); + ProcessWindowEvent(evt); + if (!self) + return; + } +} + +void LabeledCheckBox::OnLabelHover(wxMouseEvent& e) +{ + e.Skip(); + // Label and frame send enter / leave to each other, so check the position on leave. + // Event position, as wxGetMousePosition() does not work on Wayland + wxPoint pos = e.GetPosition(); + if (e.GetEventObject() == m_text) + pos += m_text->GetPosition(); + m_hovered = e.Entering() || m_text_box->GetClientRect().Contains(pos); + m_check->SetHalfChecked(m_check->IsHalfChecked()); // back to the normal icon + ShowHover(); +} + +void LabeledCheckBox::ShowHover() +{ + if (!m_hovered) + return; + // CheckBox sets its icons on every change, so this is called after each of them. + // Reset them first: on MSW setting the normal icon drops the hover one. + m_check->SetHalfChecked(m_check->IsHalfChecked()); + m_check->SetBitmapLabel(m_check->GetBitmapCurrent()); +} + +void LabeledCheckBox::OnLabelClick(wxMouseEvent& e) +{ + if (!IsEnabled()) + return e.Skip(); + TakeFocus(); + m_check->SetValue(!GetValue()); + OnToggled(); +} + +void LabeledCheckBox::OnKeyDown(wxKeyEvent& e) +{ + if (e.GetKeyCode() == WXK_SPACE) { + if (IsEnabled()) { + m_check->SetValue(!GetValue()); + OnToggled(); + } + return; + } + if (e.GetKeyCode() != WXK_TAB || !m_text_box->HandleAsNavigationKey(e)) + e.Skip(); +} + +// Frame takes keyboard focus: a native button cant take it while macOS full keyboard access is off ([NSView canBecomeKeyView]) +void LabeledCheckBox::UpdateFocusTarget() +{ + if (m_text_box->IsShown()) + m_check->DisableFocusFromKeyboard(); // one tab stop. SetCanFocus() would work on GTK only +} + +// With no label there is no frame to focus, only the check +void LabeledCheckBox::TakeFocus() +{ + if (m_text_box->IsShown()) + m_text_box->SetFocus(); + else + m_check->SetFocus(); +} + +void LabeledCheckBox::ShowFocus(bool focused) +{ + if (!IsBeingDeleted()) + m_text_box->SetBorderColor(focused ? wxColour("#009688") : GetBackgroundColour()); +} + +void LabeledCheckBox::UpdateLabelColor() +{ + // Own state only: IsEnabled() is also false while an ancestor is disabled, e.g. the main frame under a modal dialog + if (m_text->SetForegroundColour(m_check->IsThisEnabled() ? GetForegroundColour() : StateColor::darkModeColorFor(wxColour("#6B6A6A")))) + m_text->Refresh(); +} + +void LabeledCheckBox::UpdateMetrics() +{ + const wxSize padding = FromDIP(wxSize(5, 2)); // around the text, same as RadioGroup + wxSizer* text_sizer = m_text->GetContainingSizer(); + text_sizer->GetItem(m_text)->SetBorder(padding.x); + m_text_box->GetSizer()->GetItem(text_sizer)->SetBorder(padding.y); + // Keep the check on the first text line + const int offset = m_text_box->IsShown() ? padding.y + (m_text->GetCharHeight() - m_check->GetMinSize().y) / 2 : 0; + GetSizer()->GetItem(m_check)->SetBorder(std::max(offset, 0)); + + // Label::Wrap() starts from the full text, -1 unwraps + const int text_width = m_wrap_width - m_check->GetMinSize().x - 2 * padding.x; + m_text->Wrap(m_wrap_width > 0 && text_width > 0 ? text_width : -1); +} + +void LabeledCheckBox::Relayout() +{ + UpdateMetrics(); + Fit(); + SendSizeEventToParent(); +} + +void LabeledCheckBox::Rescale() +{ + m_check->Rescale(); + ShowHover(); + Relayout(); +} + +void LabeledCheckBox::SetLabel(const wxString& label) +{ + wxPanel::SetLabel(label); + m_text->SetLabel(label); + m_text_box->Show(!label.empty()); + UpdateFocusTarget(); + Relayout(); +} + +bool LabeledCheckBox::SetFont(const wxFont& font) +{ + const bool changed = wxPanel::SetFont(font); + m_text->SetFont(font); + Relayout(); + return changed; +} + +bool LabeledCheckBox::SetForegroundColour(const wxColour& colour) +{ + const bool changed = wxPanel::SetForegroundColour(colour); + UpdateLabelColor(); + return changed; +} + +bool LabeledCheckBox::SetBackgroundColour(const wxColour& colour) +{ + const bool changed = wxPanel::SetBackgroundColour(colour); + m_check->SetBackgroundColour(colour); + m_text_box->SetBackgroundColour(colour); + m_text->SetBackgroundColour(colour); + ShowFocus(HasFocus()); // a hidden frame has the background color + return changed; +} + +bool LabeledCheckBox::Enable(bool enable) +{ + if (!m_check->Enable(enable)) + return false; + m_text_box->Enable(enable); // it holds the focus, so it must not be a tab stop while disabled + UpdateLabelColor(); + return true; +} + +void LabeledCheckBox::DoSetToolTip(wxToolTip* tip) +{ + const wxString text = tip ? tip->GetTip() : wxString(); + for (wxWindow* win : std::initializer_list{m_check, m_text_box, m_text}) + win->SetToolTip(text); + wxPanel::DoSetToolTip(tip); +} + +// wx only changes the text of an existing tooltip here and does not call DoSetToolTip() again +void LabeledCheckBox::DoSetToolTipText(const wxString& tip) +{ + wxPanel::DoSetToolTipText(tip); + for (wxWindow* win : std::initializer_list{m_check, m_text_box, m_text}) + win->SetToolTip(tip); +} diff --git a/src/slic3r/GUI/Widgets/LabeledCheckBox.hpp b/src/slic3r/GUI/Widgets/LabeledCheckBox.hpp new file mode 100644 index 0000000000..8f3dacffac --- /dev/null +++ b/src/slic3r/GUI/Widgets/LabeledCheckBox.hpp @@ -0,0 +1,74 @@ +#ifndef slic3r_GUI_LabeledCheckBox_hpp_ +#define slic3r_GUI_LabeledCheckBox_hpp_ + +#include "CheckBox.hpp" +#include "Label.hpp" +#include "StaticBox.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// CheckBox with a clickable label +class LabeledCheckBox : public wxPanel +{ +public: + LabeledCheckBox(wxWindow* parent, const wxString& label = wxEmptyString, wxWindowID id = wxID_ANY); + + void SetValue(bool value); + bool GetValue() const { return m_check->GetValue(); } + bool IsChecked() const { return m_check->GetValue(); } + void SetHalfChecked(bool half = true); + + void Wrap(int width); + void AutoWrap(bool enable = true); + + Label* GetLabelCtrl() { return m_text; } + const Label* GetLabelCtrl() const { return m_text; } + + void Rescale(); + + void SetLabel(const wxString& label) override; + bool SetFont(const wxFont& font) override; + bool SetForegroundColour(const wxColour& colour) override; // label color + bool SetBackgroundColour(const wxColour& colour) override; + + bool Enable(bool enable = true) override; + bool IsEnabled() const { return m_check->IsEnabled(); } + + bool HasFocus() const override { return m_text_box->HasFocus() || m_check->HasFocus(); } + +protected: + void DoSetToolTip(wxToolTip* tip) override; + void DoSetToolTipText(const wxString& tip) override; + +private: + void OnToggled(); // sends the events + void OnLabelClick(wxMouseEvent& e); + void OnLabelHover(wxMouseEvent& e); + void OnKeyDown(wxKeyEvent& e); // Space toggles, like a native check box + void OnSize(wxSizeEvent& e); + void UpdateFocusTarget(); // the frame takes the focus when there is a label + void TakeFocus(); + void ShowFocus(bool focused); + void ShowHover(); // hover icon on the check while the mouse is on the label + void UpdateLabelColor(); + void UpdateMetrics(); // borders and wrap + void Relayout(); + + CheckBox* m_check {nullptr}; + StaticBox* m_text_box {nullptr}; + Label* m_text {nullptr}; + + int m_wrap_width {-1}; // control width to wrap for, -1: no wrap + bool m_auto_wrap {false}; + bool m_hovered {false}; // mouse is on the label +}; + +#endif // !slic3r_GUI_LabeledCheckBox_hpp_ diff --git a/src/slic3r/GUI/calib_dlg.cpp b/src/slic3r/GUI/calib_dlg.cpp index 6f0e51a64a..ea9c655fb8 100644 --- a/src/slic3r/GUI/calib_dlg.cpp +++ b/src/slic3r/GUI/calib_dlg.cpp @@ -14,6 +14,7 @@ #include #include "slic3r/GUI/Widgets/Button.hpp" #include "slic3r/GUI/Widgets/Label.hpp" +#include #include "slic3r/GUI/Widgets/LabeledStaticBox.hpp" #include "slic3r/GUI/Widgets/RadioGroup.hpp" #include "slic3r/GUI/Widgets/TextInput.hpp" @@ -65,20 +66,15 @@ int GetTextMax(wxWindow* parent, const std::vector& labels) return text_size.x + parent->FromDIP(10); } -CheckBox* add_scale_checkbox(wxWindow* parent, wxSizer* settings_sizer) +LabeledCheckBox* add_scale_checkbox(wxWindow* parent, wxSizer* settings_sizer) { - auto row = new wxBoxSizer(wxHORIZONTAL); - auto cb = new CheckBox(parent); + auto cb = new LabeledCheckBox(parent, _L("Auto-scale for nozzle")); cb->SetValue(true); - auto text = new wxStaticText(parent, wxID_ANY, _L("Auto-scale for nozzle"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT); cb->SetToolTip(_L("This model is designed around a 0.4 mm nozzle with a 0.2 mm layer height.\n" "When the scaling option is enabled (recommended), it dynamically resizes to match your current nozzle diameter" " and an appropriate layer height, making the test both accurate and easy to read.\n" "Turn scaling off only if you wish to print the reference model exactly as-is.")); - text->SetToolTip(cb->GetToolTipText()); - row->Add(cb , 0, wxALL | wxALIGN_CENTER_VERTICAL, parent->FromDIP(2)); - row->Add(text, 0, wxALL | wxALIGN_CENTER_VERTICAL, parent->FromDIP(2)); - settings_sizer->Add(row, 0, wxLEFT | wxTOP, parent->FromDIP(3)); + settings_sizer->Add(cb, 0, wxLEFT | wxTOP, parent->FromDIP(3)); return cb; } @@ -837,16 +833,12 @@ VFA_Test_Dlg::VFA_Test_Dlg(wxWindow* parent, wxWindowID id, Plater* plater) // Auto-adjust parameters to the filament's max volumetric speed auto auto_adjust_sizer = new wxBoxSizer(wxHORIZONTAL); - m_cbAutoAdjust = new CheckBox(this); + m_cbAutoAdjust = new LabeledCheckBox(this, _L("Auto-adjust to max volumetric speed")); m_cbAutoAdjust->SetValue(true); - auto auto_adjust_text = new wxStaticText(this, wxID_ANY, _L("Auto-adjust to max volumetric speed"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT); m_cbAutoAdjust->SetToolTip(_L("If the end speed would exceed the filament's maximum volumetric speed, automatically lower the layer " "height (keeping standard values and staying within the machine's limits) to reach it. If even the " "minimum layer height is not enough, lower the end speed instead.")); - auto_adjust_text->SetToolTip(m_cbAutoAdjust->GetToolTipText()); - auto_adjust_sizer->Add(m_cbAutoAdjust , 0, wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(2)); - auto_adjust_sizer->Add(auto_adjust_text, 0, wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(2)); - settings_sizer->Add(auto_adjust_sizer, 0, wxLEFT | wxTOP, FromDIP(3)); + settings_sizer->Add(m_cbAutoAdjust, 0, wxLEFT | wxTOP, FromDIP(3)); settings_sizer->AddSpacer(FromDIP(5)); diff --git a/src/slic3r/GUI/calib_dlg.hpp b/src/slic3r/GUI/calib_dlg.hpp index eb0c5c9c01..478a8933d1 100644 --- a/src/slic3r/GUI/calib_dlg.hpp +++ b/src/slic3r/GUI/calib_dlg.hpp @@ -10,6 +10,7 @@ #include "Widgets/ComboBox.hpp" #include "Widgets/TextInput.hpp" #include "Widgets/LabeledStaticBox.hpp" +#include "Widgets/LabeledCheckBox.hpp" #include "Widgets/RadioGroup.hpp" #include "GUI_App.hpp" #include "wx/hyperlink.h" @@ -72,7 +73,7 @@ protected: TextInput* m_tiStart; TextInput* m_tiEnd; TextInput* m_tiStep; - CheckBox* m_cbResize; + LabeledCheckBox* m_cbResize; Plater* m_plater; }; @@ -107,8 +108,8 @@ protected: TextInput* m_tiStart; TextInput* m_tiEnd; TextInput* m_tiStep; - CheckBox* m_cbAutoAdjust; - CheckBox* m_cbResize; + LabeledCheckBox* m_cbAutoAdjust; + LabeledCheckBox* m_cbResize; Plater* m_plater; };