Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Update to 0.12 #228

Merged
merged 10 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,3 @@ exclude = ["examples/design-demo", "iced"]
[patch."https://github.com/pop-os/libcosmic"]
libcosmic = { path = "./" }

# [patch."https://github.com/pop-os/cosmic-time"]
# cosmic-time = { path = "../cosmic-time" }
Empty file.
1 change: 1 addition & 0 deletions examples/cosmic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ log = "0.4.17"
[dependencies.cosmic-time]
git = "https://github.com/pop-os/cosmic-time"
default-features = false
branch = "update-0.12"
features = ["libcosmic", "once_cell"]
5 changes: 3 additions & 2 deletions examples/cosmic/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use cosmic::{
widget::{self, column, container, horizontal_space, row, text},
window::{self, close, drag, minimize, toggle_maximize},
},
iced_futures::event::listen_raw,
keyboard_nav,
prelude::*,
theme::{self, Theme},
Expand Down Expand Up @@ -358,7 +359,7 @@ impl Application for Window {
}

fn subscription(&self) -> Subscription<Message> {
let window_break = subscription::events_with(|event, _| match event {
let window_break = listen_raw(|event, _| match event {
cosmic::iced::Event::Window(
_window_id,
window::Event::Resized { width, height: _ },
Expand Down Expand Up @@ -450,7 +451,7 @@ impl Application for Window {
_ => (),
},
Message::ToggleWarning => self.toggle_warning(),
Message::FontsLoaded => {}
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
Expand Down
44 changes: 2 additions & 42 deletions examples/cosmic/src/window/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use apply::Apply;
use cosmic::{
cosmic_theme,
iced::widget::{checkbox, column, progress_bar, radio, slider, text, text_input},
iced::{id, Alignment, Length},
iced::{Alignment, Length},
iced_core::id,
theme::ThemeType,
widget::{
button, color_picker::ColorPickerUpdate, cosmic_container::container, dropdown, icon,
Expand Down Expand Up @@ -474,50 +475,9 @@ impl State {
&self.entry_value,
)
.on_input(Message::InputChanged)
// .on_submit(Message::Activate(None))
.size(20)
.id(INPUT_ID.clone())
.into(),
cosmic::widget::text_input("test", &self.entry_value)
.on_clear(Message::InputChanged("".to_string()))
.width(Length::Fill)
.on_input(Message::InputChanged)
.into(),
cosmic::widget::text_input("test", &self.entry_value)
.width(Length::Fixed(600.0))
.padding(32)
.on_input(Message::InputChanged)
.into(),
cosmic::widget::search_input("test", &self.entry_value)
.on_clear(Message::InputChanged("".to_string()))
.width(Length::Fill)
.on_input(Message::InputChanged)
.into(),
cosmic::widget::text_input("test", &self.entry_value)
.width(Length::Fixed(600.0))
.on_input(Message::InputChanged)
.into(),
cosmic::widget::search_input("test", &self.entry_value)
.on_clear(Message::InputChanged("".to_string()))
.width(Length::Fixed(100.0))
.on_input(Message::InputChanged)
.into(),
cosmic::widget::search_input("test", &self.entry_value)
.on_clear(Message::InputChanged("".to_string()))
.padding([24, 48])
.width(Length::Fixed(400.0))
.on_input(Message::InputChanged)
.into(),
cosmic::widget::search_input("test", &self.entry_value)
.on_clear(Message::InputChanged("".to_string()))
.width(Length::Fixed(400.0))
.on_input(Message::InputChanged)
.into(),
cosmic::widget::search_input("test", &self.entry_value)
.on_clear(Message::InputChanged("".to_string()))
.width(Length::Fixed(800.0))
.on_input(Message::InputChanged)
.into(),
self.color_picker_model
.picker_button(Message::ColorPickerUpdate, None)
.width(Length::Fixed(128.0))
Expand Down
2 changes: 1 addition & 1 deletion iced
Submodule iced updated 346 files
3 changes: 2 additions & 1 deletion src/app/cosmic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use iced::event::wayland::{self, WindowEvent};
#[cfg(feature = "wayland")]
use iced::event::PlatformSpecific;
use iced::window;
use iced_futures::event::listen_raw;
#[cfg(not(feature = "wayland"))]
use iced_runtime::command::Action;
#[cfg(not(feature = "wayland"))]
Expand Down Expand Up @@ -126,7 +127,7 @@ where
}

fn subscription(&self) -> Subscription<Self::Message> {
let window_events = iced::subscription::events_with(|event, _| {
let window_events = listen_raw(|event, _| {
match event {
iced::Event::Window(id, window::Event::Resized { width, height }) => {
return Some(Message::WindowResize(id, width, height));
Expand Down
4 changes: 2 additions & 2 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub(crate) fn iced_settings<App: Application>(

iced.antialiasing = settings.antialiasing;
iced.default_font = settings.default_font;
iced.default_text_size = settings.default_text_size;
iced.default_text_size = iced::Pixels(settings.default_text_size);
iced.exit_on_close_request = settings.exit_on_close;
iced.id = Some(App::APP_ID.to_owned());

Expand Down Expand Up @@ -362,7 +362,7 @@ where
type Executor: iced_futures::Executor;

/// Argument received [`Application::new`].
type Flags: Clone;
type Flags;

/// Message type specific to our app.
type Message: Clone + std::fmt::Debug + Send + 'static;
Expand Down
2 changes: 1 addition & 1 deletion src/app/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use crate::{font, Theme};
#[cfg(feature = "wayland")]
use iced::Limits;
use iced_core::layout::Limits;
use iced_core::Font;

/// Configure a new COSMIC application.
Expand Down
2 changes: 1 addition & 1 deletion src/applet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ pub fn run<App: Application>(autosize: bool, flags: App::Flags) -> iced::Result

iced.antialiasing = settings.antialiasing;
iced.default_font = settings.default_font;
iced.default_text_size = settings.default_text_size;
iced.default_text_size = settings.default_text_size.into();
iced.id = Some(App::APP_ID.to_owned());

{
Expand Down
10 changes: 5 additions & 5 deletions src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub const FONT: Font = Font {
family: Family::Name("Fira Sans"),
weight: iced_core::font::Weight::Normal,
stretch: iced_core::font::Stretch::Normal,
monospaced: false,
style: iced_core::font::Style::Normal,
};

pub const FONT_DATA: &[u8] = include_bytes!("../res/Fira/FiraSans-Regular.otf");
Expand All @@ -25,7 +25,7 @@ pub const FONT_LIGHT: Font = Font {
family: Family::Name("Fira Sans"),
weight: iced_core::font::Weight::Light,
stretch: iced_core::font::Stretch::Normal,
monospaced: false,
style: iced_core::font::Style::Normal,
};

pub const FONT_LIGHT_DATA: &[u8] = include_bytes!("../res/Fira/FiraSans-Light.otf");
Expand All @@ -34,7 +34,7 @@ pub const FONT_SEMIBOLD: Font = Font {
family: Family::Name("Fira Sans"),
weight: iced_core::font::Weight::Semibold,
stretch: iced_core::font::Stretch::Normal,
monospaced: false,
style: iced_core::font::Style::Normal,
};

pub const FONT_SEMIBOLD_DATA: &[u8] = include_bytes!("../res/Fira/FiraSans-SemiBold.otf");
Expand All @@ -43,7 +43,7 @@ pub const FONT_BOLD: Font = Font {
family: Family::Name("Fira Sans"),
weight: iced_core::font::Weight::Bold,
stretch: iced_core::font::Stretch::Normal,
monospaced: false,
style: iced_core::font::Style::Normal,
};

pub const FONT_BOLD_DATA: &[u8] = include_bytes!("../res/Fira/FiraSans-Bold.otf");
Expand All @@ -52,7 +52,7 @@ pub const FONT_MONO_REGULAR: Font = Font {
family: Family::Name("Fira Mono"),
weight: iced_core::font::Weight::Normal,
stretch: iced_core::font::Stretch::Normal,
monospaced: true,
style: iced_core::font::Style::Normal,
};

pub const FONT_MONO_REGULAR_DATA: &[u8] = include_bytes!("../res/Fira/FiraMono-Regular.otf");
Expand Down
5 changes: 3 additions & 2 deletions src/keyboard_nav.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
use iced::{
event,
keyboard::{self, KeyCode},
mouse, subscription, Command, Event, Subscription,
mouse, Command, Event, Subscription,
};
use iced_core::{
widget::{operation, Id, Operation},
Rectangle,
};
use iced_futures::event::listen_raw;

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum Message {
Expand All @@ -24,7 +25,7 @@ pub enum Message {
}

pub fn subscription() -> Subscription<Message> {
subscription::events_with(|event, status| {
listen_raw(|event, status| {
if event::Status::Ignored != status {
return None;
}
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,6 @@ pub use theme::{style, Theme};

pub mod widget;

type Paragraph = <Renderer as iced_core::text::Renderer>::Paragraph;
pub type Renderer = iced::Renderer<Theme>;
pub type Element<'a, Message> = iced::Element<'a, Message, Renderer>;
100 changes: 83 additions & 17 deletions src/theme/style/iced.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,23 +146,6 @@ impl iced_button::StyleSheet for Theme {
}
}

fn focused(&self, style: &Self::Style) -> iced_button::Appearance {
if let Button::Custom { hover, .. } = style {
return hover(self);
}

let active = self.active(style);
let component = style.cosmic(self);
iced_button::Appearance {
background: match style {
Button::Link => None,
Button::LinkActive => Some(Background::Color(component.divider.into())),
_ => Some(Background::Color(component.hover.into())),
},
..active
}
}

fn disabled(&self, style: &Self::Style) -> iced_button::Appearance {
let active = self.active(style);

Expand Down Expand Up @@ -1101,3 +1084,86 @@ impl crate::widget::card::style::StyleSheet for Theme {
}
}
}

#[derive(Default)]
pub enum TextEditor {
#[default]
Default,
Custom(Box<dyn iced_style::text_editor::StyleSheet<Style = Theme>>),
}

impl iced_style::text_editor::StyleSheet for Theme {
type Style = TextEditor;

fn active(&self, style: &Self::Style) -> iced_style::text_editor::Appearance {
if let TextEditor::Custom(style) = style {
return style.active(self);
}

let cosmic = self.cosmic();
iced_style::text_editor::Appearance {
background: iced::Color::from(cosmic.bg_color()).into(),
border_radius: cosmic.corner_radii.radius_0.into(),
border_width: f32::from(cosmic.space_xxxs()),
border_color: iced::Color::from(cosmic.bg_divider()),
}
}

fn focused(&self, style: &Self::Style) -> iced_style::text_editor::Appearance {
if let TextEditor::Custom(style) = style {
return style.focused(self);
}

let cosmic = self.cosmic();
iced_style::text_editor::Appearance {
background: iced::Color::from(cosmic.bg_color()).into(),
border_radius: cosmic.corner_radii.radius_0.into(),
border_width: f32::from(cosmic.space_xxxs()),
border_color: iced::Color::from(cosmic.accent.base),
}
}

fn placeholder_color(&self, style: &Self::Style) -> Color {
if let TextEditor::Custom(style) = style {
return style.placeholder_color(self);
}
let palette = self.cosmic();
let mut neutral_9 = palette.palette.neutral_9;
neutral_9.alpha = 0.7;
neutral_9.into()
}

fn value_color(&self, style: &Self::Style) -> Color {
if let TextEditor::Custom(style) = style {
return style.value_color(self);
}
let palette = self.cosmic();

palette.palette.neutral_9.into()
}

fn disabled_color(&self, style: &Self::Style) -> Color {
if let TextEditor::Custom(style) = style {
return style.disabled_color(self);
}
let palette = self.cosmic();
let mut neutral_9 = palette.palette.neutral_9;
neutral_9.alpha = 0.5;
neutral_9.into()
}

fn selection_color(&self, style: &Self::Style) -> Color {
if let TextEditor::Custom(style) = style {
return style.selection_color(self);
}
let cosmic = self.cosmic();
cosmic.accent.base.into()
}

fn disabled(&self, style: &Self::Style) -> iced_style::text_editor::Appearance {
if let TextEditor::Custom(style) = style {
return style.disabled(self);
}
self.active(style)
}
}
10 changes: 8 additions & 2 deletions src/widget/aspect_ratio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,18 @@ where
Widget::height(&self.container)
}

fn layout(&self, renderer: &Renderer, limits: &layout::Limits) -> layout::Node {
fn layout(
&self,
tree: &mut Tree,
renderer: &Renderer,
limits: &layout::Limits,
) -> layout::Node {
let custom_limits = layout::Limits::new(
self.constrain_limits(limits.min()),
self.constrain_limits(limits.max()),
);
self.container.layout(renderer, &custom_limits)
self.container
.layout(&mut tree.children[0], renderer, &custom_limits)
}

fn operate(
Expand Down
13 changes: 11 additions & 2 deletions src/widget/button/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,23 @@ where
self.height
}

fn layout(&self, renderer: &Renderer, limits: &layout::Limits) -> layout::Node {
fn layout(
&self,
tree: &mut Tree,
renderer: &Renderer,
limits: &layout::Limits,
) -> layout::Node {
layout(
renderer,
limits,
self.width,
self.height,
self.padding,
|renderer, limits| self.content.as_widget().layout(renderer, limits),
|renderer, limits| {
self.content
.as_widget()
.layout(&mut tree.children[0], renderer, limits)
},
)
}

Expand Down
Loading
Loading