Class: Collavre::UserTheme
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- ApplicationRecord
- Collavre::UserTheme
- Defined in:
- app/models/collavre/user_theme.rb
Instance Method Summary collapse
-
#dark? ⇒ Boolean
Returns true if the theme has a dark background (lightness < 50%).
Instance Method Details
#dark? ⇒ Boolean
Returns true if the theme has a dark background (lightness < 50%)
11 12 13 14 15 16 17 18 |
# File 'app/models/collavre/user_theme.rb', line 11 def dark? bg = variables["--surface-bg"].to_s return false unless bg.match?(/\A#[0-9a-fA-F]{6}\z/) r, g, b = bg[1..2].to_i(16), bg[3..4].to_i(16), bg[5..6].to_i(16) luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255.0 luminance < 0.5 end |