Module: Lich::Common::GUI::ThemeUtils

Defined in:
documented/common/gui/theme_utils.rb

Overview

Provides utility methods for applying themes in the GUI.

Examples:

Applying a theme

Lich::Common::GUI::ThemeUtils.apply_theme_settings(true)

Class Method Summary collapse

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.

Examples:

Applying favorites styling to a widget

Lich::Common::GUI::ThemeUtils.apply_favorites_styling(widget, true, true)

Parameters:

  • widget (Gtk::Widget)

    The widget to apply the favorites styling to.

  • theme_state (Boolean)

    The state of the theme (true for dark theme, false for light theme).

  • is_favorite (Boolean) (defaults to: false)

    Indicates if the widget is a favorite.



172
173
174
175
176
177
178
179
# File 'documented/common/gui/theme_utils.rb', line 172

def self.apply_favorites_styling(widget, theme_state, is_favorite = false)
  provider = create_favorites_css_provider(theme_state)
  widget.style_context.add_provider(provider, Gtk::StyleProvider::PRIORITY_USER)

  if is_favorite
    widget.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.

Examples:

Applying style to buttons

Lich::Common::GUI::ThemeUtils.apply_style_to_buttons(ui_elements, Lich::Common::GUI::ThemeUtils.light_theme_button)

Parameters:

  • ui_elements (Hash)

    A hash of UI elements where keys are identifiers and values are the elements.

  • color (Gdk::RGBA)

    The color to apply to the buttons.



76
77
78
79
80
81
82
# File 'documented/common/gui/theme_utils.rb', line 76

def self.apply_style_to_buttons(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.

Examples:

Applying dark theme settings

Lich::Common::GUI::ThemeUtils.apply_theme_settings(true)

Parameters:

  • theme_state (Boolean)

    The state of the theme (true for dark theme, false for light theme).



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.

Examples:

Applying theme to a notebook

Lich::Common::GUI::ThemeUtils.apply_theme_to_notebook(notebook, false)

Parameters:

  • notebook (Gtk::Notebook)

    The notebook to apply the theme to.

  • theme_state (Boolean)

    The state of the theme (true for dark theme, false for light theme).



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.

Examples:

Applying theme to a window

Lich::Common::GUI::ThemeUtils.apply_theme_to_window(window, true)

Parameters:

  • window (Gtk::Window)

    The window to apply the theme to.

  • theme_state (Boolean)

    The state of the theme (true for dark theme, false for light theme).



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.

Examples:

Creating favorites CSS for dark theme

css = Lich::Common::GUI::ThemeUtils.create_favorites_css(true)

Parameters:

  • theme_state (Boolean)

    The state of the theme (true for dark theme, false for light theme).

Returns:

  • (String)

    The generated CSS string.



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.

Examples:

Creating a favorites CSS provider

provider = Lich::Common::GUI::ThemeUtils.create_favorites_css_provider(false)

Parameters:

  • theme_state (Boolean)

    The state of the theme (true for dark theme, false for light theme).

Returns:

  • (Gtk::CssProvider)

    The CSS provider with the favorites styling.



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.message}"
  end

  provider
end

.darkmode_backgroundGdk::RGBA

Returns the background color for the dark theme.

Examples:

Getting dark theme background color

color = Lich::Common::GUI::ThemeUtils.darkmode_background

Returns:

  • (Gdk::RGBA)

    The dark theme background color.



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.

Examples:

Getting favorite button background color for light theme

color = Lich::Common::GUI::ThemeUtils.favorite_button_background(false)

Parameters:

  • theme_state (Boolean)

    The state of the theme (true for dark theme, false for light theme).

Returns:

  • (Gdk::RGBA)

    The background color for the favorite button.



199
200
201
202
203
204
205
# File 'documented/common/gui/theme_utils.rb', line 199

def self.favorite_button_background(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.

Examples:

Getting favorite indicator color for dark theme

color = Lich::Common::GUI::ThemeUtils.favorite_indicator_color(true)

Parameters:

  • theme_state (Boolean)

    The state of the theme (true for dark theme, false for light theme).

Returns:

  • (Gdk::RGBA)

    The color for the favorite indicator.



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_backgroundGdk::RGBA

Returns the background color for the light theme.

Examples:

Getting light theme background color

color = Lich::Common::GUI::ThemeUtils.light_theme_background

Returns:

  • (Gdk::RGBA)

    The light theme background color.



22
23
24
# File 'documented/common/gui/theme_utils.rb', line 22

def self.light_theme_background
  Gdk::RGBA::parse("#d3d3d3")
end

.light_theme_buttonGdk::RGBA

Returns the button color for the light theme.

Examples:

Getting light theme button color

color = Lich::Common::GUI::ThemeUtils.light_theme_button

Returns:

  • (Gdk::RGBA)

    The light theme button color.



30
31
32
# File 'documented/common/gui/theme_utils.rb', line 30

def self.light_theme_button
  Gdk::RGBA::parse("#f0f0f0")
end