wip: update to use cosmic-advanced-text
This commit is contained in:
parent
98ec1bbd48
commit
5da0bef35e
36 changed files with 367 additions and 282 deletions
|
|
@ -7,7 +7,7 @@ use std::future::Future;
|
|||
pub struct Executor(tokio::runtime::Runtime);
|
||||
|
||||
#[cfg(feature = "tokio")]
|
||||
impl iced_native::Executor for Executor {
|
||||
impl iced::Executor for Executor {
|
||||
fn new() -> Result<Self, iced::futures::io::Error> {
|
||||
Ok(Self(
|
||||
tokio::runtime::Builder::new_multi_thread()
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use std::future::Future;
|
|||
pub struct Executor(tokio::runtime::Runtime);
|
||||
|
||||
#[cfg(feature = "tokio")]
|
||||
impl iced_native::Executor for Executor {
|
||||
impl iced::Executor for Executor {
|
||||
fn new() -> Result<Self, iced::futures::io::Error> {
|
||||
// Current thread executor requires calling `block_on` to actually run
|
||||
// futures. Main thread is busy with things other than running futures,
|
||||
|
|
|
|||
29
src/font.rs
29
src/font.rs
|
|
@ -3,17 +3,22 @@
|
|||
|
||||
pub use iced::Font;
|
||||
|
||||
pub const FONT: Font = Font::External {
|
||||
name: "Fira Sans Regular",
|
||||
bytes: include_bytes!("../res/Fira/FiraSans-Regular.otf"),
|
||||
};
|
||||
pub const FONT: Font = Font::with_name("Fira Sans Regular");
|
||||
// pub const FONT: Font = Font::External {
|
||||
// name: "Fira Sans Regular",
|
||||
// bytes: include_bytes!("../res/Fira/FiraSans-Regular.otf"),
|
||||
// };
|
||||
|
||||
pub const FONT_LIGHT: Font = Font::External {
|
||||
name: "Fira Sans Light",
|
||||
bytes: include_bytes!("../res/Fira/FiraSans-Light.otf"),
|
||||
};
|
||||
pub const FONT_LIGHT: Font = Font::with_name("Fira Sans Light");
|
||||
|
||||
pub const FONT_SEMIBOLD: Font = Font::External {
|
||||
name: "Fira Sans SemiBold",
|
||||
bytes: include_bytes!("../res/Fira/FiraSans-SemiBold.otf"),
|
||||
};
|
||||
// pub const FONT_LIGHT: Font = Font::External {
|
||||
// name: "Fira Sans Light",
|
||||
// bytes: include_bytes!("../res/Fira/FiraSans-Light.otf"),
|
||||
// };
|
||||
|
||||
pub const FONT_SEMIBOLD: Font = Font::with_name("Fira Sans SemiBold");
|
||||
|
||||
// pub const FONT_SEMIBOLD: Font = Font::External {
|
||||
// name: "Fira Sans SemiBold",
|
||||
// bytes: include_bytes!("../res/Fira/FiraSans-SemiBold.otf"),
|
||||
// };
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use iced::{
|
|||
keyboard::{self, KeyCode},
|
||||
mouse, subscription, Command, Event, Subscription,
|
||||
};
|
||||
use iced_native::widget::{operation, Id, Operation};
|
||||
use iced_core::widget::{operation, Id, Operation};
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum Message {
|
||||
|
|
|
|||
|
|
@ -5,8 +5,6 @@
|
|||
|
||||
pub use cosmic_theme;
|
||||
pub use iced;
|
||||
pub use iced_lazy;
|
||||
pub use iced_native;
|
||||
#[cfg(feature = "wayland")]
|
||||
pub use iced_sctk;
|
||||
pub use iced_style;
|
||||
|
|
|
|||
|
|
@ -27,11 +27,8 @@ pub fn settings<Flags: Default>() -> iced::Settings<Flags> {
|
|||
#[must_use]
|
||||
pub fn settings_with_flags<Flags>(flags: Flags) -> iced::Settings<Flags> {
|
||||
iced::Settings {
|
||||
default_font: match font::FONT {
|
||||
iced::Font::Default => None,
|
||||
iced::Font::External { bytes, .. } => Some(bytes),
|
||||
},
|
||||
default_text_size: 18,
|
||||
default_font: font::FONT,
|
||||
default_text_size: 18.0,
|
||||
..iced::Settings::with_flags(flags)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
105
src/theme/mod.rs
105
src/theme/mod.rs
|
|
@ -12,11 +12,12 @@ pub use self::segmented_button::SegmentedButton;
|
|||
|
||||
use cosmic_theme::Component;
|
||||
use cosmic_theme::LayeredTheme;
|
||||
use iced_core::BorderRadius;
|
||||
use iced_core::renderer::BorderRadius;
|
||||
use iced_style::application;
|
||||
use iced_style::button;
|
||||
use iced_style::checkbox;
|
||||
use iced_style::container;
|
||||
use iced_style::core::text;
|
||||
use iced_style::menu;
|
||||
use iced_style::pane_grid;
|
||||
use iced_style::pick_list;
|
||||
|
|
@ -25,8 +26,8 @@ use iced_style::radio;
|
|||
use iced_style::rule;
|
||||
use iced_style::scrollable;
|
||||
use iced_style::slider;
|
||||
use iced_style::slider::Rail;
|
||||
use iced_style::svg;
|
||||
use iced_style::text;
|
||||
use iced_style::text_input;
|
||||
use iced_style::toggler;
|
||||
|
||||
|
|
@ -218,8 +219,8 @@ impl button::StyleSheet for Theme {
|
|||
let component = style.cosmic(self);
|
||||
button::Appearance {
|
||||
border_radius: match style {
|
||||
Button::Link => BorderRadius::from(0.0),
|
||||
_ => BorderRadius::from(24.0),
|
||||
Button::Link => 0.0,
|
||||
_ => 24.0,
|
||||
},
|
||||
background: match style {
|
||||
Button::Link | Button::Text => None,
|
||||
|
|
@ -252,22 +253,23 @@ impl button::StyleSheet for Theme {
|
|||
}
|
||||
}
|
||||
|
||||
fn focused(&self, style: &Self::Style) -> button::Appearance {
|
||||
if let Button::Custom { hover, .. } = style {
|
||||
return hover(self);
|
||||
}
|
||||
// TODO add back
|
||||
// fn focused(&self, style: &Self::Style) -> button::Appearance {
|
||||
// if let Button::Custom { hover, .. } = style {
|
||||
// return hover(self);
|
||||
// }
|
||||
|
||||
let active = self.active(style);
|
||||
let component = style.cosmic(self);
|
||||
button::Appearance {
|
||||
background: match style {
|
||||
Button::Link => None,
|
||||
Button::LinkActive => Some(Background::Color(component.divider.into())),
|
||||
_ => Some(Background::Color(component.hover.into())),
|
||||
},
|
||||
..active
|
||||
}
|
||||
}
|
||||
// let active = self.active(style);
|
||||
// let component = style.cosmic(self);
|
||||
// button::Appearance {
|
||||
// background: match style {
|
||||
// Button::Link => None,
|
||||
// Button::LinkActive => Some(Background::Color(component.divider.into())),
|
||||
// _ => Some(Background::Color(component.hover.into())),
|
||||
// },
|
||||
// ..active
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -301,7 +303,7 @@ impl checkbox::StyleSheet for Theme {
|
|||
} else {
|
||||
palette.background.base.into()
|
||||
}),
|
||||
checkmark_color: palette.accent.on.into(),
|
||||
icon_color: palette.accent.on.into(),
|
||||
border_radius: 4.0,
|
||||
border_width: if is_checked { 0.0 } else { 1.0 },
|
||||
border_color: if is_checked {
|
||||
|
|
@ -318,7 +320,7 @@ impl checkbox::StyleSheet for Theme {
|
|||
} else {
|
||||
palette.background.base.into()
|
||||
}),
|
||||
checkmark_color: palette.background.on.into(),
|
||||
icon_color: palette.background.on.into(),
|
||||
border_radius: 4.0,
|
||||
border_width: if is_checked { 0.0 } else { 1.0 },
|
||||
border_color: neutral_7.into(),
|
||||
|
|
@ -330,7 +332,7 @@ impl checkbox::StyleSheet for Theme {
|
|||
} else {
|
||||
palette.background.base.into()
|
||||
}),
|
||||
checkmark_color: palette.success.on.into(),
|
||||
icon_color: palette.success.on.into(),
|
||||
border_radius: 4.0,
|
||||
border_width: if is_checked { 0.0 } else { 1.0 },
|
||||
border_color: if is_checked {
|
||||
|
|
@ -347,7 +349,7 @@ impl checkbox::StyleSheet for Theme {
|
|||
} else {
|
||||
palette.background.base.into()
|
||||
}),
|
||||
checkmark_color: palette.destructive.on.into(),
|
||||
icon_color: palette.destructive.on.into(),
|
||||
border_radius: 4.0,
|
||||
border_width: if is_checked { 0.0 } else { 1.0 },
|
||||
border_color: if is_checked {
|
||||
|
|
@ -374,7 +376,7 @@ impl checkbox::StyleSheet for Theme {
|
|||
} else {
|
||||
neutral_10.into()
|
||||
}),
|
||||
checkmark_color: palette.accent.on.into(),
|
||||
icon_color: palette.accent.on.into(),
|
||||
border_radius: 4.0,
|
||||
border_width: if is_checked { 0.0 } else { 1.0 },
|
||||
border_color: if is_checked {
|
||||
|
|
@ -391,7 +393,7 @@ impl checkbox::StyleSheet for Theme {
|
|||
} else {
|
||||
neutral_10.into()
|
||||
}),
|
||||
checkmark_color: self.current_container().on.into(),
|
||||
icon_color: self.current_container().on.into(),
|
||||
border_radius: 4.0,
|
||||
border_width: if is_checked { 0.0 } else { 1.0 },
|
||||
border_color: if is_checked {
|
||||
|
|
@ -408,7 +410,7 @@ impl checkbox::StyleSheet for Theme {
|
|||
} else {
|
||||
neutral_10.into()
|
||||
}),
|
||||
checkmark_color: palette.success.on.into(),
|
||||
icon_color: palette.success.on.into(),
|
||||
border_radius: 4.0,
|
||||
border_width: if is_checked { 0.0 } else { 1.0 },
|
||||
border_color: if is_checked {
|
||||
|
|
@ -425,7 +427,7 @@ impl checkbox::StyleSheet for Theme {
|
|||
} else {
|
||||
neutral_10.into()
|
||||
}),
|
||||
checkmark_color: palette.destructive.on.into(),
|
||||
icon_color: palette.destructive.on.into(),
|
||||
border_radius: 4.0,
|
||||
border_width: if is_checked { 0.0 } else { 1.0 },
|
||||
border_color: if is_checked {
|
||||
|
|
@ -538,11 +540,15 @@ impl slider::StyleSheet for Theme {
|
|||
|
||||
//TODO: no way to set rail thickness
|
||||
slider::Appearance {
|
||||
rail_colors: (
|
||||
cosmic.accent.base.into(),
|
||||
//TODO: no way to set color before/after slider
|
||||
Color::TRANSPARENT,
|
||||
),
|
||||
rail: Rail {
|
||||
colors: (
|
||||
cosmic.accent.base.into(),
|
||||
//TODO: no way to set color before/after slider
|
||||
Color::TRANSPARENT,
|
||||
),
|
||||
width: 4.0,
|
||||
},
|
||||
|
||||
handle: slider::Handle {
|
||||
shape: slider::HandleShape::Circle { radius: 10.0 },
|
||||
color: cosmic.accent.base.into(),
|
||||
|
|
@ -610,7 +616,8 @@ impl pick_list::StyleSheet for Theme {
|
|||
border_radius: 24.0,
|
||||
border_width: 0.0,
|
||||
border_color: Color::TRANSPARENT,
|
||||
icon_size: 0.7,
|
||||
// icon_size: 0.7, // TODO: how to replace
|
||||
handle_color: cosmic.on_bg_color().into(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -856,7 +863,11 @@ impl scrollable::StyleSheet for Theme {
|
|||
}
|
||||
}
|
||||
|
||||
fn hovered(&self, _style: &Self::Style) -> scrollable::Scrollbar {
|
||||
fn hovered(
|
||||
&self,
|
||||
_style: &Self::Style,
|
||||
is_mouse_over_scrollbar: bool,
|
||||
) -> scrollable::Scrollbar {
|
||||
let theme = self.cosmic();
|
||||
|
||||
scrollable::Scrollbar {
|
||||
|
|
@ -948,7 +959,7 @@ pub enum Text {
|
|||
Default,
|
||||
Color(Color),
|
||||
// TODO: Can't use dyn Fn since this must be copy
|
||||
Custom(fn(&Theme) -> text::Appearance),
|
||||
Custom(fn(&Theme) -> iced_widget::text::Appearance),
|
||||
}
|
||||
|
||||
impl From<Color> for Text {
|
||||
|
|
@ -957,16 +968,16 @@ impl From<Color> for Text {
|
|||
}
|
||||
}
|
||||
|
||||
impl text::StyleSheet for Theme {
|
||||
impl iced_widget::text::StyleSheet for Theme {
|
||||
type Style = Text;
|
||||
|
||||
fn appearance(&self, style: Self::Style) -> text::Appearance {
|
||||
fn appearance(&self, style: Self::Style) -> iced_widget::text::Appearance {
|
||||
match style {
|
||||
Text::Accent => text::Appearance {
|
||||
Text::Accent => iced_widget::text::Appearance {
|
||||
color: Some(self.cosmic().accent.base.into()),
|
||||
},
|
||||
Text::Default => text::Appearance { color: None },
|
||||
Text::Color(c) => text::Appearance { color: Some(c) },
|
||||
Text::Default => iced_widget::text::Appearance { color: None },
|
||||
Text::Color(c) => iced_widget::text::Appearance { color: Some(c) },
|
||||
Text::Custom(f) => f(self),
|
||||
}
|
||||
}
|
||||
|
|
@ -995,12 +1006,14 @@ impl text_input::StyleSheet for Theme {
|
|||
border_radius: 8.0,
|
||||
border_width: 1.0,
|
||||
border_color: self.current_container().component.divider.into(),
|
||||
icon_color: self.current_container().on.into(),
|
||||
},
|
||||
TextInput::Search => text_input::Appearance {
|
||||
background: Color::from(bg).into(),
|
||||
border_radius: 24.0,
|
||||
border_width: 0.0,
|
||||
border_color: Color::TRANSPARENT,
|
||||
icon_color: self.current_container().on.into(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
@ -1016,12 +1029,14 @@ impl text_input::StyleSheet for Theme {
|
|||
border_radius: 8.0,
|
||||
border_width: 1.0,
|
||||
border_color: palette.accent.base.into(),
|
||||
icon_color: self.current_container().on.into(),
|
||||
},
|
||||
TextInput::Search => text_input::Appearance {
|
||||
background: Color::from(bg).into(),
|
||||
border_radius: 24.0,
|
||||
border_width: 0.0,
|
||||
border_color: Color::TRANSPARENT,
|
||||
icon_color: self.current_container().on.into(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
@ -1037,12 +1052,14 @@ impl text_input::StyleSheet for Theme {
|
|||
border_radius: 8.0,
|
||||
border_width: 1.0,
|
||||
border_color: palette.accent.base.into(),
|
||||
icon_color: self.current_container().on.into(),
|
||||
},
|
||||
TextInput::Search => text_input::Appearance {
|
||||
background: Color::from(bg).into(),
|
||||
border_radius: 24.0,
|
||||
border_width: 0.0,
|
||||
border_color: Color::TRANSPARENT,
|
||||
icon_color: self.current_container().on.into(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
@ -1065,4 +1082,12 @@ impl text_input::StyleSheet for Theme {
|
|||
|
||||
palette.accent.base.into()
|
||||
}
|
||||
|
||||
fn disabled_color(&self, style: &Self::Style) -> Color {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn disabled(&self, style: &Self::Style) -> text_input::Appearance {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
use crate::widget::segmented_button::{Appearance, ItemAppearance, StyleSheet};
|
||||
use crate::{theme::Theme, widget::segmented_button::ItemStatusAppearance};
|
||||
use iced_core::{Background, BorderRadius};
|
||||
use iced_core::{renderer::BorderRadius, Background};
|
||||
use palette::{rgb::Rgb, Alpha};
|
||||
|
||||
#[derive(Default)]
|
||||
|
|
@ -141,7 +141,7 @@ impl StyleSheet for Theme {
|
|||
|
||||
mod horizontal {
|
||||
use crate::widget::segmented_button::{ItemAppearance, ItemStatusAppearance};
|
||||
use iced_core::{Background, BorderRadius};
|
||||
use iced_core::{renderer::BorderRadius, Background};
|
||||
use palette::{rgb::Rgb, Alpha};
|
||||
|
||||
pub fn selection_active(cosmic: &cosmic_theme::Theme<Alpha<Rgb, f32>>) -> ItemStatusAppearance {
|
||||
|
|
@ -222,7 +222,7 @@ pub fn hover(
|
|||
|
||||
mod vertical {
|
||||
use crate::widget::segmented_button::{ItemAppearance, ItemStatusAppearance};
|
||||
use iced_core::{Background, BorderRadius};
|
||||
use iced_core::{renderer::BorderRadius, Background};
|
||||
use palette::{rgb::Rgb, Alpha};
|
||||
|
||||
pub fn selection_active(cosmic: &cosmic_theme::Theme<Alpha<Rgb, f32>>) -> ItemStatusAppearance {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
use iced::widget::Container;
|
||||
use iced::Size;
|
||||
use iced_native::alignment;
|
||||
use iced_native::event::{self, Event};
|
||||
use iced_native::layout;
|
||||
use iced_native::mouse;
|
||||
use iced_native::overlay;
|
||||
use iced_native::renderer;
|
||||
use iced_native::widget::{Operation, Tree};
|
||||
use iced_native::{Clipboard, Element, Layout, Length, Padding, Point, Rectangle, Shell, Widget};
|
||||
use iced_core::alignment;
|
||||
use iced_core::event::{self, Event};
|
||||
use iced_core::layout;
|
||||
use iced_core::mouse;
|
||||
use iced_core::overlay;
|
||||
use iced_core::renderer;
|
||||
use iced_core::widget::{Operation, Tree};
|
||||
use iced_core::{Clipboard, Element, Layout, Length, Padding, Point, Rectangle, Shell, Widget};
|
||||
|
||||
pub use iced_style::container::{Appearance, StyleSheet};
|
||||
|
||||
|
|
@ -27,7 +27,7 @@ where
|
|||
#[allow(missing_debug_implementations)]
|
||||
pub struct AspectRatio<'a, Message, Renderer>
|
||||
where
|
||||
Renderer: iced_native::Renderer,
|
||||
Renderer: iced_core::Renderer,
|
||||
Renderer::Theme: StyleSheet,
|
||||
{
|
||||
ratio: f32,
|
||||
|
|
@ -36,7 +36,7 @@ where
|
|||
|
||||
impl<'a, Message, Renderer> AspectRatio<'a, Message, Renderer>
|
||||
where
|
||||
Renderer: iced_native::Renderer,
|
||||
Renderer: iced_core::Renderer,
|
||||
Renderer::Theme: StyleSheet,
|
||||
{
|
||||
fn constrain_limits(&self, size: Size) -> Size {
|
||||
|
|
@ -55,7 +55,7 @@ where
|
|||
|
||||
impl<'a, Message, Renderer> AspectRatio<'a, Message, Renderer>
|
||||
where
|
||||
Renderer: iced_native::Renderer,
|
||||
Renderer: iced_core::Renderer,
|
||||
Renderer::Theme: StyleSheet,
|
||||
{
|
||||
/// Creates an empty [`Container`].
|
||||
|
|
@ -92,14 +92,14 @@ where
|
|||
|
||||
/// Sets the maximum width of the [`Container`].
|
||||
#[must_use]
|
||||
pub fn max_width(mut self, max_width: u32) -> Self {
|
||||
pub fn max_width(mut self, max_width: f32) -> Self {
|
||||
self.container = self.container.max_width(max_width);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the maximum height of the [`Container`] in pixels.
|
||||
#[must_use]
|
||||
pub fn max_height(mut self, max_height: u32) -> Self {
|
||||
pub fn max_height(mut self, max_height: f32) -> Self {
|
||||
self.container = self.container.max_height(max_height);
|
||||
self
|
||||
}
|
||||
|
|
@ -142,14 +142,14 @@ where
|
|||
|
||||
impl<'a, Message, Renderer> Widget<Message, Renderer> for AspectRatio<'a, Message, Renderer>
|
||||
where
|
||||
Renderer: iced_native::Renderer,
|
||||
Renderer: iced_core::Renderer,
|
||||
Renderer::Theme: StyleSheet,
|
||||
{
|
||||
fn children(&self) -> Vec<Tree> {
|
||||
self.container.children()
|
||||
}
|
||||
|
||||
fn diff(&self, tree: &mut Tree) {
|
||||
fn diff(&mut self, tree: &mut Tree) {
|
||||
self.container.diff(tree);
|
||||
}
|
||||
|
||||
|
|
@ -169,8 +169,16 @@ where
|
|||
self.container.layout(renderer, &custom_limits)
|
||||
}
|
||||
|
||||
fn operate(&self, tree: &mut Tree, layout: Layout<'_>, operation: &mut dyn Operation<Message>) {
|
||||
self.container.operate(tree, layout, operation);
|
||||
fn operate(
|
||||
&self,
|
||||
tree: &mut Tree,
|
||||
layout: Layout<'_>,
|
||||
renderer: &Renderer,
|
||||
operation: &mut dyn iced_core::widget::Operation<
|
||||
iced_core::widget::OperationOutputWrapper<Message>,
|
||||
>,
|
||||
) {
|
||||
self.container.operate(tree, layout, renderer, operation);
|
||||
}
|
||||
|
||||
fn on_event(
|
||||
|
|
@ -228,7 +236,7 @@ where
|
|||
}
|
||||
|
||||
fn overlay<'b>(
|
||||
&'b self,
|
||||
&'b mut self,
|
||||
tree: &'b mut Tree,
|
||||
layout: Layout<'_>,
|
||||
renderer: &Renderer,
|
||||
|
|
@ -241,7 +249,7 @@ impl<'a, Message, Renderer> From<AspectRatio<'a, Message, Renderer>>
|
|||
for Element<'a, Message, Renderer>
|
||||
where
|
||||
Message: 'a,
|
||||
Renderer: 'a + iced_native::Renderer,
|
||||
Renderer: 'a + iced_core::Renderer,
|
||||
Renderer::Theme: StyleSheet,
|
||||
{
|
||||
fn from(column: AspectRatio<'a, Message, Renderer>) -> Element<'a, Message, Renderer> {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
use cosmic_theme::LayeredTheme;
|
||||
use iced::widget::Container;
|
||||
use iced_native::alignment;
|
||||
use iced_native::event::{self, Event};
|
||||
use iced_native::layout;
|
||||
use iced_native::mouse;
|
||||
use iced_native::overlay;
|
||||
use iced_native::renderer;
|
||||
use iced_native::widget::{Operation, Tree};
|
||||
use iced_native::{Clipboard, Element, Layout, Length, Padding, Point, Rectangle, Shell, Widget};
|
||||
use iced_core::alignment;
|
||||
use iced_core::event::{self, Event};
|
||||
use iced_core::layout;
|
||||
use iced_core::mouse;
|
||||
use iced_core::overlay;
|
||||
use iced_core::renderer;
|
||||
use iced_core::widget::{Operation, Tree};
|
||||
use iced_core::{Clipboard, Element, Layout, Length, Padding, Point, Rectangle, Shell, Widget};
|
||||
pub use iced_style::container::{Appearance, StyleSheet};
|
||||
|
||||
pub fn container<'a, Message: 'static, T>(
|
||||
|
|
@ -25,7 +25,7 @@ where
|
|||
#[allow(missing_debug_implementations)]
|
||||
pub struct LayerContainer<'a, Message, Renderer>
|
||||
where
|
||||
Renderer: iced_native::Renderer,
|
||||
Renderer: iced_core::Renderer,
|
||||
Renderer::Theme: StyleSheet + Clone + cosmic_theme::LayeredTheme,
|
||||
{
|
||||
layer: Option<cosmic_theme::Layer>,
|
||||
|
|
@ -34,7 +34,7 @@ where
|
|||
|
||||
impl<'a, Message, Renderer> LayerContainer<'a, Message, Renderer>
|
||||
where
|
||||
Renderer: iced_native::Renderer,
|
||||
Renderer: iced_core::Renderer,
|
||||
Renderer::Theme: StyleSheet + Clone + cosmic_theme::LayeredTheme,
|
||||
<Renderer::Theme as StyleSheet>::Style: std::convert::From<crate::theme::Container>,
|
||||
{
|
||||
|
|
@ -83,14 +83,14 @@ where
|
|||
|
||||
/// Sets the maximum width of the [`LayerContainer`].
|
||||
#[must_use]
|
||||
pub fn max_width(mut self, max_width: u32) -> Self {
|
||||
pub fn max_width(mut self, max_width: f32) -> Self {
|
||||
self.container = self.container.max_width(max_width);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the maximum height of the [`LayerContainer`] in pixels.
|
||||
#[must_use]
|
||||
pub fn max_height(mut self, max_height: u32) -> Self {
|
||||
pub fn max_height(mut self, max_height: f32) -> Self {
|
||||
self.container = self.container.max_height(max_height);
|
||||
self
|
||||
}
|
||||
|
|
@ -133,14 +133,14 @@ where
|
|||
|
||||
impl<'a, Message, Renderer> Widget<Message, Renderer> for LayerContainer<'a, Message, Renderer>
|
||||
where
|
||||
Renderer: iced_native::Renderer,
|
||||
Renderer: iced_core::Renderer,
|
||||
Renderer::Theme: StyleSheet + Clone + cosmic_theme::LayeredTheme,
|
||||
{
|
||||
fn children(&self) -> Vec<Tree> {
|
||||
self.container.children()
|
||||
}
|
||||
|
||||
fn diff(&self, tree: &mut Tree) {
|
||||
fn diff(&mut self, tree: &mut Tree) {
|
||||
self.container.diff(tree);
|
||||
}
|
||||
|
||||
|
|
@ -156,8 +156,16 @@ where
|
|||
self.container.layout(renderer, limits)
|
||||
}
|
||||
|
||||
fn operate(&self, tree: &mut Tree, layout: Layout<'_>, operation: &mut dyn Operation<Message>) {
|
||||
self.container.operate(tree, layout, operation);
|
||||
fn operate(
|
||||
&self,
|
||||
tree: &mut Tree,
|
||||
layout: Layout<'_>,
|
||||
renderer: &Renderer,
|
||||
operation: &mut dyn iced_core::widget::Operation<
|
||||
iced_core::widget::OperationOutputWrapper<Message>,
|
||||
>,
|
||||
) {
|
||||
self.container.operate(tree, layout, renderer, operation);
|
||||
}
|
||||
|
||||
fn on_event(
|
||||
|
|
@ -222,7 +230,7 @@ where
|
|||
}
|
||||
|
||||
fn overlay<'b>(
|
||||
&'b self,
|
||||
&'b mut self,
|
||||
tree: &'b mut Tree,
|
||||
layout: Layout<'_>,
|
||||
renderer: &Renderer,
|
||||
|
|
@ -235,7 +243,7 @@ impl<'a, Message, Renderer> From<LayerContainer<'a, Message, Renderer>>
|
|||
for Element<'a, Message, Renderer>
|
||||
where
|
||||
Message: 'a,
|
||||
Renderer: 'a + iced_native::Renderer,
|
||||
Renderer: 'a + iced_core::Renderer,
|
||||
Renderer::Theme: StyleSheet + Clone + cosmic_theme::LayeredTheme,
|
||||
{
|
||||
fn from(column: LayerContainer<'a, Message, Renderer>) -> Element<'a, Message, Renderer> {
|
||||
|
|
|
|||
|
|
@ -74,12 +74,12 @@ impl<'a, Message: Clone + 'static> HeaderBar<'a, Message> {
|
|||
});
|
||||
|
||||
let mut widget = widget::row(packed)
|
||||
.height(Length::Units(50))
|
||||
.height(Length::Fixed(50.0))
|
||||
.padding(8)
|
||||
.spacing(8)
|
||||
.apply(widget::container)
|
||||
.center_y()
|
||||
.apply(widget::mouse_listener);
|
||||
.apply(widget::mouse_area);
|
||||
|
||||
if let Some(message) = self.on_drag.clone() {
|
||||
widget = widget.on_press(message);
|
||||
|
|
|
|||
|
|
@ -90,7 +90,13 @@ impl<'a> IconSource<'a> {
|
|||
}
|
||||
|
||||
/// Get a handle to a raster image from memory.
|
||||
pub fn raster_from_memory(bytes: impl Into<Cow<'static, [u8]>>) -> Self {
|
||||
pub fn raster_from_memory(
|
||||
bytes: impl Into<Cow<'static, [u8]>>
|
||||
+ std::convert::AsRef<[u8]>
|
||||
+ std::marker::Send
|
||||
+ std::marker::Sync
|
||||
+ 'static,
|
||||
) -> Self {
|
||||
IconSource::Handle(Handle::Image(image::Handle::from_memory(bytes)))
|
||||
}
|
||||
|
||||
|
|
@ -98,7 +104,11 @@ impl<'a> IconSource<'a> {
|
|||
pub fn raster_from_pixels(
|
||||
width: u32,
|
||||
height: u32,
|
||||
pixels: impl Into<Cow<'static, [u8]>>,
|
||||
pixels: impl Into<Cow<'static, [u8]>>
|
||||
+ std::convert::AsRef<[u8]>
|
||||
+ std::marker::Send
|
||||
+ std::marker::Sync
|
||||
+ 'static,
|
||||
) -> Self {
|
||||
IconSource::Handle(Handle::Image(image::Handle::from_pixels(
|
||||
width, height, pixels,
|
||||
|
|
@ -165,7 +175,7 @@ impl From<svg::Handle> for IconSource<'static> {
|
|||
}
|
||||
|
||||
/// A lazily-generated icon.
|
||||
#[derive(Hash, Setters)]
|
||||
#[derive(Setters)]
|
||||
pub struct Icon<'a> {
|
||||
#[setters(skip)]
|
||||
source: IconSource<'a>,
|
||||
|
|
@ -181,6 +191,18 @@ pub struct Icon<'a> {
|
|||
force_svg: bool,
|
||||
}
|
||||
|
||||
// TODO what to do here
|
||||
impl Hash for Icon<'_> {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
self.source.hash(state);
|
||||
self.theme.hash(state);
|
||||
self.style.hash(state);
|
||||
self.size.hash(state);
|
||||
self.content_fit.hash(state);
|
||||
self.force_svg.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
/// A lazily-generated icon.
|
||||
#[must_use]
|
||||
pub fn icon<'a>(source: impl Into<IconSource<'a>>, size: u16) -> Icon<'a> {
|
||||
|
|
@ -199,8 +221,8 @@ pub fn icon<'a>(source: impl Into<IconSource<'a>>, size: u16) -> Icon<'a> {
|
|||
impl<'a> Icon<'a> {
|
||||
fn raster_element<Message: 'static>(&self, handle: image::Handle) -> Element<'static, Message> {
|
||||
Image::new(handle)
|
||||
.width(self.width.unwrap_or(Length::Units(self.size)))
|
||||
.height(self.height.unwrap_or(Length::Units(self.size)))
|
||||
.width(self.width.unwrap_or(Length::Fixed(self.size as f32)))
|
||||
.height(self.height.unwrap_or(Length::Fixed(self.size as f32)))
|
||||
.content_fit(self.content_fit)
|
||||
.into()
|
||||
}
|
||||
|
|
@ -208,8 +230,8 @@ impl<'a> Icon<'a> {
|
|||
fn svg_element<Message: 'static>(&self, handle: svg::Handle) -> Element<'static, Message> {
|
||||
svg::Svg::<Renderer>::new(handle)
|
||||
.style(self.style.clone())
|
||||
.width(self.width.unwrap_or(Length::Units(self.size)))
|
||||
.height(self.height.unwrap_or(Length::Units(self.size)))
|
||||
.width(self.width.unwrap_or(Length::Fixed(self.size as f32)))
|
||||
.height(self.height.unwrap_or(Length::Fixed(self.size as f32)))
|
||||
.content_fit(self.content_fit)
|
||||
.into()
|
||||
}
|
||||
|
|
@ -228,7 +250,7 @@ impl<'a> Icon<'a> {
|
|||
let mut source = IconSource::Name(Cow::Borrowed(""));
|
||||
std::mem::swap(&mut source, &mut self.source);
|
||||
|
||||
iced_lazy::lazy(hash, move || -> Element<Message> {
|
||||
iced::widget::lazy(hash, move |_| -> Element<Message> {
|
||||
match source.load(self.size, self.theme.as_deref(), self.force_svg) {
|
||||
Handle::Svg(handle) => self.svg_element(handle),
|
||||
Handle::Image(handle) => self.raster_element(handle),
|
||||
|
|
|
|||
|
|
@ -4,14 +4,14 @@ use iced::futures::channel::mpsc::UnboundedSender;
|
|||
use iced::widget::Container;
|
||||
pub use subscription::*;
|
||||
|
||||
use iced_native::alignment;
|
||||
use iced_native::event::{self, Event};
|
||||
use iced_native::layout;
|
||||
use iced_native::mouse;
|
||||
use iced_native::overlay;
|
||||
use iced_native::renderer;
|
||||
use iced_native::widget::{Operation, Tree};
|
||||
use iced_native::{Clipboard, Element, Layout, Length, Padding, Point, Rectangle, Shell, Widget};
|
||||
use iced_core::alignment;
|
||||
use iced_core::event::{self, Event};
|
||||
use iced_core::layout;
|
||||
use iced_core::mouse;
|
||||
use iced_core::overlay;
|
||||
use iced_core::renderer;
|
||||
use iced_core::widget::{Operation, Tree};
|
||||
use iced_core::{Clipboard, Element, Layout, Length, Padding, Point, Rectangle, Shell, Widget};
|
||||
use std::{fmt::Debug, hash::Hash};
|
||||
|
||||
pub use iced_style::container::{Appearance, StyleSheet};
|
||||
|
|
@ -44,7 +44,7 @@ where
|
|||
#[allow(missing_debug_implementations)]
|
||||
pub struct RectangleTrackingContainer<'a, Message, Renderer, I>
|
||||
where
|
||||
Renderer: iced_native::Renderer,
|
||||
Renderer: iced_core::Renderer,
|
||||
Renderer::Theme: StyleSheet,
|
||||
{
|
||||
tx: UnboundedSender<(I, Rectangle)>,
|
||||
|
|
@ -54,7 +54,7 @@ where
|
|||
|
||||
impl<'a, Message, Renderer, I> RectangleTrackingContainer<'a, Message, Renderer, I>
|
||||
where
|
||||
Renderer: iced_native::Renderer,
|
||||
Renderer: iced_core::Renderer,
|
||||
Renderer::Theme: StyleSheet,
|
||||
I: 'a + Hash + Copy + Send + Sync + Debug,
|
||||
{
|
||||
|
|
@ -93,14 +93,14 @@ where
|
|||
|
||||
/// Sets the maximum width of the [`Container`].
|
||||
#[must_use]
|
||||
pub fn max_width(mut self, max_width: u32) -> Self {
|
||||
pub fn max_width(mut self, max_width: f32) -> Self {
|
||||
self.container = self.container.max_width(max_width);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the maximum height of the [`Container`] in pixels.
|
||||
#[must_use]
|
||||
pub fn max_height(mut self, max_height: u32) -> Self {
|
||||
pub fn max_height(mut self, max_height: f32) -> Self {
|
||||
self.container = self.container.max_height(max_height);
|
||||
self
|
||||
}
|
||||
|
|
@ -144,7 +144,7 @@ where
|
|||
impl<'a, Message, Renderer, I> Widget<Message, Renderer>
|
||||
for RectangleTrackingContainer<'a, Message, Renderer, I>
|
||||
where
|
||||
Renderer: iced_native::Renderer,
|
||||
Renderer: iced_core::Renderer,
|
||||
Renderer::Theme: StyleSheet,
|
||||
I: 'a + Hash + Copy + Send + Sync + Debug,
|
||||
{
|
||||
|
|
@ -152,7 +152,7 @@ where
|
|||
self.container.children()
|
||||
}
|
||||
|
||||
fn diff(&self, tree: &mut Tree) {
|
||||
fn diff(&mut self, tree: &mut Tree) {
|
||||
self.container.diff(tree);
|
||||
}
|
||||
|
||||
|
|
@ -168,8 +168,16 @@ where
|
|||
self.container.layout(renderer, limits)
|
||||
}
|
||||
|
||||
fn operate(&self, tree: &mut Tree, layout: Layout<'_>, operation: &mut dyn Operation<Message>) {
|
||||
self.container.operate(tree, layout, operation);
|
||||
fn operate(
|
||||
&self,
|
||||
tree: &mut Tree,
|
||||
layout: Layout<'_>,
|
||||
renderer: &Renderer,
|
||||
operation: &mut dyn iced_core::widget::Operation<
|
||||
iced_core::widget::OperationOutputWrapper<Message>,
|
||||
>,
|
||||
) {
|
||||
self.container.operate(tree, layout, renderer, operation);
|
||||
}
|
||||
|
||||
fn on_event(
|
||||
|
|
@ -229,7 +237,7 @@ where
|
|||
}
|
||||
|
||||
fn overlay<'b>(
|
||||
&'b self,
|
||||
&'b mut self,
|
||||
tree: &'b mut Tree,
|
||||
layout: Layout<'_>,
|
||||
renderer: &Renderer,
|
||||
|
|
@ -242,7 +250,7 @@ impl<'a, Message, Renderer, I> From<RectangleTrackingContainer<'a, Message, Rend
|
|||
for Element<'a, Message, Renderer>
|
||||
where
|
||||
Message: 'a,
|
||||
Renderer: 'a + iced_native::Renderer,
|
||||
Renderer: 'a + iced_core::Renderer,
|
||||
Renderer::Theme: StyleSheet,
|
||||
I: 'a + Hash + Copy + Send + Sync + Debug,
|
||||
{
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ pub fn rectangle_tracker_subscription<
|
|||
R: 'static + Hash + Copy + Send + Sync + Debug + Eq,
|
||||
>(
|
||||
id: I,
|
||||
) -> iced::Subscription<(I, RectangleUpdate<R>)> {
|
||||
) -> iced::Subscription<Option<(I, RectangleUpdate<R>)>> {
|
||||
subscription::unfold(id, State::Ready, move |state| start_listening(id, state))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,6 @@ pub fn scrollable<'a, Message>(
|
|||
element: impl Into<Element<'a, Message>>,
|
||||
) -> widget::Scrollable<'a, Message, Renderer> {
|
||||
widget::scrollable(element)
|
||||
.scrollbar_width(8)
|
||||
.scroller_width(8)
|
||||
// .scrollbar_width(8) TODO add these back
|
||||
// .scroller_width(8)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ use apply::Apply;
|
|||
|
||||
/// A search field for COSMIC applications.
|
||||
pub fn field<Message: 'static + Clone>(
|
||||
id: iced::widget::text_input::Id,
|
||||
id: iced_core::id::Id,
|
||||
phrase: &str,
|
||||
on_change: fn(String) -> Message,
|
||||
on_clear: Message,
|
||||
|
|
@ -29,7 +29,7 @@ pub fn field<Message: 'static + Clone>(
|
|||
/// A search field for COSMIC applications.
|
||||
#[must_use]
|
||||
pub struct Field<'a, Message: 'static + Clone> {
|
||||
id: iced::widget::text_input::Id,
|
||||
id: iced_core::id::Id,
|
||||
phrase: &'a str,
|
||||
on_change: fn(String) -> Message,
|
||||
on_clear: Message,
|
||||
|
|
@ -38,7 +38,8 @@ pub struct Field<'a, Message: 'static + Clone> {
|
|||
|
||||
impl<'a, Message: 'static + Clone> Field<'a, Message> {
|
||||
pub fn into_element(mut self) -> crate::Element<'a, Message> {
|
||||
let mut input = iced::widget::text_input("", self.phrase, self.on_change)
|
||||
let mut input = iced::widget::text_input("", self.phrase)
|
||||
.on_input(self.on_change)
|
||||
.style(crate::theme::TextInput::Search)
|
||||
.width(Length::Fill)
|
||||
.id(self.id);
|
||||
|
|
@ -52,8 +53,8 @@ impl<'a, Message: 'static + Clone> Field<'a, Message> {
|
|||
input,
|
||||
clear_button().on_press(self.on_clear)
|
||||
)
|
||||
.width(Length::Units(300))
|
||||
.height(Length::Units(38))
|
||||
.width(Length::Fixed(300.0))
|
||||
.height(Length::Fixed(38.0))
|
||||
.padding([0, 16])
|
||||
.spacing(8)
|
||||
.align_items(iced::Alignment::Center)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use crate::iced;
|
|||
|
||||
/// A model for managing the state of a search widget.
|
||||
pub struct Model {
|
||||
pub input_id: iced::widget::text_input::Id,
|
||||
pub input_id: iced_core::id::Id,
|
||||
pub phrase: String,
|
||||
pub state: State,
|
||||
}
|
||||
|
|
@ -29,7 +29,7 @@ impl Model {
|
|||
impl Default for Model {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
input_id: iced::widget::text_input::Id::unique(),
|
||||
input_id: iced_core::id::Id::unique(),
|
||||
phrase: String::with_capacity(32),
|
||||
state: State::Inactive,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use super::style::StyleSheet;
|
|||
use super::widget::{SegmentedButton, SegmentedVariant};
|
||||
|
||||
use iced::{Length, Rectangle, Size};
|
||||
use iced_native::layout;
|
||||
use iced_core::layout;
|
||||
|
||||
/// Horizontal [`SegmentedButton`].
|
||||
pub type HorizontalSegmentedButton<'a, SelectionMode, Message, Renderer> =
|
||||
|
|
@ -25,10 +25,10 @@ pub fn horizontal<SelectionMode: Default, Message, Renderer>(
|
|||
model: &Model<SelectionMode>,
|
||||
) -> SegmentedButton<Horizontal, SelectionMode, Message, Renderer>
|
||||
where
|
||||
Renderer: iced_native::Renderer
|
||||
+ iced_native::text::Renderer
|
||||
+ iced_native::image::Renderer
|
||||
+ iced_native::svg::Renderer,
|
||||
Renderer: iced_core::Renderer
|
||||
+ iced_core::text::Renderer
|
||||
+ iced_core::image::Renderer
|
||||
+ iced_core::svg::Renderer,
|
||||
Renderer::Theme: StyleSheet,
|
||||
Model<SelectionMode>: Selectable,
|
||||
{
|
||||
|
|
@ -38,10 +38,10 @@ where
|
|||
impl<'a, SelectionMode, Message, Renderer> SegmentedVariant
|
||||
for SegmentedButton<'a, Horizontal, SelectionMode, Message, Renderer>
|
||||
where
|
||||
Renderer: iced_native::Renderer
|
||||
+ iced_native::text::Renderer
|
||||
+ iced_native::image::Renderer
|
||||
+ iced_native::svg::Renderer,
|
||||
Renderer: iced_core::Renderer
|
||||
+ iced_core::text::Renderer
|
||||
+ iced_core::image::Renderer
|
||||
+ iced_core::svg::Renderer,
|
||||
Renderer::Theme: StyleSheet,
|
||||
Model<SelectionMode>: Selectable,
|
||||
SelectionMode: Default,
|
||||
|
|
@ -49,8 +49,8 @@ where
|
|||
type Renderer = Renderer;
|
||||
|
||||
fn variant_appearance(
|
||||
theme: &<Self::Renderer as iced_native::Renderer>::Theme,
|
||||
style: &<<Self::Renderer as iced_native::Renderer>::Theme as StyleSheet>::Style,
|
||||
theme: &<Self::Renderer as iced_core::Renderer>::Theme,
|
||||
style: &<<Self::Renderer as iced_core::Renderer>::Theme as StyleSheet>::Style,
|
||||
) -> super::Appearance {
|
||||
theme.horizontal(style)
|
||||
}
|
||||
|
|
@ -85,7 +85,7 @@ where
|
|||
}
|
||||
|
||||
let size = limits
|
||||
.height(Length::Units(height as u16))
|
||||
.height(Length::Fixed(height))
|
||||
.resolve(Size::new(width, height));
|
||||
|
||||
layout::Node::new(size)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright 2022 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use iced_core::{Background, BorderRadius, Color};
|
||||
use iced_core::{renderer::BorderRadius, Background, Color};
|
||||
|
||||
/// Appearance of the segmented button.
|
||||
#[derive(Default, Clone, Copy)]
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use super::style::StyleSheet;
|
|||
use super::widget::{SegmentedButton, SegmentedVariant};
|
||||
|
||||
use iced::{Length, Rectangle, Size};
|
||||
use iced_native::layout;
|
||||
use iced_core::layout;
|
||||
|
||||
/// A type marker defining the vertical variant of a [`SegmentedButton`].
|
||||
pub struct Vertical;
|
||||
|
|
@ -25,10 +25,10 @@ pub fn vertical<SelectionMode, Message, Renderer>(
|
|||
model: &Model<SelectionMode>,
|
||||
) -> SegmentedButton<Vertical, SelectionMode, Message, Renderer>
|
||||
where
|
||||
Renderer: iced_native::Renderer
|
||||
+ iced_native::text::Renderer
|
||||
+ iced_native::image::Renderer
|
||||
+ iced_native::svg::Renderer,
|
||||
Renderer: iced_core::Renderer
|
||||
+ iced_core::text::Renderer
|
||||
+ iced_core::image::Renderer
|
||||
+ iced_core::svg::Renderer,
|
||||
Renderer::Theme: StyleSheet,
|
||||
Model<SelectionMode>: Selectable,
|
||||
SelectionMode: Default,
|
||||
|
|
@ -39,10 +39,10 @@ where
|
|||
impl<'a, SelectionMode, Message, Renderer> SegmentedVariant
|
||||
for SegmentedButton<'a, Vertical, SelectionMode, Message, Renderer>
|
||||
where
|
||||
Renderer: iced_native::Renderer
|
||||
+ iced_native::text::Renderer
|
||||
+ iced_native::image::Renderer
|
||||
+ iced_native::svg::Renderer,
|
||||
Renderer: iced_core::Renderer
|
||||
+ iced_core::text::Renderer
|
||||
+ iced_core::image::Renderer
|
||||
+ iced_core::svg::Renderer,
|
||||
Renderer::Theme: StyleSheet,
|
||||
Model<SelectionMode>: Selectable,
|
||||
SelectionMode: Default,
|
||||
|
|
@ -50,8 +50,8 @@ where
|
|||
type Renderer = Renderer;
|
||||
|
||||
fn variant_appearance(
|
||||
theme: &<Self::Renderer as iced_native::Renderer>::Theme,
|
||||
style: &<<Self::Renderer as iced_native::Renderer>::Theme as StyleSheet>::Style,
|
||||
theme: &<Self::Renderer as iced_core::Renderer>::Theme,
|
||||
style: &<<Self::Renderer as iced_core::Renderer>::Theme as StyleSheet>::Style,
|
||||
) -> super::Appearance {
|
||||
theme.vertical(style)
|
||||
}
|
||||
|
|
@ -86,7 +86,7 @@ where
|
|||
}
|
||||
|
||||
let size = limits
|
||||
.height(Length::Units(height as u16))
|
||||
.height(Length::Fixed(height))
|
||||
.resolve(Size::new(width, height));
|
||||
|
||||
layout::Node::new(size)
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@ use iced::{
|
|||
alignment, event, keyboard, mouse, touch, Background, Color, Command, Element, Event, Length,
|
||||
Point, Rectangle, Size,
|
||||
};
|
||||
use iced_core::BorderRadius;
|
||||
use iced_native::widget::{self, operation, tree, Operation};
|
||||
use iced_native::{layout, renderer, widget::Tree, Clipboard, Layout, Shell, Widget};
|
||||
use iced_core::renderer::BorderRadius;
|
||||
use iced_core::widget::{self, operation, tree, Operation};
|
||||
use iced_core::{layout, renderer, widget::Tree, Clipboard, Layout, Shell, Widget};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
/// State that is maintained by each individual widget.
|
||||
|
|
@ -46,15 +46,15 @@ impl operation::Focusable for LocalState {
|
|||
|
||||
/// Isolates variant-specific behaviors from [`SegmentedButton`].
|
||||
pub trait SegmentedVariant {
|
||||
type Renderer: iced_native::Renderer;
|
||||
type Renderer: iced_core::Renderer;
|
||||
|
||||
/// Get the appearance for this variant of the widget.
|
||||
fn variant_appearance(
|
||||
theme: &<Self::Renderer as iced_native::Renderer>::Theme,
|
||||
style: &<<Self::Renderer as iced_native::Renderer>::Theme as StyleSheet>::Style,
|
||||
theme: &<Self::Renderer as iced_core::Renderer>::Theme,
|
||||
style: &<<Self::Renderer as iced_core::Renderer>::Theme as StyleSheet>::Style,
|
||||
) -> super::Appearance
|
||||
where
|
||||
<Self::Renderer as iced_native::Renderer>::Theme: StyleSheet;
|
||||
<Self::Renderer as iced_core::Renderer>::Theme: StyleSheet;
|
||||
|
||||
/// Calculates the bounds for the given button by its position.
|
||||
fn variant_button_bounds(&self, bounds: Rectangle, position: usize) -> Rectangle;
|
||||
|
|
@ -67,10 +67,10 @@ pub trait SegmentedVariant {
|
|||
#[derive(Setters)]
|
||||
pub struct SegmentedButton<'a, Variant, SelectionMode, Message, Renderer>
|
||||
where
|
||||
Renderer: iced_native::Renderer
|
||||
+ iced_native::text::Renderer
|
||||
+ iced_native::image::Renderer
|
||||
+ iced_native::svg::Renderer,
|
||||
Renderer: iced_core::Renderer
|
||||
+ iced_core::text::Renderer
|
||||
+ iced_core::image::Renderer
|
||||
+ iced_core::svg::Renderer,
|
||||
Renderer::Theme: StyleSheet,
|
||||
Model<SelectionMode>: Selectable,
|
||||
SelectionMode: Default,
|
||||
|
|
@ -91,13 +91,13 @@ where
|
|||
/// Spacing between icon and text in button.
|
||||
pub(super) button_spacing: u16,
|
||||
/// Desired font for active tabs.
|
||||
pub(super) font_active: Renderer::Font,
|
||||
pub(super) font_active: Option<Renderer::Font>,
|
||||
/// Desired font for hovered tabs.
|
||||
pub(super) font_hovered: Renderer::Font,
|
||||
pub(super) font_hovered: Option<Renderer::Font>,
|
||||
/// Desired font for inactive tabs.
|
||||
pub(super) font_inactive: Renderer::Font,
|
||||
pub(super) font_inactive: Option<Renderer::Font>,
|
||||
/// Size of the font.
|
||||
pub(super) font_size: u16,
|
||||
pub(super) font_size: f32,
|
||||
/// Size of icon
|
||||
pub(super) icon_size: u16,
|
||||
/// Desired width of the widget.
|
||||
|
|
@ -122,10 +122,10 @@ where
|
|||
impl<'a, Variant, SelectionMode, Message, Renderer>
|
||||
SegmentedButton<'a, Variant, SelectionMode, Message, Renderer>
|
||||
where
|
||||
Renderer: iced_native::Renderer
|
||||
+ iced_native::text::Renderer
|
||||
+ iced_native::image::Renderer
|
||||
+ iced_native::svg::Renderer,
|
||||
Renderer: iced_core::Renderer
|
||||
+ iced_core::text::Renderer
|
||||
+ iced_core::image::Renderer
|
||||
+ iced_core::svg::Renderer,
|
||||
Renderer::Theme: StyleSheet,
|
||||
Self: SegmentedVariant<Renderer = Renderer>,
|
||||
Model<SelectionMode>: Selectable,
|
||||
|
|
@ -141,10 +141,10 @@ where
|
|||
button_padding: [4, 4, 4, 4],
|
||||
button_height: 32,
|
||||
button_spacing: 4,
|
||||
font_active: Renderer::Font::default(),
|
||||
font_hovered: Renderer::Font::default(),
|
||||
font_inactive: Renderer::Font::default(),
|
||||
font_size: 17,
|
||||
font_active: None,
|
||||
font_hovered: None,
|
||||
font_inactive: None,
|
||||
font_size: 17.0,
|
||||
icon_size: 16,
|
||||
height: Length::Shrink,
|
||||
width: Length::Fill,
|
||||
|
|
@ -212,6 +212,7 @@ where
|
|||
pub(super) fn max_button_dimensions(&self, renderer: &Renderer, bounds: Size) -> (f32, f32) {
|
||||
let mut width = 0.0f32;
|
||||
let mut height = 0.0f32;
|
||||
let font = renderer.default_font();
|
||||
|
||||
for key in self.model.order.iter().copied() {
|
||||
let mut button_width = 0.0f32;
|
||||
|
|
@ -219,7 +220,7 @@ where
|
|||
|
||||
// Add text to measurement if text was given.
|
||||
if let Some(text) = self.model.text(key) {
|
||||
let (w, h) = renderer.measure(text, self.font_size, Default::default(), bounds);
|
||||
let (w, h) = renderer.measure(text, self.font_size, font, bounds);
|
||||
|
||||
button_width = w;
|
||||
button_height = h;
|
||||
|
|
@ -253,10 +254,10 @@ where
|
|||
impl<'a, Variant, SelectionMode, Message, Renderer> Widget<Message, Renderer>
|
||||
for SegmentedButton<'a, Variant, SelectionMode, Message, Renderer>
|
||||
where
|
||||
Renderer: iced_native::Renderer
|
||||
+ iced_native::text::Renderer
|
||||
+ iced_native::image::Renderer
|
||||
+ iced_native::svg::Renderer,
|
||||
Renderer: iced_core::Renderer
|
||||
+ iced_core::text::Renderer
|
||||
+ iced_core::image::Renderer
|
||||
+ iced_core::svg::Renderer,
|
||||
Renderer::Theme: StyleSheet,
|
||||
Self: SegmentedVariant<Renderer = Renderer>,
|
||||
Model<SelectionMode>: Selectable,
|
||||
|
|
@ -379,7 +380,10 @@ where
|
|||
&self,
|
||||
tree: &mut Tree,
|
||||
_layout: Layout<'_>,
|
||||
operation: &mut dyn Operation<Message>,
|
||||
renderer: &Renderer,
|
||||
operation: &mut dyn iced_core::widget::Operation<
|
||||
iced_core::widget::OperationOutputWrapper<Message>,
|
||||
>,
|
||||
) {
|
||||
let state = tree.state.downcast_mut::<LocalState>();
|
||||
operation.focusable(state, self.id.as_ref().map(|id| &id.0));
|
||||
|
|
@ -392,7 +396,7 @@ where
|
|||
cursor_position: iced::Point,
|
||||
_viewport: &iced::Rectangle,
|
||||
_renderer: &Renderer,
|
||||
) -> iced_native::mouse::Interaction {
|
||||
) -> iced_core::mouse::Interaction {
|
||||
let bounds = layout.bounds();
|
||||
|
||||
if bounds.contains(cursor_position) {
|
||||
|
|
@ -402,15 +406,15 @@ where
|
|||
.contains(cursor_position)
|
||||
{
|
||||
return if self.model.items[key].enabled {
|
||||
iced_native::mouse::Interaction::Pointer
|
||||
iced_core::mouse::Interaction::Pointer
|
||||
} else {
|
||||
iced_native::mouse::Interaction::Idle
|
||||
iced_core::mouse::Interaction::Idle
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
iced_native::mouse::Interaction::Idle
|
||||
iced_core::mouse::Interaction::Idle
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
|
|
@ -418,7 +422,7 @@ where
|
|||
&self,
|
||||
tree: &Tree,
|
||||
renderer: &mut Renderer,
|
||||
theme: &<Renderer as iced_native::Renderer>::Theme,
|
||||
theme: &<Renderer as iced_core::Renderer>::Theme,
|
||||
_style: &renderer::Style,
|
||||
layout: Layout<'_>,
|
||||
_cursor_position: iced::Point,
|
||||
|
|
@ -458,6 +462,7 @@ where
|
|||
} else {
|
||||
(appearance.inactive, &self.font_inactive)
|
||||
};
|
||||
let font = font.unwrap_or_else(|| renderer.default_font());
|
||||
|
||||
let button_appearance = if nth == 0 {
|
||||
status_appearance.first
|
||||
|
|
@ -536,7 +541,7 @@ where
|
|||
unimplemented!()
|
||||
}
|
||||
icon::Handle::Svg(handle) => {
|
||||
iced_native::svg::Renderer::draw(renderer, handle, icon_color, icon_bounds);
|
||||
iced_core::svg::Renderer::draw(renderer, handle, icon_color, icon_bounds);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -550,7 +555,7 @@ where
|
|||
bounds.y = y;
|
||||
|
||||
// Draw the text in this button.
|
||||
renderer.fill_text(iced_native::text::Text {
|
||||
renderer.fill_text(iced_core::text::Text {
|
||||
content: text,
|
||||
size: f32::from(self.font_size),
|
||||
bounds,
|
||||
|
|
@ -575,7 +580,7 @@ where
|
|||
unimplemented!()
|
||||
}
|
||||
icon::Handle::Svg(handle) => {
|
||||
iced_native::svg::Renderer::draw(
|
||||
iced_core::svg::Renderer::draw(
|
||||
renderer,
|
||||
handle,
|
||||
Some(status_appearance.text_color),
|
||||
|
|
@ -588,11 +593,11 @@ where
|
|||
}
|
||||
|
||||
fn overlay<'b>(
|
||||
&'b self,
|
||||
&'b mut self,
|
||||
_tree: &'b mut Tree,
|
||||
_layout: iced_native::Layout<'_>,
|
||||
_layout: iced_core::Layout<'_>,
|
||||
_renderer: &Renderer,
|
||||
) -> Option<iced_native::overlay::Element<'b, Message, Renderer>> {
|
||||
) -> Option<iced_core::overlay::Element<'b, Message, Renderer>> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
@ -601,10 +606,10 @@ impl<'a, Variant, SelectionMode, Message, Renderer>
|
|||
From<SegmentedButton<'a, Variant, SelectionMode, Message, Renderer>>
|
||||
for Element<'a, Message, Renderer>
|
||||
where
|
||||
Renderer: iced_native::Renderer
|
||||
+ iced_native::text::Renderer
|
||||
+ iced_native::image::Renderer
|
||||
+ iced_native::svg::Renderer
|
||||
Renderer: iced_core::Renderer
|
||||
+ iced_core::text::Renderer
|
||||
+ iced_core::image::Renderer
|
||||
+ iced_core::svg::Renderer
|
||||
+ 'a,
|
||||
Renderer::Theme: StyleSheet,
|
||||
SegmentedButton<'a, Variant, SelectionMode, Message, Renderer>:
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ where
|
|||
.button_padding([16, 0, 16, 0])
|
||||
.button_height(32)
|
||||
.style(crate::theme::SegmentedButton::Selection)
|
||||
.font_active(crate::font::FONT_SEMIBOLD)
|
||||
.font_active(Some(crate::font::FONT_SEMIBOLD))
|
||||
}
|
||||
|
||||
/// A selection of multiple choices appearing as a conjoined button.
|
||||
|
|
@ -45,5 +45,5 @@ where
|
|||
.button_padding([16, 0, 16, 0])
|
||||
.button_height(32)
|
||||
.style(crate::theme::SegmentedButton::Selection)
|
||||
.font_active(crate::font::FONT_SEMIBOLD)
|
||||
.font_active(Some(crate::font::FONT_SEMIBOLD))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,13 +76,13 @@ impl<'a, Message: 'static> SpinButton<'a, Message> {
|
|||
.on_press(model::Message::Increment),
|
||||
]
|
||||
.width(Length::Fill)
|
||||
.height(Length::Units(32))
|
||||
.height(Length::Fixed(32.0))
|
||||
.align_items(Alignment::Center),
|
||||
)
|
||||
.padding([4, 4])
|
||||
.align_y(Vertical::Center)
|
||||
.width(Length::Units(95))
|
||||
.height(Length::Units(32))
|
||||
.width(Length::Fixed(95.0))
|
||||
.height(Length::Fixed(32.0))
|
||||
.style(theme::Container::custom(container_style))
|
||||
.apply(Element::from)
|
||||
.map(on_change)
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ pub use iced::widget::Text;
|
|||
/// [`Text`]: widget::Text
|
||||
pub fn text<'a, Renderer>(text: impl Into<Cow<'a, str>>) -> Text<'a, Renderer>
|
||||
where
|
||||
Renderer: iced_native::text::Renderer,
|
||||
Renderer: iced_core::text::Renderer,
|
||||
Renderer::Theme: iced::widget::text::StyleSheet,
|
||||
{
|
||||
Text::new(text)
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ pub fn toggler<'a, Message>(
|
|||
is_checked: bool,
|
||||
f: impl Fn(bool) -> Message + 'a,
|
||||
) -> widget::Toggler<'a, Message, Renderer> {
|
||||
widget::Toggler::new(is_checked, label, f)
|
||||
widget::Toggler::new(label, is_checked, f)
|
||||
.size(24)
|
||||
.spacing(12)
|
||||
.width(Length::Shrink)
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ where
|
|||
.button_padding([16, 0, 16, 0])
|
||||
.button_height(48)
|
||||
.style(crate::theme::SegmentedButton::ViewSwitcher)
|
||||
.font_active(crate::font::FONT_SEMIBOLD)
|
||||
.font_active(Some(crate::font::FONT_SEMIBOLD))
|
||||
}
|
||||
|
||||
/// A collection of tabs for developing a tabbed interface.
|
||||
|
|
@ -45,5 +45,5 @@ where
|
|||
.button_padding([16, 0, 16, 0])
|
||||
.button_height(48)
|
||||
.style(crate::theme::SegmentedButton::ViewSwitcher)
|
||||
.font_active(crate::font::FONT_SEMIBOLD)
|
||||
.font_active(Some(crate::font::FONT_SEMIBOLD))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue