feat: get active wallpaper and show it in display_container widget

This commit is contained in:
Michael Aaron Murphy 2023-05-31 01:38:50 +02:00
parent a4eee2186c
commit a3802021b6
No known key found for this signature in database
GPG key ID: B2732D4240C9212C
5 changed files with 62 additions and 24 deletions

View file

@ -8,15 +8,13 @@
pub mod app;
pub use app::{Message, SettingsApp};
pub mod config;
#[macro_use]
pub mod localize;
pub mod widget;
pub mod pages;
pub mod theme;
pub mod widget;
use cosmic::{
iced::{wayland::actions::window::SctkWindowSettings, Application, Limits},

View file

@ -9,6 +9,7 @@ use cosmic::{
iced::widget::{column, container, horizontal_space, row, text},
iced::Length,
iced_runtime::core::image::Handle as ImageHandle,
iced_widget::core::renderer::BorderRadius,
theme,
widget::{list_column, settings, toggler},
Element,
@ -57,7 +58,7 @@ impl Page {
Message::SameBackground(value) => self.same_background = value,
Message::Select(id) => {
if let Some(path) = self.selection.paths.get(id) {
wallpaper::set(&mut self.config, Entry::new(Output::All, path.to_owned()));
wallpaper::set(&mut self.config, Entry::new(Output::All, path.clone()));
self.selection.active = id;
}
}
@ -65,6 +66,20 @@ impl Page {
Message::Update((config, selection)) => {
self.config = config;
self.selection = selection;
if let Some(entry) = self
.config
.backgrounds
.iter()
.find(|b| b.output == Output::All)
{
self.same_background = true;
for (entity, path) in self.selection.paths.iter() {
if path == &entry.source {
self.selection.active = entity;
}
}
}
}
}
}
@ -88,7 +103,9 @@ impl page::Page<crate::pages::Message> for Page {
Some(Box::pin(async move {
let config = wallpaper::config();
let mut backgrounds = wallpaper::load_each_from_path("/usr/share/backgrounds".into());
let mut backgrounds =
wallpaper::load_each_from_path("/usr/share/backgrounds/pop/".into());
let mut update = Context::default();
let start = Instant::now();
@ -142,19 +159,7 @@ pub fn settings() -> Section<crate::pages::Message> {
let mut children = Vec::with_capacity(3);
if let Some(image) = page.selection.handles.get(page.selection.active) {
let display_preview = row!(
horizontal_space(Length::Fill),
container(
cosmic::iced::widget::image(image.clone()).width(Length::Fixed(300.0))
)
.padding(4)
.style(theme::Container::Background),
horizontal_space(Length::Fill),
)
.padding([0, 0, 8, 0])
.into();
children.push(display_preview);
children.push(crate::widget::display_container(image.clone(), 300.0));
}
children.push(

15
app/src/theme.rs Normal file
View file

@ -0,0 +1,15 @@
// Copyright 2023 System76 <info@system76.com>
// SPDX-License-Identifier: GPL-3.0-only
use cosmic::{iced_widget::core::renderer::BorderRadius, theme};
#[must_use]
pub fn display_container() -> cosmic::theme::Container {
theme::Container::custom(|_theme| cosmic::iced::widget::container::Appearance {
text_color: None,
background: Some(cosmic::iced::Background::Color(cosmic::iced::Color::WHITE)),
border_color: cosmic::iced::Color::WHITE,
border_radius: BorderRadius::from(4.0),
border_width: 3.0,
})
}

View file

@ -2,12 +2,15 @@
// SPDX-License-Identifier: GPL-3.0-only
use apply::Apply;
use cosmic::iced::{
self,
widget::{button, column, container, horizontal_space, row, vertical_space, Button},
Length,
};
use cosmic::widget::{divider, icon, list, settings, text};
use cosmic::{
iced::{
self,
widget::{button, column, container, horizontal_space, row, vertical_space, Button},
Length,
},
iced_widget::core::image,
};
use cosmic::{theme, Element};
use cosmic_settings_page as page;
@ -131,3 +134,19 @@ pub fn unimplemented_page<Message: 'static>() -> Element<'static, Message> {
.add(text("We haven't created that panel yet, and/or it is using a similar idea as current Pop! designs."))
.into()
}
#[must_use]
pub fn display_container<'a, Message: 'a>(
image: image::Handle,
width: f32,
) -> cosmic::Element<'a, Message> {
row!(
horizontal_space(Length::Fill),
container(cosmic::iced::widget::image(image).width(Length::Fixed(width)))
.padding(4)
.style(crate::theme::display_container()),
horizontal_space(Length::Fill),
)
.padding([0, 0, 8, 0])
.into()
}

View file

@ -28,6 +28,7 @@ pub fn set(config: &mut Config, entry: Entry) {
entry.output.to_string(),
entry.source.display()
);
if let Err(why) = config.set_entry(&context, entry) {
tracing::error!(?why, "failed to set background");
}