22#include " Label.hpp"
33#include " TextCtrl.h"
44#include " slic3r/GUI/Widgets/Label.hpp"
5+ #ifdef __APPLE__
6+ #include " slic3r/Utils/MacDarkMode.hpp"
7+ #endif
58
69#include < wx/dcclient.h>
710#include < wx/dcgraph.h>
@@ -63,8 +66,7 @@ void TextInput::Create(wxWindow * parent,
6366 text_ctrl = new TextCtrl (this , wxID_ANY, text, {4 , 4 }, wxDefaultSize, style | wxBORDER_NONE | wxTE_PROCESS_ENTER);
6467 text_ctrl->SetFont (Label::Body_14);
6568 text_ctrl->SetInitialSize (text_ctrl->GetBestSize ());
66- text_ctrl->SetBackgroundColour (background_color.colorForStates (state_handler.states ()));
67- text_ctrl->SetForegroundColour (text_color.colorForStates (state_handler.states ()));
69+ UpdateTextCtrlColours ();
6870 state_handler.attach_child (text_ctrl);
6971 text_ctrl->Bind (wxEVT_KILL_FOCUS, [this ](auto &e) {
7072 OnEdit ();
@@ -141,6 +143,28 @@ void TextInput::SetTextColor(StateColor const& color)
141143{
142144 text_color= color;
143145 state_handler.update_binds ();
146+ UpdateTextCtrlColours ();
147+ }
148+
149+ void TextInput::UpdateTextCtrlColours ()
150+ {
151+ if (!text_ctrl)
152+ return ;
153+
154+ const int states = state_handler.states ();
155+ #ifdef __APPLE__
156+ const wxColour bg = background_color.colorForStatesNoDark (states);
157+ const wxColour fg = text_color.colorForStatesNoDark (states);
158+ #else
159+ const wxColour bg = background_color.colorForStates (states);
160+ const wxColour fg = text_color.colorForStates (states);
161+ #endif
162+ text_ctrl->SetBackgroundColour (bg);
163+ text_ctrl->SetForegroundColour (fg);
164+ #ifdef __APPLE__
165+ Slic3r::GUI::set_textfield_native_colours (text_ctrl->GetHandle (), bg, fg, true );
166+ #endif
167+ text_ctrl->Refresh ();
144168}
145169
146170void TextInput::Rescale ()
@@ -160,8 +184,7 @@ bool TextInput::Enable(bool enable)
160184 wxCommandEvent e (EVT_ENABLE_CHANGED );
161185 e.SetEventObject (this );
162186 GetEventHandler ()->ProcessEvent (e);
163- text_ctrl->SetBackgroundColour (background_color.colorForStates (state_handler.states ()));
164- text_ctrl->SetForegroundColour (text_color.colorForStates (state_handler.states ()));
187+ UpdateTextCtrlColours ();
165188 }
166189 return result;
167190}
0 commit comments