Module: Lich::Common::GUI::ThemeUtils
- Defined in:
- documented/common/gui/theme_utils.rb
Overview
Provides utility methods for applying themes in the GUI.
Class Method Summary collapse
-
.apply_favorites_styling(widget, theme_state, is_favorite = false) ⇒ void
Applies the favorites styling to the specified widget based on the theme state.
-
.apply_style_to_buttons(ui_elements, color) ⇒ void
Applies the specified color style to all button elements in the provided UI elements.
-
.apply_theme_settings(theme_state) ⇒ void
Applies the theme settings based on the provided state.
-
.apply_theme_to_notebook(notebook, theme_state) ⇒ void
Applies the theme to the specified notebook based on the theme state.
-
.apply_theme_to_window(window, theme_state) ⇒ void
Applies the theme to the specified window based on the theme state.
-
.create_favorites_css(theme_state) ⇒ String
Creates CSS for favorite items based on the theme state.
-
.create_favorites_css_provider(theme_state) ⇒ Gtk::CssProvider
Creates a CSS provider for the favorites styling based on the theme state.
-
.darkmode_background ⇒ Gdk::RGBA
Returns the background color for the dark theme.
-
.favorite_button_background(theme_state) ⇒ Gdk::RGBA
Returns the background color for the favorite button based on the theme state.
-
.favorite_indicator_color(theme_state) ⇒ Gdk::RGBA
Returns the color for the favorite indicator based on the theme state.
-
.light_theme_background ⇒ Gdk::RGBA
Returns the background color for the light theme.
-
.light_theme_button ⇒ Gdk::RGBA
Returns the button color for the light theme.
Class Method Details
.apply_favorites_styling(widget, theme_state, is_favorite = false) ⇒ void
This method returns an undefined value.
Applies the favorites styling to the specified widget based on the theme state.
172 173 174 175 176 177 178 179 |
# File 'documented/common/gui/theme_utils.rb', line 172 def self.apply_favorites_styling(, theme_state, is_favorite = false) provider = create_favorites_css_provider(theme_state) .style_context.add_provider(provider, Gtk::StyleProvider::PRIORITY_USER) if is_favorite .style_context.add_class('favorite-character') end end |
.apply_style_to_buttons(ui_elements, color) ⇒ void
This method returns an undefined value.
Applies the specified color style to all button elements in the provided UI elements.
76 77 78 79 80 81 82 |
# File 'documented/common/gui/theme_utils.rb', line 76 def self.(ui_elements, color) ui_elements.each do |_key, element| if element.is_a?(Gtk::Button) element.override_background_color(:normal, color) end end end |
.apply_theme_settings(theme_state) ⇒ void
This method returns an undefined value.
Applies the theme settings based on the provided state.
14 15 16 |
# File 'documented/common/gui/theme_utils.rb', line 14 def self.apply_theme_settings(theme_state) Gtk::Settings.default.gtk_application_prefer_dark_theme = theme_state end |
.apply_theme_to_notebook(notebook, theme_state) ⇒ void
This method returns an undefined value.
Applies the theme to the specified notebook based on the theme state.
62 63 64 65 66 67 68 |
# File 'documented/common/gui/theme_utils.rb', line 62 def self.apply_theme_to_notebook(notebook, theme_state) if theme_state notebook.override_background_color(:normal, darkmode_background) else notebook.override_background_color(:normal, light_theme_background) end end |
.apply_theme_to_window(window, theme_state) ⇒ void
This method returns an undefined value.
Applies the theme to the specified window based on the theme state.
48 49 50 51 52 53 54 |
# File 'documented/common/gui/theme_utils.rb', line 48 def self.apply_theme_to_window(window, theme_state) if theme_state window.override_background_color(:normal, darkmode_background) else window.override_background_color(:normal, light_theme_background) end end |
.create_favorites_css(theme_state) ⇒ String
Creates CSS for favorite items based on the theme state.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'documented/common/gui/theme_utils.rb', line 89 def self.create_favorites_css(theme_state) if theme_state # Dark theme favorites styling <<~CSS .favorite-character { background: linear-gradient(135deg, #2d3748 0%, #4a5568 100%); border: 2px solid #ffd700; border-radius: 4px; box-shadow: 0 2px 4px rgba(255, 215, 0, 0.3); } .favorite-character:hover { background: linear-gradient(135deg, #4a5568 0%, #2d3748 100%); border-color: #ffed4e; box-shadow: 0 4px 8px rgba(255, 215, 0, 0.4); } .favorite-button { color: #ffd700; font-weight: bold; font-size: 16px; } .favorite-button:hover { color: #ffed4e; background: rgba(255, 215, 0, 0.1); } CSS else # Light theme favorites styling <<~CSS .favorite-character { background: linear-gradient(135deg, #fff8dc 0%, #f0f8ff 100%); border: 2px solid #daa520; border-radius: 4px; box-shadow: 0 2px 4px rgba(218, 165, 32, 0.3); } .favorite-character:hover { background: linear-gradient(135deg, #f0f8ff 0%, #fff8dc 100%); border-color: #b8860b; box-shadow: 0 4px 8px rgba(218, 165, 32, 0.4); } .favorite-button { color: #b8860b; font-weight: bold; font-size: 16px; } .favorite-button:hover { color: #daa520; background: rgba(218, 165, 32, 0.1); } CSS end end |
.create_favorites_css_provider(theme_state) ⇒ Gtk::CssProvider
Creates a CSS provider for the favorites styling based on the theme state.
152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'documented/common/gui/theme_utils.rb', line 152 def self.create_favorites_css_provider(theme_state) provider = Gtk::CssProvider.new css_data = create_favorites_css(theme_state) begin provider.load_from_data(css_data) rescue StandardError => e Lich.log "error: Error loading favorites CSS: #{e.}" end provider end |
.darkmode_background ⇒ Gdk::RGBA
Returns the background color for the dark theme.
38 39 40 |
# File 'documented/common/gui/theme_utils.rb', line 38 def self.darkmode_background Gdk::RGBA::parse("rgba(40,40,40,1)") end |
.favorite_button_background(theme_state) ⇒ Gdk::RGBA
Returns the background color for the favorite button based on the theme state.
199 200 201 202 203 204 205 |
# File 'documented/common/gui/theme_utils.rb', line 199 def self.(theme_state) if theme_state Gdk::RGBA::parse("rgba(255, 215, 0, 0.1)") # Transparent gold else Gdk::RGBA::parse("rgba(218, 165, 32, 0.1)") # Transparent goldenrod end end |
.favorite_indicator_color(theme_state) ⇒ Gdk::RGBA
Returns the color for the favorite indicator based on the theme state.
186 187 188 189 190 191 192 |
# File 'documented/common/gui/theme_utils.rb', line 186 def self.favorite_indicator_color(theme_state) if theme_state Gdk::RGBA::parse("#ffd700") # Gold for dark theme else Gdk::RGBA::parse("#b8860b") # Dark goldenrod for light theme end end |
.light_theme_background ⇒ Gdk::RGBA
Returns the background color for the light theme.
22 23 24 |
# File 'documented/common/gui/theme_utils.rb', line 22 def self.light_theme_background Gdk::RGBA::parse("#d3d3d3") end |
.light_theme_button ⇒ Gdk::RGBA
Returns the button color for the light theme.
30 31 32 |
# File 'documented/common/gui/theme_utils.rb', line 30 def self. Gdk::RGBA::parse("#f0f0f0") end |