Skip to content

Commit 075062c

Browse files
committed
improv: color schemes
- moved load more button to footer - made color schemes page responsive - fixed footer appearing in other pages - fixed grid sizing - added spacing between scrollbar and content
1 parent b7ae44c commit 075062c

File tree

7 files changed

+310
-140
lines changed

7 files changed

+310
-140
lines changed

i18n/en/cosmic_ext_tweaks.ftl

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import-color-scheme = Import color scheme
1515
delete-color-scheme = Delete color scheme
1616
available-color-schemes-body = Find and install color schemes
1717
install-color-scheme = Install color scheme
18+
set-color-scheme = Set color scheme
1819
find-color-schemes = Find color schemes
1920
open-containing-folder = Open containing folder
2021
open-link = Open link
@@ -80,4 +81,4 @@ view = View
8081
## Shortcuts
8182

8283
warning = Warning: this will remove your existing custom shortcuts
83-
windows-desc = Super+Arrows to move windows. Ctrl+Alt+Arrows to navigate workspaces.
84+
windows-desc = Super+Arrows to move windows. Ctrl+Alt+Arrows to navigate workspaces.
Loading

src/app.rs

+56-27
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use crate::{
3131
fl,
3232
pages::{
3333
self,
34-
color_schemes::{self, ColorSchemes, Tab},
34+
color_schemes::{self, ColorSchemes, Status, Tab},
3535
dock::Dock,
3636
layouts::Layouts,
3737
panel::Panel,
@@ -367,32 +367,60 @@ impl Application for TweakTool {
367367

368368
fn footer(&self) -> Option<Element<Self::Message>> {
369369
let spacing = cosmic::theme::active().cosmic().spacing;
370-
if let Some(Tab::Installed) = self.color_schemes.model.active_data::<Tab>() {
371-
Some(
372-
widget::row()
373-
.push(widget::horizontal_space())
374-
.push(
375-
widget::button::standard(fl!("save-current-color-scheme"))
376-
.trailing_icon(icons::get_handle("arrow-into-box-symbolic", 16))
377-
.on_press(Message::ColorSchemes(Box::new(
378-
color_schemes::Message::SaveCurrentColorScheme(None),
379-
))),
380-
)
381-
.push(
382-
widget::button::standard(fl!("import-color-scheme"))
383-
.trailing_icon(icons::get_handle("document-save-symbolic", 16))
384-
.on_press(Message::ColorSchemes(Box::new(
385-
color_schemes::Message::StartImport,
386-
))),
387-
)
388-
.spacing(spacing.space_xxs)
389-
.apply(widget::container)
390-
.class(cosmic::style::Container::Card)
391-
.padding(spacing.space_xxs)
392-
.into(),
393-
)
394-
} else {
395-
None
370+
371+
match self.nav_model.active_data::<Page>() {
372+
Some(Page::ColorSchemes) => match self.color_schemes.model.active_data::<Tab>() {
373+
Some(Tab::Installed) => Some(
374+
widget::row()
375+
.push(widget::horizontal_space())
376+
.push(
377+
widget::button::standard(fl!("save-current-color-scheme"))
378+
.trailing_icon(icons::get_handle("arrow-into-box-symbolic", 16))
379+
.on_press(Message::ColorSchemes(Box::new(
380+
color_schemes::Message::SaveCurrentColorScheme(None),
381+
))),
382+
)
383+
.push(
384+
widget::button::standard(fl!("import-color-scheme"))
385+
.trailing_icon(icons::get_handle("document-save-symbolic", 16))
386+
.on_press(Message::ColorSchemes(Box::new(
387+
color_schemes::Message::StartImport,
388+
))),
389+
)
390+
.spacing(spacing.space_xxs)
391+
.apply(widget::container)
392+
.class(cosmic::style::Container::Card)
393+
.padding(spacing.space_xxs)
394+
.into(),
395+
),
396+
Some(Tab::Available) => Some(
397+
widget::row()
398+
.push(widget::horizontal_space())
399+
.push(match self.color_schemes.status {
400+
Status::Idle => widget::button::standard(fl!("show-more"))
401+
.leading_icon(crate::core::icons::get_handle(
402+
"content-loading-symbolic",
403+
16,
404+
))
405+
.on_press(Message::ColorSchemes(Box::new(
406+
color_schemes::Message::FetchAvailableColorSchemes(
407+
color_schemes::ColorSchemeProvider::CosmicThemes,
408+
self.color_schemes.limit,
409+
),
410+
))),
411+
Status::LoadingMore | Status::Loading => {
412+
widget::button::standard(fl!("loading"))
413+
}
414+
})
415+
.spacing(spacing.space_xxs)
416+
.apply(widget::container)
417+
.class(cosmic::style::Container::Card)
418+
.padding(spacing.space_xxs)
419+
.into(),
420+
),
421+
None => None,
422+
},
423+
_ => None,
396424
}
397425
}
398426

@@ -585,6 +613,7 @@ impl Application for TweakTool {
585613

586614
impl TweakTool {
587615
fn update_config(&mut self) -> Task<cosmic::app::Message<Message>> {
616+
self.color_schemes.refresh_theme_mode();
588617
app::command::set_theme(self.config.app_theme.theme())
589618
}
590619

src/core/icons.rs

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ impl IconCache {
5757
bundle!("list-add-symbolic", 16);
5858
bundle!("symbolic-link-symbolic", 14);
5959
bundle!("user-trash-symbolic", 14);
60+
bundle!("selection-mode-symbolic", 14);
6061
bundle!("folder-download-symbolic", 14);
6162
bundle!("arrow-circular-bottom-right-symbolic", 14);
6263

src/pages/color_schemes.rs

+74-55
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use cosmic::{
1010
self,
1111
segmented_button::{self, SingleSelect},
1212
},
13-
Apply, Element, Task,
13+
Element, Task,
1414
};
1515
use providers::cosmic_themes::CosmicTheme;
1616

@@ -28,7 +28,7 @@ pub struct ColorSchemes {
2828
theme_builder_config: Option<Config>,
2929
theme_builder: ThemeBuilder,
3030
pub model: segmented_button::Model<SingleSelect>,
31-
status: Status,
31+
pub status: Status,
3232
pub limit: usize,
3333
offset: usize,
3434
}
@@ -422,64 +422,38 @@ impl ColorSchemes {
422422
.into()
423423
}
424424

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;
427428

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+
})
438438
.into()
439439
}
440440

441441
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+
}
483457
}
484458

485459
pub fn fetch_installed_color_schemes() -> anyhow::Result<Vec<ColorScheme>> {
@@ -540,4 +514,49 @@ impl ColorSchemes {
540514

541515
Ok(color_schemes)
542516
}
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+
}
543562
}

0 commit comments

Comments
 (0)