From 7421aa3dc4674849e9ac19f45e1330364cf03a90 Mon Sep 17 00:00:00 2001 From: genusistimelord Date: Mon, 22 Jan 2024 12:25:28 -0500 Subject: [PATCH] update everything else but Menu. Though Grid is still not rendering 2 of the widgets correcty? --- Cargo.toml | 64 +++++------ .../cupertino/cupertino_button/src/main.rs | 10 +- examples/modal_component/src/main.rs | 3 +- examples/sliderbar/Cargo.toml | 4 +- examples/split_scroller/src/main.rs | 18 +-- src/native/context_menu.rs | 52 +++++---- src/native/cupertino/cupertino_button.rs | 41 ++++--- src/native/cupertino/cupertino_spinner.rs | 10 +- src/native/cupertino/cupertino_switch.rs | 11 +- src/native/helpers.rs | 49 +++++--- src/native/menu/menu_bar.rs | 2 +- src/native/menu/menu_tree.rs | 2 +- src/native/mod.rs | 36 +++--- src/native/overlay/context_menu.rs | 44 ++++--- src/native/overlay/time_picker.rs | 108 ++++++++++-------- src/native/quad.rs | 30 +++-- src/native/segmented_button.rs | 64 ++++++----- src/native/selection_list.rs | 58 ++++++---- src/native/selection_list/list.rs | 34 +++--- src/native/slide_bar.rs | 29 +++-- src/native/spinner.rs | 51 +++------ src/native/split.rs | 92 ++++++++------- src/native/tab_bar.rs | 92 +++++++++------ src/native/tabs.rs | 39 ++++--- src/native/time_picker.rs | 22 ++-- src/native/wrap.rs | 60 ++++++---- src/style/tab_bar.rs | 4 +- 27 files changed, 574 insertions(+), 455 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5ae2c53d..678e3e4f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,20 +48,19 @@ default = [ "floating_element", "grid", "modal", - #"tab_bar", - #"tabs", - #"time_picker", - #"slide_bar", - #"wrap", - #"selection_list", - #"split", + "tab_bar", + "tabs", + "time_picker", + "slide_bar", + "wrap", + "selection_list", + "split", + "quad", + "context_menu", + "spinner", + "cupertino", + "segmented_button", #"menu", - #"quad", - #"context_menu", - #"spinner", - #"cupertino", - #"segmented_button", - #"num-traits" ] [dependencies] @@ -78,12 +77,6 @@ git = "https://github.com/iced-rs/iced.git" #rev = "b474a2b7a763dcde6a377cb409001a7b5285ee8d" #version = "0.1.1" -#[dependencies.iced_renderer] -#git = "https://github.com/iced-rs/iced.git" -#rev = "751ea77c29f6eb3d00f45f0a04c833a1d03a425c" -#features = ["wgpu"] -#version = "0.1.1" - [profile.dev.package."*"] opt-level = 2 @@ -100,25 +93,22 @@ members = [ "examples/modal", "examples/modal_component", "examples/multiple_modals", - #"examples/cupertino/cupertino_button", - #"examples/cupertino/cupertino_spinner", - #"examples/cupertino/cupertino_switch", - - - - #"examples/tab_bar", - #"examples/tabs", - #"examples/time_picker", - #"examples/wrap", - #"examples/selection_list", - #"examples/split", - #"examples/split_scroller", + "examples/tab_bar", + "examples/tabs", + "examples/time_picker", + "examples/sliderbar", + "examples/wrap", + "examples/selection_list", + "examples/split", + "examples/split_scroller", + "examples/context_menu", + "examples/spinner", + "examples/cupertino/cupertino_button", + "examples/cupertino/cupertino_spinner", + "examples/cupertino/cupertino_switch", + "examples/WidgetIDReturn", + "examples/segmented_button", #"examples/menu", - #"examples/spinner", - #"examples/context_menu", - #"examples/WidgetIDReturn", - #"examples/segmented_button", - #"examples/sliderbar", ] [workspace.dependencies.iced] diff --git a/examples/cupertino/cupertino_button/src/main.rs b/examples/cupertino/cupertino_button/src/main.rs index 94a5a9c2..2539c44f 100644 --- a/examples/cupertino/cupertino_button/src/main.rs +++ b/examples/cupertino/cupertino_button/src/main.rs @@ -1,7 +1,7 @@ use iced::{ alignment, executor, font, widget::{column, container, text, Text}, - Application, Command, Element, Length, Renderer, Settings, Theme, + Application, Command, Element, Length, Settings, Theme, }; use iced_aw::native::cupertino::cupertino_button::CupertinoButton; @@ -69,7 +69,7 @@ impl Application for ButtonApp { } fn view(&self) -> Element { - let disabled: CupertinoButton = CupertinoButton::new() + let disabled = CupertinoButton::new() .on_pressed(None) .body(Text::new("Disabled") .size(24) @@ -78,7 +78,7 @@ impl Application for ButtonApp { .height(Length::Fixed(50.0)) ); - let disabled_filled: CupertinoButton = CupertinoButton::new() + let disabled_filled = CupertinoButton::new() .on_pressed(None) .is_filled(true) .body(Text::new("Disabled") @@ -88,7 +88,7 @@ impl Application for ButtonApp { .height(Length::Fixed(50.0)) ); - let enabled: CupertinoButton = CupertinoButton::new() + let enabled = CupertinoButton::new() .on_pressed(Some(Message::EnabledButtonClicked)) .body(Text::new("Enabled") .size(24) @@ -97,7 +97,7 @@ impl Application for ButtonApp { .height(Length::Fixed(50.0)) ); - let enabled_filled: CupertinoButton = CupertinoButton::new() + let enabled_filled = CupertinoButton::new() .on_pressed(Some(Message::EnabledFilledButtonClicked)) .is_filled(true) .body(Text::new("Enabled") diff --git a/examples/modal_component/src/main.rs b/examples/modal_component/src/main.rs index 5e74e3ff..dc7f25b8 100644 --- a/examples/modal_component/src/main.rs +++ b/examples/modal_component/src/main.rs @@ -103,8 +103,7 @@ impl Application for ModalExample { }, None => "None", } - ))) - .into(), + ))), ); let overlay = if state.show_modal { diff --git a/examples/sliderbar/Cargo.toml b/examples/sliderbar/Cargo.toml index 22276daa..bc6c8191 100644 --- a/examples/sliderbar/Cargo.toml +++ b/examples/sliderbar/Cargo.toml @@ -7,5 +7,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -iced_aw.workspace = true +iced_aw = { workspace = true, features = [ + "slide_bar", +] } iced.workspace = true diff --git a/examples/split_scroller/src/main.rs b/examples/split_scroller/src/main.rs index 919c34c2..49aac80f 100644 --- a/examples/split_scroller/src/main.rs +++ b/examples/split_scroller/src/main.rs @@ -213,7 +213,7 @@ mod demo { button, column, container, horizontal_space, progress_bar, radio, row, scrollable, slider, text, vertical_space, }; - use iced::{theme, Alignment, Color}; + use iced::{theme, Alignment, Border, Color}; use iced::{Command, Element, Length, Theme}; use once_cell::sync::Lazy; @@ -506,14 +506,18 @@ mod demo { fn hovered_horizontal(&self, style: &Self::Style, _is_mouse_over: bool) -> Scrollbar { Scrollbar { background: style.active(&theme::Scrollable::default()).background, - border_radius: 0.0.into(), - border_width: 0.0, - border_color: Default::default(), + border: Border { + color: Default::default(), + width: 0.0, + radius: 0.0.into(), + }, scroller: Scroller { color: Color::from_rgb8(250, 85, 134), - border_radius: 0.0.into(), - border_width: 0.0, - border_color: Default::default(), + border: Border { + color: Default::default(), + width: 0.0, + radius: 0.0.into(), + }, }, } } diff --git a/src/native/context_menu.rs b/src/native/context_menu.rs index 293c2d72..b91847c9 100644 --- a/src/native/context_menu.rs +++ b/src/native/context_menu.rs @@ -33,27 +33,32 @@ pub use crate::style::context_menu::StyleSheet; /// ); /// ``` #[allow(missing_debug_implementations)] -pub struct ContextMenu<'a, Overlay, Message, Renderer = crate::Renderer> -where - Overlay: Fn() -> Element<'a, Message, Renderer>, +pub struct ContextMenu< + 'a, + Overlay, + Message, + Theme = iced_widget::Theme, + Renderer = iced_widget::Renderer, +> where + Overlay: Fn() -> Element<'a, Message, Theme, Renderer>, Message: Clone, Renderer: core::Renderer, - Renderer::Theme: StyleSheet, + Theme: StyleSheet, { /// The underlying element. - underlay: Element<'a, Message, Renderer>, + underlay: Element<'a, Message, Theme, Renderer>, /// The content of [`ContextMenuOverlay`]. overlay: Overlay, /// The style of the [`ContextMenu`]. - style: ::Style, + style: ::Style, } -impl<'a, Overlay, Message, Renderer> ContextMenu<'a, Overlay, Message, Renderer> +impl<'a, Overlay, Message, Theme, Renderer> ContextMenu<'a, Overlay, Message, Theme, Renderer> where - Overlay: Fn() -> Element<'a, Message, Renderer>, + Overlay: Fn() -> Element<'a, Message, Theme, Renderer>, Message: Clone, Renderer: core::Renderer, - Renderer::Theme: StyleSheet, + Theme: StyleSheet, { /// Creates a new [`ContextMenu`] /// @@ -62,32 +67,31 @@ where /// `overlay`: The content of [`ContextMenuOverlay`] which will be displayed when `underlay` is clicked. pub fn new(underlay: U, overlay: Overlay) -> Self where - U: Into>, + U: Into>, { ContextMenu { underlay: underlay.into(), overlay, - style: ::Style::default(), + style: ::Style::default(), } } /// Sets the style of the [`ContextMenu`]. #[must_use] - pub fn style(mut self, style: ::Style) -> Self { + pub fn style(mut self, style: ::Style) -> Self { self.style = style; self } } -impl<'a, Content, Message, Renderer> Widget - for ContextMenu<'a, Content, Message, Renderer> +impl<'a, Content, Message, Theme, Renderer> Widget + for ContextMenu<'a, Content, Message, Theme, Renderer> where - Content: 'a + Fn() -> Element<'a, Message, Renderer>, + Content: 'a + Fn() -> Element<'a, Message, Theme, Renderer>, Message: 'a + Clone, Renderer: 'a + core::Renderer, - Renderer::Theme: StyleSheet, + Theme: StyleSheet, { - fn size(&self) -> core::Size { self.underlay.as_widget().size() } @@ -102,7 +106,7 @@ where &self, state: &Tree, renderer: &mut Renderer, - theme: &Renderer::Theme, + theme: &Theme, style: &renderer::Style, layout: Layout<'_>, cursor: Cursor, @@ -214,7 +218,7 @@ where state: &'b mut Tree, layout: Layout<'_>, renderer: &Renderer, - ) -> Option> { + ) -> Option> { let s: &mut State = state.state.downcast_mut(); if !s.show { @@ -235,15 +239,15 @@ where } } -impl<'a, Content, Message, Renderer> From> - for Element<'a, Message, Renderer> +impl<'a, Content, Message, Theme, Renderer> From> + for Element<'a, Message, Theme, Renderer> where - Content: 'a + Fn() -> Element<'a, Message, Renderer>, + Content: 'a + Fn() -> Element<'a, Message, Theme, Renderer>, Message: 'a + Clone, Renderer: 'a + core::Renderer, - Renderer::Theme: StyleSheet, + Theme: 'a + StyleSheet, { - fn from(modal: ContextMenu<'a, Content, Message, Renderer>) -> Self { + fn from(modal: ContextMenu<'a, Content, Message, Theme, Renderer>) -> Self { Element::new(modal) } } diff --git a/src/native/cupertino/cupertino_button.rs b/src/native/cupertino/cupertino_button.rs index a9edb82d..8e9405b0 100644 --- a/src/native/cupertino/cupertino_button.rs +++ b/src/native/cupertino/cupertino_button.rs @@ -1,6 +1,7 @@ use crate::graphics::SF_UI_ROUNDED; use crate::native::cupertino::cupertino_colors::{secondary_system_fill, system_blue}; +use iced_widget::core::{Border, Shadow}; use iced_widget::{ core::{ self, event, @@ -31,15 +32,15 @@ use iced_widget::{ * */ #[allow(missing_debug_implementations)] -pub struct CupertinoButton<'a, Message, Renderer> +pub struct CupertinoButton<'a, Message, Theme, Renderer> where Message: Clone, Renderer: core::Renderer, - Renderer::Theme: application::StyleSheet, + Theme: application::StyleSheet, { on_pressed: Option, is_filled: bool, - body: Element<'a, Message, Renderer>, + body: Element<'a, Message, Theme, Renderer>, /// `colour` is an option here because there is already logic to set the colour /// depending on if the button is enabled/disabled. But if the button causes a @@ -48,11 +49,11 @@ where colour: Option, } -impl<'a, Message, Renderer> Default for CupertinoButton<'a, Message, Renderer> +impl<'a, Message, Theme, Renderer> Default for CupertinoButton<'a, Message, Theme, Renderer> where Message: Clone, Renderer: core::Renderer + core::text::Renderer + 'a, - Renderer::Theme: application::StyleSheet + text::StyleSheet, + Theme: 'a + application::StyleSheet + text::StyleSheet, { fn default() -> Self { Self { @@ -64,11 +65,11 @@ where } } -impl<'a, Message, Renderer> CupertinoButton<'a, Message, Renderer> +impl<'a, Message, Theme, Renderer> CupertinoButton<'a, Message, Theme, Renderer> where Message: Clone, Renderer: core::Renderer + core::text::Renderer + 'a, - Renderer::Theme: application::StyleSheet + text::StyleSheet, + Theme: 'a + application::StyleSheet + text::StyleSheet, { /// Creates a new [`CupertinoButton`] widget. #[must_use] @@ -81,7 +82,7 @@ where pub fn body(mut self, body: T) -> Self where Message: Clone, - T: Into>, + T: Into>, { let as_text = body.into().font(SF_UI_ROUNDED); @@ -114,11 +115,12 @@ where const VERTICAL_PADDING: f32 = 14.0; // const HORIZONTAL_PADDING: f32 = 64.0; -impl<'a, Message, Renderer> Widget for CupertinoButton<'a, Message, Renderer> +impl<'a, Message, Theme, Renderer> Widget + for CupertinoButton<'a, Message, Theme, Renderer> where Message: Clone, Renderer: core::Renderer + core::text::Renderer, - Renderer::Theme: application::StyleSheet, + Theme: application::StyleSheet, { fn size(&self) -> Size { self.body.as_widget().size() @@ -143,7 +145,7 @@ where &self, state: &Tree, renderer: &mut Renderer, - theme: &Renderer::Theme, + theme: &Theme, style: &renderer::Style, layout: Layout<'_>, cursor: Cursor, @@ -173,9 +175,12 @@ where renderer.fill_quad( Quad { bounds: rectangle, - border_radius: [16.0, 16.0, 16.0, 16.0].into(), - border_width: 5.0, - border_color: Color::TRANSPARENT, + border: Border { + radius: (16.0).into(), + width: 5.0, + color: Color::TRANSPARENT, + }, + shadow: Shadow::default(), }, Background::Color(colour), ); @@ -250,14 +255,14 @@ where } } -impl<'a, Message, Renderer> From> - for Element<'a, Message, Renderer> +impl<'a, Message, Theme, Renderer> From> + for Element<'a, Message, Theme, Renderer> where Message: Clone + 'a, Renderer: core::Renderer + core::text::Renderer + 'a, - Renderer::Theme: application::StyleSheet, + Theme: 'a + application::StyleSheet, { - fn from(alert: CupertinoButton<'a, Message, Renderer>) -> Self { + fn from(alert: CupertinoButton<'a, Message, Theme, Renderer>) -> Self { Self::new(alert) } } diff --git a/src/native/cupertino/cupertino_spinner.rs b/src/native/cupertino/cupertino_spinner.rs index b2f2175f..9889eb43 100644 --- a/src/native/cupertino/cupertino_spinner.rs +++ b/src/native/cupertino/cupertino_spinner.rs @@ -90,12 +90,12 @@ impl CupertinoSpinner { } } -impl Widget> for CupertinoSpinner { +impl Widget for CupertinoSpinner { fn size(&self) -> Size { Size::new(self.width, self.height) } - fn layout(&self, _tree: &mut Tree, _renderer: &Renderer, limits: &Limits) -> Node { + fn layout(&self, _tree: &mut Tree, _renderer: &Renderer, limits: &Limits) -> Node { Node::new(limits.width(self.width).height(self.height).resolve( self.width, self.height, @@ -106,7 +106,7 @@ impl Widget> for CupertinoSpinner { fn draw( &self, state: &Tree, - renderer: &mut Renderer, + renderer: &mut Renderer, _theme: &Theme, _style: &renderer::Style, layout: Layout<'_>, @@ -181,7 +181,7 @@ impl Widget> for CupertinoSpinner { event: Event, _layout: Layout<'_>, _cursor: Cursor, - _renderer: &Renderer, + _renderer: &Renderer, _clipboard: &mut dyn Clipboard, shell: &mut Shell<'_, Message>, _viewport: &Rectangle, @@ -202,7 +202,7 @@ impl Widget> for CupertinoSpinner { } } -impl<'a, Message, Theme> From for Element<'a, Message, Renderer> { +impl<'a, Message, Theme> From for Element<'a, Message, Theme, Renderer> { fn from(spinner: CupertinoSpinner) -> Self { Self::new(spinner) } diff --git a/src/native/cupertino/cupertino_switch.rs b/src/native/cupertino/cupertino_switch.rs index f3cd0c7e..57d34e98 100644 --- a/src/native/cupertino/cupertino_switch.rs +++ b/src/native/cupertino/cupertino_switch.rs @@ -136,7 +136,7 @@ where } } -impl Widget> for CupertinoSwitch +impl Widget for CupertinoSwitch where Message: Clone, { @@ -144,14 +144,14 @@ where Size::new(Length::Shrink, Length::Shrink) } - fn layout(&self, _tree: &mut Tree, _renderer: &Renderer, limits: &Limits) -> Node { + fn layout(&self, _tree: &mut Tree, _renderer: &Renderer, limits: &Limits) -> Node { layout::atomic(limits, Length::Shrink, Length::Shrink) } fn draw( &self, state: &Tree, - renderer: &mut Renderer, + renderer: &mut Renderer, _theme: &Theme, _style: &renderer::Style, layout: Layout<'_>, @@ -301,7 +301,7 @@ where event: Event, layout: Layout<'_>, cursor: Cursor, - _renderer: &Renderer, + _renderer: &Renderer, _clipboard: &mut dyn Clipboard, shell: &mut Shell<'_, Message>, _viewport: &Rectangle, @@ -368,9 +368,10 @@ where } } -impl<'a, Message, Theme> From> for Element<'a, Message, Renderer> +impl<'a, Message, Theme> From> for Element<'a, Message, Theme, Renderer> where Message: Clone + 'a, + Theme: 'a, { fn from(switch: CupertinoSwitch) -> Self { Self::new(switch) diff --git a/src/native/helpers.rs b/src/native/helpers.rs index cf07c9e7..cb7b007f 100644 --- a/src/native/helpers.rs +++ b/src/native/helpers.rs @@ -196,6 +196,29 @@ where crate::DatePicker::new(show_picker, date, underlay, on_cancel, on_submit) } +#[cfg(feature = "time_picker")] +/// Shortcut helper to create a [`DatePicker`] Widget. +/// +/// [`DatePicker`]: crate::DatePicker +pub fn time_picker<'a, Message, Theme, U, F>( + show_picker: bool, + time: impl Into, + underlay: U, + on_cancel: Message, + on_submit: F, +) -> crate::TimePicker<'a, Message, Theme> +where + Message: 'a + Clone, + Theme: 'a + + crate::style::time_picker::StyleSheet + + iced_widget::button::StyleSheet + + iced_widget::text::StyleSheet, + U: Into>, + F: 'static + Fn(crate::core::time::Time) -> Message, +{ + crate::TimePicker::new(show_picker, time, underlay, on_cancel, on_submit) +} + #[cfg(feature = "floating_element")] /// Shortcut helper to create a [`FloatingElement`] Widget. /// @@ -245,9 +268,9 @@ where /// /// [`Wrap`]: crate::Wrap #[must_use] -pub fn wrap_horizontal( - children: Vec>, -) -> crate::Wrap +pub fn wrap_horizontal( + children: Vec>, +) -> crate::Wrap where Renderer: core::Renderer, { @@ -259,9 +282,9 @@ where /// /// [`Wrap`]: crate::Wrap #[must_use] -pub fn wrap_vertical( - children: Vec>, -) -> crate::Wrap +pub fn wrap_vertical( + children: Vec>, +) -> crate::Wrap where Renderer: core::Renderer, { @@ -319,19 +342,19 @@ where /// /// [`SelectionList`]: crate::SelectionList #[must_use] -pub fn selection_list_with<'a, T, Message, Renderer>( +pub fn selection_list_with<'a, T, Message, Theme, Renderer>( options: &'a [T], on_selected: impl Fn(usize, T) -> Message + 'static, text_size: f32, padding: f32, - style: ::Style, + style: ::Style, selected: Option, font: iced_widget::runtime::Font, -) -> crate::SelectionList<'a, T, Message, Renderer> +) -> crate::SelectionList<'a, T, Message, Theme, Renderer> where Message: 'a + Clone, Renderer: 'a + core::Renderer + core::text::Renderer, - Renderer::Theme: crate::style::selection_list::StyleSheet + Theme: 'a + crate::style::selection_list::StyleSheet + iced_widget::container::StyleSheet + iced_widget::scrollable::StyleSheet, T: Clone + Display + Eq + Hash, @@ -353,14 +376,14 @@ where /// /// [`SelectionList`]: crate::SelectionList #[must_use] -pub fn selection_list<'a, T, Message, Renderer>( +pub fn selection_list<'a, T, Message, Theme, Renderer>( options: &'a [T], on_selected: impl Fn(usize, T) -> Message + 'static, -) -> crate::SelectionList<'a, T, Message, Renderer> +) -> crate::SelectionList<'a, T, Message, Theme, Renderer> where Message: 'a + Clone, Renderer: 'a + core::Renderer + core::text::Renderer, - Renderer::Theme: crate::style::selection_list::StyleSheet + Theme: 'a + crate::style::selection_list::StyleSheet + iced_widget::container::StyleSheet + iced_widget::scrollable::StyleSheet, T: Clone + Display + Eq + Hash, diff --git a/src/native/menu/menu_bar.rs b/src/native/menu/menu_bar.rs index 0e4a19fb..838d5717 100644 --- a/src/native/menu/menu_bar.rs +++ b/src/native/menu/menu_bar.rs @@ -56,7 +56,7 @@ impl Default for MenuBarState { /// A `MenuBar` collects `MenuTree`s and handles /// all the layout, event processing and drawing #[allow(missing_debug_implementations)] -pub struct MenuBar<'a, Message, Renderer = crate::Renderer> +pub struct MenuBar<'a, Message, Renderer = iced_widget::Renderer> where Renderer: renderer::Renderer, Renderer::Theme: StyleSheet, diff --git a/src/native/menu/menu_tree.rs b/src/native/menu/menu_tree.rs index 21f8be3a..49904b02 100644 --- a/src/native/menu/menu_tree.rs +++ b/src/native/menu/menu_tree.rs @@ -10,7 +10,7 @@ use iced_widget::core::{renderer, Element}; /// but there's no need to explicitly distinguish them here, if a menu tree /// has children, it's a menu, otherwise it's an item #[allow(missing_debug_implementations)] -pub struct MenuTree<'a, Message, Renderer = crate::Renderer> { +pub struct MenuTree<'a, Message, Renderer = iced_widget::Renderer> { /// The menu tree will be flatten into a vector to build a linear widget tree, /// the `index` field is the index of the item in that vector pub(super) index: usize, diff --git a/src/native/mod.rs b/src/native/mod.rs index 1117eb4d..bbb4f57c 100644 --- a/src/native/mod.rs +++ b/src/native/mod.rs @@ -14,20 +14,20 @@ pub use common::InnerBounds; pub mod badge; #[cfg(feature = "badge")] /// A badge for color highlighting small information. -pub type Badge<'a, Message, Renderer> = badge::Badge<'a, Message, Renderer>; +pub type Badge<'a, Message, Theme, Renderer> = badge::Badge<'a, Message, Theme, Renderer>; #[cfg(feature = "number_input")] pub mod number_input; #[cfg(feature = "number_input")] /// A field that can only be filled with numeric type. -pub type NumberInput<'a, T, Message, Renderer> = - number_input::NumberInput<'a, T, Message, Renderer>; +pub type NumberInput<'a, T, Message, Theme, Renderer> = + number_input::NumberInput<'a, T, Message, Theme, Renderer>; #[cfg(feature = "card")] pub mod card; #[cfg(feature = "card")] /// A card consisting of a head, body and optional foot. -pub type Card<'a, Message, Renderer> = card::Card<'a, Message, Renderer>; +pub type Card<'a, Message, Theme, Renderer> = card::Card<'a, Message, Theme, Renderer>; #[cfg(feature = "color_picker")] pub mod color_picker; @@ -49,8 +49,8 @@ pub use date_picker::DatePicker; pub mod selection_list; #[cfg(feature = "selection_list")] /// A widget for selecting a single value from a dynamic scrollable list of options. -pub type SelectionList<'a, T, Message, Renderer> = - selection_list::SelectionList<'a, T, Message, Renderer>; +pub type SelectionList<'a, T, Message, Theme, Renderer> = + selection_list::SelectionList<'a, T, Message, Theme, Renderer>; #[cfg(feature = "selection_list")] pub use selection_list::List; @@ -58,14 +58,14 @@ pub use selection_list::List; pub mod floating_element; #[cfg(feature = "floating_element")] /// A floating element floating over some content. -pub type FloatingElement<'a, Message, Renderer> = - floating_element::FloatingElement<'a, Message, Renderer>; +pub type FloatingElement<'a, Message, Theme, Renderer> = + floating_element::FloatingElement<'a, Message, Theme, Renderer>; #[cfg(feature = "grid")] pub mod grid; #[cfg(feature = "grid")] /// A container that distributes its contents in a grid. -pub type Grid<'a, Message, Renderer> = grid::Grid<'a, Message, Renderer>; +pub type Grid<'a, Message, Theme, Renderer> = grid::Grid<'a, Message, Theme, Renderer>; #[cfg(feature = "grid")] pub use grid::GridRow; @@ -73,19 +73,19 @@ pub use grid::GridRow; pub mod modal; #[cfg(feature = "modal")] /// A modal content as an overlay. -pub type Modal<'a, Message, Renderer> = modal::Modal<'a, Message, Renderer>; +pub type Modal<'a, Message, Theme, Renderer> = modal::Modal<'a, Message, Theme, Renderer>; #[cfg(feature = "split")] pub mod split; #[cfg(feature = "split")] /// A split can divide the available space by half to display two different elements. -pub type Split<'a, Message, Renderer> = split::Split<'a, Message, Renderer>; +pub type Split<'a, Message, Theme, Renderer> = split::Split<'a, Message, Theme, Renderer>; #[cfg(feature = "tab_bar")] pub mod tab_bar; #[cfg(feature = "tab_bar")] /// A tab bar to show tabs. -pub type TabBar = tab_bar::TabBar; +pub type TabBar = tab_bar::TabBar; #[cfg(feature = "tab_bar")] pub use tab_bar::TabLabel; @@ -94,7 +94,8 @@ pub use tab_bar::TabLabel; pub mod tabs; #[cfg(feature = "tabs")] /// A [`Tabs`] widget for showing a [`TabBar`](super::tab_bar::TabBar) -pub type Tabs<'a, Message, TabId, Renderer> = tabs::Tabs<'a, Message, TabId, Renderer>; +pub type Tabs<'a, Message, TabId, Theme, Renderer> = + tabs::Tabs<'a, Message, TabId, Theme, Renderer>; #[cfg(feature = "tabs")] pub use tabs::TabBarPosition; @@ -108,7 +109,8 @@ pub use time_picker::TimePicker; pub mod wrap; #[cfg(feature = "wrap")] /// A container that distributes its contents horizontally. -pub type Wrap<'a, B, Message, Direction> = wrap::Wrap<'a, B, Message, Direction>; +pub type Wrap<'a, Message, Direction, Theme, Renderer> = + wrap::Wrap<'a, Message, Direction, Theme, Renderer>; #[cfg(feature = "menu")] pub mod menu; @@ -121,7 +123,7 @@ pub mod spinner; #[cfg(feature = "spinner")] /// A spinner widget, a circle spinning around the center of the widget. -pub type Spinner = spinner::Spinner; +pub type Spinner = spinner::Spinner; #[cfg(feature = "context_menu")] pub mod context_menu; @@ -134,8 +136,8 @@ pub type ContextMenu<'a, Overlay, Message, Renderer> = pub mod segmented_button; #[cfg(feature = "segmented_button")] /// A badge for color highlighting small information. -pub type SegmentedButton<'a, Message, Renderer> = - segmented_button::SegmentedButton<'a, Message, Renderer>; +pub type SegmentedButton<'a, Message, Theme, Renderer> = + segmented_button::SegmentedButton<'a, Message, Theme, Renderer>; #[cfg(feature = "slide_bar")] pub mod slide_bar; diff --git a/src/native/overlay/context_menu.rs b/src/native/overlay/context_menu.rs index 1cc0a5b0..4f064ce7 100644 --- a/src/native/overlay/context_menu.rs +++ b/src/native/overlay/context_menu.rs @@ -12,42 +12,47 @@ use iced_widget::core::{ mouse::{self, Cursor}, overlay, renderer, touch, widget::tree::Tree, - window, Clipboard, Color, Element, Event, Layout, Point, Rectangle, Shell, Size, Vector, + window, Border, Clipboard, Color, Element, Event, Layout, Point, Rectangle, Shadow, Shell, + Size, Vector, }; /// The overlay of the [`ContextMenu`](crate::native::ContextMenu). #[allow(missing_debug_implementations)] -pub struct ContextMenuOverlay<'a, Message, Renderer = crate::Renderer> -where +pub struct ContextMenuOverlay< + 'a, + Message, + Theme = iced_widget::Theme, + Renderer = iced_widget::Renderer, +> where Message: 'a + Clone, Renderer: 'a + core::Renderer, - Renderer::Theme: StyleSheet, + Theme: StyleSheet, { /// The state of the [`ContextMenuOverlay`]. tree: &'a mut Tree, /// The content of the [`ContextMenuOverlay`]. - content: Element<'a, Message, Renderer>, + content: Element<'a, Message, Theme, Renderer>, /// The style of the [`ContextMenuOverlay`]. - style: ::Style, + style: ::Style, /// The state shared between [`ContextMenu`](crate::native::ContextMenu) and [`ContextMenuOverlay`]. state: &'a mut context_menu::State, } -impl<'a, Message, Renderer> ContextMenuOverlay<'a, Message, Renderer> +impl<'a, Message, Theme, Renderer> ContextMenuOverlay<'a, Message, Theme, Renderer> where Message: Clone, Renderer: core::Renderer, - Renderer::Theme: StyleSheet, + Theme: 'a + StyleSheet, { /// Creates a new [`ContextMenuOverlay`]. pub(crate) fn new( tree: &'a mut Tree, content: C, - style: ::Style, + style: ::Style, state: &'a mut context_menu::State, ) -> Self where - C: Into>, + C: Into>, { ContextMenuOverlay { tree, @@ -58,17 +63,17 @@ where } /// Turn this [`ContextMenuOverlay`] into an overlay [`Element`](overlay::Element). - pub fn overlay(self, position: Point) -> overlay::Element<'a, Message, Renderer> { + pub fn overlay(self, position: Point) -> overlay::Element<'a, Message, Theme, Renderer> { overlay::Element::new(position, Box::new(self)) } } -impl<'a, Message, Renderer> overlay::Overlay - for ContextMenuOverlay<'a, Message, Renderer> +impl<'a, Message, Theme, Renderer> overlay::Overlay + for ContextMenuOverlay<'a, Message, Theme, Renderer> where Message: 'a + Clone, Renderer: 'a + core::Renderer, - Renderer::Theme: StyleSheet, + Theme: StyleSheet, { fn layout( &mut self, @@ -102,7 +107,7 @@ where fn draw( &self, renderer: &mut Renderer, - theme: &Renderer::Theme, + theme: &Theme, style: &renderer::Style, layout: Layout<'_>, cursor: Cursor, @@ -115,9 +120,12 @@ where renderer.fill_quad( renderer::Quad { bounds, - border_radius: (0.0).into(), - border_width: 0.0, - border_color: Color::TRANSPARENT, + border: Border { + radius: (0.0).into(), + width: 0.0, + color: Color::TRANSPARENT, + }, + shadow: Shadow::default(), }, style_sheet.background, ); diff --git a/src/native/overlay/time_picker.rs b/src/native/overlay/time_picker.rs index a0883a70..75db22a7 100644 --- a/src/native/overlay/time_picker.rs +++ b/src/native/overlay/time_picker.rs @@ -32,8 +32,8 @@ use iced_widget::{ text::Renderer as _, touch, widget::tree::Tree, - Alignment, Clipboard, Color, Element, Event, Layout, Length, Overlay, Padding, Point, - Rectangle, Renderer as _, Shell, Size, Vector, Widget, + Alignment, Border, Clipboard, Color, Element, Event, Layout, Length, Overlay, Padding, + Point, Rectangle, Renderer as _, Shadow, Shell, Size, Vector, Widget, }, graphics::geometry::Renderer as _, renderer::Renderer, @@ -64,9 +64,9 @@ where /// The state of the [`TimePickerOverlay`]. state: &'a mut State, /// The cancel button of the [`TimePickerOverlay`]. - cancel_button: Button<'a, Message, Renderer>, + cancel_button: Button<'a, Message, Theme, Renderer>, /// The submit button of the [`TimePickerOverlay`]. - submit_button: Button<'a, Message, Renderer>, + submit_button: Button<'a, Message, Theme, Renderer>, /// The function that produces a message when the submit button of the [`TimePickerOverlay`] is pressed. on_submit: &'a dyn Fn(Time) -> Message, /// The position of the [`TimePickerOverlay`]. @@ -120,7 +120,7 @@ where /// Turn this [`TimePickerOverlay`] into an overlay [`Element`](overlay::Element). #[must_use] - pub fn overlay(self) -> overlay::Element<'a, Message, Renderer> { + pub fn overlay(self) -> overlay::Element<'a, Message, Theme, Renderer> { overlay::Element::new(self.position, Box::new(self)) } @@ -132,7 +132,7 @@ where layout: Layout<'_>, cursor: Cursor, _shell: &mut Shell, - _renderer: &Renderer, + _renderer: &Renderer, _clipboard: &mut dyn Clipboard, ) -> event::Status { if cursor.is_over(layout.bounds()) { @@ -305,7 +305,7 @@ where layout: Layout<'_>, cursor: Cursor, _shell: &mut Shell, - _renderer: &Renderer, + _renderer: &Renderer, _clipboard: &mut dyn Clipboard, ) -> event::Status { let mut digital_clock_children = layout.children(); @@ -440,7 +440,7 @@ where _layout: Layout<'_>, _cursor: Cursor, _shell: &mut Shell, - _renderer: &Renderer, + _renderer: &Renderer, _clipboard: &mut dyn Clipboard, ) -> event::Status { if self.state.focus == Focus::None { @@ -502,14 +502,14 @@ where } } -impl<'a, Message, Theme> Overlay> for TimePickerOverlay<'a, Message, Theme> +impl<'a, Message, Theme> Overlay for TimePickerOverlay<'a, Message, Theme> where Message: 'static + Clone, Theme: 'a + StyleSheet + button::StyleSheet + text::StyleSheet + container::StyleSheet, { fn layout( &mut self, - renderer: &Renderer, + renderer: &Renderer, bounds: Size, position: Point, _translation: Vector, @@ -537,7 +537,7 @@ where )); // Clock-Canvas - let mut clock = Row::<(), Renderer>::new() + let mut clock = Row::<(), Renderer>::new() .width(Length::Fill) .height(Length::Fill) .layout(self.tree, renderer, &limits); @@ -609,7 +609,7 @@ where event: Event, layout: Layout<'_>, cursor: Cursor, - renderer: &Renderer, + renderer: &Renderer, clipboard: &mut dyn Clipboard, shell: &mut Shell, ) -> event::Status { @@ -714,7 +714,7 @@ where layout: Layout<'_>, cursor: Cursor, viewport: &Rectangle, - renderer: &Renderer, + renderer: &Renderer, ) -> mouse::Interaction { let mut children = layout.children(); let mouse_interaction = mouse::Interaction::default(); @@ -829,7 +829,7 @@ where fn draw( &self, - renderer: &mut Renderer, + renderer: &mut Renderer, theme: &Theme, style: &renderer::Style, layout: Layout<'_>, @@ -859,9 +859,12 @@ where renderer.fill_quad( renderer::Quad { bounds, - border_radius: style_sheet[&style_state].border_radius.into(), - border_width: style_sheet[&style_state].border_width, - border_color: style_sheet[&style_state].border_color, + border: Border { + radius: style_sheet[&style_state].border_radius.into(), + width: style_sheet[&style_state].border_width, + color: style_sheet[&style_state].border_color, + }, + shadow: Shadow::default(), }, style_sheet[&style_state].background, ); @@ -912,9 +915,12 @@ where renderer.fill_quad( renderer::Quad { bounds: cancel_button_layout.bounds(), - border_radius: style_sheet[&StyleState::Focused].border_radius.into(), - border_width: style_sheet[&StyleState::Focused].border_width, - border_color: style_sheet[&StyleState::Focused].border_color, + border: Border { + radius: style_sheet[&StyleState::Focused].border_radius.into(), + width: style_sheet[&StyleState::Focused].border_width, + color: style_sheet[&StyleState::Focused].border_color, + }, + shadow: Shadow::default(), }, Color::TRANSPARENT, ); @@ -924,9 +930,12 @@ where renderer.fill_quad( renderer::Quad { bounds: submit_button_layout.bounds(), - border_radius: style_sheet[&StyleState::Focused].border_radius.into(), - border_width: style_sheet[&StyleState::Focused].border_width, - border_color: style_sheet[&StyleState::Focused].border_color, + border: Border { + radius: style_sheet[&StyleState::Focused].border_radius.into(), + width: style_sheet[&StyleState::Focused].border_width, + color: style_sheet[&StyleState::Focused].border_color, + }, + shadow: Shadow::default(), }, Color::TRANSPARENT, ); @@ -937,7 +946,7 @@ where /// Defines the layout of the digital clock of the time picker. fn digital_clock( time_picker: &mut TimePickerOverlay<'_, Message, Theme>, - renderer: &Renderer, + renderer: &Renderer, limits: Limits, ) -> Node where @@ -947,7 +956,7 @@ where let arrow_size = renderer.default_size().0; let font_size = 1.2 * renderer.default_size().0; - let mut digital_clock_row = Row::>::new() + let mut digital_clock_row = Row::::new() .align_items(Alignment::Center) .height(Length::Shrink) .width(Length::Shrink) @@ -1055,7 +1064,7 @@ where .center_x() .center_y(); - let element: Element> = Element::new(container); + let element: Element = Element::new(container); let container_tree = if let Some(child_tree) = time_picker.tree.children.get_mut(2) { child_tree.diff(element.as_widget()); child_tree @@ -1073,7 +1082,7 @@ where /// Draws the analog clock. #[allow(clippy::too_many_lines)] fn draw_clock( - renderer: &mut Renderer, + renderer: &mut Renderer, time_picker: &TimePickerOverlay<'_, Message, Theme>, layout: Layout<'_>, cursor: Cursor, @@ -1377,7 +1386,7 @@ fn draw_clock( /// Draws the digital clock. #[allow(clippy::too_many_lines)] fn draw_digital_clock( - renderer: &mut Renderer, + renderer: &mut Renderer, time_picker: &TimePickerOverlay<'_, Message, Theme>, layout: Layout<'_>, cursor: Cursor, @@ -1393,7 +1402,7 @@ fn draw_digital_clock( .expect("Graphics: Layout should have digital clock children") .children(); - let f = |renderer: &mut Renderer, layout: Layout<'_>, text: String, target: Focus| { + let f = |renderer: &mut Renderer, layout: Layout<'_>, text: String, target: Focus| { let style_state = if time_picker.state.focus == target { StyleState::Focused } else { @@ -1423,19 +1432,22 @@ fn draw_digital_clock( renderer.fill_quad( renderer::Quad { bounds: layout.bounds(), - border_color: style - .get(&style_state) - .expect("Style Sheet not found.") - .border_color, - border_radius: style - .get(&style_state) - .expect("Style Sheet not found.") - .border_radius - .into(), - border_width: style - .get(&style_state) - .expect("Style Sheet not found.") - .border_width, + border: Border { + radius: style + .get(&style_state) + .expect("Style Sheet not found.") + .border_radius + .into(), + width: style + .get(&style_state) + .expect("Style Sheet not found.") + .border_width, + color: style + .get(&style_state) + .expect("Style Sheet not found.") + .border_color, + }, + shadow: Shadow::default(), }, style .get(&style_state) @@ -1695,9 +1707,9 @@ where Theme: StyleSheet + button::StyleSheet, { /// The cancel button of the [`TimePickerOverlay`]. - cancel_button: Element<'a, Message, Renderer>, + cancel_button: Element<'a, Message, Theme, Renderer>, /// The submit button of the [`TimePickerOverlay`]. - submit_button: Element<'a, Message, Renderer>, + submit_button: Element<'a, Message, Theme, Renderer>, } impl<'a, Message, Theme> Default for TimePickerOverlayButtons<'a, Message, Theme> @@ -1726,7 +1738,7 @@ where } #[allow(clippy::unimplemented)] -impl<'a, Message, Theme> Widget> +impl<'a, Message, Theme> Widget for TimePickerOverlayButtons<'a, Message, Theme> where Message: Clone, @@ -1747,14 +1759,14 @@ where unimplemented!("This should never be reached!") } - fn layout(&self, _tree: &mut Tree, _renderer: &Renderer, _limits: &Limits) -> Node { + fn layout(&self, _tree: &mut Tree, _renderer: &Renderer, _limits: &Limits) -> Node { unimplemented!("This should never be reached!") } fn draw( &self, _state: &Tree, - _renderer: &mut Renderer, + _renderer: &mut Renderer, _theme: &Theme, _style: &renderer::Style, _layout: Layout<'_>, @@ -1766,7 +1778,7 @@ where } impl<'a, Message, Theme> From> - for Element<'a, Message, Renderer> + for Element<'a, Message, Theme, Renderer> where Message: 'a + Clone, Theme: 'a + StyleSheet + button::StyleSheet, diff --git a/src/native/quad.rs b/src/native/quad.rs index b4975e3e..9ad06794 100644 --- a/src/native/quad.rs +++ b/src/native/quad.rs @@ -7,7 +7,7 @@ use iced_widget::core::{ mouse::Cursor, renderer, widget::Tree, - Color, Element, Layout, Length, Rectangle, Size, Widget, + Border, Color, Element, Layout, Length, Rectangle, Shadow, Size, Widget, }; use crate::native::InnerBounds; @@ -47,7 +47,7 @@ impl Default for Quad { } } -impl Widget for Quad +impl Widget for Quad where Renderer: renderer::Renderer, { @@ -64,7 +64,7 @@ where &self, _state: &Tree, renderer: &mut Renderer, - _theme: &::Theme, + _theme: &Theme, _style: &renderer::Style, layout: Layout<'_>, _cursor: Cursor, @@ -74,9 +74,12 @@ where renderer.fill_quad( renderer::Quad { bounds: layout.bounds(), - border_radius: self.border_radius.into(), - border_width: self.border_width, - border_color: self.border_color, + border: Border { + radius: self.border_radius.into(), + width: self.border_width, + color: self.border_color, + }, + shadow: Shadow::default(), }, b, ); @@ -84,17 +87,22 @@ where renderer.fill_quad( renderer::Quad { bounds: self.inner_bounds.get_bounds(layout.bounds()), - border_radius: self.border_radius.into(), - border_width: self.border_width, - border_color: self.border_color, + border: Border { + radius: self.border_radius.into(), + width: self.border_width, + color: self.border_color, + }, + shadow: Shadow::default(), }, self.color, ); } } -impl From for Element<'_, Message, Renderer> + +impl<'a, Message, Theme, Renderer> From for Element<'a, Message, Theme, Renderer> where - Renderer: renderer::Renderer, + Renderer: 'a + renderer::Renderer, + Theme: 'a, { fn from(value: Quad) -> Self { Self::new(value) diff --git a/src/native/segmented_button.rs b/src/native/segmented_button.rs index 9233a1e2..748d666e 100644 --- a/src/native/segmented_button.rs +++ b/src/native/segmented_button.rs @@ -5,8 +5,8 @@ use iced_widget::core::{ mouse::{self, Cursor}, renderer, touch, widget::Tree, - Alignment, Background, Clipboard, Color, Element, Event, Layout, Length, Padding, Point, - Rectangle, Shell, Widget, + Alignment, Background, Border, Clipboard, Color, Element, Event, Layout, Length, Padding, + Point, Rectangle, Shadow, Shell, Widget, }; pub use crate::style::segmented_button::StyleSheet; @@ -25,10 +25,10 @@ pub use crate::style::segmented_button::StyleSheet; /// let segmented_button = SegmentedButton::::new(Text::new("Text")); /// ``` #[allow(missing_debug_implementations)] -pub struct SegmentedButton<'a, Message, Renderer> +pub struct SegmentedButton<'a, Message, Theme, Renderer> where Renderer: iced_widget::core::Renderer, - Renderer::Theme: StyleSheet, + Theme: StyleSheet, { is_selected: bool, on_click: Message, @@ -43,15 +43,15 @@ where /// The vertical alignment of the [`SegmentedButton`] vertical_alignment: Alignment, /// The style of the [`SegmentedButton`] - style: ::Style, + style: ::Style, /// The content [`Element`] of the [`SegmentedButton`] - content: Element<'a, Message, Renderer>, + content: Element<'a, Message, Theme, Renderer>, } -impl<'a, Message, Renderer> SegmentedButton<'a, Message, Renderer> +impl<'a, Message, Theme, Renderer> SegmentedButton<'a, Message, Theme, Renderer> where Renderer: iced_widget::core::Renderer, - Renderer::Theme: StyleSheet, + Theme: StyleSheet, { /// Creates a new [`SegmentedButton`](SegmentedButton) with the given content. /// @@ -59,7 +59,7 @@ where /// * the content [`Element`] to display in the [`SegmentedButton`](SegmentedButton). pub fn new(content: T, value: V, selected: Option, f: F) -> Self where - T: Into>, + T: Into>, V: Eq + Copy, F: FnOnce(V) -> Message, { @@ -71,7 +71,7 @@ where height: Length::Shrink, horizontal_alignment: Alignment::Center, vertical_alignment: Alignment::Center, - style: ::Style::default(), + style: ::Style::default(), content: content.into(), } } @@ -113,17 +113,18 @@ where /// Sets the style of the [`SegmentedButton`](SegmentedButton). #[must_use] - pub fn style(mut self, style: ::Style) -> Self { + pub fn style(mut self, style: ::Style) -> Self { self.style = style; self } } -impl<'a, Message, Renderer> Widget for SegmentedButton<'a, Message, Renderer> +impl<'a, Message, Theme, Renderer> Widget + for SegmentedButton<'a, Message, Theme, Renderer> where Message: 'a + Clone, Renderer: 'a + iced_widget::core::Renderer, - Renderer::Theme: StyleSheet, + Theme: StyleSheet, { fn children(&self) -> Vec { vec![Tree::new(&self.content)] @@ -202,7 +203,7 @@ where &self, tree: &Tree, renderer: &mut Renderer, - theme: &Renderer::Theme, + theme: &Theme, _style: &renderer::Style, layout: Layout<'_>, cursor: Cursor, @@ -220,9 +221,12 @@ where renderer.fill_quad( renderer::Quad { bounds, - border_radius: 2.0.into(), - border_width: style_sheet.border_width, - border_color: style_sheet.border_color.unwrap_or(Color::BLACK), + border: Border { + radius: 2.0.into(), + width: style_sheet.border_width, + color: style_sheet.border_color.unwrap_or(Color::BLACK), + }, + shadow: Shadow::default(), }, style_sheet.background, ); @@ -235,9 +239,12 @@ where width: bounds.width, height: bounds.height, }, - border_radius: 2.0.into(), - border_width: 0.0, - border_color: Color::TRANSPARENT, + border: Border { + radius: 2.0.into(), + width: 0.0, + color: Color::TRANSPARENT, + }, + shadow: Shadow::default(), }, style_sheet.selected_color, ); @@ -252,9 +259,12 @@ where width: bounds.width, height: bounds.height, }, - border_radius: 2.0.into(), - border_width: 0.0, - border_color: Color::TRANSPARENT, + border: Border { + radius: 2.0.into(), + width: 0.0, + color: Color::TRANSPARENT, + }, + shadow: Shadow::default(), }, Background::Color([0.0, 0.0, 0.0, 0.5].into()), ); @@ -276,14 +286,14 @@ where } } -impl<'a, Message, Renderer> From> - for Element<'a, Message, Renderer> +impl<'a, Message, Theme, Renderer> From> + for Element<'a, Message, Theme, Renderer> where Message: 'a + Clone, Renderer: 'a + iced_widget::core::Renderer, - Renderer::Theme: StyleSheet, + Theme: 'a + StyleSheet, { - fn from(segmented_button: SegmentedButton<'a, Message, Renderer>) -> Self { + fn from(segmented_button: SegmentedButton<'a, Message, Theme, Renderer>) -> Self { Self::new(segmented_button) } } diff --git a/src/native/selection_list.rs b/src/native/selection_list.rs index ab3183ca..875d21c1 100644 --- a/src/native/selection_list.rs +++ b/src/native/selection_list.rs @@ -13,7 +13,8 @@ use iced_widget::{ renderer, text::{Paragraph, Text}, widget::{tree, Tree}, - Clipboard, Element, Event, Layout, Length, Pixels, Rectangle, Shell, Size, Widget, + Border, Clipboard, Element, Event, Layout, Length, Pixels, Rectangle, Shadow, Shell, Size, + Widget, }, graphics, runtime::Font, @@ -28,15 +29,20 @@ pub use list::List; /// A widget for selecting a single value from a dynamic scrollable list of options. #[allow(missing_debug_implementations)] #[allow(clippy::type_repetition_in_bounds)] -pub struct SelectionList<'a, T, Message, Renderer = crate::Renderer> -where +pub struct SelectionList< + 'a, + T, + Message, + Theme = iced_widget::Theme, + Renderer = iced_widget::Renderer, +> where T: Clone + ToString + Eq + Hash, [T]: ToOwned>, Renderer: core::Renderer + core::text::Renderer, - Renderer::Theme: StyleSheet + container::StyleSheet, + Theme: StyleSheet + container::StyleSheet, { /// Container for Rendering List. - container: Container<'a, Message, Renderer>, + container: Container<'a, Message, Theme, Renderer>, /// List of Elements to Render. options: &'a [T], /// Label Font @@ -50,15 +56,15 @@ where /// The Text Size text_size: f32, /// Style for Looks - style: ::Style, + style: ::Style, } #[allow(clippy::type_repetition_in_bounds)] -impl<'a, T, Message, Renderer> SelectionList<'a, T, Message, Renderer> +impl<'a, T, Message, Theme, Renderer> SelectionList<'a, T, Message, Theme, Renderer> where Message: 'a + Clone, Renderer: 'a + core::Renderer + core::text::Renderer, - Renderer::Theme: StyleSheet + container::StyleSheet + scrollable::StyleSheet, + Theme: 'a + StyleSheet + container::StyleSheet + scrollable::StyleSheet, T: Clone + Display + Eq + Hash, [T]: ToOwned>, { @@ -72,7 +78,7 @@ where font: Font::default(), text_size: 12.0, padding: 5.0, - style: ::Style::default(), + style: ::Style::default(), on_selected: Box::new(on_selected), selected: None, phantomdata: PhantomData, @@ -82,7 +88,7 @@ where Self { options, font: Font::default(), - style: ::Style::default(), + style: ::Style::default(), container, width: Length::Fill, height: Length::Fill, @@ -99,7 +105,7 @@ where on_selected: impl Fn(usize, T) -> Message + 'static, text_size: f32, padding: f32, - style: ::Style, + style: ::Style, selected: Option, font: Font, ) -> Self { @@ -143,25 +149,26 @@ where /// Sets the style of the [`SelectionList`]. #[must_use] - pub fn style(mut self, style: ::Style) -> Self { + pub fn style(mut self, style: ::Style) -> Self { self.style = style; self } } -impl<'a, T, Message, Renderer> Widget for SelectionList<'a, T, Message, Renderer> +impl<'a, T, Message, Theme, Renderer> Widget + for SelectionList<'a, T, Message, Theme, Renderer> where T: 'a + Clone + ToString + Eq + Hash + Display, Message: 'static, Renderer: core::Renderer + core::text::Renderer + 'a, - Renderer::Theme: StyleSheet + container::StyleSheet, + Theme: StyleSheet + container::StyleSheet, { fn children(&self) -> Vec { - vec![Tree::new(&self.container as &dyn Widget<_, _>)] + vec![Tree::new(&self.container as &dyn Widget<_, _, _>)] } fn diff(&self, tree: &mut Tree) { - tree.diff_children(&[&self.container as &dyn Widget<_, _>]); + tree.diff_children(&[&self.container as &dyn Widget<_, _, _>]); let state = tree.state.downcast_mut::(); state.values = self @@ -266,7 +273,7 @@ where &self, state: &Tree, renderer: &mut Renderer, - theme: &Renderer::Theme, + theme: &Theme, style: &renderer::Style, layout: Layout<'_>, cursor: Cursor, @@ -275,9 +282,12 @@ where renderer.fill_quad( renderer::Quad { bounds: layout.bounds(), - border_color: theme.style(&self.style).border_color, - border_width: theme.style(&self.style).border_width, - border_radius: (0.0).into(), + border: Border { + radius: (0.0).into(), + width: theme.style(&self.style).border_width, + color: theme.style(&self.style).border_color, + }, + shadow: Shadow::default(), }, theme.style(&self.style).background, ); @@ -297,15 +307,15 @@ where } } -impl<'a, T, Message, Renderer> From> - for Element<'a, Message, Renderer> +impl<'a, T, Message, Theme, Renderer> From> + for Element<'a, Message, Theme, Renderer> where T: Clone + ToString + Eq + Hash + Display, Message: 'static, Renderer: 'a + core::Renderer + core::text::Renderer, - Renderer::Theme: StyleSheet + container::StyleSheet, + Theme: 'a + StyleSheet + container::StyleSheet, { - fn from(selection_list: SelectionList<'a, T, Message, Renderer>) -> Self { + fn from(selection_list: SelectionList<'a, T, Message, Theme, Renderer>) -> Self { Element::new(selection_list) } } diff --git a/src/native/selection_list/list.rs b/src/native/selection_list/list.rs index 5894a401..c2810004 100644 --- a/src/native/selection_list/list.rs +++ b/src/native/selection_list/list.rs @@ -13,8 +13,8 @@ use iced_widget::{ tree::{State, Tag}, Tree, }, - Clipboard, Color, Element, Event, Layout, Length, Pixels, Point, Rectangle, Shell, Size, - Widget, + Border, Clipboard, Color, Element, Event, Layout, Length, Pixels, Point, Rectangle, Shadow, + Shell, Size, Widget, }, text::LineHeight, }; @@ -27,12 +27,12 @@ use std::{ /// The Private [`List`] Handles the Actual list rendering. #[allow(missing_debug_implementations)] -pub struct List<'a, T: 'a, Message, Renderer> +pub struct List<'a, T: 'a, Message, Theme, Renderer> where T: Clone + Display + Eq + Hash, [T]: ToOwned>, Renderer: core::Renderer + core::text::Renderer, - Renderer::Theme: StyleSheet, + Theme: StyleSheet, { /// Options pointer to hold all rendered strings pub options: &'a [T], @@ -40,7 +40,7 @@ where /// Label Font pub font: Renderer::Font, /// Style for Font colors and Box hover colors. - pub style: ::Style, + pub style: ::Style, /// Function Pointer On Select to call on Mouse button press. pub on_selected: Box Message>, /// The padding Width @@ -64,11 +64,12 @@ pub struct ListState { pub options: Vec, } -impl<'a, T, Message, Renderer> Widget for List<'a, T, Message, Renderer> +impl<'a, T, Message, Theme, Renderer> Widget + for List<'a, T, Message, Theme, Renderer> where T: Clone + Display + Eq + Hash, Renderer: core::Renderer + core::text::Renderer, - Renderer::Theme: StyleSheet, + Theme: StyleSheet, { fn tag(&self) -> Tag { Tag::of::() @@ -208,7 +209,7 @@ where &self, state: &Tree, renderer: &mut Renderer, - theme: &Renderer::Theme, + theme: &Theme, _style: &renderer::Style, layout: Layout<'_>, _cursor: Cursor, @@ -241,9 +242,12 @@ where renderer.fill_quad( renderer::Quad { bounds, - border_radius: (0.0).into(), - border_width: 0.0, - border_color: Color::TRANSPARENT, + border: Border { + radius: (0.0).into(), + width: 0.0, + color: Color::TRANSPARENT, + }, + shadow: Shadow::default(), }, if is_selected { theme.style(&self.style).selected_background @@ -280,15 +284,15 @@ where } } -impl<'a, T, Message, Renderer> From> - for Element<'a, Message, Renderer> +impl<'a, T, Message, Theme, Renderer> From> + for Element<'a, Message, Theme, Renderer> where T: Clone + Display + Eq + Hash, Message: 'a, Renderer: 'a + core::Renderer + core::text::Renderer, - Renderer::Theme: StyleSheet, + Theme: 'a + StyleSheet, { - fn from(list: List<'a, T, Message, Renderer>) -> Element<'a, Message, Renderer> { + fn from(list: List<'a, T, Message, Theme, Renderer>) -> Element<'a, Message, Theme, Renderer> { Element::new(list) } } diff --git a/src/native/slide_bar.rs b/src/native/slide_bar.rs index a5c4bb50..19dbec5e 100644 --- a/src/native/slide_bar.rs +++ b/src/native/slide_bar.rs @@ -8,7 +8,8 @@ use iced_widget::core::{ mouse::{self, Cursor}, renderer, touch, widget::{tree, Tree}, - Clipboard, Color, Element, Event, Layout, Length, Point, Rectangle, Shell, Size, Widget, + Border, Clipboard, Color, Element, Event, Layout, Length, Point, Rectangle, Shadow, Shell, + Size, Widget, }; use std::ops::RangeInclusive; @@ -127,7 +128,7 @@ where } } -impl<'a, T, Message, Renderer> Widget for SlideBar<'a, T, Message> +impl<'a, T, Message, Theme, Renderer> Widget for SlideBar<'a, T, Message> where T: Copy + Into + num_traits::FromPrimitive, Message: Clone, @@ -191,7 +192,7 @@ where &self, _tree: &Tree, renderer: &mut Renderer, - _theme: &::Theme, + _theme: &Theme, _style: &renderer::Style, layout: Layout<'_>, _cursor: Cursor, @@ -319,9 +320,12 @@ where renderer.fill_quad( renderer::Quad { bounds: layout.bounds(), - border_radius: slider.border_radius.into(), - border_width: slider.border_width, - border_color: slider.border_color, + border: Border { + radius: slider.border_radius.into(), + width: slider.border_width, + color: slider.border_color, + }, + shadow: Shadow::default(), }, background, ); @@ -330,20 +334,25 @@ where renderer.fill_quad( renderer::Quad { bounds: active_progress_bounds, - border_radius: slider.border_radius.into(), - border_width: 0.0, - border_color: Color::TRANSPARENT, + border: Border { + radius: slider.border_radius.into(), + width: 0.0, + color: Color::TRANSPARENT, + }, + shadow: Shadow::default(), }, slider.color, ); } } -impl<'a, T, Message, Renderer> From> for Element<'a, Message, Renderer> +impl<'a, T, Message, Theme, Renderer> From> + for Element<'a, Message, Theme, Renderer> where T: 'a + Copy + Into + num_traits::FromPrimitive, Renderer: 'a + renderer::Renderer, Message: 'a + Clone, + Theme: 'a, { fn from(value: SlideBar<'a, T, Message>) -> Self { Self::new(value) diff --git a/src/native/spinner.rs b/src/native/spinner.rs index 5be9eb70..4908bacd 100644 --- a/src/native/spinner.rs +++ b/src/native/spinner.rs @@ -12,21 +12,14 @@ use iced_widget::core::{ tree::{State, Tag}, Tree, }, - window, Clipboard, Color, Element, Event, Layout, Length, Rectangle, Shell, Size, Vector, - Widget, -}; -use std::{ - marker::PhantomData, - time::{Duration, Instant}, + window, Border, Clipboard, Color, Element, Event, Layout, Length, Rectangle, Shadow, Shell, + Size, Vector, Widget, }; +use std::time::{Duration, Instant}; /// A spinner widget, a circle spinning around the center of the widget. #[allow(missing_debug_implementations)] -pub struct Spinner -where - Renderer: core::Renderer, - Renderer::Theme: StyleSheet, -{ +pub struct Spinner { /// The width of the [`Spinner`]. width: Length, /// The height of the [`Spinner`]. @@ -35,31 +28,20 @@ where rate: Duration, /// The radius of the spinning circle. circle_radius: f32, - #[allow(missing_docs)] - renderer: PhantomData, } -impl Default for Spinner -where - Renderer: core::Renderer, - Renderer::Theme: StyleSheet, -{ +impl Default for Spinner { fn default() -> Self { Self { width: Length::Fixed(20.0), height: Length::Fixed(20.0), rate: Duration::from_secs_f32(1.0), circle_radius: 2.0, - renderer: PhantomData, } } } -impl Spinner -where - Renderer: core::Renderer, - Renderer::Theme: StyleSheet, -{ +impl Spinner { /// Creates a new [`Spinner`] widget. #[must_use] pub fn new() -> Self { @@ -106,18 +88,21 @@ fn fill_circle(renderer: &mut impl core::Renderer, position: Vector, radius: f32 width: radius * 2.0, height: radius * 2.0, }, - border_radius: radius.into(), - border_width: 0.0, - border_color: Color::TRANSPARENT, + border: Border { + radius: radius.into(), + width: 0.0, + color: Color::TRANSPARENT, + }, + shadow: Shadow::default(), }, color, ); } -impl Widget for Spinner +impl Widget for Spinner where Renderer: core::Renderer, - Renderer::Theme: StyleSheet, + Theme: StyleSheet, { fn size(&self) -> Size { Size::new(self.width, self.height) @@ -135,7 +120,7 @@ where &self, state: &Tree, renderer: &mut Renderer, - _theme: &Renderer::Theme, + _theme: &Theme, style: &renderer::Style, layout: Layout<'_>, _cursor: Cursor, @@ -219,12 +204,12 @@ where } } -impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> +impl<'a, Message, Theme, Renderer> From for Element<'a, Message, Theme, Renderer> where Renderer: core::Renderer + 'a, - Renderer::Theme: StyleSheet, + Theme: 'a + StyleSheet, { - fn from(spinner: Spinner) -> Self { + fn from(spinner: Spinner) -> Self { Self::new(spinner) } } diff --git a/src/native/split.rs b/src/native/split.rs index a2ccf7a8..0ede7cd8 100644 --- a/src/native/split.rs +++ b/src/native/split.rs @@ -13,8 +13,8 @@ use iced_widget::{ tree::{State, Tag}, Operation, Tree, }, - Clipboard, Color, Element, Event, Layout, Length, Padding, Point, Rectangle, Shell, Size, - Widget, + Border, Clipboard, Color, Element, Event, Layout, Length, Padding, Point, Rectangle, + Shadow, Shell, Size, Widget, }, Container, Row, }; @@ -40,15 +40,15 @@ pub use crate::style::split::{Appearance, StyleSheet}; /// let split = Split::new(first, second, Some(300), Axis::Vertical, Message::Resized); /// ``` #[allow(missing_debug_implementations)] -pub struct Split<'a, Message, Renderer> +pub struct Split<'a, Message, Theme, Renderer> where Renderer: core::Renderer, - Renderer::Theme: StyleSheet, + Theme: StyleSheet, { /// The first element of the [`Split`]. - first: Element<'a, Message, Renderer>, + first: Element<'a, Message, Theme, Renderer>, /// The second element of the [`Split`]. - second: Element<'a, Message, Renderer>, + second: Element<'a, Message, Theme, Renderer>, /// The position of the divider. divider_position: Option, /// The axis to split at. @@ -69,14 +69,14 @@ where /// The message that is send when the divider of the [`Split`] is moved. on_resize: Box Message>, /// The style of the [`Split`]. - style: ::Style, + style: ::Style, } -impl<'a, Message, Renderer> Split<'a, Message, Renderer> +impl<'a, Message, Theme, Renderer> Split<'a, Message, Theme, Renderer> where Message: 'a, Renderer: 'a + core::Renderer, - Renderer::Theme: StyleSheet + container::StyleSheet, + Theme: 'a + StyleSheet + container::StyleSheet, { /// Creates a new [`Split`]. /// @@ -94,8 +94,8 @@ where on_resize: F, ) -> Self where - A: Into>, - B: Into>, + A: Into>, + B: Into>, F: 'static + Fn(u16) -> Message, { Self { @@ -116,7 +116,7 @@ where min_size_first: 5, min_size_second: 5, on_resize: Box::new(on_resize), - style: ::Style::default(), + style: ::Style::default(), } } @@ -165,16 +165,17 @@ where /// Sets the style of the [`Split`]. #[must_use] - pub fn style(mut self, style: ::Style) -> Self { + pub fn style(mut self, style: ::Style) -> Self { self.style = style; self } } -impl<'a, Message, Renderer> Widget for Split<'a, Message, Renderer> +impl<'a, Message, Theme, Renderer> Widget + for Split<'a, Message, Theme, Renderer> where Renderer: 'a + core::Renderer, - Renderer::Theme: StyleSheet, + Theme: StyleSheet, { fn tag(&self) -> Tag { Tag::of::() @@ -197,7 +198,7 @@ where } fn layout(&self, tree: &mut Tree, renderer: &Renderer, limits: &Limits) -> Node { - let space = Row::::new() + let space = Row::::new() .width(Length::Fill) .height(Length::Fill) .layout(tree, renderer, limits); @@ -341,7 +342,7 @@ where &self, state: &Tree, renderer: &mut Renderer, - theme: &Renderer::Theme, + theme: &Theme, style: &renderer::Style, layout: Layout<'_>, cursor: Cursor, @@ -355,9 +356,12 @@ where renderer.fill_quad( renderer::Quad { bounds: layout.bounds(), - border_radius: (0.0).into(), - border_width: theme.active(&self.style).border_width, - border_color: theme.active(&self.style).border_color, + border: Border { + radius: (0.0).into(), + width: theme.active(&self.style).border_width, + color: theme.active(&self.style).border_color, + }, + shadow: Shadow::default(), }, theme .active(&self.style) @@ -373,9 +377,12 @@ where renderer.fill_quad( renderer::Quad { bounds: first_layout.bounds(), - border_radius: (0.0).into(), - border_width: 0.0, - border_color: Color::TRANSPARENT, + border: Border { + radius: (0.0).into(), + width: 0.0, + color: Color::TRANSPARENT, + }, + shadow: Shadow::default(), }, if first_layout .bounds() @@ -410,9 +417,12 @@ where renderer.fill_quad( renderer::Quad { bounds: second_layout.bounds(), - border_radius: (0.0).into(), - border_width: 0.0, - border_color: Color::TRANSPARENT, + border: Border { + radius: (0.0).into(), + width: 0.0, + color: Color::TRANSPARENT, + }, + shadow: Shadow::default(), }, if second_layout .bounds() @@ -450,9 +460,12 @@ where renderer.fill_quad( renderer::Quad { bounds: divider_layout.bounds(), - border_radius: (0.0).into(), - border_width: divider_style.divider_border_width, - border_color: divider_style.divider_border_color, + border: Border { + radius: (0.0).into(), + width: divider_style.divider_border_width, + color: divider_style.divider_border_color, + }, + shadow: Shadow::default(), }, divider_style.divider_background, ); @@ -485,7 +498,7 @@ where state: &'b mut Tree, layout: Layout<'_>, renderer: &Renderer, - ) -> Option> { + ) -> Option> { let mut children = layout.children(); let first_layout = children.next()?; let _divider_layout = children.next()?; @@ -510,16 +523,16 @@ where } /// Do a horizontal split. -fn horizontal_split<'a, Message, Renderer>( +fn horizontal_split<'a, Message, Theme, Renderer>( tree: &mut Tree, - split: &Split<'a, Message, Renderer>, + split: &Split<'a, Message, Theme, Renderer>, renderer: &Renderer, limits: &Limits, space: &Node, ) -> Node where Renderer: 'a + core::Renderer, - Renderer::Theme: StyleSheet, + Theme: StyleSheet, { if space.bounds().height < split.spacing + f32::from(split.min_size_first + split.min_size_second) @@ -589,16 +602,16 @@ where } /// Do a vertical split. -fn vertical_split<'a, Message, Renderer>( +fn vertical_split<'a, Message, Theme, Renderer>( tree: &mut Tree, - split: &Split<'a, Message, Renderer>, + split: &Split<'a, Message, Theme, Renderer>, renderer: &Renderer, limits: &Limits, space: &Node, ) -> Node where Renderer: 'a + core::Renderer, - Renderer::Theme: StyleSheet, + Theme: StyleSheet, { if space.bounds().width < split.spacing + f32::from(split.min_size_first + split.min_size_second) @@ -667,13 +680,14 @@ where Node::with_children(space.bounds().size(), vec![first, divider, second]) } -impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> +impl<'a, Message, Theme, Renderer> From> + for Element<'a, Message, Theme, Renderer> where Message: 'a, Renderer: 'a + core::Renderer, - Renderer::Theme: StyleSheet, + Theme: 'a + StyleSheet, { - fn from(split_pane: Split<'a, Message, Renderer>) -> Self { + fn from(split_pane: Split<'a, Message, Theme, Renderer>) -> Self { Element::new(split_pane) } } diff --git a/src/native/tab_bar.rs b/src/native/tab_bar.rs index 9db2efdd..5eebf23a 100644 --- a/src/native/tab_bar.rs +++ b/src/native/tab_bar.rs @@ -16,8 +16,8 @@ use iced_widget::{ mouse::{self, Cursor}, renderer, touch, widget::Tree, - Alignment, Clipboard, Color, Element, Event, Layout, Length, Point, Rectangle, Shell, Size, - Widget, + Alignment, Border, Clipboard, Color, Element, Event, Layout, Length, Point, Rectangle, + Shadow, Shell, Size, Widget, }, runtime::Font, text::{self, LineHeight}, @@ -66,10 +66,10 @@ const DEFAULT_SPACING: f32 = 0.0; /// .set_active_tab(&TabId::One); /// ``` #[allow(missing_debug_implementations)] -pub struct TabBar +pub struct TabBar where Renderer: core::Renderer + core::text::Renderer, - Renderer::Theme: StyleSheet, + Theme: StyleSheet, TabId: Eq + Clone, { /// The index of the currently active tab. @@ -105,7 +105,7 @@ where /// The optional text font of the [`TabBar`]. text_font: Option, /// The style of the [`TabBar`]. - style: ::Style, + style: ::Style, /// Where the icon is placed relative to text position: Position, #[allow(clippy::missing_docs_in_private_items)] @@ -126,10 +126,10 @@ pub enum Position { Left, } -impl TabBar +impl TabBar where Renderer: core::Renderer + core::text::Renderer, - Renderer::Theme: StyleSheet, + Theme: StyleSheet, TabId: Eq + Clone, { /// Creates a new [`TabBar`] with the index of the selected tab and a specified @@ -174,7 +174,7 @@ where spacing: DEFAULT_SPACING, font: None, text_font: None, - style: ::Style::default(), + style: ::Style::default(), position: Position::default(), _renderer: PhantomData, } @@ -324,7 +324,7 @@ where /// Sets the style of the [`TabBar`]. #[must_use] - pub fn style(mut self, style: ::Style) -> Self { + pub fn style(mut self, style: ::Style) -> Self { self.style = style; self } @@ -337,10 +337,11 @@ where } } -impl Widget for TabBar +impl Widget + for TabBar where Renderer: core::Renderer + core::text::Renderer, - Renderer::Theme: StyleSheet + text::StyleSheet, + Theme: StyleSheet + text::StyleSheet, TabId: Eq + Clone, { fn size(&self) -> Size { @@ -353,13 +354,17 @@ where renderer: &Renderer, limits: &layout::Limits, ) -> layout::Node { - fn layout_icon(icon: &char, size: f32, font: Option) -> Text<'_, Renderer> + fn layout_icon( + icon: &char, + size: f32, + font: Option, + ) -> Text<'_, Theme, Renderer> where Renderer: iced_widget::core::text::Renderer, Renderer::Font: From, - Renderer::Theme: iced_widget::text::StyleSheet, + Theme: iced_widget::text::StyleSheet, { - Text::::new(icon.to_string()) + Text::::new(icon.to_string()) .size(size) .font(font.unwrap_or_default()) .horizontal_alignment(alignment::Horizontal::Center) @@ -368,13 +373,17 @@ where .width(Length::Shrink) } - fn layout_text(text: &str, size: f32, font: Option) -> Text<'_, Renderer> + fn layout_text( + text: &str, + size: f32, + font: Option, + ) -> Text<'_, Theme, Renderer> where Renderer: iced_widget::core::text::Renderer, Renderer::Font: From, - Renderer::Theme: iced_widget::text::StyleSheet, + Theme: iced_widget::text::StyleSheet, { - Text::::new(text) + Text::::new(text) .size(size) .font(font.unwrap_or_default()) .horizontal_alignment(alignment::Horizontal::Center) @@ -386,7 +395,7 @@ where let row = self .tab_labels .iter() - .fold(Row::::new(), |row, tab_label| { + .fold(Row::::new(), |row, tab_label| { let mut label_row = Row::new() .push( match tab_label { @@ -489,7 +498,7 @@ where .spacing(self.spacing) .align_items(Alignment::Center); - let element: Element = Element::new(row); + let element: Element = Element::new(row); let tab_tree = if let Some(child_tree) = tree.children.get_mut(0) { child_tree.diff(element.as_widget()); child_tree @@ -588,7 +597,7 @@ where &self, _state: &Tree, renderer: &mut Renderer, - theme: &Renderer::Theme, + theme: &Theme, _style: &renderer::Style, layout: Layout<'_>, cursor: Cursor, @@ -606,9 +615,12 @@ where renderer.fill_quad( renderer::Quad { bounds, - border_radius: (0.0).into(), - border_width: style_sheet.border_width, - border_color: style_sheet.border_color.unwrap_or(Color::TRANSPARENT), + border: Border { + radius: (0.0).into(), + width: style_sheet.border_width, + color: style_sheet.border_color.unwrap_or(Color::TRANSPARENT), + }, + shadow: Shadow::default(), }, style_sheet .background @@ -639,13 +651,13 @@ where clippy::too_many_lines, clippy::too_many_arguments )] -fn draw_tab( +fn draw_tab( renderer: &mut Renderer, tab: &TabLabel, layout: Layout<'_>, position: Position, - theme: &Renderer::Theme, - style: &::Style, + theme: &Theme, + style: &::Style, is_selected: bool, cursor: Cursor, icon_data: (Font, f32), @@ -653,7 +665,7 @@ fn draw_tab( close_size: f32, ) where Renderer: core::Renderer + core::text::Renderer, - Renderer::Theme: StyleSheet + text::StyleSheet, + Theme: StyleSheet + text::StyleSheet, { fn icon_bound_rectangle(item: Option>) -> Rectangle { item.expect("Graphics: Layout should have an icons layout for an IconText") @@ -683,9 +695,12 @@ fn draw_tab( renderer.fill_quad( renderer::Quad { bounds, - border_radius: (0.0).into(), - border_width: style.tab_label_border_width, - border_color: style.tab_label_border_color, + border: Border { + radius: (0.0).into(), + width: style.tab_label_border_width, + color: style.tab_label_border_color, + }, + shadow: Shadow::default(), }, style.tab_label_background, ); @@ -819,9 +834,12 @@ fn draw_tab( renderer.fill_quad( renderer::Quad { bounds: cross_bounds, - border_radius: style.icon_border_radius, - border_width: style.border_width, - border_color: style.border_color.unwrap_or(Color::TRANSPARENT), + border: Border { + radius: style.icon_border_radius, + width: style.border_width, + color: style.border_color.unwrap_or(Color::TRANSPARENT), + }, + shadow: Shadow::default(), }, style .icon_background @@ -831,15 +849,15 @@ fn draw_tab( }; } -impl<'a, Message, TabId, Renderer> From> - for Element<'a, Message, Renderer> +impl<'a, Message, TabId, Theme, Renderer> From> + for Element<'a, Message, Theme, Renderer> where Renderer: 'a + core::Renderer + core::text::Renderer, - Renderer::Theme: StyleSheet + text::StyleSheet, + Theme: 'a + StyleSheet + text::StyleSheet, Message: 'a, TabId: 'a + Eq + Clone, { - fn from(tab_bar: TabBar) -> Self { + fn from(tab_bar: TabBar) -> Self { Element::new(tab_bar) } } diff --git a/src/native/tabs.rs b/src/native/tabs.rs index 215345db..b69ac6fa 100644 --- a/src/native/tabs.rs +++ b/src/native/tabs.rs @@ -52,20 +52,20 @@ pub use tab_bar_position::TabBarPosition; /// .push(TabId::One, TabLabel::Text(String::from("One")), Text::new(String::from("One"))) /// .push(TabId::Two, TabLabel::Text(String::from("Two")), Text::new(String::from("Two"))) /// .push(TabId::Three, TabLabel::Text(String::from("Three")), Text::new(String::from("Three"))) -/// .set_active_tab(&TabId::Two); +/// .set_active_tab(&TabId::Two);Theme /// ``` /// #[allow(missing_debug_implementations)] -pub struct Tabs<'a, Message, TabId, Renderer = crate::Renderer> +pub struct Tabs<'a, Message, TabId, Theme = iced_widget::Theme, Renderer = iced_widget::Renderer> where Renderer: 'a + core::Renderer + core::text::Renderer, - Renderer::Theme: StyleSheet, + Theme: StyleSheet, TabId: Eq + Clone, { /// The [`TabBar`](crate::native::TabBar) of the [`Tabs`]. - tab_bar: TabBar, + tab_bar: TabBar, /// The vector containing the content of the tabs. - tabs: Vec>, + tabs: Vec>, /// The vector containing the indices of the tabs. indices: Vec, /// The position of the [`TabBar`](crate::native::TabBar). @@ -78,10 +78,10 @@ where height: Length, } -impl<'a, Message, TabId, Renderer> Tabs<'a, Message, TabId, Renderer> +impl<'a, Message, TabId, Theme, Renderer> Tabs<'a, Message, TabId, Theme, Renderer> where Renderer: 'a + core::Renderer + core::text::Renderer, - Renderer::Theme: StyleSheet + text::StyleSheet, + Theme: StyleSheet + text::StyleSheet, TabId: Eq + Clone, { /// Creates a new [`Tabs`] widget with the index of the selected tab and a @@ -108,7 +108,7 @@ where /// * the function that will be called if a tab is selected by the user. /// It takes the index of the selected tab. pub fn new_with_tabs( - tabs: Vec<(TabId, TabLabel, Element<'a, Message, Renderer>)>, + tabs: Vec<(TabId, TabLabel, Element<'a, Message, Theme, Renderer>)>, on_select: F, ) -> Self where @@ -195,7 +195,7 @@ where #[must_use] pub fn push(mut self, id: TabId, tab_label: TabLabel, element: E) -> Self where - E: Into>, + E: Into>, { self.tab_bar = self .tab_bar @@ -243,7 +243,7 @@ where /// Sets the style of the [`TabBar`](super::tab_bar::TabBar). #[must_use] - pub fn tab_bar_style(mut self, style: ::Style) -> Self { + pub fn tab_bar_style(mut self, style: ::Style) -> Self { self.tab_bar = self.tab_bar.style(style); self } @@ -288,10 +288,11 @@ where } } -impl<'a, Message, TabId, Renderer> Widget for Tabs<'a, Message, TabId, Renderer> +impl<'a, Message, TabId, Theme, Renderer> Widget + for Tabs<'a, Message, TabId, Theme, Renderer> where Renderer: core::Renderer + core::text::Renderer, - Renderer::Theme: StyleSheet + text::StyleSheet, + Theme: StyleSheet + text::StyleSheet, TabId: Eq + Clone, { fn children(&self) -> Vec { @@ -334,7 +335,7 @@ where &tab_content_limits, ) } else { - Row::::new() + Row::::new() .width(Length::Fill) .height(Length::Fill) .layout(tree, renderer, &tab_content_limits) @@ -501,7 +502,7 @@ where &self, state: &Tree, renderer: &mut Renderer, - theme: &Renderer::Theme, + theme: &Theme, style: &renderer::Style, layout: Layout<'_>, cursor: Cursor, @@ -557,7 +558,7 @@ where state: &'b mut Tree, layout: Layout<'_>, renderer: &Renderer, - ) -> Option> { + ) -> Option> { let layout = match self.tab_bar_position { TabBarPosition::Top => layout.children().nth(1), TabBarPosition::Bottom => layout.children().next(), @@ -594,15 +595,15 @@ where } } -impl<'a, Message, TabId, Renderer> From> - for Element<'a, Message, Renderer> +impl<'a, Message, TabId, Theme, Renderer> From> + for Element<'a, Message, Theme, Renderer> where Renderer: 'a + core::Renderer + core::text::Renderer, - Renderer::Theme: StyleSheet + text::StyleSheet, + Theme: 'a + StyleSheet + text::StyleSheet, Message: 'a, TabId: 'a + Eq + Clone, { - fn from(tabs: Tabs<'a, Message, TabId, Renderer>) -> Self { + fn from(tabs: Tabs<'a, Message, TabId, Theme, Renderer>) -> Self { Element::new(tabs) } } diff --git a/src/native/time_picker.rs b/src/native/time_picker.rs index 23c1cb41..eb25b2a1 100644 --- a/src/native/time_picker.rs +++ b/src/native/time_picker.rs @@ -59,7 +59,7 @@ where /// The time to show. time: Time, /// The underlying element. - underlay: Element<'a, Message, Renderer>, + underlay: Element<'a, Message, Theme, Renderer>, /// The message that is send if the cancel button of the [`TimePickerOverlay`] is pressed. on_cancel: Message, /// The function that produces a message when the submit button of the [`TimePickerOverlay`] is pressed. @@ -67,7 +67,7 @@ where /// The style of the [`TimePickerOverlay`]. style: ::Style, /// The buttons of the overlay. - overlay_state: Element<'a, Message, Renderer>, + overlay_state: Element<'a, Message, Theme, Renderer>, /// Toggle the use of the 24h clock of the [`TimePickerOverlay`]. use_24h: bool, /// Toggle the use of the seconds of the [`TimePickerOverlay`]. @@ -97,7 +97,7 @@ where on_submit: F, ) -> Self where - U: Into>>, + U: Into>, F: 'static + Fn(Time) -> Message, { Self { @@ -166,7 +166,7 @@ impl State { } } -impl<'a, Message, Theme> Widget> for TimePicker<'a, Message, Theme> +impl<'a, Message, Theme> Widget for TimePicker<'a, Message, Theme> where Message: 'static + Clone, Theme: StyleSheet + button::StyleSheet + text::StyleSheet + container::StyleSheet, @@ -191,7 +191,7 @@ where self.underlay.as_widget().size() } - fn layout(&self, tree: &mut Tree, renderer: &Renderer, limits: &Limits) -> Node { + fn layout(&self, tree: &mut Tree, renderer: &Renderer, limits: &Limits) -> Node { self.underlay .as_widget() .layout(&mut tree.children[0], renderer, limits) @@ -203,7 +203,7 @@ where event: Event, layout: Layout<'_>, cursor: Cursor, - renderer: &Renderer, + renderer: &Renderer, clipboard: &mut dyn Clipboard, shell: &mut Shell<'_, Message>, viewport: &Rectangle, @@ -226,7 +226,7 @@ where layout: Layout<'_>, cursor: Cursor, viewport: &Rectangle, - renderer: &Renderer, + renderer: &Renderer, ) -> mouse::Interaction { self.underlay.as_widget().mouse_interaction( &state.children[0], @@ -240,7 +240,7 @@ where fn draw( &self, state: &Tree, - renderer: &mut Renderer, + renderer: &mut Renderer, theme: &Theme, style: &renderer::Style, layout: Layout<'_>, @@ -262,8 +262,8 @@ where &'b mut self, state: &'b mut Tree, layout: Layout<'_>, - renderer: &Renderer, - ) -> Option>> { + renderer: &Renderer, + ) -> Option> { let picker_state: &mut State = state.state.downcast_mut(); if !self.show_picker { @@ -291,7 +291,7 @@ where } impl<'a, Message, Theme> From> - for Element<'a, Message, Renderer> + for Element<'a, Message, Theme, Renderer> where Message: 'static + Clone, Theme: 'a + StyleSheet + button::StyleSheet + text::StyleSheet + container::StyleSheet, diff --git a/src/native/wrap.rs b/src/native/wrap.rs index d491091d..e82eb928 100644 --- a/src/native/wrap.rs +++ b/src/native/wrap.rs @@ -14,9 +14,15 @@ use std::marker::PhantomData; /// A container that distributes its contents horizontally. #[allow(missing_debug_implementations)] -pub struct Wrap<'a, Message, Direction, Renderer = crate::Renderer> { +pub struct Wrap< + 'a, + Message, + Direction, + Theme = iced_widget::Theme, + Renderer = iced_widget::Renderer, +> { /// The elements to distribute. - pub elements: Vec>, + pub elements: Vec>, /// The alignment of the [`Wrap`]. pub alignment: Alignment, /// The width of the [`Wrap`]. @@ -39,7 +45,7 @@ pub struct Wrap<'a, Message, Direction, Renderer = crate::Renderer> { _direction: PhantomData, } -impl<'a, Message, Renderer> Wrap<'a, Message, direction::Horizontal, Renderer> { +impl<'a, Message, Theme, Renderer> Wrap<'a, Message, direction::Horizontal, Theme, Renderer> { /// Creates an empty horizontal [`Wrap`]. #[must_use] pub fn new() -> Self { @@ -51,7 +57,7 @@ impl<'a, Message, Renderer> Wrap<'a, Message, direction::Horizontal, Renderer> { /// It expects: /// * the vector containing the [`Element`]s for this [`Wrap`]. #[must_use] - pub fn with_elements(elements: Vec>) -> Self { + pub fn with_elements(elements: Vec>) -> Self { Self { elements, ..Wrap::default() @@ -59,7 +65,7 @@ impl<'a, Message, Renderer> Wrap<'a, Message, direction::Horizontal, Renderer> { } } -impl<'a, Message, Renderer> Wrap<'a, Message, direction::Vertical, Renderer> { +impl<'a, Message, Theme, Renderer> Wrap<'a, Message, direction::Vertical, Theme, Renderer> { /// Creates an empty vertical [`Wrap`]. #[must_use] pub fn new_vertical() -> Self { @@ -71,7 +77,7 @@ impl<'a, Message, Renderer> Wrap<'a, Message, direction::Vertical, Renderer> { /// It expects: /// * the vector containing the [`Element`]s for this [`Wrap`]. #[must_use] - pub fn with_elements_vertical(elements: Vec>) -> Self { + pub fn with_elements_vertical(elements: Vec>) -> Self { Self { elements, ..Wrap::default() @@ -79,7 +85,7 @@ impl<'a, Message, Renderer> Wrap<'a, Message, direction::Vertical, Renderer> { } } -impl<'a, Message, Renderer, Direction> Wrap<'a, Message, Direction, Renderer> { +impl<'a, Message, Renderer, Direction, Theme> Wrap<'a, Message, Direction, Theme, Renderer> { /// Sets the spacing of the [`Wrap`]. #[must_use] pub const fn spacing(mut self, units: f32) -> Self { @@ -147,15 +153,15 @@ impl<'a, Message, Renderer, Direction> Wrap<'a, Message, Direction, Renderer> { #[must_use] pub fn push(mut self, element: E) -> Self where - E: Into>, + E: Into>, { self.elements.push(element.into()); self } } -impl<'a, Message, Renderer, Direction> Widget - for Wrap<'a, Message, Direction, Renderer> +impl<'a, Message, Renderer, Direction, Theme> Widget + for Wrap<'a, Message, Direction, Theme, Renderer> where Self: WrapLayout, Renderer: core::Renderer, @@ -211,7 +217,7 @@ where state: &'b mut Tree, layout: Layout<'_>, renderer: &Renderer, - ) -> Option> { + ) -> Option> { self.elements .iter_mut() .zip(&mut state.children) @@ -246,7 +252,7 @@ where &self, state: &Tree, renderer: &mut Renderer, - theme: &::Theme, + theme: &Theme, style: &renderer::Style, layout: Layout<'_>, cursor: Cursor, @@ -284,33 +290,37 @@ where } } -impl<'a, Message, Renderer> From> - for Element<'a, Message, Renderer> +impl<'a, Message, Theme, Renderer> From> + for Element<'a, Message, Theme, Renderer> where Renderer: 'a + core::Renderer, Message: 'a, + Theme: 'a, { fn from( - wrap: Wrap<'a, Message, direction::Vertical, Renderer>, - ) -> Element<'a, Message, Renderer> { + wrap: Wrap<'a, Message, direction::Vertical, Theme, Renderer>, + ) -> Element<'a, Message, Theme, Renderer> { Element::new(wrap) } } -impl<'a, Message, Renderer> From> - for Element<'a, Message, Renderer> +impl<'a, Message, Theme, Renderer> From> + for Element<'a, Message, Theme, Renderer> where Renderer: 'a + core::Renderer, Message: 'a, + Theme: 'a, { fn from( - wrap: Wrap<'a, Message, direction::Horizontal, Renderer>, - ) -> Element<'a, Message, Renderer> { + wrap: Wrap<'a, Message, direction::Horizontal, Theme, Renderer>, + ) -> Element<'a, Message, Theme, Renderer> { Element::new(wrap) } } -impl<'a, Message, Renderer, Direction> Default for Wrap<'a, Message, Direction, Renderer> { +impl<'a, Message, Renderer, Direction, Theme> Default + for Wrap<'a, Message, Direction, Theme, Renderer> +{ fn default() -> Self { Self { elements: vec![], @@ -336,8 +346,8 @@ where fn inner_layout(&self, tree: &mut Tree, renderer: &Renderer, limits: &Limits) -> Node; } -impl<'a, Message, Renderer> WrapLayout - for Wrap<'a, Message, direction::Horizontal, Renderer> +impl<'a, Message, Theme, Renderer> WrapLayout + for Wrap<'a, Message, direction::Horizontal, Theme, Renderer> where Renderer: core::Renderer + 'a, { @@ -423,8 +433,8 @@ where } } -impl<'a, Message, Renderer> WrapLayout - for Wrap<'a, Message, direction::Vertical, Renderer> +impl<'a, Message, Theme, Renderer> WrapLayout + for Wrap<'a, Message, direction::Vertical, Theme, Renderer> where Renderer: core::Renderer + 'a, { diff --git a/src/style/tab_bar.rs b/src/style/tab_bar.rs index d915ca8e..2a8ba4ad 100644 --- a/src/style/tab_bar.rs +++ b/src/style/tab_bar.rs @@ -9,7 +9,7 @@ use std::rc::Rc; use iced_widget::{ - core::{Background, BorderRadius, Color}, + core::{border::Radius, Background, Color}, style::Theme, }; @@ -41,7 +41,7 @@ pub struct Appearance { pub icon_background: Option, /// How soft/hard the corners of the icon border are - pub icon_border_radius: BorderRadius, + pub icon_border_radius: Radius, /// The text color of the tab labels. pub text_color: Color,