diff --git a/src/gd_sophia_editor.erl b/src/gd_sophia_editor.erl index 6319610..30217c9 100644 --- a/src/gd_sophia_editor.erl +++ b/src/gd_sophia_editor.erl @@ -25,6 +25,7 @@ -define(H, 255). % High -define(M, 192). % Medium -define(L, 128). % Low +-define(X, 32). % X-Low -define(Z, 0). % Zilch @@ -44,6 +45,7 @@ -define(brown, {?L, ?L, ?Z}). -define(magenta, {?L, ?Z, ?L}). -define(cyan, {?Z, ?L, ?L}). +-define(not_black, {?X, ?X, ?X}). -define(grey, {?L, ?L, ?L}). -define(white, {?M, ?M, ?M}). @@ -63,7 +65,8 @@ palette(light) -> ?COMMENT => ?grey, ?STRING => ?red, ?NUMBER => ?magenta, - ?OPERATOR => ?brown}; + ?OPERATOR => ?brown, + bg => ?high_white}; palette(dark) -> #{?DEFAULT => ?white, ?KEYWORD => ?light_cyan, @@ -71,10 +74,15 @@ palette(dark) -> ?COMMENT => ?grey, ?STRING => ?light_red, ?NUMBER => ?light_magenta, - ?OPERATOR => ?yellow}. + ?OPERATOR => ?yellow, + bg => ?not_black}. color_mode() -> - light. + {R, G, B, _} = wxSystemSettings:getColour(?wxSYS_COLOUR_WINDOW), + case (lists:sum([R, G, B]) div 3) > 128 of + true -> light; + false -> dark + end. new(Parent) -> @@ -104,13 +112,15 @@ set_text(STC, Text) -> %% ====================================================================== set_colors(STC) -> - wxStyledTextCtrl:styleClearAll(STC), - Palette = palette(color_mode()), + ok = wxStyledTextCtrl:styleClearAll(STC), + Palette = #{bg := BGC} = palette(color_mode()), Colorize = fun(Style) -> Color = maps:get(Style, Palette), - wxStyledTextCtrl:styleSetForeground(STC, Style, Color) + ok = wxStyledTextCtrl:styleSetForeground(STC, Style, Color), + ok = wxStyledTextCtrl:styleSetBackground(STC, Style, BGC) end, + ok = wxStyledTextCtrl:styleSetBackground(STC, ?wxSTC_STYLE_DEFAULT, BGC), lists:foreach(Colorize, styles()).