Skip to content

Commit 014c396

Browse files
committed
Workaround to fix text colour not changing in status bar
It was noticed that the text color in the status bar doesn't change according to the theme settings. Looking for info I found that it's an know issue in wxWidgets which setting the color of native controls is not always possible. Considering we use the wxFLAT style, drawing the status bar ourselves is the easiest and most effective way to work around this issue. I included a grip icon similar to the Windows version, since no system resource is available for use (as with other system icons). NOTE: Fixed a theme issue that was preventing the status bar text from using its setting in the theme color. Thanks to Nova711 (on Discord).
1 parent 974118f commit 014c396

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/wings_status.erl

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ update_theme() ->
5151
init([Frame]) ->
5252
try
5353
SB0 = wxStatusBar:new(Frame),
54-
SB = wx_object:set_pid(SB0, self()),
54+
SB = wx_object:set_pid(SB0, self()),
5555
SBG = wings_color:rgb4bv(wings_pref:get_value(info_line_bg)),
5656
SFG = wings_color:rgb4bv(wings_pref:get_value(info_line_text)),
5757
wxStatusBar:setBackgroundColour(SB, SBG),
@@ -61,6 +61,8 @@ init([Frame]) ->
6161
wxStatusBar:setStatusStyles(SB, [?wxSB_FLAT, ?wxSB_NORMAL]),
6262
wxFrame:setStatusBar(Frame, SB),
6363
wxFrame:setStatusBarPane(Frame, 0),
64+
%% this will "fix" the custom painting theme
65+
wxWindow:connect(SB, paint, [{callback, fun custom_draw/2}]),
6466
{SB, #state{sb=SB, frame=Frame}}
6567
catch _:Reason:ST ->
6668
io:format("Error ~p ~p ~n",[Reason, ST]),
@@ -103,6 +105,29 @@ code_change(_, _, State) ->
103105
terminate(_, _) ->
104106
ok.
105107

108+
custom_draw(#wx{obj=Obj, event=#wxPaint{}}, _) ->
109+
Size = wxWindow:getSize(Obj),
110+
DC = case os:type() of
111+
{win32, _} -> %% Flicker on windows
112+
wx:typeCast(wxBufferedPaintDC:new(Obj), wxPaintDC);
113+
_ ->
114+
wxPaintDC:new(Obj)
115+
end,
116+
wxDC:clear(DC),
117+
case wxStatusBar:getFieldsCount(Obj) of
118+
2 ->
119+
{true,{Xl,Yl,_,_Hl}} = wxStatusBar:getFieldRect(Obj, 0),
120+
{true,{Xr,Yr,_Wr,_Hr}} = wxStatusBar:getFieldRect(Obj, 1),
121+
wxDC:drawText(DC, wxStatusBar:getStatusText(Obj,[{number,0}]), {Xl+3,Yl+2}),
122+
wxDC:drawText(DC, wxStatusBar:getStatusText(Obj,[{number,1}]), {Xr+3,Yr+2});
123+
_ -> ok
124+
end,
125+
GrpPen = wxPen:new(wxSystemSettings:getColour(?wxSYS_COLOUR_3DSHADOW)),
126+
wxDC:setPen(DC,GrpPen),
127+
draw_grip(DC, Size, 3),
128+
wxPen:destroy(GrpPen),
129+
wxPaintDC:destroy(DC).
130+
106131
update_status({value, Prev}, Prev, _SB) ->
107132
Prev;
108133
update_status(none, _, SB) ->
@@ -132,6 +157,11 @@ set_status(Msgs={Left, Right}, SB) ->
132157
wxStatusBar:setStatusText(SB, Right, [{number, 1}]),
133158
Msgs.
134159

160+
draw_grip(_, _, 0) -> ok;
161+
draw_grip(DC, {W,H}=Size, C) ->
162+
[wxDC:drawRectangle(DC, {W-(3*I)-1, H-(3*(4-C))-1}, {2,2}) || I <- lists:seq(C,1,-1)],
163+
draw_grip(DC, Size, C-1).
164+
135165
str(undefined, Old) -> Old;
136166
str(New, _) -> str_clean(New).
137167

0 commit comments

Comments
 (0)