examples: fix libcosmic features, warnings, etc.

This commit is contained in:
Michael Aaron Murphy 2025-12-05 17:59:42 +01:00
parent f39ad728c9
commit 05c6608842
No known key found for this signature in database
GPG key ID: B2732D4240C9212C
23 changed files with 40 additions and 46 deletions

View file

@ -8,18 +8,15 @@ open = "5.3.2"
[dependencies.libcosmic] [dependencies.libcosmic]
path = "../../" path = "../../"
default-features = false
features = [ features = [
"debug", "debug",
"winit", "winit",
"tokio", "tokio",
"xdg-portal", "xdg-portal",
"dbus-config",
"desktop", "desktop",
"a11y", "a11y",
"wayland", "wayland",
"wgpu", "wgpu",
"single-instance", "single-instance",
"multi-window",
"about", "about",
] ]

View file

@ -14,16 +14,13 @@ tracing-log = "0.2.0"
[dependencies.libcosmic] [dependencies.libcosmic]
path = "../../" path = "../../"
default-features = false
features = [ features = [
"debug", "debug",
"winit", "winit",
"tokio", "tokio",
"xdg-portal", "xdg-portal",
"dbus-config",
"a11y", "a11y",
"wgpu", "wgpu",
"single-instance", "single-instance",
"multi-window",
"surface-message", "surface-message",
] ]

View file

@ -10,5 +10,4 @@ chrono = "0.4.40"
[dependencies.libcosmic] [dependencies.libcosmic]
path = "../../" path = "../../"
default-features = false
features = ["debug", "winit", "tokio", "xdg-portal", "wgpu"] features = ["debug", "winit", "tokio", "xdg-portal", "wgpu"]

View file

@ -113,6 +113,9 @@ where
{ {
fn update_title(&mut self) -> cosmic::app::Task<Message> { fn update_title(&mut self) -> cosmic::app::Task<Message> {
self.set_header_title(String::from("Calendar Demo")); self.set_header_title(String::from("Calendar Demo"));
self.set_window_title(String::from("Calendar Demo")) self.set_window_title(
String::from("Calendar Demo"),
self.core.main_window_id().unwrap(),
)
} }
} }

View file

@ -4,7 +4,7 @@
use cosmic_config::{Config, ConfigGet, ConfigSet}; use cosmic_config::{Config, ConfigGet, ConfigSet};
fn test_config(config: Config) { fn test_config(config: Config) {
let watcher = config let _watcher = config
.watch(|config, keys| { .watch(|config, keys| {
println!("Changed: {:?}", keys); println!("Changed: {:?}", keys);
for key in keys.iter() { for key in keys.iter() {

View file

@ -10,13 +10,12 @@ tracing-log = "0.2.0"
[dependencies.libcosmic] [dependencies.libcosmic]
path = "../../" path = "../../"
default-features = false
features = [ features = [
"debug", "debug",
"winit", "winit",
"wgpu",
"tokio", "tokio",
"xdg-portal", "xdg-portal",
"multi-window",
"surface-message", "surface-message",
"wayland", "wayland",
] ]

View file

@ -37,7 +37,6 @@ pub enum Message {
pub struct App { pub struct App {
core: Core, core: Core,
button_label: String, button_label: String,
show_context: bool,
hide_content: bool, hide_content: bool,
} }
@ -69,7 +68,6 @@ impl cosmic::Application for App {
core, core,
button_label: String::from("Right click me"), button_label: String::from("Right click me"),
hide_content: false, hide_content: false,
show_context: false,
}; };
app.set_header_title("COSMIC Context Menu Demo".into()); app.set_header_title("COSMIC Context Menu Demo".into());
@ -102,7 +100,7 @@ impl cosmic::Application for App {
} }
/// Creates a view after each update. /// Creates a view after each update.
fn view(&self) -> Element<Self::Message> { fn view(&self) -> Element<'_, Self::Message> {
let widget = cosmic::widget::context_menu( let widget = cosmic::widget::context_menu(
cosmic::widget::button::text(self.button_label.to_string()).on_press(Message::Clicked), cosmic::widget::button::text(self.button_label.to_string()).on_press(Message::Clicked),
self.context_menu(), self.context_menu(),

View file

@ -9,5 +9,4 @@ tracing-subscriber = "0.3.19"
[dependencies.libcosmic] [dependencies.libcosmic]
path = "../../" path = "../../"
default-features = false features = ["debug", "winit", "wgpu", "tokio"]
features = ["debug", "winit", "tokio"]

View file

@ -79,7 +79,7 @@ impl cosmic::Application for App {
} }
/// Creates a view after each update. /// Creates a view after each update.
fn view(&self) -> Element<Self::Message> { fn view(&self) -> Element<'_, Self::Message> {
let mut content = cosmic::widget::column().spacing(12); let mut content = cosmic::widget::column().spacing(12);
for (id, image) in self.images.iter().enumerate() { for (id, image) in self.images.iter().enumerate() {
@ -108,6 +108,9 @@ where
{ {
fn update_title(&mut self) -> Task<Message> { fn update_title(&mut self) -> Task<Message> {
self.set_header_title(String::from("Image Button Demo")); self.set_header_title(String::from("Image Button Demo"));
self.set_window_title(String::from("Image Button Demo")) self.set_window_title(
String::from("Image Button Demo"),
self.core.main_window_id().unwrap(),
)
} }
} }

View file

@ -10,5 +10,4 @@ tracing-log = "0.2.0"
[dependencies.libcosmic] [dependencies.libcosmic]
path = "../../" path = "../../"
default-features = false features = ["debug", "winit", "tokio", "xdg-portal", "wgpu"]
features = ["debug", "winit", "tokio", "xdg-portal", "multi-window"]

View file

@ -110,7 +110,7 @@ impl cosmic::Application for App {
(app, Task::none()) (app, Task::none())
} }
fn header_start(&self) -> Vec<Element<Self::Message>> { fn header_start(&self) -> Vec<Element<'_, Self::Message>> {
vec![menu_bar(&self.config, &self.key_binds)] vec![menu_bar(&self.config, &self.key_binds)]
} }
@ -137,7 +137,7 @@ impl cosmic::Application for App {
} }
/// Creates a view after each update. /// Creates a view after each update.
fn view(&self) -> Element<Self::Message> { fn view(&self) -> Element<'_, Self::Message> {
let text = if self.config.hide_content { let text = if self.config.hide_content {
cosmic::widget::text("") cosmic::widget::text("")
} else { } else {

View file

@ -6,4 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
libcosmic = { path = "../..", features = ["debug", "winit", "tokio", "single-instance", "multi-window", "dbus-config", "wgpu", "wayland"] } libcosmic = { path = "../..", features = ["debug", "winit", "tokio", "single-instance", "wgpu", "wayland"] }

View file

@ -2,11 +2,11 @@ use std::collections::HashMap;
use cosmic::{ use cosmic::{
app::Core, app::Core,
iced::{self, event, window}, iced::{self, event, window, Subscription},
iced_core::{id, Alignment, Length, Point}, iced_core::{id, Alignment, Length, Point},
iced_widget::{column, container, scrollable, text}, iced_widget::{column, container, scrollable, text},
prelude::*,
widget::{button, header_bar}, widget::{button, header_bar},
ApplicationExt, Task,
}; };
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
@ -57,7 +57,7 @@ impl cosmic::Application for MultiWindow {
(windows, cosmic::app::Task::none()) (windows, cosmic::app::Task::none())
} }
fn subscription(&self) -> cosmic::iced_futures::Subscription<Self::Message> { fn subscription(&self) -> Subscription<Self::Message> {
event::listen_with(|event, _, id| { event::listen_with(|event, _, id| {
if let iced::Event::Window(window_event) = event { if let iced::Event::Window(window_event) = event {
match window_event { match window_event {
@ -74,7 +74,7 @@ impl cosmic::Application for MultiWindow {
}) })
} }
fn update(&mut self, message: Self::Message) -> iced::Task<cosmic::Action<Self::Message>> { fn update(&mut self, message: Self::Message) -> Task<cosmic::Action<Self::Message>> {
match message { match message {
Message::CloseWindow(id) => window::close(id), Message::CloseWindow(id) => window::close(id),
Message::WindowClosed(id) => { Message::WindowClosed(id) => {
@ -119,7 +119,7 @@ impl cosmic::Application for MultiWindow {
} }
} }
fn view_window(&self, id: window::Id) -> cosmic::prelude::Element<Self::Message> { fn view_window(&self, id: window::Id) -> Element<'_, Self::Message> {
let w = self.windows.get(&id).unwrap(); let w = self.windows.get(&id).unwrap();
let input_id = w.input_id.clone(); let input_id = w.input_id.clone();
@ -152,7 +152,7 @@ impl cosmic::Application for MultiWindow {
} }
} }
fn view(&self) -> cosmic::prelude::Element<Self::Message> { fn view(&self) -> Element<'_, Self::Message> {
self.view_window(self.core.main_window_id().unwrap()) self.view_window(self.core.main_window_id().unwrap())
} }
} }

View file

@ -10,5 +10,4 @@ tracing-log = "0.2.0"
[dependencies.libcosmic] [dependencies.libcosmic]
path = "../../" path = "../../"
default-features = false features = ["debug", "winit", "tokio", "xdg-portal", "wgpu"]
features = ["debug", "winit", "tokio", "xdg-portal", "multi-window"]

View file

@ -172,7 +172,7 @@ impl cosmic::Application for App {
} }
/// Creates a view after each update. /// Creates a view after each update.
fn view(&self) -> Element<Self::Message> { fn view(&self) -> Element<'_, Self::Message> {
let page_content = self let page_content = self
.nav_model .nav_model
.active_data::<String>() .active_data::<String>()

View file

@ -16,6 +16,5 @@ tracing-subscriber = "0.3.19"
url = "2.5.4" url = "2.5.4"
[dependencies.libcosmic] [dependencies.libcosmic]
features = ["debug", "winit", "multi-window", "wayland", "tokio"] features = ["debug", "winit", "wgpu", "wayland", "tokio"]
path = "../../" path = "../../"
default-features = false

View file

@ -82,7 +82,7 @@ impl cosmic::Application for App {
(app, cmd) (app, cmd)
} }
fn header_end(&self) -> Vec<Element<Self::Message>> { fn header_end(&self) -> Vec<Element<'_, Self::Message>> {
// Places a button the header to create open dialogs. // Places a button the header to create open dialogs.
vec![button::suggested("Open").on_press(Message::OpenFile).into()] vec![button::suggested("Open").on_press(Message::OpenFile).into()]
} }
@ -186,13 +186,17 @@ impl cosmic::Application for App {
Message::CloseError => { Message::CloseError => {
self.error_status = None; self.error_status = None;
} }
Message::Surface(surface) => {} Message::Surface(action) => {
return cosmic::task::message(cosmic::Action::Cosmic(
cosmic::app::Action::Surface(action),
));
}
} }
Task::none() Task::none()
} }
fn view(&self) -> Element<Self::Message> { fn view(&self) -> Element<'_, Self::Message> {
let mut content = Vec::new(); let mut content = Vec::new();
if let Some(error) = self.error_status.as_deref() { if let Some(error) = self.error_status.as_deref() {

View file

@ -7,6 +7,6 @@ edition = "2021"
fraction = "0.15.3" fraction = "0.15.3"
[dependencies.libcosmic] [dependencies.libcosmic]
features = ["debug", "multi-window", "wayland", "winit", "desktop", "tokio"] features = ["debug", "wgpu", "winit", "desktop", "tokio"]
path = "../.." path = "../.."
default-features = false default-features = false

View file

@ -130,7 +130,7 @@ impl Application for SpinButtonExamplApp {
Task::none() Task::none()
} }
fn view(&self) -> Element<Self::Message> { fn view(&'_ self) -> Element<'_, Self::Message> {
let space_xs = cosmic::theme::spacing().space_xs; let space_xs = cosmic::theme::spacing().space_xs;
let vert_spinner_row = iced::widget::row![ let vert_spinner_row = iced::widget::row![

View file

@ -10,6 +10,5 @@ tracing-log = "0.2.0"
chrono = "*" chrono = "*"
[dependencies.libcosmic] [dependencies.libcosmic]
features = ["debug", "multi-window", "wayland", "winit", "desktop", "tokio"] features = ["debug", "wgpu", "winit", "desktop", "tokio"]
path = "../.." path = "../.."
default-features = false

View file

@ -204,7 +204,7 @@ impl cosmic::Application for App {
} }
/// Creates a view after each update. /// Creates a view after each update.
fn view(&self) -> Element<Self::Message> { fn view(&self) -> Element<'_, Self::Message> {
cosmic::widget::responsive(|size| { cosmic::widget::responsive(|size| {
if size.width < 600.0 { if size.width < 600.0 {
widget::compact_table(&self.table_model) widget::compact_table(&self.table_model)

View file

@ -10,5 +10,4 @@ tracing-log = "0.2.0"
[dependencies.libcosmic] [dependencies.libcosmic]
path = "../../" path = "../../"
default-features = false features = ["debug", "winit", "wgpu", "tokio", "xdg-portal"]
features = ["debug", "winit", "tokio", "xdg-portal"]

View file

@ -87,7 +87,7 @@ impl cosmic::Application for App {
} }
/// Creates a view after each update. /// Creates a view after each update.
fn view(&self) -> Element<Self::Message> { fn view(&self) -> Element<'_, Self::Message> {
let editable = cosmic::widget::editable_input( let editable = cosmic::widget::editable_input(
"Input text here", "Input text here",
&self.input, &self.input,
@ -118,6 +118,6 @@ where
fn update_title(&mut self) -> Task<Message> { fn update_title(&mut self) -> Task<Message> {
let window_title = format!("COSMIC TextInputs Demo"); let window_title = format!("COSMIC TextInputs Demo");
self.set_header_title(window_title.clone()); self.set_header_title(window_title.clone());
self.set_window_title(window_title) self.set_window_title(window_title, self.core.main_window_id().unwrap())
} }
} }