Skip to content

Commit 93bdc43

Browse files
jeremypwzeebokmicahilbery
authored
elementary high contrast (light) stylescheme (#1602)
* Trial elementary high contrast theme base on elementary-light * Tweak for improved contrast * Further tweaks * Provide fallback for failure to get scheme or colors * Lint and other cleanup * Change cyan from BLUEBERRY500 to MINT900 * Use silver for line number background * Make comments more distinct * Update data/styles/elementary-highcontrast-light.xml Fix extra spaces Co-authored-by: Micah Ilbery <[email protected]> * Update data/styles/elementary-highcontrast-light.xml Use elementary red color Co-authored-by: Micah Ilbery <[email protected]> --------- Co-authored-by: Ryan Kornheisl <[email protected]> Co-authored-by: Micah Ilbery <[email protected]>
1 parent 7db9c9d commit 93bdc43

File tree

4 files changed

+188
-24
lines changed

4 files changed

+188
-24
lines changed

data/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ endforeach
1616
install_data([
1717
'styles/elementary-dark.xml',
1818
'styles/elementary-light.xml',
19+
'styles/elementary-highcontrast-light.xml',
1920
], install_dir: get_option('datadir') / 'gtksourceview-4' / 'styles')
2021

2122
install_data([
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<style-scheme id="elementary-highcontrast-light" _name="elementary High Contrast Light" version="1.0">
4+
<author>Elementary Developers</author>
5+
<_description>High Contrast color scheme using the elementary color palette</_description>
6+
7+
<!-- Background Colors Palette -->
8+
<color name="bg-0" value="#abacae"/> <!-- SILVER700-->
9+
<color name="bg-1" value="#d4d4d4"/> <!-- SILVER300-->
10+
<color name="bg-2" value="#fafafa"/> <!-- SILVER100-->
11+
<color name="bg-3" value="#EAEAEA"/> <!-- 50% SILVER300 + 50% WHITE
12+
13+
-->
14+
15+
<!--Foreground Colors Palette -->
16+
<color name="fg-0" value="#000000"/> <!-- BLACK900 -->
17+
<color name="fg-1" value="#1a1a1a"/> <!-- BLACK700 -->
18+
<color name="fg-2" value="#abacae"/> <!-- SILVER500 -->
19+
20+
<!--Highlight Colors Palette -->
21+
<color name="mud" value="#804b00"/> <!-- LATTE900 -->
22+
<color name="latte" value="#e7c591"/> <!-- LATTE300 -->
23+
<color name="yellow" value="#d48e15"/> <!-- BANANA700 -->
24+
<color name="orange" value="#cc3b02"/> <!-- ORANGE700 -->
25+
<color name="pink" value="#bc245d"/> <!-- BUBBLEGUM700 -->
26+
<color name="purple" value="#452981"/> <!-- GRAPE900 -->
27+
<color name="cyan" value="#007367"/> <!-- MINT900 -->
28+
<color name="blue" value="#0d52bf"/> <!-- BLUEBERRY700 -->
29+
<color name="lime" value="#68b723"/> <!-- LIME500 -->
30+
<color name="green" value="#206b00"/> <!-- LIME900 -->
31+
<color name="red" value="#a10705"/> <!-- STRAWBERRY700 -->
32+
<color name="black" value="#000000"/>
33+
34+
35+
<!-- Global Settings -->
36+
<style name="text" foreground="fg-0" background="bg-2"/>
37+
<style name="selection" background="latte"/>
38+
<style name="cursor" foreground="fg-0"/>
39+
<style name="secondary-cursor" foreground="fg-1"/>
40+
<style name="current-line" background="bg-1"/>
41+
<style name="line-numbers" foreground="fg-1" background="bg-3"/>
42+
<style name="background-pattern" background="bg-3"/>
43+
<style name="draw-spaces" foreground="fg-2"/>
44+
45+
<!-- Bracket Matching -->
46+
<style name="bracket-match" foreground="lime" background="bg-2" bold="true"/>
47+
<style name="bracket-mismatch" foreground="red" background="fg-2" bold="true"/>
48+
49+
<!-- Right Margin -->
50+
<style name="right-margin" foreground="bg-3" background="fg-1"/>
51+
52+
<!-- Search Matching -->
53+
<style name="search-match" foreground="black" background="yellow"/>
54+
55+
<!-- Comments -->
56+
<style name="def:comment" foreground="blue" italic="true"/>
57+
<style name="def:shebang" foreground="fg-1" bold="true"/>
58+
<style name="def:doc-comment-element" italic="true"/>
59+
60+
<!-- Constants -->
61+
<style name="def:constant" foreground="cyan"/>
62+
<style name="def:special-char" foreground="green"/>
63+
64+
<!-- Identifiers -->
65+
<style name="def:identifier" foreground="blue" bold="true"/>
66+
67+
<!-- Statements -->
68+
<style name="def:statement" foreground="orange"/>
69+
70+
<!-- Types -->
71+
<style name="def:type" foreground="green" bold="true"/>
72+
<style name="def:string" foreground="pink"/>
73+
<style name="def:keyword" foreground="mud" bold="true"/>
74+
75+
<!-- Markup -->
76+
<style name="def:emphasis" italic="true"/>
77+
<style name="def:strong-emphasis" foreground="orange"/>
78+
<style name="def:inline-code" foreground="blue"/>
79+
<style name="def:insertion" underline="single"/>
80+
<style name="def:deletion" strikethrough="true"/>
81+
<style name="def:link-text" foreground="fg-1"/>
82+
<style name="def:link-symbol" foreground="fg-1" bold="true"/>
83+
<style name="def:link-destination" italic="true" underline="single"/>
84+
<style name="def:heading" foreground="yellow"/>
85+
<style name="def:thematic-break" foreground="yellow"/>
86+
<style name="def:preformatted-section" foreground="blue"/>
87+
<style name="def:list-marker" foreground="orange"/>
88+
89+
<!-- Operators -->
90+
<style name="def:operator" foreground="lime" bold="true" />
91+
92+
<!-- Others -->
93+
<style name="def:preprocessor" foreground="purple"/>
94+
<style name="def:error" foreground="red" bold="true"/>
95+
<style name="def:note" foreground="pink" bold="true"/>
96+
<style name="def:net-address" italic="true" underline="single"/>
97+
98+
<!-- Language specific styles -->
99+
<style name="diff:added-line" foreground="green"/>
100+
<style name="diff:removed-line" foreground="red"/>
101+
<style name="diff:changed-line" foreground="yellow"/>
102+
<style name="diff:special-case" use-style="def:constant"/>
103+
<style name="diff:location" use-style="def:statement"/>
104+
<style name="diff:diff-file" use-style="def:type"/>
105+
106+
<style name="xml:tags" foreground="cyan" bold="true"/>
107+
<style name="xml:attribute-name" foreground="purple" bold="true"/>
108+
<style name="xml:namespace" foreground="lime" bold="true"/>
109+
110+
<style name="js:built-in-constructor" use-style="def:identifier"/>
111+
112+
<style name="latex:display-math" foreground="purple"/>
113+
<style name="latex:command" foreground="green" bold="true"/>
114+
<style name="latex:include" use-style="def:preprocessor"/>
115+
116+
<style name="sh:variable" foreground="purple"/>
117+
118+
<!-- legacy styles for old lang files -->
119+
<style name="Others" foreground="green" bold="true"/>
120+
<style name="Others 2" foreground="cyan"/>
121+
<style name="Others 3" foreground="purple"/>
122+
123+
</style-scheme>

src/Widgets/HeaderBar.vala

Lines changed: 63 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class Scratch.HeaderBar : Hdy.HeaderBar {
1616
public Gtk.ToggleButton sidebar_button { get; private set; }
1717
public Gtk.ToggleButton terminal_button { get; private set; }
1818

19-
private const string STYLE_SCHEME_HIGH_CONTRAST = "classic";
19+
private const string STYLE_SCHEME_HIGH_CONTRAST = "elementary-highcontrast-light";
2020
private const string STYLE_SCHEME_LIGHT = "elementary-light";
2121
private const string STYLE_SCHEME_DARK = "elementary-dark";
2222

@@ -169,7 +169,6 @@ public class Scratch.HeaderBar : Hdy.HeaderBar {
169169
margin_top = 6,
170170
margin_bottom = 6
171171
};
172-
173172
color_box.add (color_button_white);
174173
color_box.add (color_button_light);
175174
color_box.add (color_button_dark);
@@ -320,28 +319,52 @@ public class Scratch.HeaderBar : Hdy.HeaderBar {
320319
});
321320
}
322321

323-
private void style_color_button (Gtk.Widget color_button, string style_id) {
324-
string background = "#FFF";
325-
string foreground = "#333";
322+
private void style_color_button (Gtk.ToggleButton color_button, string style_id) {
323+
var background = "";
324+
var foreground = "";
326325

326+
Gtk.SourceStyleScheme? scheme = null;
327327
var sssm = Gtk.SourceStyleSchemeManager.get_default ();
328328
if (style_id in sssm.scheme_ids) {
329-
var scheme = sssm.get_scheme (style_id);
330-
color_button.tooltip_text = scheme.name;
329+
scheme = sssm.get_scheme (style_id);
330+
// We currently ship and hard-code the style schemes so can assume the "text" key
331+
// is present but if in future we permit the user to specify their own default
332+
// schemes (e.g. through separate settings keys) then this may not be the case.
333+
// so do a certain amount of validity checking
334+
var text_style = scheme.get_style ("text");
335+
var background_pattern_style = scheme.get_style ("background-pattern");
336+
if (text_style != null) {
337+
if (text_style.background_set) {
338+
background = text_style.background;
339+
}
340+
341+
if (text_style.foreground_set) {
342+
foreground = text_style.foreground;
343+
}
344+
}
331345

332-
var background_style = scheme.get_style ("background-pattern");
333-
var foreground_style = scheme.get_style ("text");
346+
if (background_pattern_style != null) {
347+
if (background == "" && background_pattern_style.background_set) {
348+
background = background_pattern_style.background;
349+
}
350+
351+
if (foreground == "" && background_pattern_style.foreground_set) {
352+
foreground = background_pattern_style.foreground;
353+
}
354+
}
334355

335-
if (background_style != null && background_style.background_set && !("rgba" in background_style.background)) {
336-
background = background_style.background;
356+
//Fallback to white and grey if necessary
357+
if (background == "" || background.contains ("rgba")) {
358+
background = "";
337359
}
338360

339-
if (foreground_style != null && foreground_style.foreground_set) {
340-
foreground = foreground_style.foreground;
361+
if (foreground == "" || foreground.contains ("rgba")) {
362+
foreground = "";
341363
}
342364
}
343365

344-
var style_css = """
366+
if (background != "" && foreground != "") {
367+
var style_css = """
345368
.color-button radio {
346369
background-color: %s;
347370
color: %s;
@@ -350,17 +373,34 @@ public class Scratch.HeaderBar : Hdy.HeaderBar {
350373
}
351374
""".printf (background, foreground);
352375

353-
var css_provider = new Gtk.CssProvider ();
376+
var css_provider = new Gtk.CssProvider ();
354377

355-
try {
356-
css_provider.load_from_data (style_css);
357-
} catch (Error e) {
358-
critical ("Unable to style color button: %s", e.message);
359-
}
378+
try {
379+
css_provider.load_from_data (style_css);
380+
} catch (Error e) {
381+
critical ("Unable to style color button: %s", e.message);
382+
}
360383

361-
unowned var style_context = color_button.get_style_context ();
362-
style_context.add_class (Granite.STYLE_CLASS_COLOR_BUTTON);
363-
style_context.add_provider (css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
384+
unowned var style_context = color_button.get_style_context ();
385+
style_context.add_class (Granite.STYLE_CLASS_COLOR_BUTTON);
386+
style_context.add_provider (css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
387+
color_button.tooltip_text = scheme.name;
388+
} else if (scheme != null || background == "" || foreground == "") {
389+
//Fallback to standard radio buttons (should not happen)
390+
switch (style_id) {
391+
case STYLE_SCHEME_LIGHT:
392+
color_button.label = _("Light");
393+
break;
394+
case STYLE_SCHEME_DARK:
395+
color_button.label = _("Dark");
396+
break;
397+
case STYLE_SCHEME_HIGH_CONTRAST:
398+
color_button.label = _("Contrast");
399+
break;
400+
default:
401+
assert_not_reached ();
402+
}
403+
}
364404
}
365405

366406
private void on_share_menu_changed () {

src/Widgets/SourceView.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ namespace Scratch.Widgets {
306306
}
307307
} else {
308308
var scheme = style_scheme_manager.get_scheme (Scratch.settings.get_string ("style-scheme"));
309-
source_buffer.style_scheme = scheme ?? style_scheme_manager.get_scheme ("classic");
309+
source_buffer.style_scheme = scheme ?? style_scheme_manager.get_scheme ("elementary-highcontrast-light");
310310
}
311311

312312
git_diff_gutter_renderer.set_style_scheme (source_buffer.style_scheme);

0 commit comments

Comments
 (0)