This commit is contained in:
Alexandru Scvorțov 2024-11-26 21:46:59 -05:00 • committed by GitHub
commit 8a83a06b23
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 132 additions and 123 deletions

View file

@ -1,7 +1,7 @@
// Copyright 2022 System76 <info@system76.com>
// SPDX-License-Identifier: MPL-2.0
use cosmic::iced::{Application, Settings};
use cosmic::{app::Settings, iced::Limits};
mod window;
use env_logger::Env;
@ -15,13 +15,9 @@ pub fn main() -> cosmic::iced::Result {
env_logger::init_from_env(env);
cosmic::icon_theme::set_default("Pop");
#[allow(clippy::field_reassign_with_default)]
let settings = Settings {
default_font: cosmic::font::default(),
window: cosmic::iced::window::Settings {
min_size: Some(cosmic::iced::Size::new(600., 300.)),
..cosmic::iced::window::Settings::default()
},
..Settings::default()
};
Window::run(settings)
let settings = Settings::default()
.default_font(cosmic::font::default())
.size_limits(Limits::NONE.min_width(600.).min_height(300.));
cosmic::app::run::<window::Window>(settings, ())?;
Ok(())
}

View file

@ -1,16 +1,16 @@
/// Copyright 2022 System76 <info@system76.com>
// SPDX-License-Identifier: MPL-2.0
use cosmic::{
app::{command, Application, Core},
cosmic_theme::{
palette::{rgb::Rgb, Srgba},
ThemeBuilder,
},
font::load_fonts,
iced::{self, Application, Length, Subscription, Task},
iced::{
subscription,
self,
widget::{self, column, container, horizontal_space, row, text},
window::{self, close, drag, minimize, toggle_maximize},
Length, Size, Subscription,
},
iced_futures::event::listen_raw,
keyboard_nav,
@ -20,7 +20,7 @@ use cosmic::{
button, header_bar, icon, list, nav_bar, nav_bar_toggle, scrollable, segmented_button,
settings, warning,
},
Element,
ApplicationExt, Element,
};
use cosmic_time::{Instant, Timeline};
use std::{
@ -145,8 +145,8 @@ impl Default for Page {
static WINDOW_WIDTH: AtomicU32 = AtomicU32::new(0);
const BREAK_POINT: u32 = 900;
#[derive(Default)]
pub struct Window {
core: Core,
bluetooth: bluetooth::State,
debug: bool,
demo: demo::State,
@ -161,7 +161,6 @@ pub struct Window {
show_minimize: bool,
system_and_accounts: system_and_accounts::State,
theme: Theme,
title: String,
show_warning: bool,
warning_message: String,
scale_factor: f64,
@ -210,7 +209,6 @@ pub enum Message {
ToggleNavBar,
ToggleNavBarCondensed,
ToggleWarning,
FontsLoaded,
Tick(Instant),
}
@ -231,7 +229,7 @@ impl Window {
}
fn page_title<Message: 'static>(&self, page: Page) -> Element<Message> {
row!(text(page.title()).size(28), horizontal_space(Length::Fill),).into()
row!(text(page.title()).size(28), horizontal_space(),).into()
}
fn is_condensed(&self) -> bool {
@ -253,10 +251,7 @@ impl Window {
.label(page.title())
.padding(0)
.on_press(Message::from(page)),
row!(
text(sub_page.title()).size(28),
horizontal_space(Length::Fill),
),
row!(text(sub_page.title()).size(28), horizontal_space(),),
)
.spacing(10)
.into()
@ -281,7 +276,7 @@ impl Window {
)
.spacing(2)
.into(),
horizontal_space(iced::Length::Fill).into(),
horizontal_space().into(),
icon::from_name("go-next-symbolic").size(20).icon().into(),
])
.spacing(16),
@ -290,7 +285,7 @@ impl Window {
)
.width(Length::Fill)
.padding(0)
.style(theme::iced::Button::Transparent)
.class(theme::iced::Button::Transparent)
.on_press(Message::from(sub_page.into_page()))
// .id(BTN.clone())
.into()
@ -322,17 +317,43 @@ impl Application for Window {
type Executor = cosmic::executor::Default;
type Flags = ();
type Message = Message;
type Theme = Theme;
fn new(_flags: ()) -> (Self, Task<Self::Message>) {
let mut window = Window::default()
.nav_bar_toggled(true)
.show_maximize(true)
.show_minimize(true);
/// The unique application ID to supply to the window manager.
const APP_ID: &'static str = "org.cosmic.CosmicDemo";
fn core(&self) -> &Core {
&self.core
}
fn core_mut(&mut self) -> &mut Core {
&mut self.core
}
fn init(core: Core, _flags: ()) -> (Self, command::Task<Self::Message>) {
let mut window = Window {
core,
bluetooth: bluetooth::State::default(),
debug: false,
demo: demo::State::default(),
editor: editor::State::default(),
desktop: desktop::State::default(),
nav_bar: segmented_button::SingleSelectModel::default(),
nav_id_to_page: segmented_button::SecondaryMap::default(),
nav_bar_toggled_condensed: false,
nav_bar_toggled: true,
page: Page::default(),
show_maximize: true,
show_minimize: true,
system_and_accounts: system_and_accounts::State::default(),
theme: Theme::default(),
show_warning: false,
warning_message: String::from("You were not supposed to touch that."),
scale_factor: 1.0,
scale_factor_string: String::new(),
timeline: Rc::new(RefCell::new(Timeline::default())),
};
window.title = String::from("COSMIC Design System - Iced");
window.set_scale_factor(1.0);
window.warning_message = String::from("You were not supposed to touch that.");
window.insert_page(Page::Demo);
window.insert_page(Page::Editor);
@ -352,19 +373,18 @@ impl Application for Window {
window.insert_page(Page::Applications);
window.demo.timeline = window.timeline.clone();
(window, load_fonts().map(|_| Message::FontsLoaded))
}
let command = window.set_window_title(
"COSMIC Design System - Iced".into(),
window.core.main_window_id().unwrap(),
);
fn title(&self) -> String {
self.title.clone()
(window, command)
}
fn subscription(&self) -> Subscription<Message> {
let window_break = listen_raw(|event, _| match event {
cosmic::iced::Event::Window(
_window_id,
window::Event::Resized { width, height: _ },
) => {
let window_break = listen_raw(|event, _, _| match event {
cosmic::iced::Event::Window(window::Event::Resized(Size { width, height: _ })) => {
let width = width as u32;
let old_width = WINDOW_WIDTH.load(Ordering::Relaxed);
if old_width == 0
|| old_width < BREAK_POINT && width > BREAK_POINT
@ -385,12 +405,12 @@ impl Application for Window {
self.timeline
.borrow()
.as_subscription()
.map(|(_, instant)| Self::Message::Tick(instant)),
.map(|(_, instant)| Message::Tick(instant)),
])
}
fn update(&mut self, message: Message) -> iced::Task<Self::Message> {
let mut ret = Task::none();
fn update(&mut self, message: Message) -> command::Task<Self::Message> {
let mut ret = command::Task::none();
match message {
Message::NavBar(key) => {
if let Some(page) = self.nav_id_to_page.get(key).copied() {
@ -404,7 +424,10 @@ impl Application for Window {
}
Message::Demo(message) => match self.demo.update(message) {
Some(demo::Output::Debug(debug)) => self.debug = debug,
Some(demo::Output::ScalingFactor(factor)) => self.set_scale_factor(factor),
Some(demo::Output::ScalingFactor(factor)) => {
self.set_scale_factor(factor);
ret = self.core.set_scaling_factor(factor);
}
Some(demo::Output::ThemeChanged(theme)) => {
self.theme = match theme {
demo::ThemeVariant::Light => Theme::light(),
@ -424,6 +447,7 @@ impl Application for Window {
)),
demo::ThemeVariant::System => cosmic::theme::system_preference(),
};
ret = command::set_theme(self.theme.clone())
}
Some(demo::Output::ToggleWarning) => self.toggle_warning(),
None => (),
@ -451,7 +475,6 @@ impl Application for Window {
_ => (),
},
Message::ToggleWarning => self.toggle_warning(),
Message::FontsLoaded => {} // Message::Tick(instant) => self.timeline.borrow_mut().now(instant), Message::Tick(instant) => self.timeline.borrow_mut().now(instant),
Message::Tick(instant) => self.timeline.borrow_mut().now(instant),
}
ret
@ -574,7 +597,7 @@ impl Application for Window {
.padding([0, 8, 8, 8])
.width(Length::Fill)
.height(Length::Fill)
.style(theme::Container::Background)
.class(theme::Container::Background)
.into();
let warning = warning(&self.warning_message)
.on_close(Message::ToggleWarning)
@ -584,22 +607,14 @@ impl Application for Window {
header,
container(column(vec![
warning,
iced::widget::vertical_space(Length::Fixed(12.0)).into(),
iced::widget::Space::with_height(Length::Fixed(12.0)).into(),
content,
]))
.style(theme::Container::Background)
.class(theme::Container::Background)
]
.into()
} else {
column(vec![header, content]).into()
}
}
fn scale_factor(&self) -> f64 {
self.scale_factor
}
fn theme(&self) -> Theme {
self.theme.clone()
}
}

View file

@ -28,13 +28,14 @@ impl State {
column!(
list_column().add(settings::item(
"Bluetooth",
toggler(None, self.enabled, Message::Enable)
toggler(self.enabled).on_toggle(Message::Enable)
)),
text("Now visible as \"TODO\", just kidding")
)
.spacing(8)
.into(),
settings::view_section("Devices")
settings::section()
.title("Devices")
.add(settings::item("No devices found", text("")))
.into(),
])

View file

@ -125,11 +125,12 @@ impl Default for State {
checkbox_value: false,
dropdown_selected: Some(0),
dropdown_options: vec!["Option 1", "Option 2", "Option 3", "Option 4"],
scaling_value: spin_button::Model::default()
.value(1.0)
.min(0.5)
.max(2.0)
.step(0.25),
scaling_value: spin_button::Model {
value: 1.0.into(),
min: 0.5.into(),
max: 2.0.into(),
step: 0.25.into(),
},
slider_value: 50.0,
spin_button: spin_button::Model::default().min(-10).max(10),
toggler_value: false,
@ -232,7 +233,7 @@ impl State {
]
.into_iter()
.fold(
column![].spacing(10).align_items(Alignment::Center),
column![].spacing(10).align_x(Alignment::Center),
|row, theme| {
row.push(radio(
format!("{:?}", theme),
@ -258,12 +259,13 @@ impl State {
match self.tab_bar.active_data() {
None => panic!("no tab is active"),
Some(DemoView::TabA) => settings::view_column(vec![
settings::view_section("Debug")
settings::section()
.title("Debug")
.add(settings::item("Debug theme", choose_theme))
.add(settings::item("Debug icon theme", choose_icon_theme))
.add(settings::item(
"Debug layout",
toggler(None, window.debug, Message::Debug),
toggler(window.debug).on_toggle(Message::Debug),
))
.add(settings::item(
"Scaling Factor",
@ -276,10 +278,11 @@ impl State {
.into(),
]))
.into(),
settings::view_section("Controls")
settings::section()
.title("Controls")
.add(settings::item(
"Toggler",
toggler(None, self.toggler_value, Message::TogglerToggled),
toggler(self.toggler_value).on_toggle(Message::TogglerToggled),
))
.add(settings::item(
"Pick List (TODO)",
@ -305,8 +308,8 @@ impl State {
.add(settings::item_row(vec![checkbox(
"Checkbox",
self.checkbox_value,
Message::CheckboxToggled,
)
.on_toggle(Message::CheckboxToggled)
.into()]))
.add(settings::item(
format!(
@ -354,7 +357,7 @@ impl State {
.width(Length::Shrink)
.on_activate(Message::MultiSelection)
.apply(container)
.center_x()
.center_x(Length::Fill)
.width(Length::Fill)
.into(),
text("Vertical With Spacing").into(),
@ -424,13 +427,12 @@ impl State {
])
.padding(0)
.into(),
Some(DemoView::TabC) => {
settings::view_column(vec![settings::view_section("Tab C")
.add(text("Nothing here yet").width(Length::Fill))
.into()])
.padding(0)
.into()
}
Some(DemoView::TabC) => settings::view_column(vec![settings::section()
.title("Tab C")
.add(text("Nothing here yet").width(Length::Fill))
.into()])
.padding(0)
.into(),
},
container(text("Background container with some text").size(24))
.layer(cosmic_theme::Layer::Background)

View file

@ -147,46 +147,40 @@ impl State {
fn view_desktop_options<'a>(&'a self, window: &'a Window) -> Element<'a, Message> {
settings::view_column(vec![
window.parent_page_button(DesktopPage::DesktopOptions),
settings::view_section("Super Key Action")
.add(settings::item("Launcher", horizontal_space(Length::Fill)))
.add(settings::item("Workspaces", horizontal_space(Length::Fill)))
.add(settings::item(
"Applications",
horizontal_space(Length::Fill),
))
settings::section()
.title("Super Key Action")
.add(settings::item("Launcher", horizontal_space()))
.add(settings::item("Workspaces", horizontal_space()))
.add(settings::item("Applications", horizontal_space()))
.into(),
settings::view_section("Hot Corner")
settings::section()
.title("Hot Corner")
.add(settings::item(
"Enable top-left hot corner for Workspaces",
toggler(None, self.top_left_hot_corner, Message::TopLeftHotCorner),
toggler(self.top_left_hot_corner).on_toggle(Message::TopLeftHotCorner),
))
.into(),
settings::view_section("Top Panel")
settings::section()
.title("Top Panel")
.add(settings::item(
"Show Workspaces Button",
toggler(
None,
self.show_workspaces_button,
Message::ShowWorkspacesButton,
),
toggler(self.show_workspaces_button).on_toggle(Message::ShowWorkspacesButton),
))
.add(settings::item(
"Show Applications Button",
toggler(
None,
self.show_applications_button,
Message::ShowApplicationsButton,
),
toggler(self.show_applications_button)
.on_toggle(Message::ShowApplicationsButton),
))
.into(),
settings::view_section("Window Controls")
settings::section()
.title("Window Controls")
.add(settings::item(
"Show Minimize Button",
toggler(None, self.show_minimize_button, Message::ShowMinimizeButton),
toggler(self.show_minimize_button).on_toggle(Message::ShowMinimizeButton),
))
.add(settings::item(
"Show Maximize Button",
toggler(None, self.show_maximize_button, Message::ShowMaximizeButton),
toggler(self.show_maximize_button).on_toggle(Message::ShowMaximizeButton),
))
.into(),
])
@ -232,25 +226,25 @@ impl State {
settings::view_column(vec![
window.parent_page_button(DesktopPage::Wallpaper),
row!(
horizontal_space(Length::Fill),
horizontal_space(),
container(
image("/usr/share/backgrounds/pop/kate-hazen-COSMIC-desktop-wallpaper.png")
.width(Length::Fixed(300.0))
)
.padding(4)
.style(theme::Container::Background),
horizontal_space(Length::Fill),
.class(theme::Container::Background),
horizontal_space(),
)
.into(),
list_column()
.add(settings::item(
"Same background on all displays",
toggler(None, self.same_background, Message::SameBackground),
toggler(self.same_background).on_toggle(Message::SameBackground),
))
.add(settings::item("Background fit", text("TODO")))
.add(settings::item(
"Slideshow",
toggler(None, self.slideshow, Message::Slideshow),
toggler(self.slideshow).on_toggle(Message::Slideshow),
))
.into(),
column(image_column).spacing(16).into(),
@ -261,24 +255,23 @@ impl State {
fn view_desktop_workspaces<'a>(&'a self, window: &'a Window) -> Element<'a, Message> {
settings::view_column(vec![
window.parent_page_button(DesktopPage::Wallpaper),
settings::view_section("Workspace Behavior")
.add(settings::item(
"Dynamic workspaces",
horizontal_space(Length::Fill),
))
settings::section()
.title("Workspace Behavior")
.add(settings::item("Dynamic workspaces", horizontal_space()))
.add(settings::item(
"Fixed Number of Workspaces",
horizontal_space(Length::Fill),
horizontal_space(),
))
.into(),
settings::view_section("Multi-monitor Behavior")
settings::section()
.title("Multi-monitor Behavior")
.add(settings::item(
"Workspaces Span Displays",
horizontal_space(Length::Fill),
horizontal_space(),
))
.add(settings::item(
"Displays Have Separate Workspaces",
horizontal_space(Length::Fill),
horizontal_space(),
))
.into(),
])

View file

@ -71,8 +71,8 @@ impl State {
.apply(button::icon)
.on_press(Message::AddNew);
let tab_header = row!(tabs, new_tab_button).align_items(Alignment::Center);
let tab_header = row!(tabs, new_tab_button).align_y(Alignment::Center);
row!(tab_header, horizontal_space(Length::Fill)).into()
row!(tab_header, horizontal_space()).into()
}
}

View file

@ -1,6 +1,5 @@
use cosmic::{
iced::widget::{horizontal_space, row, text},
iced::Length,
widget::{icon, list_column, settings},
Element,
};
@ -61,22 +60,24 @@ impl State {
settings::view_column(vec![
window.parent_page_button(SystemAndAccountsPage::About),
row!(
horizontal_space(Length::Fill),
horizontal_space(),
icon::from_name("distributor-logo").size(78).icon(),
horizontal_space(Length::Fill),
horizontal_space(),
)
.into(),
list_column()
.add(settings::item("Device name", text("TODO")))
.into(),
settings::view_section("Hardware")
settings::section()
.title("Hardware")
.add(settings::item("Hardware model", text("TODO")))
.add(settings::item("Memory", text("TODO")))
.add(settings::item("Processor", text("TODO")))
.add(settings::item("Graphics", text("TODO")))
.add(settings::item("Disk Capacity", text("TODO")))
.into(),
settings::view_section("Operating System")
settings::section()
.title("Operating System")
.add(settings::item("Operating system", text("TODO")))
.add(settings::item(
"Operating system architecture",
@ -85,7 +86,8 @@ impl State {
.add(settings::item("Desktop environment", text("TODO")))
.add(settings::item("Windowing system", text("TODO")))
.into(),
settings::view_section("Related settings")
settings::section()
.title("Related settings")
.add(settings::item("Get support", text("TODO")))
.into(),
])