Fix dark-theme backgrounds across device, HMS, and AMS UI on macOS

Give previously-bare panels a keyed background so the existing dark-UI walk
can theme them. Runtime-created widgets (HMS items, device firmware/nozzle
panels) route their whole subtree through one UpdateDarkUIWin(this) call
instead of per-widget darkModeColorFor, which also themes their child text
and follows live light/dark switches. Extruder-card chips re-apply their
colours from Sidebar::sys_color_changed so a live switch updates them too.
This commit is contained in:
SoftFever
2026-07-19 20:16:17 +08:00
parent bd854c5ce5
commit f7f0c82abb
9 changed files with 80 additions and 26 deletions

View File

@@ -460,6 +460,17 @@ enum class ActionButtonType : int {
abSendGCode
};
// Background for the extruder-group title chip and its edit buttons, matching the StaticGroup
// interior. macOS keeps a lighter #F7F7F7 tint in light mode; dark mode uses the mapped colour.
static wxColour extruder_group_chip_bg()
{
#ifdef __WXOSX__
if (!wxGetApp().dark_mode())
return wxColour("#F7F7F7");
#endif
return StateColor::darkModeColorFor(*wxWHITE);
}
// Interactive title row for the sidebar extruder cards: "<title> ( <count> ) [edit]". The count shows the
// extruder's physical nozzle count on multi-nozzle printers (hidden elsewhere, SetCount(-1)), and the
// trailing button opens the manual nozzle-count editor when enabled (a plain dot otherwise).
@@ -468,11 +479,7 @@ class HoverLabel : public wxPanel
public:
HoverLabel(wxWindow *parent, const wxString &label) : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE)
{
#ifdef __WXOSX__
SetBackgroundColour("#F7F7F7");
#else
SetBackgroundColour(*wxWHITE);
#endif
SetBackgroundColour(extruder_group_chip_bg());
auto sizer = new wxBoxSizer(wxHORIZONTAL);
m_label = new wxStaticText(this, wxID_ANY, label, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
@@ -496,11 +503,7 @@ public:
m_hover_btn = new ScalableButton(this, wxID_ANY, "dot");
m_hover_btn->SetMinSize(wxSize(FromDIP(25), -1));
#ifdef __WXOSX__
m_hover_btn->SetBackgroundColour("#F7F7F7");
#else
m_hover_btn->SetBackgroundColour(*wxWHITE);
#endif
m_hover_btn->SetBackgroundColour(extruder_group_chip_bg());
m_hover_btn->Bind(wxEVT_COMMAND_BUTTON_CLICKED, [this](auto &evt) {
if (m_enabled && m_hover_on_click)
m_hover_on_click();
@@ -550,6 +553,17 @@ public:
void Rescale() { m_hover_btn->msw_rescale(); }
// Re-apply the chip colours on a live light/dark switch (they are set once at construction).
void sys_color_changed()
{
SetBackgroundColour(extruder_group_chip_bg());
m_label->SetForegroundColour(StateColor::darkModeColorFor(wxColour("#6B6B6B")));
for (wxStaticText *t : {m_brace_left, m_count, m_brace_right})
t->SetForegroundColour(StateColor::darkModeColorFor(wxColour("#262E30")));
m_hover_btn->SetBackgroundColour(extruder_group_chip_bg());
Refresh();
}
private:
// Content changed: the cached best size (ours and, transitively, our ancestors') is stale,
// and the parent must re-lay this row or the sizer keeps allocating the old width.
@@ -625,6 +639,15 @@ struct ExtruderGroup : StaticGroup
for (int i = 0; i < 4; ++i)
ams[i]->msw_rescale();
}
void sys_color_changed()
{
if (hover_label)
hover_label->sys_color_changed();
if (btn_edit)
btn_edit->SetBackgroundColour(extruder_group_chip_bg());
Refresh();
}
};
struct Sidebar::priv
@@ -1275,11 +1298,7 @@ ExtruderGroup::ExtruderGroup(wxWindow * parent, int index, wxString const &title
//label_ams->SetMinSize({FromDIP(70), -1});
if (index >= 0) {
btn_edit = new ScalableButton(this, wxID_ANY, "dot");
#ifdef __WXOSX__
btn_edit->SetBackgroundColour("#F7F7F7");
#else
btn_edit->SetBackgroundColour(*wxWHITE);
#endif
btn_edit->SetBackgroundColour(extruder_group_chip_bg());
btn_edit->Hide();
btn_edit->Bind(wxEVT_COMMAND_BUTTON_CLICKED, [this, index](auto &evt) {
PopupWindow *window = new AMSCountPopupWindow(this, index);
@@ -3866,6 +3885,10 @@ void Sidebar::sys_color_changed()
p->image_printer->SetSize(FromDIP(PRINTER_THUMBNAIL_SIZE));
p->image_printer_bed->SetSize(FromDIP(PRINTER_THUMBNAIL_SIZE));
for (ExtruderGroup *ext : {p->left_extruder, p->right_extruder, p->single_extruder})
if (ext)
ext->sys_color_changed();
// call a kill focus event to ensure new colors applied
for (ComboBox* combo : std::vector<ComboBox*>{p->combo_printer, p->combo_nozzle_dia, p->combo_printer_bed}){
wxFocusEvent fakeEvent(wxEVT_KILL_FOCUS);