Skip to content

elementary high contrast (light) stylescheme #1602

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions data/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ endforeach
install_data([
'styles/elementary-dark.xml',
'styles/elementary-light.xml',
'styles/elementary-highcontrast-light.xml',
], install_dir: get_option('datadir') / 'gtksourceview-4' / 'styles')

install_data([
Expand Down
123 changes: 123 additions & 0 deletions data/styles/elementary-highcontrast-light.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="UTF-8"?>

<style-scheme id="elementary-highcontrast-light" _name="elementary High Contrast Light" version="1.0">
<author>Elementary Developers</author>
<_description>High Contrast color scheme using the elementary color palette</_description>

<!-- Background Colors Palette -->
<color name="bg-0" value="#abacae"/> <!-- SILVER700-->
<color name="bg-1" value="#d4d4d4"/> <!-- SILVER300-->
<color name="bg-2" value="#fafafa"/> <!-- SILVER100-->
<color name="bg-3" value="#f7efe1"/> <!-- 50% LATTE100 + 50% WHITE

-->

<!--Foreground Colors Palette -->
<color name="fg-0" value="#000000"/> <!-- BLACK900 -->
<color name="fg-1" value="#1a1a1a"/> <!-- BLACK700 -->
<color name="fg-2" value="#abacae"/> <!-- SILVER500 -->

<!--Highlight Colors Palette -->
<color name="mud" value="#804b00"/> <!-- LATTE900 -->
<color name="latte" value="#e7c591"/> <!-- LATTE300 -->
<color name="yellow" value="#d48e15"/> <!-- BANANA700 -->
<color name="orange" value="#cc3b02"/> <!-- ORANGE700 -->
<color name="pink" value="#bc245d"/> <!-- BUBBLEGUM700 -->
<color name="purple" value="#452981"/> <!-- GRAPE900 -->
<color name="cyan" value="#3689e6"/> <!-- BLUEBERRY500 -->
<color name="blue" value="#0d52bf"/> <!-- BLUEBERRY700 -->
<color name="lime" value="#68b723"/> <!-- LIME500 -->
<color name="green" value="#206b00"/> <!-- LIME900 -->
<color name="red" value="#FF0000"/>
<color name="black" value="#000000"/>


<!-- Global Settings -->
<style name="text" foreground="fg-0" background="bg-2"/>
<style name="selection" background="latte"/>
<style name="cursor" foreground="fg-0"/>
<style name="secondary-cursor" foreground="fg-1"/>
<style name="current-line" background="bg-1"/>
<style name="line-numbers" foreground="fg-1" background="bg-3"/>
<style name="background-pattern" background="bg-3"/>
<style name="draw-spaces" foreground="fg-2"/>

<!-- Bracket Matching -->
<style name="bracket-match" foreground="lime" background="bg-2" bold="true"/>
<style name="bracket-mismatch" foreground="red" background="fg-2" bold="true"/>

<!-- Right Margin -->
<style name="right-margin" foreground="bg-3" background="fg-1"/>

<!-- Search Matching -->
<style name="search-match" foreground="black" background="yellow"/>

<!-- Comments -->
<style name="def:comment" foreground="fg-1"/>
<style name="def:shebang" foreground="fg-1" bold="true"/>
<style name="def:doc-comment-element" italic="true"/>

<!-- Constants -->
<style name="def:constant" foreground="cyan"/>
<style name="def:special-char" foreground="green"/>

<!-- Identifiers -->
<style name="def:identifier" foreground="blue" bold="true"/>

<!-- Statements -->
<style name="def:statement" foreground="orange"/>

<!-- Types -->
<style name="def:type" foreground="green" bold="true"/>
<style name="def:string" foreground="pink"/>
<style name="def:keyword" foreground="mud" bold="true"/>

<!-- Markup -->
<style name="def:emphasis" italic="true"/>
<style name="def:strong-emphasis" foreground="orange"/>
<style name="def:inline-code" foreground="blue"/>
<style name="def:insertion" underline="single"/>
<style name="def:deletion" strikethrough="true"/>
<style name="def:link-text" foreground="fg-1"/>
<style name="def:link-symbol" foreground="fg-1" bold="true"/>
<style name="def:link-destination" italic="true" underline="single"/>
<style name="def:heading" foreground="yellow"/>
<style name="def:thematic-break" foreground="yellow"/>
<style name="def:preformatted-section" foreground="blue"/>
<style name="def:list-marker" foreground="orange"/>

<!-- Operators -->
<style name="def:operator" foreground="lime" bold="true" />

<!-- Others -->
<style name="def:preprocessor" foreground="purple"/>
<style name="def:error" foreground="red" bold="true"/>
<style name="def:note" foreground="pink" bold="true"/>
<style name="def:net-address" italic="true" underline="single"/>

<!-- Language specific styles -->
<style name="diff:added-line" foreground="green"/>
<style name="diff:removed-line" foreground="red"/>
<style name="diff:changed-line" foreground="yellow"/>
<style name="diff:special-case" use-style="def:constant"/>
<style name="diff:location" use-style="def:statement"/>
<style name="diff:diff-file" use-style="def:type"/>

<style name="xml:tags" foreground="cyan" bold="true"/>
<style name="xml:attribute-name" foreground="purple" bold="true"/>
<style name="xml:namespace" foreground="lime" bold="true"/>

<style name="js:built-in-constructor" use-style="def:identifier"/>

<style name="latex:display-math" foreground="purple"/>
<style name="latex:command" foreground="green" bold="true"/>
<style name="latex:include" use-style="def:preprocessor"/>

<style name="sh:variable" foreground="purple"/>

<!-- legacy styles for old lang files -->
<style name="Others" foreground="green" bold="true"/>
<style name="Others 2" foreground="cyan"/>
<style name="Others 3" foreground="purple"/>

</style-scheme>
86 changes: 63 additions & 23 deletions src/Widgets/HeaderBar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class Scratch.HeaderBar : Hdy.HeaderBar {
public Gtk.ToggleButton sidebar_button { get; private set; }
public Gtk.ToggleButton terminal_button { get; private set; }

private const string STYLE_SCHEME_HIGH_CONTRAST = "classic";
private const string STYLE_SCHEME_HIGH_CONTRAST = "elementary-highcontrast-light";
private const string STYLE_SCHEME_LIGHT = "elementary-light";
private const string STYLE_SCHEME_DARK = "elementary-dark";

Expand Down Expand Up @@ -169,7 +169,6 @@ public class Scratch.HeaderBar : Hdy.HeaderBar {
margin_top = 6,
margin_bottom = 6
};

color_box.add (color_button_white);
color_box.add (color_button_light);
color_box.add (color_button_dark);
Expand Down Expand Up @@ -320,28 +319,52 @@ public class Scratch.HeaderBar : Hdy.HeaderBar {
});
}

private void style_color_button (Gtk.Widget color_button, string style_id) {
string background = "#FFF";
string foreground = "#333";
private void style_color_button (Gtk.ToggleButton color_button, string style_id) {
var background = "";
var foreground = "";

Gtk.SourceStyleScheme? scheme = null;
var sssm = Gtk.SourceStyleSchemeManager.get_default ();
if (style_id in sssm.scheme_ids) {
var scheme = sssm.get_scheme (style_id);
color_button.tooltip_text = scheme.name;
scheme = sssm.get_scheme (style_id);
// We currently ship and hard-code the style schemes so can assume the "text" key
// is present but if in future we permit the user to specify their own default
// schemes(e.g. through separate settings keys) then this may not be the case.
// so do a certain amount of validity checking
var text_style = scheme.get_style ("text");
var background_pattern_style = scheme.get_style ("background-pattern");
if (text_style != null) {
if (text_style.background_set) {
background = text_style.background;
}

if (text_style.foreground_set) {
foreground = text_style.foreground;
}
}

var background_style = scheme.get_style ("background-pattern");
var foreground_style = scheme.get_style ("text");
if (background_pattern_style != null) {
if (background == "" && background_pattern_style.background_set) {
background = background_pattern_style.background;
}

if (foreground == "" && background_pattern_style.foreground_set) {
foreground = background_pattern_style.foreground;
}
}

if (background_style != null && background_style.background_set && !("rgba" in background_style.background)) {
background = background_style.background;
//Fallback to white and grey if necessary
if (background == "" || background.contains ("rgba")) {
background ="";
}

if (foreground_style != null && foreground_style.foreground_set) {
foreground = foreground_style.foreground;
if (foreground == "" || foreground.contains ("rgba")) {
foreground ="";
}
}

var style_css = """
if (background != "" && foreground != "") {
var style_css = """
.color-button radio {
background-color: %s;
color: %s;
Expand All @@ -350,17 +373,34 @@ public class Scratch.HeaderBar : Hdy.HeaderBar {
}
""".printf (background, foreground);

var css_provider = new Gtk.CssProvider ();
var css_provider = new Gtk.CssProvider ();

try {
css_provider.load_from_data (style_css);
} catch (Error e) {
critical ("Unable to style color button: %s", e.message);
}
try {
css_provider.load_from_data (style_css);
} catch (Error e) {
critical ("Unable to style color button: %s", e.message);
}

unowned var style_context = color_button.get_style_context ();
style_context.add_class (Granite.STYLE_CLASS_COLOR_BUTTON);
style_context.add_provider (css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
unowned var style_context = color_button.get_style_context ();
style_context.add_class (Granite.STYLE_CLASS_COLOR_BUTTON);
style_context.add_provider (css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
color_button.tooltip_text = scheme.name;
} else if (scheme != null || background == "" || foreground == "") {
//Fallback to standard radio buttons (shouldnt happen)
switch (style_id) {
case STYLE_SCHEME_LIGHT:
color_button.label = _("Light");
break;
case STYLE_SCHEME_DARK:
color_button.label = _("Dark");
break;
case STYLE_SCHEME_HIGH_CONTRAST:
color_button.label = _("Contrast");
break;
default:
assert_not_reached ();
}
}
}

private void on_share_menu_changed () {
Expand Down
2 changes: 1 addition & 1 deletion src/Widgets/SourceView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ namespace Scratch.Widgets {
}
} else {
var scheme = style_scheme_manager.get_scheme (Scratch.settings.get_string ("style-scheme"));
source_buffer.style_scheme = scheme ?? style_scheme_manager.get_scheme ("classic");
source_buffer.style_scheme = scheme ?? style_scheme_manager.get_scheme ("elementary-highcontrast-light");
}

git_diff_gutter_renderer.set_style_scheme (source_buffer.style_scheme);
Expand Down