[chronojump] Better management of background color contrast and labels



commit 1f13da458ac7ad24b6e6768ea0d4c32313395d8e
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed Apr 8 17:12:31 2020 +0200

    Better management of background color contrast and labels

 src/gui/app1/chronojump.cs | 36 ++++++++++++++++++------------------
 src/gui/preferences.cs     |  1 +
 src/preferences.cs         |  1 +
 src/sqlite/preferences.cs  |  3 +++
 src/utilGtk.cs             | 34 +++++++++++++++++++---------------
 5 files changed, 42 insertions(+), 33 deletions(-)
---
diff --git a/src/gui/app1/chronojump.cs b/src/gui/app1/chronojump.cs
index 12a11e93..d97eea84 100644
--- a/src/gui/app1/chronojump.cs
+++ b/src/gui/app1/chronojump.cs
@@ -748,26 +748,26 @@ public partial class ChronoJumpWindow
        {
                if(personsAtTop)
                {
-                       UtilGtk.ContrastLabelsHBox (viewport_hpaned_contacts_main, hbox_top_person);
-                       UtilGtk.ContrastLabelsHBox (viewport_hpaned_contacts_main, hbox_top_person_encoder);
-                       UtilGtk.ContrastLabelsTable (viewport_rest_time_contacts, table_rest_time_contacts);
-                       UtilGtk.ContrastLabelsTable (viewport_rest_time_encoder, table_rest_time_encoder);
-               }
-
-               UtilGtk.ContrastLabelsNotebook (viewport_hpaned_contacts_main, app1s_notebook);
+                       UtilGtk.ContrastLabelsHBox (preferences.colorBackgroundIsDark, hbox_top_person);
+                       UtilGtk.ContrastLabelsHBox (preferences.colorBackgroundIsDark, 
hbox_top_person_encoder);
+                       UtilGtk.ContrastLabelsTable (preferences.colorBackgroundIsDark, 
table_rest_time_contacts);
+                       UtilGtk.ContrastLabelsTable (preferences.colorBackgroundIsDark, 
table_rest_time_encoder);
 
-               if(UtilGtk.ColorIsDark(viewport_rest_time_encoder.Style.Background(StateType.Normal)))
-               {
-                       image_contacts_rest_time_dark_blue.Visible = false;
-                       image_contacts_rest_time_clear_yellow.Visible = true;
-                       image_encoder_rest_time_dark_blue.Visible = false;
-                       image_encoder_rest_time_clear_yellow.Visible = true;
-               } else {
-                       image_contacts_rest_time_dark_blue.Visible = true;
-                       image_contacts_rest_time_clear_yellow.Visible = false;
-                       image_encoder_rest_time_dark_blue.Visible = true;
-                       image_encoder_rest_time_clear_yellow.Visible = false;
+                       if(preferences.colorBackgroundIsDark)
+                       {
+                               image_contacts_rest_time_dark_blue.Visible = false;
+                               image_contacts_rest_time_clear_yellow.Visible = true;
+                               image_encoder_rest_time_dark_blue.Visible = false;
+                               image_encoder_rest_time_clear_yellow.Visible = true;
+                       } else {
+                               image_contacts_rest_time_dark_blue.Visible = true;
+                               image_contacts_rest_time_clear_yellow.Visible = false;
+                               image_encoder_rest_time_dark_blue.Visible = true;
+                               image_encoder_rest_time_clear_yellow.Visible = false;
+                       }
                }
+
+               UtilGtk.ContrastLabelsNotebook (preferences.colorBackgroundIsDark, app1s_notebook);
        }
 
        private void testNewStuff()
diff --git a/src/gui/preferences.cs b/src/gui/preferences.cs
index f0099cff..1e794cb6 100644
--- a/src/gui/preferences.cs
+++ b/src/gui/preferences.cs
@@ -1898,6 +1898,7 @@ public class PreferencesWindow
                preferences.colorBackgroundString = Preferences.PreferencesChange(
                                SqlitePreferences.ColorBackground, preferences.colorBackgroundString,
                                UtilGtk.ColorToColorString(colorBackground)); //this does the reverse of 
Gdk.Color.Parse on UtilGtk.ColorParse()
+               preferences.colorBackgroundIsDark = UtilGtk.ColorIsDark(colorBackground);
 
                preferences.logoAnimatedShow = Preferences.PreferencesChange(
                                SqlitePreferences.LogoAnimatedShow, preferences.logoAnimatedShow,
diff --git a/src/preferences.cs b/src/preferences.cs
index 8033e70b..ddda622f 100644
--- a/src/preferences.cs
+++ b/src/preferences.cs
@@ -36,6 +36,7 @@ public class Preferences
        public enum MenuTypes { ALL, TEXT, ICONS};
        public MenuTypes menuType;
        public string colorBackgroundString;
+       public bool colorBackgroundIsDark; //this is assigned when colorBackgroundString changes. And this is 
used by the rest of the program. Not stored on SQL.
        public bool logoAnimatedShow;
 
        public enum UnitsEnum { METRIC, IMPERIAL };
diff --git a/src/sqlite/preferences.cs b/src/sqlite/preferences.cs
index 3893f53e..f74e6bf9 100644
--- a/src/sqlite/preferences.cs
+++ b/src/sqlite/preferences.cs
@@ -369,7 +369,10 @@ class SqlitePreferences : Sqlite
                                preferences.menuType = (Preferences.MenuTypes)
                                        Enum.Parse(typeof(Preferences.MenuTypes), reader[1].ToString());
                        else if(reader[0].ToString() == ColorBackground)
+                       {
                                preferences.colorBackgroundString = reader[1].ToString();
+                               preferences.colorBackgroundIsDark = UtilGtk.ColorIsDark(reader[1].ToString());
+                       }
                        else if(reader[0].ToString() == LogoAnimatedShow)
                                preferences.logoAnimatedShow = reader[1].ToString() == "True";
                        else if(reader[0].ToString() == UnitsStr)
diff --git a/src/utilGtk.cs b/src/utilGtk.cs
index ef5b0603..d389686b 100644
--- a/src/utilGtk.cs
+++ b/src/utilGtk.cs
@@ -500,6 +500,10 @@ public class UtilGtk
                //3 components come in ushort (0-65535)
                return (color.Red + color.Green + color.Blue < 3 * 65535 / 2.0);
        }
+       public static bool ColorIsDark(string colorString)
+       {
+               return ColorIsDark(ColorParse(colorString));
+       }
 
        public static Gdk.Color GetBackgroundColorSelected() {
                Gtk.Style regularLabel = Gtk.Rc.GetStyle (new Gtk.Label());
@@ -602,38 +606,38 @@ public class UtilGtk
                e.ModifyBg(StateType.Prelight, color);
        }
 
-       public static void ContrastLabelsHBox (Gtk.Viewport v, Gtk.HBox hbox)
+       public static void ContrastLabelsHBox (bool bgDark, Gtk.HBox hbox)
        {
-               contrastLabelsContainer (v, (Gtk.Container) hbox);
+               contrastLabelsContainer (bgDark, (Gtk.Container) hbox);
        }
-       public static void ContrastLabelsVBox (Gtk.Viewport v, Gtk.VBox vbox)
+       public static void ContrastLabelsVBox (bool bgDark, Gtk.VBox vbox)
        {
-               contrastLabelsContainer (v, (Gtk.Container) vbox);
+               contrastLabelsContainer (bgDark, (Gtk.Container) vbox);
        }
-       public static void ContrastLabelsTable (Gtk.Viewport v, Gtk.Table table)
+       public static void ContrastLabelsTable (bool bgDark, Gtk.Table table)
        {
-               contrastLabelsContainer (v, (Gtk.Container) table);
+               contrastLabelsContainer (bgDark, (Gtk.Container) table);
        }
-       public static void ContrastLabelsNotebook (Gtk.Viewport v, Gtk.Notebook notebook)
+       public static void ContrastLabelsNotebook (bool bgDark, Gtk.Notebook notebook)
        {
-               contrastLabelsContainer (v, (Gtk.Container) notebook);
+               contrastLabelsContainer (bgDark, (Gtk.Container) notebook);
        }
 
-       private static void contrastLabelsContainer (Gtk.Viewport v, Gtk.Container container)
+       private static void contrastLabelsContainer (bool bgDark, Gtk.Container container)
        {
                foreach(Gtk.Widget w in container.Children)
                {
                        if(w.GetType() == typeof(Gtk.Label))
-                               labelDoContrastColor (v, (Gtk.Label) w);
+                               labelDoContrastColor (bgDark, (Gtk.Label) w);
 
                        else if(w.GetType() == typeof(Gtk.Alignment))
                        {
                                Gtk.Widget child = ((Gtk.Alignment) w).Child;
                                if(isContainer(child))
-                                       contrastLabelsContainer (v, (Gtk.Container) child);
+                                       contrastLabelsContainer (bgDark, (Gtk.Container) child);
                        }
                        else if(isContainer(w))
-                               contrastLabelsContainer (v, (Gtk.Container) w);
+                               contrastLabelsContainer (bgDark, (Gtk.Container) w);
                }
        }
 
@@ -649,15 +653,15 @@ public class UtilGtk
                        );
        }
 
-       private static void labelDoContrastColor (Gtk.Viewport v, Gtk.Label l)
+       private static void labelDoContrastColor (bool bgDark, Gtk.Label l)
        {
-               if(ColorIsDark(v.Style.Background(StateType.Normal)))
+               if(bgDark)
                {
                        l.ModifyFg(StateType.Normal, YELLOW_LIGHT);
                        l.ModifyFg(StateType.Active, YELLOW_LIGHT); //needed for CheckButton and RadioButton
                } else {
                        l.ModifyFg(StateType.Normal, BLACK);
-//                     l.ModifyFg(StateType.Active, BLACK);
+                       //l.ModifyFg(StateType.Active, BLACK);
                }
        }
        


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]