Re: dark theme

Neil Hodgson <[email protected]> Fri, 5 May 2023 16:10:07 -0700 (PDT)
Newsgroups gmane.editors.scite.general
Message-ID <[email protected]>
Andrew:

The way I see it dark mode in its very essence requires a non-literal 
interpretation of config colour strings. If that interpretation can not 
happen within the function which converts the colour strings to Scintilla 
colour type on properties refresh, then all the various colour data would 
need to be chased up and converted after properties refresh, somehow. 


Colour strings are not always resolved to colour integer values at read 
time. Properties are read and reread at different events in an effort to 
optimize performance.

Its likely that different contexts (edit pane, output pane, windows chrome, 
printing) will have different transformations.

Around scite version 2.20 I had hacked the colour(alpha)fromstring 
functions to adapt to state to enable darkmode, contrast, and saturation 
adjustment. If there was any hack to allow it now, I would think it 
worthwhile to create a darkmode but the StyleDefinition object someways 
seems to guard against it.


A non-hacky implementation will need to build infrastructure to support 
colour translations.

Perhaps start from this basic change to style fore and back. It also needs 
the default colours to be set explicitly 
(style.*.32=$(font.base),back:#FFFFFF,fore:#000000) since SciTE's standard 
properties provide differences from Scintilla's built-in black-on-white 
colours. This simple InvertLight function produces poor results in many 
cases.

Neil

diff -r 3b944ea15374 src/SciTEBase.h
--- a/src/SciTEBase.h Sat Apr 22 18:57:42 2023 +1000
+++ b/src/SciTEBase.h Sat May 06 08:46:59 2023 +1000
@@ -392,6 +392,8 @@
  bool wrapOutput;
  SA::Wrap wrapStyle;
  SA::IdleStyling idleStyling;
+ enum class ColourTranslation { none, invertLight } colourTranslation = 
ColourTranslation::invertLight;
+ SA::Colour TranslateColour(SA::Colour colour) const noexcept;
  SA::Alpha alphaIndicator;
  bool underIndicator;
  std::string foldColour;
diff -r 3b944ea15374 src/SciTEProps.cxx
--- a/src/SciTEProps.cxx Sat Apr 22 18:57:42 2023 +1000
+++ b/src/SciTEProps.cxx Sat May 06 08:46:59 2023 +1000
@@ -342,6 +342,27 @@
  return sd;
 }
 
+namespace {
+
+constexpr Scintilla::Colour InvertLight(Scintilla::Colour c) noexcept {
+ const unsigned int red = c & 0xffU;
+ const unsigned int green = (c >> 8) & 0xffU;
+ const unsigned int blue = (c >> 16) & 0xffU;
+ const unsigned int newRed = (green + blue) / 2;
+ const unsigned int newGreen = (red + blue) / 2;
+ const unsigned int newBlue = (red + green) / 2;
+ return ColourRGB(0xffU - newRed, 0xffU - newGreen, 0xffU - newBlue);
+}
+
+}
+
+Scintilla::Colour SciTEBase::TranslateColour(Scintilla::Colour colour) 
const noexcept {
+ if (colourTranslation == ColourTranslation::invertLight) {
+ return InvertLight(colour);
+ }
+ return colour;
+}
+
 void SciTEBase::SetOneStyle(GUI::ScintillaWindow &win, int style, 
std::string_view definition) {
  const StyleDefinition sd(definition);
  if (sd.specified & StyleDefinition::sdItalics)
@@ -357,9 +378,9 @@
  win.StyleSetCheckMonospaced(style, inMonospacedList);
  }
  if (sd.specified & StyleDefinition::sdFore)
- win.StyleSetFore(style, sd.Fore());
+ win.StyleSetFore(style, TranslateColour(sd.Fore()));
  if (sd.specified & StyleDefinition::sdBack)
- win.StyleSetBack(style, sd.Back());
+ win.StyleSetBack(style, TranslateColour(sd.Back()));
  if (sd.specified & StyleDefinition::sdSize)
  win.StyleSetSizeFractional(style, sd.FractionalSize());
  if (sd.specified & StyleDefinition::sdEOLFilled)

-- 
You received this message because you are subscribed to the Google Groups "scite-interest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/scite-interest/95c3b519-e86a-4f4b-8374-94fe79c83749n%40googlegroups.com.