@@ -10,7 +10,7 @@ use cosmic::{
10
10
self ,
11
11
segmented_button:: { self , SingleSelect } ,
12
12
} ,
13
- Apply , Element , Task ,
13
+ Element , Task ,
14
14
} ;
15
15
use providers:: cosmic_themes:: CosmicTheme ;
16
16
@@ -28,7 +28,7 @@ pub struct ColorSchemes {
28
28
theme_builder_config : Option < Config > ,
29
29
theme_builder : ThemeBuilder ,
30
30
pub model : segmented_button:: Model < SingleSelect > ,
31
- status : Status ,
31
+ pub status : Status ,
32
32
pub limit : usize ,
33
33
offset : usize ,
34
34
}
@@ -422,64 +422,38 @@ impl ColorSchemes {
422
422
. into ( )
423
423
}
424
424
425
- fn installed_themes < ' a > ( & self ) -> Element < ' a , Message > {
426
- let spacing = cosmic:: theme:: active ( ) . cosmic ( ) . spacing ;
425
+ fn installed_themes < ' a > ( & ' a self ) -> Element < ' a , Message > {
426
+ widget:: responsive ( move |size| {
427
+ let spacing = cosmic:: theme:: active ( ) . cosmic ( ) . spacing ;
427
428
428
- widget:: flex_row (
429
- self . installed
430
- . iter ( )
431
- . map ( |color_scheme| preview:: installed ( color_scheme, & self . selected ) )
432
- . collect ( ) ,
433
- )
434
- . row_spacing ( spacing. space_xs )
435
- . column_spacing ( spacing. space_xs )
436
- . apply ( widget:: container)
437
- . apply ( widget:: scrollable)
429
+ widget:: scrollable ( ColorScheme :: installed_grid (
430
+ & self . installed ,
431
+ & self . selected ,
432
+ spacing,
433
+ size. width as usize ,
434
+ ) )
435
+ . spacing ( spacing. space_xxs )
436
+ . into ( )
437
+ } )
438
438
. into ( )
439
439
}
440
440
441
441
fn available_themes < ' a > ( & ' a self ) -> Element < ' a , Message > {
442
- let spacing = cosmic:: theme:: active ( ) . cosmic ( ) . spacing ;
443
-
444
- let loading: Option < Element < ' a , Message > > = if let Status :: Loading = self . status {
445
- Some ( widget:: text ( fl ! ( "loading" ) ) . into ( ) )
446
- } else {
447
- None
448
- } ;
449
-
450
- let available: Option < Element < ' a , Message > > = match self . status {
451
- Status :: Idle | Status :: LoadingMore => {
452
- let mut themes: Vec < Element < Message > > =
453
- self . available . iter ( ) . map ( preview:: available) . collect ( ) ;
454
-
455
- let load_button = match self . status {
456
- Status :: Idle => widget:: button:: standard ( fl ! ( "show-more" ) )
457
- . leading_icon ( crate :: core:: icons:: get_handle (
458
- "content-loading-symbolic" ,
459
- 16 ,
460
- ) )
461
- . on_press ( Message :: FetchAvailableColorSchemes (
462
- ColorSchemeProvider :: CosmicThemes ,
463
- self . limit ,
464
- ) ) ,
465
- Status :: LoadingMore | Status :: Loading => {
466
- widget:: button:: standard ( fl ! ( "loading" ) )
467
- }
468
- } ;
469
-
470
- themes. push ( load_button. width ( 240.0 ) . height ( 160.0 ) . into ( ) ) ;
471
- let widgets = widget:: flex_row ( themes)
472
- . row_spacing ( spacing. space_xs )
473
- . column_spacing ( spacing. space_xs ) ;
474
- Some ( widgets. into ( ) )
475
- }
476
- Status :: Loading => None ,
477
- } ;
478
-
479
- widget:: container ( widget:: scrollable ( widget:: column:: with_children (
480
- loading. into_iter ( ) . chain ( available) . collect ( ) ,
481
- ) ) )
482
- . into ( )
442
+ match self . status {
443
+ Status :: Idle | Status :: LoadingMore => widget:: responsive ( move |size| {
444
+ let spacing = cosmic:: theme:: active ( ) . cosmic ( ) . spacing ;
445
+
446
+ widget:: scrollable ( ColorScheme :: available_grid (
447
+ & self . available ,
448
+ spacing,
449
+ size. width as usize ,
450
+ ) )
451
+ . spacing ( spacing. space_xxs )
452
+ . into ( )
453
+ } )
454
+ . into ( ) ,
455
+ Status :: Loading => widget:: text ( fl ! ( "loading" ) ) . into ( ) ,
456
+ }
483
457
}
484
458
485
459
pub fn fetch_installed_color_schemes ( ) -> anyhow:: Result < Vec < ColorScheme > > {
@@ -540,4 +514,49 @@ impl ColorSchemes {
540
514
541
515
Ok ( color_schemes)
542
516
}
517
+
518
+ pub fn refresh_theme_mode ( & mut self ) {
519
+ let theme_mode_config = ThemeMode :: config ( ) . ok ( ) ;
520
+ let theme_mode = theme_mode_config
521
+ . as_ref ( )
522
+ . map ( |c| match ThemeMode :: get_entry ( c) {
523
+ Ok ( t) => t,
524
+ Err ( ( errors, t) ) => {
525
+ for e in errors {
526
+ log:: error!( "{e}" ) ;
527
+ }
528
+ t
529
+ }
530
+ } )
531
+ . unwrap_or_default ( ) ;
532
+ let theme_builder_config = if theme_mode. is_dark {
533
+ ThemeBuilder :: dark_config ( )
534
+ } else {
535
+ ThemeBuilder :: light_config ( )
536
+ }
537
+ . ok ( ) ;
538
+
539
+ let theme_builder = theme_builder_config. as_ref ( ) . map_or_else (
540
+ || {
541
+ if theme_mode. is_dark {
542
+ ThemeBuilder :: dark ( )
543
+ } else {
544
+ ThemeBuilder :: light ( )
545
+ }
546
+ } ,
547
+ |c| match ThemeBuilder :: get_entry ( c) {
548
+ Ok ( t) => t,
549
+ Err ( ( errors, t) ) => {
550
+ for e in errors {
551
+ log:: error!( "{e}" ) ;
552
+ }
553
+ t
554
+ }
555
+ } ,
556
+ ) ;
557
+
558
+ self . theme_mode = theme_mode;
559
+ self . theme_builder = theme_builder;
560
+ self . theme_builder_config = theme_builder_config;
561
+ }
543
562
}
0 commit comments