@@ -60,10 +60,12 @@ enum ContextView {
60
60
MonospaceFont ,
61
61
SystemFont ,
62
62
}
63
+
63
64
#[ allow( clippy:: struct_excessive_bools) ]
64
65
pub struct Page {
65
66
entity : page:: Entity ,
66
67
on_enter_handle : Option < cosmic:: iced:: task:: Handle > ,
68
+ accent_palette : AccentPalette ,
67
69
can_reset : bool ,
68
70
no_custom_window_hint : bool ,
69
71
context_view : Option < ContextView > ,
@@ -96,12 +98,21 @@ pub struct Page {
96
98
auto_switch_descs : [ Cow < ' static , str > ; 4 ] ,
97
99
98
100
tk_config : Option < Config > ,
99
-
101
+ settings_config : crate :: config :: Config ,
100
102
day_time : bool ,
101
103
}
102
104
105
+ #[ derive( Default ) ]
106
+ pub struct AccentPalette {
107
+ dark : Option < Vec < Srgba > > ,
108
+ light : Option < Vec < Srgba > > ,
109
+ theme : Vec < Srgba > ,
110
+ }
111
+
103
112
impl Default for Page {
104
113
fn default ( ) -> Self {
114
+ let settings_config = crate :: config:: Config :: new ( ) ;
115
+
105
116
let theme_mode_config = ThemeMode :: config ( ) . ok ( ) ;
106
117
let theme_mode = theme_mode_config
107
118
. as_ref ( )
@@ -116,26 +127,52 @@ impl Default for Page {
116
127
} )
117
128
. unwrap_or_default ( ) ;
118
129
119
- ( theme_mode_config, theme_mode) . into ( )
130
+ let accent_palette = AccentPalette {
131
+ dark : settings_config. accent_palette_dark ( ) . ok ( ) ,
132
+ light : settings_config. accent_palette_light ( ) . ok ( ) ,
133
+ theme : Vec :: new ( ) ,
134
+ } ;
135
+
136
+ let mut page: Page = (
137
+ settings_config,
138
+ theme_mode_config,
139
+ theme_mode,
140
+ accent_palette,
141
+ )
142
+ . into ( ) ;
143
+ page. update_accent_palette ( ) ;
144
+ page
120
145
}
121
146
}
122
147
123
148
impl
124
149
From < (
150
+ crate :: config:: Config ,
125
151
Option < Config > ,
126
152
ThemeMode ,
127
153
Option < Config > ,
128
154
ThemeBuilder ,
129
155
Option < Config > ,
156
+ AccentPalette ,
130
157
) > for Page
131
158
{
132
159
fn from (
133
- ( theme_mode_config, theme_mode, theme_builder_config, theme_builder, tk_config) : (
160
+ (
161
+ settings_config,
162
+ theme_mode_config,
163
+ theme_mode,
164
+ theme_builder_config,
165
+ theme_builder,
166
+ tk_config,
167
+ accent_palette,
168
+ ) : (
169
+ crate :: config:: Config ,
134
170
Option < Config > ,
135
171
ThemeMode ,
136
172
Option < Config > ,
137
173
ThemeBuilder ,
138
174
Option < Config > ,
175
+ AccentPalette ,
139
176
) ,
140
177
) -> Self {
141
178
let theme = if theme_mode. is_dark {
@@ -212,12 +249,14 @@ impl
212
249
icon_theme_active : None ,
213
250
icon_themes : Vec :: new ( ) ,
214
251
icon_handles : Vec :: new ( ) ,
252
+ accent_palette,
215
253
theme,
216
254
theme_mode_config,
217
255
theme_builder_config,
218
256
theme_mode,
219
257
theme_builder,
220
258
tk_config,
259
+ settings_config,
221
260
day_time : true ,
222
261
auto_switch_descs : [
223
262
fl ! ( "auto-switch" , "sunrise" ) . into ( ) ,
@@ -229,8 +268,22 @@ impl
229
268
}
230
269
}
231
270
232
- impl From < ( Option < Config > , ThemeMode ) > for Page {
233
- fn from ( ( theme_mode_config, theme_mode) : ( Option < Config > , ThemeMode ) ) -> Self {
271
+ impl
272
+ From < (
273
+ crate :: config:: Config ,
274
+ Option < Config > ,
275
+ ThemeMode ,
276
+ AccentPalette ,
277
+ ) > for Page
278
+ {
279
+ fn from (
280
+ ( settings_config, theme_mode_config, theme_mode, accent_palette) : (
281
+ crate :: config:: Config ,
282
+ Option < Config > ,
283
+ ThemeMode ,
284
+ AccentPalette ,
285
+ ) ,
286
+ ) -> Self {
234
287
let theme_builder_config = if theme_mode. is_dark {
235
288
ThemeBuilder :: dark_config ( )
236
289
} else {
@@ -259,11 +312,13 @@ impl From<(Option<Config>, ThemeMode)> for Page {
259
312
let tk_config = CosmicTk :: config ( ) . ok ( ) ;
260
313
261
314
Self :: from ( (
315
+ settings_config,
262
316
theme_mode_config,
263
317
theme_mode,
264
318
theme_builder_config,
265
319
theme_builder,
266
320
tk_config,
321
+ accent_palette,
267
322
) )
268
323
}
269
324
}
@@ -1110,6 +1165,7 @@ impl Page {
1110
1165
1111
1166
// If the theme builder changed, write a new theme to disk on a background thread.
1112
1167
if needs_build {
1168
+ self . update_accent_palette ( ) ;
1113
1169
let theme_builder = self . theme_builder . clone ( ) ;
1114
1170
let is_dark = self . theme_mode . is_dark ;
1115
1171
let current_theme = self . theme . clone ( ) ;
@@ -1186,6 +1242,21 @@ impl Page {
1186
1242
cosmic:: Task :: batch ( tasks)
1187
1243
}
1188
1244
1245
+ fn update_accent_palette ( & mut self ) {
1246
+ let palette = self . theme_builder . palette . as_ref ( ) ;
1247
+ self . accent_palette . theme = vec ! [
1248
+ palette. accent_blue,
1249
+ palette. accent_indigo,
1250
+ palette. accent_purple,
1251
+ palette. accent_pink,
1252
+ palette. accent_red,
1253
+ palette. accent_orange,
1254
+ palette. accent_yellow,
1255
+ palette. accent_green,
1256
+ palette. accent_warm_grey,
1257
+ ] ;
1258
+ }
1259
+
1189
1260
fn reload_theme_mode ( & mut self ) {
1190
1261
let entity = self . entity ;
1191
1262
let font_config = std:: mem:: take ( & mut self . font_config ) ;
@@ -1194,7 +1265,15 @@ impl Page {
1194
1265
let icon_theme_active = self . icon_theme_active . take ( ) ;
1195
1266
let day_time = self . day_time ;
1196
1267
1197
- * self = Self :: from ( ( self . theme_mode_config . clone ( ) , self . theme_mode ) ) ;
1268
+ * self = Self :: from ( (
1269
+ self . settings_config . clone ( ) ,
1270
+ self . theme_mode_config . take ( ) ,
1271
+ self . theme_mode ,
1272
+ std:: mem:: take ( & mut self . accent_palette ) ,
1273
+ ) ) ;
1274
+
1275
+ self . update_accent_palette ( ) ;
1276
+
1198
1277
self . entity = entity;
1199
1278
self . day_time = day_time;
1200
1279
self . icon_themes = icon_themes;
@@ -1624,6 +1703,58 @@ pub fn mode_and_colors() -> Section<crate::pages::Message> {
1624
1703
. theme_builder
1625
1704
. accent
1626
1705
. map_or ( palette. accent_blue , Srgba :: from) ;
1706
+
1707
+ let accent_palette_values = match (
1708
+ page. theme_mode . is_dark ,
1709
+ page. accent_palette . dark . as_ref ( ) ,
1710
+ page. accent_palette . light . as_ref ( ) ,
1711
+ ) {
1712
+ ( true , Some ( dark_palette) , _) => & dark_palette,
1713
+ ( false , _, Some ( light_palette) ) => & light_palette,
1714
+ _ => & page. accent_palette . theme ,
1715
+ } ;
1716
+
1717
+ let mut accent_palette_row =
1718
+ cosmic:: widget:: row:: with_capacity ( accent_palette_values. len ( ) ) ;
1719
+
1720
+ for & color in accent_palette_values {
1721
+ accent_palette_row = accent_palette_row. push ( color_button (
1722
+ Some ( Message :: PaletteAccent ( color. into ( ) ) ) ,
1723
+ color. into ( ) ,
1724
+ cur_accent == color,
1725
+ 48 ,
1726
+ 48 ,
1727
+ ) ) ;
1728
+ }
1729
+
1730
+ let accent_color_palette = cosmic:: iced:: widget:: column![
1731
+ text:: body( & descriptions[ accent_color] ) ,
1732
+ scrollable(
1733
+ accent_palette_row
1734
+ . push( if let Some ( c) = page. custom_accent. get_applied_color( ) {
1735
+ container( color_button(
1736
+ Some ( Message :: CustomAccent ( ColorPickerUpdate :: ToggleColorPicker ) ) ,
1737
+ c,
1738
+ cosmic:: iced:: Color :: from( cur_accent) == c,
1739
+ 48 ,
1740
+ 48 ,
1741
+ ) )
1742
+ } else {
1743
+ container(
1744
+ page. custom_accent
1745
+ . picker_button( Message :: CustomAccent , None )
1746
+ . width( Length :: Fixed ( 48.0 ) )
1747
+ . height( Length :: Fixed ( 48.0 ) ) ,
1748
+ )
1749
+ } )
1750
+ . padding( [ 0 , 0 , 16 , 0 ] )
1751
+ . spacing( 16 )
1752
+ )
1753
+ . direction( Direction :: Horizontal ( Scrollbar :: new( ) ) )
1754
+ ]
1755
+ . padding ( [ 16 , 0 , 0 , 0 ] )
1756
+ . spacing ( space_xxs) ;
1757
+
1627
1758
let mut section = settings:: section ( )
1628
1759
. title ( & section. title )
1629
1760
. add (
@@ -1682,101 +1813,7 @@ pub fn mode_and_colors() -> Section<crate::pages::Message> {
1682
1813
)
1683
1814
. toggler ( page. theme_mode . auto_switch , Message :: Autoswitch ) ,
1684
1815
)
1685
- . add (
1686
- cosmic:: iced:: widget:: column![
1687
- text:: body( & descriptions[ accent_color] ) ,
1688
- scrollable(
1689
- cosmic:: iced:: widget:: row![
1690
- color_button(
1691
- Some ( Message :: PaletteAccent ( palette. accent_blue. into( ) ) ) ,
1692
- palette. accent_blue. into( ) ,
1693
- cur_accent == palette. accent_blue,
1694
- 48 ,
1695
- 48
1696
- ) ,
1697
- color_button(
1698
- Some ( Message :: PaletteAccent ( palette. accent_indigo. into( ) ) ) ,
1699
- palette. accent_indigo. into( ) ,
1700
- cur_accent == palette. accent_indigo,
1701
- 48 ,
1702
- 48
1703
- ) ,
1704
- color_button(
1705
- Some ( Message :: PaletteAccent ( palette. accent_purple. into( ) ) ) ,
1706
- palette. accent_purple. into( ) ,
1707
- cur_accent == palette. accent_purple,
1708
- 48 ,
1709
- 48
1710
- ) ,
1711
- color_button(
1712
- Some ( Message :: PaletteAccent ( palette. accent_pink. into( ) ) ) ,
1713
- palette. accent_pink. into( ) ,
1714
- cur_accent == palette. accent_pink,
1715
- 48 ,
1716
- 48
1717
- ) ,
1718
- color_button(
1719
- Some ( Message :: PaletteAccent ( palette. accent_red. into( ) ) ) ,
1720
- palette. accent_red. into( ) ,
1721
- cur_accent == palette. accent_red,
1722
- 48 ,
1723
- 48
1724
- ) ,
1725
- color_button(
1726
- Some ( Message :: PaletteAccent ( palette. accent_orange. into( ) ) ) ,
1727
- palette. accent_orange. into( ) ,
1728
- cur_accent == palette. accent_orange,
1729
- 48 ,
1730
- 48
1731
- ) ,
1732
- color_button(
1733
- Some ( Message :: PaletteAccent ( palette. accent_yellow. into( ) ) ) ,
1734
- palette. accent_yellow. into( ) ,
1735
- cur_accent == palette. accent_yellow,
1736
- 48 ,
1737
- 48
1738
- ) ,
1739
- color_button(
1740
- Some ( Message :: PaletteAccent ( palette. accent_green. into( ) ) ) ,
1741
- palette. accent_green. into( ) ,
1742
- cur_accent == palette. accent_green,
1743
- 48 ,
1744
- 48
1745
- ) ,
1746
- color_button(
1747
- Some ( Message :: PaletteAccent ( palette. accent_warm_grey. into( ) ) ) ,
1748
- palette. accent_warm_grey. into( ) ,
1749
- cur_accent == palette. accent_warm_grey,
1750
- 48 ,
1751
- 48
1752
- ) ,
1753
- if let Some ( c) = page. custom_accent. get_applied_color( ) {
1754
- container( color_button(
1755
- Some ( Message :: CustomAccent (
1756
- ColorPickerUpdate :: ToggleColorPicker ,
1757
- ) ) ,
1758
- c,
1759
- cosmic:: iced:: Color :: from( cur_accent) == c,
1760
- 48 ,
1761
- 48 ,
1762
- ) )
1763
- } else {
1764
- container(
1765
- page. custom_accent
1766
- . picker_button( Message :: CustomAccent , None )
1767
- . width( Length :: Fixed ( 48.0 ) )
1768
- . height( Length :: Fixed ( 48.0 ) ) ,
1769
- )
1770
- } ,
1771
- ]
1772
- . padding( [ 0 , 0 , 16 , 0 ] )
1773
- . spacing( 16 )
1774
- )
1775
- . direction( Direction :: Horizontal ( Scrollbar :: new( ) ) )
1776
- ]
1777
- . padding ( [ 16 , 0 , 0 , 0 ] )
1778
- . spacing ( space_xxs) ,
1779
- )
1816
+ . add ( accent_color_palette)
1780
1817
. add (
1781
1818
settings:: item:: builder ( & descriptions[ app_bg] ) . control (
1782
1819
page. application_background
0 commit comments