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

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

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 given widget based on the theme state.

Parameters:

  • widget (Gtk::Widget)

    the widget to apply the styling to.

  • theme_state (Boolean)

    indicates whether to apply dark theme.

  • is_favorite (Boolean) (defaults to: false)

    indicates if the widget is a favorite.



156
157
158
159
160
161
162
163
# File 'documented/common/gui/theme_utils.rb', line 156

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 the buttons in the UI elements.

Parameters:

  • ui_elements (Hash)

    a hash of UI elements to style.

  • color (Gdk::RGBA)

    the color to apply to the buttons.



63
64
65
66
67
68
69
# File 'documented/common/gui/theme_utils.rb', line 63

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.

Parameters:

  • theme_state (Boolean)

    indicates whether to apply dark theme.



10
11
12
# File 'documented/common/gui/theme_utils.rb', line 10

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 specified theme to the given notebook.

Parameters:

  • notebook (Gtk::Notebook)

    the notebook to apply the theme to.

  • theme_state (Boolean)

    indicates whether to apply dark theme.



50
51
52
53
54
55
56
# File 'documented/common/gui/theme_utils.rb', line 50

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 specified theme to the given window.

Parameters:

  • window (Gtk::Window)

    the window to apply the theme to.

  • theme_state (Boolean)

    indicates whether to apply dark theme.



37
38
39
40
41
42
43
# File 'documented/common/gui/theme_utils.rb', line 37

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.

Parameters:

  • theme_state (Boolean)

    indicates whether to apply dark theme.

Returns:

  • (String)

    the generated CSS string.



75
76
77
78
79
80
81
82
83
84
85
86
87
88
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
# File 'documented/common/gui/theme_utils.rb', line 75

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.

Parameters:

  • theme_state (Boolean)

    indicates whether to apply dark theme.

Returns:

  • (Gtk::CssProvider)

    the CSS provider for favorites styling.



137
138
139
140
141
142
143
144
145
146
147
148
# File 'documented/common/gui/theme_utils.rb', line 137

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.

Returns:

  • (Gdk::RGBA)

    the dark theme background color.



28
29
30
# File 'documented/common/gui/theme_utils.rb', line 28

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.

Parameters:

  • theme_state (Boolean)

    indicates whether to apply dark theme.

Returns:

  • (Gdk::RGBA)

    the background color for the favorite button.



181
182
183
184
185
186
187
# File 'documented/common/gui/theme_utils.rb', line 181

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.

Parameters:

  • theme_state (Boolean)

    indicates whether to apply dark theme.

Returns:

  • (Gdk::RGBA)

    the color for the favorite indicator.



169
170
171
172
173
174
175
# File 'documented/common/gui/theme_utils.rb', line 169

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.

Returns:

  • (Gdk::RGBA)

    the light theme background color.



16
17
18
# File 'documented/common/gui/theme_utils.rb', line 16

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

.light_theme_buttonGdk::RGBA

Returns the button color for the light theme.

Returns:

  • (Gdk::RGBA)

    the light theme button color.



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

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