From 03b34931383e701c39c653a7662a616fe21a0947 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 14 Oct 2021 16:07:22 +0700 Subject: Remove trait-specific draw logic in `iced_native` --- examples/custom_widget/src/main.rs | 27 +++-- examples/geometry/src/main.rs | 183 ++++++++++++++++---------------- examples/integration_opengl/src/main.rs | 26 +++-- examples/integration_wgpu/src/main.rs | 30 +++--- 4 files changed, 136 insertions(+), 130 deletions(-) (limited to 'examples') diff --git a/examples/custom_widget/src/main.rs b/examples/custom_widget/src/main.rs index c9ad1905..648e7295 100644 --- a/examples/custom_widget/src/main.rs +++ b/examples/custom_widget/src/main.rs @@ -11,8 +11,7 @@ mod circle { // implemented by `iced_wgpu` and other renderers. use iced_graphics::{Backend, Defaults, Primitive, Renderer}; use iced_native::{ - layout, mouse, Background, Color, Element, Hasher, Layout, Length, - Point, Rectangle, Size, Widget, + layout, Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget, }; pub struct Circle { @@ -55,20 +54,20 @@ mod circle { &self, _renderer: &mut Renderer, _defaults: &Defaults, - layout: Layout<'_>, + _layout: Layout<'_>, _cursor_position: Point, _viewport: &Rectangle, - ) -> (Primitive, mouse::Interaction) { - ( - Primitive::Quad { - bounds: layout.bounds(), - background: Background::Color(Color::BLACK), - border_radius: self.radius, - border_width: 0.0, - border_color: Color::TRANSPARENT, - }, - mouse::Interaction::default(), - ) + ) { + // ( + // Primitive::Quad { + // bounds: layout.bounds(), + // background: Background::Color(Color::BLACK), + // border_radius: self.radius, + // border_width: 0.0, + // border_color: Color::TRANSPARENT, + // }, + // mouse::Interaction::default(), + // ) } } diff --git a/examples/geometry/src/main.rs b/examples/geometry/src/main.rs index e5115493..0745739a 100644 --- a/examples/geometry/src/main.rs +++ b/examples/geometry/src/main.rs @@ -55,98 +55,99 @@ mod rainbow { &self, _renderer: &mut Renderer, _defaults: &Defaults, - layout: Layout<'_>, - cursor_position: Point, + _layout: Layout<'_>, + _cursor_position: Point, _viewport: &Rectangle, - ) -> (Primitive, mouse::Interaction) { - let b = layout.bounds(); - - // R O Y G B I V - let color_r = [1.0, 0.0, 0.0, 1.0]; - let color_o = [1.0, 0.5, 0.0, 1.0]; - let color_y = [1.0, 1.0, 0.0, 1.0]; - let color_g = [0.0, 1.0, 0.0, 1.0]; - let color_gb = [0.0, 1.0, 0.5, 1.0]; - let color_b = [0.0, 0.2, 1.0, 1.0]; - let color_i = [0.5, 0.0, 1.0, 1.0]; - let color_v = [0.75, 0.0, 0.5, 1.0]; - - let posn_center = { - if b.contains(cursor_position) { - [cursor_position.x - b.x, cursor_position.y - b.y] - } else { - [b.width / 2.0, b.height / 2.0] - } - }; - - let posn_tl = [0.0, 0.0]; - let posn_t = [b.width / 2.0, 0.0]; - let posn_tr = [b.width, 0.0]; - let posn_r = [b.width, b.height / 2.0]; - let posn_br = [b.width, b.height]; - let posn_b = [(b.width / 2.0), b.height]; - let posn_bl = [0.0, b.height]; - let posn_l = [0.0, b.height / 2.0]; - - ( - Primitive::Translate { - translation: Vector::new(b.x, b.y), - content: Box::new(Primitive::Mesh2D { - size: b.size(), - buffers: Mesh2D { - vertices: vec![ - Vertex2D { - position: posn_center, - color: [1.0, 1.0, 1.0, 1.0], - }, - Vertex2D { - position: posn_tl, - color: color_r, - }, - Vertex2D { - position: posn_t, - color: color_o, - }, - Vertex2D { - position: posn_tr, - color: color_y, - }, - Vertex2D { - position: posn_r, - color: color_g, - }, - Vertex2D { - position: posn_br, - color: color_gb, - }, - Vertex2D { - position: posn_b, - color: color_b, - }, - Vertex2D { - position: posn_bl, - color: color_i, - }, - Vertex2D { - position: posn_l, - color: color_v, - }, - ], - indices: vec![ - 0, 1, 2, // TL - 0, 2, 3, // T - 0, 3, 4, // TR - 0, 4, 5, // R - 0, 5, 6, // BR - 0, 6, 7, // B - 0, 7, 8, // BL - 0, 8, 1, // L - ], - }, - }), - }, - mouse::Interaction::default(), - ) + ) { + // let b = layout.bounds(); + + // // R O Y G B I V + // let color_r = [1.0, 0.0, 0.0, 1.0]; + // let color_o = [1.0, 0.5, 0.0, 1.0]; + // let color_y = [1.0, 1.0, 0.0, 1.0]; + // let color_g = [0.0, 1.0, 0.0, 1.0]; + // let color_gb = [0.0, 1.0, 0.5, 1.0]; + // let color_b = [0.0, 0.2, 1.0, 1.0]; + // let color_i = [0.5, 0.0, 1.0, 1.0]; + // let color_v = [0.75, 0.0, 0.5, 1.0]; + + // let posn_center = { + // if b.contains(cursor_position) { + // [cursor_position.x - b.x, cursor_position.y - b.y] + // } else { + // [b.width / 2.0, b.height / 2.0] + // } + // }; + + // let posn_tl = [0.0, 0.0]; + // let posn_t = [b.width / 2.0, 0.0]; + // let posn_tr = [b.width, 0.0]; + // let posn_r = [b.width, b.height / 2.0]; + // let posn_br = [b.width, b.height]; + // let posn_b = [(b.width / 2.0), b.height]; + // let posn_bl = [0.0, b.height]; + // let posn_l = [0.0, b.height / 2.0]; + + // ( + // Primitive::Translate { + // translation: Vector::new(b.x, b.y), + // content: Box::new(Primitive::Mesh2D { + // size: b.size(), + // buffers: Mesh2D { + // vertices: vec![ + // Vertex2D { + // position: posn_center, + // color: [1.0, 1.0, 1.0, 1.0], + // }, + // Vertex2D { + // position: posn_tl, + // color: color_r, + // }, + // Vertex2D { + // position: posn_t, + // color: color_o, + // }, + // Vertex2D { + // position: posn_tr, + // color: color_y, + // }, + // Vertex2D { + // position: posn_r, + // color: color_g, + // }, + // Vertex2D { + // position: posn_br, + // color: color_gb, + // }, + // Vertex2D { + // position: posn_b, + // color: color_b, + // }, + // Vertex2D { + // position: posn_bl, + // color: color_i, + // }, + // Vertex2D { + // position: posn_l, + // color: color_v, + // }, + // ], + // indices: vec![ + // 0, 1, 2, // TL + // 0, 2, 3, // T + // 0, 3, 4, // TR + // 0, 4, 5, // R + // 0, 5, 6, // BR + // 0, 6, 7, // B + // 0, 7, 8, // BL + // 0, 8, 1, // L + // ], + // }, + // }), + // }, + // mouse::Interaction::default(), + // ) + // TODO } } diff --git a/examples/integration_opengl/src/main.rs b/examples/integration_opengl/src/main.rs index f80915d2..bab6331e 100644 --- a/examples/integration_opengl/src/main.rs +++ b/examples/integration_opengl/src/main.rs @@ -160,18 +160,22 @@ pub fn main() { } // And then iced on top - let mouse_interaction = renderer.backend_mut().draw( - &gl, - &viewport, - state.primitive(), - &debug.overlay(), - ); + renderer.present(|backend, primitive| { + backend.present( + &gl, + primitive, + &viewport, + &debug.overlay(), + ); + }); + // Update the mouse cursor - windowed_context.window().set_cursor_icon( - iced_winit::conversion::mouse_interaction( - mouse_interaction, - ), - ); + // TODO + // windowed_context.window().set_cursor_icon( + // iced_winit::conversion::mouse_interaction( + // mouse_interaction, + // ), + // ); windowed_context.swap_buffers().unwrap(); } diff --git a/examples/integration_wgpu/src/main.rs b/examples/integration_wgpu/src/main.rs index 7ef148bc..9980acc2 100644 --- a/examples/integration_wgpu/src/main.rs +++ b/examples/integration_wgpu/src/main.rs @@ -195,26 +195,28 @@ pub fn main() { } // And then iced on top - let mouse_interaction = renderer.backend_mut().draw( - &mut device, - &mut staging_belt, - &mut encoder, - &view, - &viewport, - state.primitive(), - &debug.overlay(), - ); + renderer.present(|backend, primitive| { + backend.present( + &mut device, + &mut staging_belt, + &mut encoder, + &view, + primitive, + &viewport, + &debug.overlay(), + ); + }); // Then we submit the work staging_belt.finish(); queue.submit(Some(encoder.finish())); // Update the mouse cursor - window.set_cursor_icon( - iced_winit::conversion::mouse_interaction( - mouse_interaction, - ), - ); + // window.set_cursor_icon( + // iced_winit::conversion::mouse_interaction( + // mouse_interaction, + // ), + // ); // And recall staging buffers local_pool -- cgit From 54a9a232f8110364972a8eef966b7b7477573f4f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 18 Oct 2021 14:48:33 +0700 Subject: Draw scrollbar in `Widget::draw` for `Scrollable` --- examples/scrollable/src/main.rs | 2 +- examples/scrollable/src/style.rs | 4 ++-- examples/styling/src/main.rs | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'examples') diff --git a/examples/scrollable/src/main.rs b/examples/scrollable/src/main.rs index 3416b83d..272f0ce2 100644 --- a/examples/scrollable/src/main.rs +++ b/examples/scrollable/src/main.rs @@ -95,7 +95,7 @@ impl Sandbox for ScrollableDemo { .on_scroll(move |offset| { Message::Scrolled(i, offset) }) - .style(*theme) + .style(theme.clone().into()) .push(Text::new(variant.title)) .push( Button::new( diff --git a/examples/scrollable/src/style.rs b/examples/scrollable/src/style.rs index ae449141..d955f52d 100644 --- a/examples/scrollable/src/style.rs +++ b/examples/scrollable/src/style.rs @@ -34,11 +34,11 @@ impl From for Box { } } -impl From for Box { +impl From for &'static dyn scrollable::StyleSheet { fn from(theme: Theme) -> Self { match theme { Theme::Light => Default::default(), - Theme::Dark => dark::Scrollable.into(), + Theme::Dark => &dark::Scrollable, } } } diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index 81d33ad3..1746d7b4 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -98,7 +98,7 @@ impl Sandbox for Styling { let scrollable = Scrollable::new(&mut self.scroll) .width(Length::Fill) .height(Length::Units(100)) - .style(self.theme) + .style(self.theme.into()) .push(Text::new("Scroll me!")) .push(Space::with_height(Length::Units(800))) .push(Text::new("You did it!")); @@ -212,11 +212,11 @@ mod style { } } - impl From for Box { + impl From for &'static dyn scrollable::StyleSheet { fn from(theme: Theme) -> Self { match theme { Theme::Light => Default::default(), - Theme::Dark => dark::Scrollable.into(), + Theme::Dark => &dark::Scrollable, } } } -- cgit From edea093350e1b576e2b7db50c525e7fa5c3bea9f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 18 Oct 2021 15:19:04 +0700 Subject: Move `Defaults` from `iced_graphics` to `iced_native` --- examples/custom_widget/src/main.rs | 5 +++-- examples/geometry/src/main.rs | 13 ++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'examples') diff --git a/examples/custom_widget/src/main.rs b/examples/custom_widget/src/main.rs index 648e7295..c8188f10 100644 --- a/examples/custom_widget/src/main.rs +++ b/examples/custom_widget/src/main.rs @@ -9,7 +9,8 @@ mod circle { // Of course, you can choose to make the implementation renderer-agnostic, // if you wish to, by creating your own `Renderer` trait, which could be // implemented by `iced_wgpu` and other renderers. - use iced_graphics::{Backend, Defaults, Primitive, Renderer}; + use iced_graphics::renderer::{self, Renderer}; + use iced_graphics::Backend; use iced_native::{ layout, Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget, }; @@ -53,7 +54,7 @@ mod circle { fn draw( &self, _renderer: &mut Renderer, - _defaults: &Defaults, + _style: &renderer::Style, _layout: Layout<'_>, _cursor_position: Point, _viewport: &Rectangle, diff --git a/examples/geometry/src/main.rs b/examples/geometry/src/main.rs index 0745739a..de157267 100644 --- a/examples/geometry/src/main.rs +++ b/examples/geometry/src/main.rs @@ -10,13 +10,11 @@ mod rainbow { // Of course, you can choose to make the implementation renderer-agnostic, // if you wish to, by creating your own `Renderer` trait, which could be // implemented by `iced_wgpu` and other renderers. - use iced_graphics::{ - triangle::{Mesh2D, Vertex2D}, - Backend, Defaults, Primitive, Renderer, - }; + use iced_graphics::renderer::{self, Renderer}; + use iced_graphics::Backend; + use iced_native::{ - layout, mouse, Element, Hasher, Layout, Length, Point, Rectangle, Size, - Vector, Widget, + layout, Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget, }; pub struct Rainbow; @@ -54,11 +52,12 @@ mod rainbow { fn draw( &self, _renderer: &mut Renderer, - _defaults: &Defaults, + _style: &renderer::Style, _layout: Layout<'_>, _cursor_position: Point, _viewport: &Rectangle, ) { + // use iced_graphics::triangle::{Mesh2D, Vertex2D}; // let b = layout.bounds(); // // R O Y G B I V -- cgit From d61cb58d92b6fcd520f665deb093f3747ffd5e5c Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 18 Oct 2021 15:36:32 +0700 Subject: Wire up `container` styling to `iced_native` --- examples/game_of_life/src/main.rs | 2 +- examples/pane_grid/src/main.rs | 34 ++++++++++++++++++++++------------ examples/scrollable/src/main.rs | 4 ++-- examples/scrollable/src/style.rs | 4 ++-- examples/styling/src/main.rs | 6 +++--- examples/tooltip/src/main.rs | 2 +- 6 files changed, 31 insertions(+), 21 deletions(-) (limited to 'examples') diff --git a/examples/game_of_life/src/main.rs b/examples/game_of_life/src/main.rs index 50112618..ee425f44 100644 --- a/examples/game_of_life/src/main.rs +++ b/examples/game_of_life/src/main.rs @@ -150,7 +150,7 @@ impl Application for GameOfLife { Container::new(content) .width(Length::Fill) .height(Length::Fill) - .style(style::Container) + .style(&style::Container) .into() } } diff --git a/examples/pane_grid/src/main.rs b/examples/pane_grid/src/main.rs index 69872bad..844b604d 100644 --- a/examples/pane_grid/src/main.rs +++ b/examples/pane_grid/src/main.rs @@ -177,7 +177,11 @@ impl Application for Example { let title_bar = pane_grid::TitleBar::new(title) .controls(pane.controls.view(id, total_panes, pane.is_pinned)) .padding(10) - .style(style::TitleBar { is_focused }); + .style(if is_focused { + &style::TitleBar::Focused + } else { + &style::TitleBar::Active + }); pane_grid::Content::new(pane.content.view( id, @@ -185,7 +189,11 @@ impl Application for Example { pane.is_pinned, )) .title_bar(title_bar) - .style(style::Pane { is_focused }) + .style(if is_focused { + &style::Pane::Focused + } else { + &style::Pane::Active + }) }) .width(Length::Fill) .height(Length::Fill) @@ -387,14 +395,16 @@ mod style { 0xC4 as f32 / 255.0, ); - pub struct TitleBar { - pub is_focused: bool, + pub enum TitleBar { + Active, + Focused, } impl container::StyleSheet for TitleBar { fn style(&self) -> container::Style { - let pane = Pane { - is_focused: self.is_focused, + let pane = match self { + Self::Active => Pane::Active, + Self::Focused => Pane::Focused, } .style(); @@ -406,8 +416,9 @@ mod style { } } - pub struct Pane { - pub is_focused: bool, + pub enum Pane { + Active, + Focused, } impl container::StyleSheet for Pane { @@ -415,10 +426,9 @@ mod style { container::Style { background: Some(Background::Color(SURFACE)), border_width: 2.0, - border_color: if self.is_focused { - Color::BLACK - } else { - Color::from_rgb(0.7, 0.7, 0.7) + border_color: match self { + Self::Active => Color::from_rgb(0.7, 0.7, 0.7), + Self::Focused => Color::BLACK, }, ..Default::default() } diff --git a/examples/scrollable/src/main.rs b/examples/scrollable/src/main.rs index 272f0ce2..bc20d428 100644 --- a/examples/scrollable/src/main.rs +++ b/examples/scrollable/src/main.rs @@ -164,7 +164,7 @@ impl Sandbox for ScrollableDemo { Container::new(scrollable) .width(Length::Fill) .height(Length::Fill) - .style(*theme), + .style(theme.clone().into()), ) .push(ProgressBar::new( 0.0..=1.0, @@ -190,7 +190,7 @@ impl Sandbox for ScrollableDemo { .height(Length::Fill) .center_x() .center_y() - .style(self.theme) + .style(self.theme.into()) .into() } } diff --git a/examples/scrollable/src/style.rs b/examples/scrollable/src/style.rs index d955f52d..66f3b9d3 100644 --- a/examples/scrollable/src/style.rs +++ b/examples/scrollable/src/style.rs @@ -16,11 +16,11 @@ impl Default for Theme { } } -impl From for Box { +impl From for &'static dyn container::StyleSheet { fn from(theme: Theme) -> Self { match theme { Theme::Light => Default::default(), - Theme::Dark => dark::Container.into(), + Theme::Dark => &dark::Container, } } } diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index 1746d7b4..d8254dd9 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -149,7 +149,7 @@ impl Sandbox for Styling { .height(Length::Fill) .center_x() .center_y() - .style(self.theme) + .style(self.theme.into()) .into() } } @@ -176,11 +176,11 @@ mod style { } } - impl From for Box { + impl From for &'static dyn container::StyleSheet { fn from(theme: Theme) -> Self { match theme { Theme::Light => Default::default(), - Theme::Dark => dark::Container.into(), + Theme::Dark => &dark::Container, } } } diff --git a/examples/tooltip/src/main.rs b/examples/tooltip/src/main.rs index cfeaf6a6..cb2f81df 100644 --- a/examples/tooltip/src/main.rs +++ b/examples/tooltip/src/main.rs @@ -115,7 +115,7 @@ fn tooltip<'a>( ) .gap(5) .padding(10) - .style(style::Tooltip) + .style(&style::Tooltip) .into() } -- cgit From 95acc1deb89c4e75b513edb0f4d53b83c7f75b30 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 18 Oct 2021 15:49:28 +0700 Subject: Implement `Widget::draw` for `custom_widget` example --- examples/custom_widget/Cargo.toml | 1 - examples/custom_widget/src/main.rs | 40 ++++++++++++++++++-------------------- 2 files changed, 19 insertions(+), 22 deletions(-) (limited to 'examples') diff --git a/examples/custom_widget/Cargo.toml b/examples/custom_widget/Cargo.toml index 3942538d..86b0d2a9 100644 --- a/examples/custom_widget/Cargo.toml +++ b/examples/custom_widget/Cargo.toml @@ -8,4 +8,3 @@ publish = false [dependencies] iced = { path = "../.." } iced_native = { path = "../../native" } -iced_graphics = { path = "../../graphics" } diff --git a/examples/custom_widget/src/main.rs b/examples/custom_widget/src/main.rs index c8188f10..78a4339e 100644 --- a/examples/custom_widget/src/main.rs +++ b/examples/custom_widget/src/main.rs @@ -9,10 +9,11 @@ mod circle { // Of course, you can choose to make the implementation renderer-agnostic, // if you wish to, by creating your own `Renderer` trait, which could be // implemented by `iced_wgpu` and other renderers. - use iced_graphics::renderer::{self, Renderer}; - use iced_graphics::Backend; + use iced_native::layout::{self, Layout}; + use iced_native::renderer; use iced_native::{ - layout, Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget, + Background, Color, Element, Hasher, Length, Point, Rectangle, Size, + Widget, }; pub struct Circle { @@ -25,9 +26,9 @@ mod circle { } } - impl Widget> for Circle + impl Widget for Circle where - B: Backend, + Renderer: renderer::Renderer, { fn width(&self) -> Length { Length::Shrink @@ -39,7 +40,7 @@ mod circle { fn layout( &self, - _renderer: &Renderer, + _renderer: &Renderer, _limits: &layout::Limits, ) -> layout::Node { layout::Node::new(Size::new(self.radius * 2.0, self.radius * 2.0)) @@ -53,30 +54,27 @@ mod circle { fn draw( &self, - _renderer: &mut Renderer, + renderer: &mut Renderer, _style: &renderer::Style, - _layout: Layout<'_>, + layout: Layout<'_>, _cursor_position: Point, _viewport: &Rectangle, ) { - // ( - // Primitive::Quad { - // bounds: layout.bounds(), - // background: Background::Color(Color::BLACK), - // border_radius: self.radius, - // border_width: 0.0, - // border_color: Color::TRANSPARENT, - // }, - // mouse::Interaction::default(), - // ) + renderer.fill_rectangle(renderer::Quad { + bounds: layout.bounds(), + background: Background::Color(Color::BLACK), + border_radius: self.radius, + border_width: 0.0, + border_color: Color::TRANSPARENT, + }); } } - impl<'a, Message, B> Into>> for Circle + impl<'a, Message, Renderer> Into> for Circle where - B: Backend, + Renderer: renderer::Renderer, { - fn into(self) -> Element<'a, Message, Renderer> { + fn into(self) -> Element<'a, Message, Renderer> { Element::new(self) } } -- cgit From 3140cdc4babcefc444f1c1d30eb0f5f4ed1df054 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 18 Oct 2021 16:02:30 +0700 Subject: Wire up styling to `Button` in `iced_native` --- examples/game_of_life/src/main.rs | 6 +++--- examples/pane_grid/src/main.rs | 10 +++++----- examples/pokedex/src/main.rs | 2 +- examples/stopwatch/src/main.rs | 6 +++--- examples/styling/src/main.rs | 8 ++++---- examples/todos/src/main.rs | 40 ++++++++++++++++++--------------------- examples/tour/src/main.rs | 4 ++-- 7 files changed, 36 insertions(+), 40 deletions(-) (limited to 'examples') diff --git a/examples/game_of_life/src/main.rs b/examples/game_of_life/src/main.rs index ee425f44..3e94bd44 100644 --- a/examples/game_of_life/src/main.rs +++ b/examples/game_of_life/src/main.rs @@ -834,12 +834,12 @@ impl Controls { Text::new(if is_playing { "Pause" } else { "Play" }), ) .on_press(Message::TogglePlayback) - .style(style::Button), + .style(&style::Button), ) .push( Button::new(&mut self.next_button, Text::new("Next")) .on_press(Message::Next) - .style(style::Button), + .style(&style::Button), ); let speed_controls = Row::new() @@ -883,7 +883,7 @@ impl Controls { .push( Button::new(&mut self.clear_button, Text::new("Clear")) .on_press(Message::Clear) - .style(style::Clear), + .style(&style::Clear), ) .into() } diff --git a/examples/pane_grid/src/main.rs b/examples/pane_grid/src/main.rs index 844b604d..4126485d 100644 --- a/examples/pane_grid/src/main.rs +++ b/examples/pane_grid/src/main.rs @@ -158,7 +158,7 @@ impl Application for Example { let pin_button = Button::new(&mut pane.pin_button, Text::new(text).size(14)) .on_press(Message::TogglePin(id)) - .style(style::Button::Pin) + .style(&style::Button::Pin) .padding(3); let title = Row::with_children(vec![ @@ -316,13 +316,13 @@ impl Content { split_horizontally, "Split horizontally", Message::Split(pane_grid::Axis::Horizontal, pane), - style::Button::Primary, + &style::Button::Primary, )) .push(button( split_vertically, "Split vertically", Message::Split(pane_grid::Axis::Vertical, pane), - style::Button::Primary, + &style::Button::Primary, )); if total_panes > 1 && !is_pinned { @@ -330,7 +330,7 @@ impl Content { close, "Close", Message::Close(pane), - style::Button::Destructive, + &style::Button::Destructive, )); } @@ -364,7 +364,7 @@ impl Controls { ) -> Element { let mut button = Button::new(&mut self.close, Text::new("Close").size(14)) - .style(style::Button::Control) + .style(&style::Button::Control) .padding(3); if total_panes > 1 && !is_pinned { button = button.on_press(Message::Close(pane)); diff --git a/examples/pokedex/src/main.rs b/examples/pokedex/src/main.rs index c99240a1..c9930158 100644 --- a/examples/pokedex/src/main.rs +++ b/examples/pokedex/src/main.rs @@ -243,7 +243,7 @@ impl From for Error { fn button<'a>(state: &'a mut button::State, text: &str) -> Button<'a, Message> { Button::new(state, Text::new(text)) .padding(10) - .style(style::Button::Primary) + .style(&style::Button::Primary) } mod style { diff --git a/examples/stopwatch/src/main.rs b/examples/stopwatch/src/main.rs index dc8a4de7..e6743620 100644 --- a/examples/stopwatch/src/main.rs +++ b/examples/stopwatch/src/main.rs @@ -112,15 +112,15 @@ impl Application for Stopwatch { let toggle_button = { let (label, color) = match self.state { - State::Idle => ("Start", style::Button::Primary), - State::Ticking { .. } => ("Stop", style::Button::Destructive), + State::Idle => ("Start", &style::Button::Primary), + State::Ticking { .. } => ("Stop", &style::Button::Destructive), }; button(&mut self.toggle, label, color).on_press(Message::Toggle) }; let reset_button = - button(&mut self.reset, "Reset", style::Button::Secondary) + button(&mut self.reset, "Reset", &style::Button::Secondary) .on_press(Message::Reset); let controls = Row::new() diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index d8254dd9..38ab0411 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -82,7 +82,7 @@ impl Sandbox for Styling { let button = Button::new(&mut self.button, Text::new("Submit")) .padding(10) .on_press(Message::ButtonPressed) - .style(self.theme); + .style(self.theme.into()); let slider = Slider::new( &mut self.slider, @@ -203,11 +203,11 @@ mod style { } } - impl From for Box { + impl From for &'static dyn button::StyleSheet { fn from(theme: Theme) -> Self { match theme { - Theme::Light => light::Button.into(), - Theme::Dark => dark::Button.into(), + Theme::Light => &light::Button, + Theme::Dark => &dark::Button, } } } diff --git a/examples/todos/src/main.rs b/examples/todos/src/main.rs index 11f23fd4..1734772d 100644 --- a/examples/todos/src/main.rs +++ b/examples/todos/src/main.rs @@ -304,7 +304,7 @@ impl Task { Button::new(edit_button, edit_icon()) .on_press(TaskMessage::Edit) .padding(10) - .style(style::Button::Icon), + .style(&style::Button::Icon), ) .into() } @@ -335,7 +335,7 @@ impl Task { ) .on_press(TaskMessage::Delete) .padding(10) - .style(style::Button::Destructive), + .style(&style::Button::Destructive), ) .into() } @@ -363,8 +363,10 @@ impl Controls { let filter_button = |state, label, filter, current_filter| { let label = Text::new(label).size(16); let button = - Button::new(state, label).style(style::Button::Filter { - selected: filter == current_filter, + Button::new(state, label).style(if filter == current_filter { + &style::Button::FilterSelected + } else { + &style::Button::FilterActive }); button.on_press(Message::FilterChanged(filter)).padding(8) @@ -602,7 +604,8 @@ mod style { use iced::{button, Background, Color, Vector}; pub enum Button { - Filter { selected: bool }, + FilterActive, + FilterSelected, Icon, Destructive, } @@ -610,20 +613,15 @@ mod style { impl button::StyleSheet for Button { fn active(&self) -> button::Style { match self { - Button::Filter { selected } => { - if *selected { - button::Style { - background: Some(Background::Color( - Color::from_rgb(0.2, 0.2, 0.7), - )), - border_radius: 10.0, - text_color: Color::WHITE, - ..button::Style::default() - } - } else { - button::Style::default() - } - } + Button::FilterActive => button::Style::default(), + Button::FilterSelected => button::Style { + background: Some(Background::Color(Color::from_rgb( + 0.2, 0.2, 0.7, + ))), + border_radius: 10.0, + text_color: Color::WHITE, + ..button::Style::default() + }, Button::Icon => button::Style { text_color: Color::from_rgb(0.5, 0.5, 0.5), ..button::Style::default() @@ -646,9 +644,7 @@ mod style { button::Style { text_color: match self { Button::Icon => Color::from_rgb(0.2, 0.2, 0.7), - Button::Filter { selected } if !selected => { - Color::from_rgb(0.2, 0.2, 0.7) - } + Button::FilterActive => Color::from_rgb(0.2, 0.2, 0.7), _ => active.text_color, }, shadow_offset: active.shadow_offset + Vector::new(0.0, 1.0), diff --git a/examples/tour/src/main.rs b/examples/tour/src/main.rs index b5af48c7..176d275c 100644 --- a/examples/tour/src/main.rs +++ b/examples/tour/src/main.rs @@ -64,7 +64,7 @@ impl Sandbox for Tour { controls = controls.push( button(back_button, "Back") .on_press(Message::BackPressed) - .style(style::Button::Secondary), + .style(&style::Button::Secondary), ); } @@ -74,7 +74,7 @@ impl Sandbox for Tour { controls = controls.push( button(next_button, "Next") .on_press(Message::NextPressed) - .style(style::Button::Primary), + .style(&style::Button::Primary), ); } -- cgit From be97a5d502df8c8b23704f5a8a0d425f4eff2215 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 18 Oct 2021 16:43:18 +0700 Subject: Introduce `mouse_interaction` method to `Widget` trait --- examples/integration_opengl/src/main.rs | 1 - examples/integration_wgpu/src/main.rs | 1 - 2 files changed, 2 deletions(-) (limited to 'examples') diff --git a/examples/integration_opengl/src/main.rs b/examples/integration_opengl/src/main.rs index bab6331e..ef79b889 100644 --- a/examples/integration_opengl/src/main.rs +++ b/examples/integration_opengl/src/main.rs @@ -68,7 +68,6 @@ pub fn main() { let mut state = program::State::new( controls, viewport.logical_size(), - conversion::cursor_position(cursor_position, viewport.scale_factor()), &mut renderer, &mut debug, ); diff --git a/examples/integration_wgpu/src/main.rs b/examples/integration_wgpu/src/main.rs index 9980acc2..c2c857d2 100644 --- a/examples/integration_wgpu/src/main.rs +++ b/examples/integration_wgpu/src/main.rs @@ -93,7 +93,6 @@ pub fn main() { let mut state = program::State::new( controls, viewport.logical_size(), - conversion::cursor_position(cursor_position, viewport.scale_factor()), &mut renderer, &mut debug, ); -- cgit From 11bcb1342796a6fabc7c5b89a15c22c754b014ce Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 20 Oct 2021 15:50:42 +0700 Subject: Wire up styling to `Slider` in `iced_native` --- examples/game_of_life/src/main.rs | 2 +- examples/styling/src/main.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'examples') diff --git a/examples/game_of_life/src/main.rs b/examples/game_of_life/src/main.rs index 3e94bd44..2c027421 100644 --- a/examples/game_of_life/src/main.rs +++ b/examples/game_of_life/src/main.rs @@ -853,7 +853,7 @@ impl Controls { speed as f32, Message::SpeedChanged, ) - .style(style::Slider), + .style(&style::Slider), ) .push(Text::new(format!("x{}", speed)).size(16)); diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index 38ab0411..34d18fc9 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -90,7 +90,7 @@ impl Sandbox for Styling { self.slider_value, Message::SliderChanged, ) - .style(self.theme); + .style(self.theme.into()); let progress_bar = ProgressBar::new(0.0..=100.0, self.slider_value).style(self.theme); @@ -221,11 +221,11 @@ mod style { } } - impl From for Box { + impl From for &'static dyn slider::StyleSheet { fn from(theme: Theme) -> Self { match theme { Theme::Light => Default::default(), - Theme::Dark => dark::Slider.into(), + Theme::Dark => &dark::Slider, } } } -- cgit From e914888f57394e4b67b40e42f1ad9df4ae8147e6 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 20 Oct 2021 18:40:39 +0700 Subject: Implement `Widget::draw` for `TextInput` --- examples/styling/src/main.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'examples') diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index 34d18fc9..cca94c8f 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -77,7 +77,7 @@ impl Sandbox for Styling { ) .padding(10) .size(20) - .style(self.theme); + .style(self.theme.into()); let button = Button::new(&mut self.button, Text::new("Submit")) .padding(10) @@ -194,11 +194,11 @@ mod style { } } - impl From for Box { + impl From for &'static dyn text_input::StyleSheet { fn from(theme: Theme) -> Self { match theme { Theme::Light => Default::default(), - Theme::Dark => dark::TextInput.into(), + Theme::Dark => &dark::TextInput, } } } -- cgit From d39ad717ed0ab85acbe935d7ab883166b36e7bc7 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 20 Oct 2021 19:06:53 +0700 Subject: Wire up styling to `Radio` in `iced_native` --- examples/scrollable/src/main.rs | 2 +- examples/scrollable/src/style.rs | 4 ++-- examples/styling/src/main.rs | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'examples') diff --git a/examples/scrollable/src/main.rs b/examples/scrollable/src/main.rs index bc20d428..2f1c5676 100644 --- a/examples/scrollable/src/main.rs +++ b/examples/scrollable/src/main.rs @@ -76,7 +76,7 @@ impl Sandbox for ScrollableDemo { Some(*theme), Message::ThemeChanged, ) - .style(*theme), + .style(theme.clone().into()), ) }, ); diff --git a/examples/scrollable/src/style.rs b/examples/scrollable/src/style.rs index 66f3b9d3..d7d64374 100644 --- a/examples/scrollable/src/style.rs +++ b/examples/scrollable/src/style.rs @@ -25,11 +25,11 @@ impl From for &'static dyn container::StyleSheet { } } -impl From for Box { +impl From for &'static dyn radio::StyleSheet { fn from(theme: Theme) -> Self { match theme { Theme::Light => Default::default(), - Theme::Dark => dark::Radio.into(), + Theme::Dark => &dark::Radio, } } } diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index cca94c8f..7e9b01ab 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -64,7 +64,7 @@ impl Sandbox for Styling { Some(self.theme), Message::ThemeChanged, ) - .style(self.theme), + .style(self.theme.into()), ) }, ); @@ -185,11 +185,11 @@ mod style { } } - impl From for Box { + impl From for &'static dyn radio::StyleSheet { fn from(theme: Theme) -> Self { match theme { Theme::Light => Default::default(), - Theme::Dark => dark::Radio.into(), + Theme::Dark => &dark::Radio, } } } -- cgit From 7c08c6bd138207b862933ee479752a4f1d18c4f2 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 21 Oct 2021 18:50:27 +0700 Subject: Remove `Renderer` trait for `Checkbox` --- examples/styling/src/main.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'examples') diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index 7e9b01ab..5ce54e23 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -108,7 +108,7 @@ impl Sandbox for Styling { "Check me!", Message::CheckboxToggled, ) - .style(self.theme); + .style(self.theme.into()); let toggler = Toggler::new( self.toggler_value, @@ -239,11 +239,11 @@ mod style { } } - impl From for Box { + impl From for &'static dyn checkbox::StyleSheet { fn from(theme: Theme) -> Self { match theme { Theme::Light => Default::default(), - Theme::Dark => dark::Checkbox.into(), + Theme::Dark => &dark::Checkbox, } } } -- cgit From e5e477aa692e33eb639e4d3acbc073fdb47f9c9a Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 30 Oct 2021 20:42:09 +0700 Subject: Migrate `geometry` example to new `Renderer` API --- examples/geometry/src/main.rs | 190 +++++++++++++++++++++--------------------- 1 file changed, 95 insertions(+), 95 deletions(-) (limited to 'examples') diff --git a/examples/geometry/src/main.rs b/examples/geometry/src/main.rs index de157267..6ef12013 100644 --- a/examples/geometry/src/main.rs +++ b/examples/geometry/src/main.rs @@ -11,10 +11,11 @@ mod rainbow { // if you wish to, by creating your own `Renderer` trait, which could be // implemented by `iced_wgpu` and other renderers. use iced_graphics::renderer::{self, Renderer}; - use iced_graphics::Backend; + use iced_graphics::{Backend, Primitive}; use iced_native::{ - layout, Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget, + layout, Element, Hasher, Layout, Length, Point, Rectangle, Size, + Vector, Widget, }; pub struct Rainbow; @@ -51,102 +52,101 @@ mod rainbow { fn draw( &self, - _renderer: &mut Renderer, + renderer: &mut Renderer, _style: &renderer::Style, - _layout: Layout<'_>, - _cursor_position: Point, + layout: Layout<'_>, + cursor_position: Point, _viewport: &Rectangle, ) { - // use iced_graphics::triangle::{Mesh2D, Vertex2D}; - // let b = layout.bounds(); - - // // R O Y G B I V - // let color_r = [1.0, 0.0, 0.0, 1.0]; - // let color_o = [1.0, 0.5, 0.0, 1.0]; - // let color_y = [1.0, 1.0, 0.0, 1.0]; - // let color_g = [0.0, 1.0, 0.0, 1.0]; - // let color_gb = [0.0, 1.0, 0.5, 1.0]; - // let color_b = [0.0, 0.2, 1.0, 1.0]; - // let color_i = [0.5, 0.0, 1.0, 1.0]; - // let color_v = [0.75, 0.0, 0.5, 1.0]; - - // let posn_center = { - // if b.contains(cursor_position) { - // [cursor_position.x - b.x, cursor_position.y - b.y] - // } else { - // [b.width / 2.0, b.height / 2.0] - // } - // }; - - // let posn_tl = [0.0, 0.0]; - // let posn_t = [b.width / 2.0, 0.0]; - // let posn_tr = [b.width, 0.0]; - // let posn_r = [b.width, b.height / 2.0]; - // let posn_br = [b.width, b.height]; - // let posn_b = [(b.width / 2.0), b.height]; - // let posn_bl = [0.0, b.height]; - // let posn_l = [0.0, b.height / 2.0]; - - // ( - // Primitive::Translate { - // translation: Vector::new(b.x, b.y), - // content: Box::new(Primitive::Mesh2D { - // size: b.size(), - // buffers: Mesh2D { - // vertices: vec![ - // Vertex2D { - // position: posn_center, - // color: [1.0, 1.0, 1.0, 1.0], - // }, - // Vertex2D { - // position: posn_tl, - // color: color_r, - // }, - // Vertex2D { - // position: posn_t, - // color: color_o, - // }, - // Vertex2D { - // position: posn_tr, - // color: color_y, - // }, - // Vertex2D { - // position: posn_r, - // color: color_g, - // }, - // Vertex2D { - // position: posn_br, - // color: color_gb, - // }, - // Vertex2D { - // position: posn_b, - // color: color_b, - // }, - // Vertex2D { - // position: posn_bl, - // color: color_i, - // }, - // Vertex2D { - // position: posn_l, - // color: color_v, - // }, - // ], - // indices: vec![ - // 0, 1, 2, // TL - // 0, 2, 3, // T - // 0, 3, 4, // TR - // 0, 4, 5, // R - // 0, 5, 6, // BR - // 0, 6, 7, // B - // 0, 7, 8, // BL - // 0, 8, 1, // L - // ], - // }, - // }), - // }, - // mouse::Interaction::default(), - // ) - // TODO + use iced_graphics::triangle::{Mesh2D, Vertex2D}; + use iced_native::Renderer as _; + + let b = layout.bounds(); + + // R O Y G B I V + let color_r = [1.0, 0.0, 0.0, 1.0]; + let color_o = [1.0, 0.5, 0.0, 1.0]; + let color_y = [1.0, 1.0, 0.0, 1.0]; + let color_g = [0.0, 1.0, 0.0, 1.0]; + let color_gb = [0.0, 1.0, 0.5, 1.0]; + let color_b = [0.0, 0.2, 1.0, 1.0]; + let color_i = [0.5, 0.0, 1.0, 1.0]; + let color_v = [0.75, 0.0, 0.5, 1.0]; + + let posn_center = { + if b.contains(cursor_position) { + [cursor_position.x - b.x, cursor_position.y - b.y] + } else { + [b.width / 2.0, b.height / 2.0] + } + }; + + let posn_tl = [0.0, 0.0]; + let posn_t = [b.width / 2.0, 0.0]; + let posn_tr = [b.width, 0.0]; + let posn_r = [b.width, b.height / 2.0]; + let posn_br = [b.width, b.height]; + let posn_b = [(b.width / 2.0), b.height]; + let posn_bl = [0.0, b.height]; + let posn_l = [0.0, b.height / 2.0]; + + let mesh = Primitive::Mesh2D { + size: b.size(), + buffers: Mesh2D { + vertices: vec![ + Vertex2D { + position: posn_center, + color: [1.0, 1.0, 1.0, 1.0], + }, + Vertex2D { + position: posn_tl, + color: color_r, + }, + Vertex2D { + position: posn_t, + color: color_o, + }, + Vertex2D { + position: posn_tr, + color: color_y, + }, + Vertex2D { + position: posn_r, + color: color_g, + }, + Vertex2D { + position: posn_br, + color: color_gb, + }, + Vertex2D { + position: posn_b, + color: color_b, + }, + Vertex2D { + position: posn_bl, + color: color_i, + }, + Vertex2D { + position: posn_l, + color: color_v, + }, + ], + indices: vec![ + 0, 1, 2, // TL + 0, 2, 3, // T + 0, 3, 4, // TR + 0, 4, 5, // R + 0, 5, 6, // BR + 0, 6, 7, // B + 0, 7, 8, // BL + 0, 8, 1, // L + ], + }, + }; + + renderer.with_translation(Vector::new(b.x, b.y), |renderer| { + renderer.draw_primitive(mesh); + }); } } -- cgit From 0aafcde0ef1533c9eeba0379de8c0082e30c7504 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 31 Oct 2021 15:35:12 +0700 Subject: Remove `widget` module re-exports in `iced_native` --- examples/integration_opengl/src/controls.rs | 8 +++----- examples/integration_wgpu/src/controls.rs | 7 +++---- 2 files changed, 6 insertions(+), 9 deletions(-) (limited to 'examples') diff --git a/examples/integration_opengl/src/controls.rs b/examples/integration_opengl/src/controls.rs index fa5aa91d..f387b4e5 100644 --- a/examples/integration_opengl/src/controls.rs +++ b/examples/integration_opengl/src/controls.rs @@ -1,9 +1,7 @@ use iced_glow::Renderer; -use iced_glutin::slider; -use iced_glutin::{ - Alignment, Color, Column, Command, Element, Length, Program, Row, Slider, - Text, -}; +use iced_glutin::widget::slider::{self, Slider}; +use iced_glutin::widget::{Column, Row, Text}; +use iced_glutin::{Alignment, Color, Command, Element, Length, Program}; pub struct Controls { background_color: Color, diff --git a/examples/integration_wgpu/src/controls.rs b/examples/integration_wgpu/src/controls.rs index 414eb9ce..4f110bd2 100644 --- a/examples/integration_wgpu/src/controls.rs +++ b/examples/integration_wgpu/src/controls.rs @@ -1,8 +1,7 @@ use iced_wgpu::Renderer; -use iced_winit::{ - slider, Alignment, Color, Column, Command, Element, Length, Program, Row, - Slider, Text, -}; +use iced_winit::widget::slider::{self, Slider}; +use iced_winit::widget::{Column, Row, Text}; +use iced_winit::{Alignment, Color, Command, Element, Length, Program}; pub struct Controls { background_color: Color, -- cgit From 844fecd602cc338ca1338a1289e5552100d4d3d5 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 31 Oct 2021 16:35:16 +0700 Subject: Rewrite cursor icon logic for `integration_opengl` example --- examples/integration_opengl/src/main.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'examples') diff --git a/examples/integration_opengl/src/main.rs b/examples/integration_opengl/src/main.rs index ef79b889..f0ff2076 100644 --- a/examples/integration_opengl/src/main.rs +++ b/examples/integration_opengl/src/main.rs @@ -169,12 +169,11 @@ pub fn main() { }); // Update the mouse cursor - // TODO - // windowed_context.window().set_cursor_icon( - // iced_winit::conversion::mouse_interaction( - // mouse_interaction, - // ), - // ); + windowed_context.window().set_cursor_icon( + iced_winit::conversion::mouse_interaction( + state.mouse_interaction(), + ), + ); windowed_context.swap_buffers().unwrap(); } -- cgit From 661cb5736ecc6e7810591216aa541db582a2fcc0 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 31 Oct 2021 16:36:34 +0700 Subject: Rewrite cursor icon logic for `integration_wgpu` example --- examples/integration_wgpu/src/main.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'examples') diff --git a/examples/integration_wgpu/src/main.rs b/examples/integration_wgpu/src/main.rs index c2c857d2..e1d691f0 100644 --- a/examples/integration_wgpu/src/main.rs +++ b/examples/integration_wgpu/src/main.rs @@ -211,11 +211,11 @@ pub fn main() { queue.submit(Some(encoder.finish())); // Update the mouse cursor - // window.set_cursor_icon( - // iced_winit::conversion::mouse_interaction( - // mouse_interaction, - // ), - // ); + window.set_cursor_icon( + iced_winit::conversion::mouse_interaction( + state.mouse_interaction(), + ), + ); // And recall staging buffers local_pool -- cgit From d36ce33a95c277ee8fe45555df17daf21ef02ef8 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 31 Oct 2021 16:53:18 +0700 Subject: Reintroduce `Box` for `style_sheet` in `Button` --- examples/game_of_life/src/main.rs | 6 +++--- examples/pane_grid/src/main.rs | 10 +++++----- examples/pokedex/src/main.rs | 2 +- examples/stopwatch/src/main.rs | 6 +++--- examples/styling/src/main.rs | 8 ++++---- examples/todos/src/main.rs | 8 ++++---- examples/tour/src/main.rs | 4 ++-- 7 files changed, 22 insertions(+), 22 deletions(-) (limited to 'examples') diff --git a/examples/game_of_life/src/main.rs b/examples/game_of_life/src/main.rs index 2c027421..3b5bfa5a 100644 --- a/examples/game_of_life/src/main.rs +++ b/examples/game_of_life/src/main.rs @@ -834,12 +834,12 @@ impl Controls { Text::new(if is_playing { "Pause" } else { "Play" }), ) .on_press(Message::TogglePlayback) - .style(&style::Button), + .style(style::Button), ) .push( Button::new(&mut self.next_button, Text::new("Next")) .on_press(Message::Next) - .style(&style::Button), + .style(style::Button), ); let speed_controls = Row::new() @@ -883,7 +883,7 @@ impl Controls { .push( Button::new(&mut self.clear_button, Text::new("Clear")) .on_press(Message::Clear) - .style(&style::Clear), + .style(style::Clear), ) .into() } diff --git a/examples/pane_grid/src/main.rs b/examples/pane_grid/src/main.rs index 4126485d..844b604d 100644 --- a/examples/pane_grid/src/main.rs +++ b/examples/pane_grid/src/main.rs @@ -158,7 +158,7 @@ impl Application for Example { let pin_button = Button::new(&mut pane.pin_button, Text::new(text).size(14)) .on_press(Message::TogglePin(id)) - .style(&style::Button::Pin) + .style(style::Button::Pin) .padding(3); let title = Row::with_children(vec![ @@ -316,13 +316,13 @@ impl Content { split_horizontally, "Split horizontally", Message::Split(pane_grid::Axis::Horizontal, pane), - &style::Button::Primary, + style::Button::Primary, )) .push(button( split_vertically, "Split vertically", Message::Split(pane_grid::Axis::Vertical, pane), - &style::Button::Primary, + style::Button::Primary, )); if total_panes > 1 && !is_pinned { @@ -330,7 +330,7 @@ impl Content { close, "Close", Message::Close(pane), - &style::Button::Destructive, + style::Button::Destructive, )); } @@ -364,7 +364,7 @@ impl Controls { ) -> Element { let mut button = Button::new(&mut self.close, Text::new("Close").size(14)) - .style(&style::Button::Control) + .style(style::Button::Control) .padding(3); if total_panes > 1 && !is_pinned { button = button.on_press(Message::Close(pane)); diff --git a/examples/pokedex/src/main.rs b/examples/pokedex/src/main.rs index c9930158..c99240a1 100644 --- a/examples/pokedex/src/main.rs +++ b/examples/pokedex/src/main.rs @@ -243,7 +243,7 @@ impl From for Error { fn button<'a>(state: &'a mut button::State, text: &str) -> Button<'a, Message> { Button::new(state, Text::new(text)) .padding(10) - .style(&style::Button::Primary) + .style(style::Button::Primary) } mod style { diff --git a/examples/stopwatch/src/main.rs b/examples/stopwatch/src/main.rs index e6743620..dc8a4de7 100644 --- a/examples/stopwatch/src/main.rs +++ b/examples/stopwatch/src/main.rs @@ -112,15 +112,15 @@ impl Application for Stopwatch { let toggle_button = { let (label, color) = match self.state { - State::Idle => ("Start", &style::Button::Primary), - State::Ticking { .. } => ("Stop", &style::Button::Destructive), + State::Idle => ("Start", style::Button::Primary), + State::Ticking { .. } => ("Stop", style::Button::Destructive), }; button(&mut self.toggle, label, color).on_press(Message::Toggle) }; let reset_button = - button(&mut self.reset, "Reset", &style::Button::Secondary) + button(&mut self.reset, "Reset", style::Button::Secondary) .on_press(Message::Reset); let controls = Row::new() diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index 5ce54e23..9e31c383 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -82,7 +82,7 @@ impl Sandbox for Styling { let button = Button::new(&mut self.button, Text::new("Submit")) .padding(10) .on_press(Message::ButtonPressed) - .style(self.theme.into()); + .style(self.theme); let slider = Slider::new( &mut self.slider, @@ -203,11 +203,11 @@ mod style { } } - impl From for &'static dyn button::StyleSheet { + impl<'a> From for Box { fn from(theme: Theme) -> Self { match theme { - Theme::Light => &light::Button, - Theme::Dark => &dark::Button, + Theme::Light => light::Button.into(), + Theme::Dark => dark::Button.into(), } } } diff --git a/examples/todos/src/main.rs b/examples/todos/src/main.rs index 1734772d..5ad8c208 100644 --- a/examples/todos/src/main.rs +++ b/examples/todos/src/main.rs @@ -304,7 +304,7 @@ impl Task { Button::new(edit_button, edit_icon()) .on_press(TaskMessage::Edit) .padding(10) - .style(&style::Button::Icon), + .style(style::Button::Icon), ) .into() } @@ -335,7 +335,7 @@ impl Task { ) .on_press(TaskMessage::Delete) .padding(10) - .style(&style::Button::Destructive), + .style(style::Button::Destructive), ) .into() } @@ -364,9 +364,9 @@ impl Controls { let label = Text::new(label).size(16); let button = Button::new(state, label).style(if filter == current_filter { - &style::Button::FilterSelected + style::Button::FilterSelected } else { - &style::Button::FilterActive + style::Button::FilterActive }); button.on_press(Message::FilterChanged(filter)).padding(8) diff --git a/examples/tour/src/main.rs b/examples/tour/src/main.rs index 176d275c..b5af48c7 100644 --- a/examples/tour/src/main.rs +++ b/examples/tour/src/main.rs @@ -64,7 +64,7 @@ impl Sandbox for Tour { controls = controls.push( button(back_button, "Back") .on_press(Message::BackPressed) - .style(&style::Button::Secondary), + .style(style::Button::Secondary), ); } @@ -74,7 +74,7 @@ impl Sandbox for Tour { controls = controls.push( button(next_button, "Next") .on_press(Message::NextPressed) - .style(&style::Button::Primary), + .style(style::Button::Primary), ); } -- cgit From fcc282bd76c88f389d510411b0ae73e1a4eaf317 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 31 Oct 2021 16:58:02 +0700 Subject: Reintroduce `Box` for `style_sheet` in `Checkbox` --- examples/styling/src/main.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'examples') diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index 9e31c383..e8829b53 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -108,7 +108,7 @@ impl Sandbox for Styling { "Check me!", Message::CheckboxToggled, ) - .style(self.theme.into()); + .style(self.theme); let toggler = Toggler::new( self.toggler_value, @@ -239,11 +239,11 @@ mod style { } } - impl From for &'static dyn checkbox::StyleSheet { + impl<'a> From for Box { fn from(theme: Theme) -> Self { match theme { Theme::Light => Default::default(), - Theme::Dark => &dark::Checkbox, + Theme::Dark => dark::Checkbox.into(), } } } -- cgit From 40a5de581144886571504b762719f057dbb2e871 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 31 Oct 2021 17:02:59 +0700 Subject: Reintroduce `Box` for `style_sheet` in `Container` --- examples/game_of_life/src/main.rs | 2 +- examples/pane_grid/src/main.rs | 8 ++++---- examples/scrollable/src/main.rs | 4 ++-- examples/scrollable/src/style.rs | 4 ++-- examples/styling/src/main.rs | 6 +++--- examples/tooltip/src/main.rs | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) (limited to 'examples') diff --git a/examples/game_of_life/src/main.rs b/examples/game_of_life/src/main.rs index 3b5bfa5a..01dcadc6 100644 --- a/examples/game_of_life/src/main.rs +++ b/examples/game_of_life/src/main.rs @@ -150,7 +150,7 @@ impl Application for GameOfLife { Container::new(content) .width(Length::Fill) .height(Length::Fill) - .style(&style::Container) + .style(style::Container) .into() } } diff --git a/examples/pane_grid/src/main.rs b/examples/pane_grid/src/main.rs index 844b604d..8225e9e7 100644 --- a/examples/pane_grid/src/main.rs +++ b/examples/pane_grid/src/main.rs @@ -178,9 +178,9 @@ impl Application for Example { .controls(pane.controls.view(id, total_panes, pane.is_pinned)) .padding(10) .style(if is_focused { - &style::TitleBar::Focused + style::TitleBar::Focused } else { - &style::TitleBar::Active + style::TitleBar::Active }); pane_grid::Content::new(pane.content.view( @@ -190,9 +190,9 @@ impl Application for Example { )) .title_bar(title_bar) .style(if is_focused { - &style::Pane::Focused + style::Pane::Focused } else { - &style::Pane::Active + style::Pane::Active }) }) .width(Length::Fill) diff --git a/examples/scrollable/src/main.rs b/examples/scrollable/src/main.rs index 2f1c5676..2eaf197e 100644 --- a/examples/scrollable/src/main.rs +++ b/examples/scrollable/src/main.rs @@ -164,7 +164,7 @@ impl Sandbox for ScrollableDemo { Container::new(scrollable) .width(Length::Fill) .height(Length::Fill) - .style(theme.clone().into()), + .style(*theme), ) .push(ProgressBar::new( 0.0..=1.0, @@ -190,7 +190,7 @@ impl Sandbox for ScrollableDemo { .height(Length::Fill) .center_x() .center_y() - .style(self.theme.into()) + .style(self.theme) .into() } } diff --git a/examples/scrollable/src/style.rs b/examples/scrollable/src/style.rs index d7d64374..068483cb 100644 --- a/examples/scrollable/src/style.rs +++ b/examples/scrollable/src/style.rs @@ -16,11 +16,11 @@ impl Default for Theme { } } -impl From for &'static dyn container::StyleSheet { +impl<'a> From for Box { fn from(theme: Theme) -> Self { match theme { Theme::Light => Default::default(), - Theme::Dark => &dark::Container, + Theme::Dark => dark::Container.into(), } } } diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index e8829b53..3692ad1e 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -149,7 +149,7 @@ impl Sandbox for Styling { .height(Length::Fill) .center_x() .center_y() - .style(self.theme.into()) + .style(self.theme) .into() } } @@ -176,11 +176,11 @@ mod style { } } - impl From for &'static dyn container::StyleSheet { + impl<'a> From for Box { fn from(theme: Theme) -> Self { match theme { Theme::Light => Default::default(), - Theme::Dark => &dark::Container, + Theme::Dark => dark::Container.into(), } } } diff --git a/examples/tooltip/src/main.rs b/examples/tooltip/src/main.rs index cb2f81df..cfeaf6a6 100644 --- a/examples/tooltip/src/main.rs +++ b/examples/tooltip/src/main.rs @@ -115,7 +115,7 @@ fn tooltip<'a>( ) .gap(5) .padding(10) - .style(&style::Tooltip) + .style(style::Tooltip) .into() } -- cgit From bd7b086ec1f9d428945f05fb12bda157f9e77dfd Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 31 Oct 2021 17:14:10 +0700 Subject: Reintroduce `Box` for `style_sheet` in `Radio` --- examples/scrollable/src/main.rs | 2 +- examples/scrollable/src/style.rs | 4 ++-- examples/styling/src/main.rs | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'examples') diff --git a/examples/scrollable/src/main.rs b/examples/scrollable/src/main.rs index 2eaf197e..272f0ce2 100644 --- a/examples/scrollable/src/main.rs +++ b/examples/scrollable/src/main.rs @@ -76,7 +76,7 @@ impl Sandbox for ScrollableDemo { Some(*theme), Message::ThemeChanged, ) - .style(theme.clone().into()), + .style(*theme), ) }, ); diff --git a/examples/scrollable/src/style.rs b/examples/scrollable/src/style.rs index 068483cb..3c8e5234 100644 --- a/examples/scrollable/src/style.rs +++ b/examples/scrollable/src/style.rs @@ -25,11 +25,11 @@ impl<'a> From for Box { } } -impl From for &'static dyn radio::StyleSheet { +impl<'a> From for Box { fn from(theme: Theme) -> Self { match theme { Theme::Light => Default::default(), - Theme::Dark => &dark::Radio, + Theme::Dark => dark::Radio.into(), } } } diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index 3692ad1e..73f965d9 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -64,7 +64,7 @@ impl Sandbox for Styling { Some(self.theme), Message::ThemeChanged, ) - .style(self.theme.into()), + .style(self.theme), ) }, ); @@ -185,11 +185,11 @@ mod style { } } - impl From for &'static dyn radio::StyleSheet { + impl<'a> From for Box { fn from(theme: Theme) -> Self { match theme { Theme::Light => Default::default(), - Theme::Dark => &dark::Radio, + Theme::Dark => dark::Radio.into(), } } } -- cgit From eed19dcf81334d0849744f1918ba880d5a7acc1c Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 31 Oct 2021 17:39:24 +0700 Subject: Reintroduce `Box` for `style_sheet` in `Scrollable` --- examples/scrollable/src/main.rs | 2 +- examples/scrollable/src/style.rs | 4 ++-- examples/styling/src/main.rs | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'examples') diff --git a/examples/scrollable/src/main.rs b/examples/scrollable/src/main.rs index 272f0ce2..3416b83d 100644 --- a/examples/scrollable/src/main.rs +++ b/examples/scrollable/src/main.rs @@ -95,7 +95,7 @@ impl Sandbox for ScrollableDemo { .on_scroll(move |offset| { Message::Scrolled(i, offset) }) - .style(theme.clone().into()) + .style(*theme) .push(Text::new(variant.title)) .push( Button::new( diff --git a/examples/scrollable/src/style.rs b/examples/scrollable/src/style.rs index 3c8e5234..ec1f13db 100644 --- a/examples/scrollable/src/style.rs +++ b/examples/scrollable/src/style.rs @@ -34,11 +34,11 @@ impl<'a> From for Box { } } -impl From for &'static dyn scrollable::StyleSheet { +impl<'a> From for Box { fn from(theme: Theme) -> Self { match theme { Theme::Light => Default::default(), - Theme::Dark => &dark::Scrollable, + Theme::Dark => dark::Scrollable.into(), } } } diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index 73f965d9..a0ba2607 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -98,7 +98,7 @@ impl Sandbox for Styling { let scrollable = Scrollable::new(&mut self.scroll) .width(Length::Fill) .height(Length::Units(100)) - .style(self.theme.into()) + .style(self.theme) .push(Text::new("Scroll me!")) .push(Space::with_height(Length::Units(800))) .push(Text::new("You did it!")); @@ -212,11 +212,11 @@ mod style { } } - impl From for &'static dyn scrollable::StyleSheet { + impl<'a> From for Box { fn from(theme: Theme) -> Self { match theme { Theme::Light => Default::default(), - Theme::Dark => &dark::Scrollable, + Theme::Dark => dark::Scrollable.into(), } } } -- cgit From 0c76e0307ff7d4450c354812f8a25047f24948b4 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 31 Oct 2021 17:42:43 +0700 Subject: Reintroduce `Box` for `style_sheet` in `Slider` --- examples/game_of_life/src/main.rs | 2 +- examples/styling/src/main.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'examples') diff --git a/examples/game_of_life/src/main.rs b/examples/game_of_life/src/main.rs index 01dcadc6..50112618 100644 --- a/examples/game_of_life/src/main.rs +++ b/examples/game_of_life/src/main.rs @@ -853,7 +853,7 @@ impl Controls { speed as f32, Message::SpeedChanged, ) - .style(&style::Slider), + .style(style::Slider), ) .push(Text::new(format!("x{}", speed)).size(16)); diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index a0ba2607..b33e26de 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -90,7 +90,7 @@ impl Sandbox for Styling { self.slider_value, Message::SliderChanged, ) - .style(self.theme.into()); + .style(self.theme); let progress_bar = ProgressBar::new(0.0..=100.0, self.slider_value).style(self.theme); @@ -221,11 +221,11 @@ mod style { } } - impl From for &'static dyn slider::StyleSheet { + impl<'a> From for Box { fn from(theme: Theme) -> Self { match theme { Theme::Light => Default::default(), - Theme::Dark => &dark::Slider, + Theme::Dark => dark::Slider.into(), } } } -- cgit From 0d3c9ef7bd3d0a0abecdf8e8b5391e32773ca20e Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 31 Oct 2021 17:45:57 +0700 Subject: Reintroduce `Box` for `style_sheet` in `TextInput` --- examples/styling/src/main.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'examples') diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index b33e26de..262db03e 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -77,7 +77,7 @@ impl Sandbox for Styling { ) .padding(10) .size(20) - .style(self.theme.into()); + .style(self.theme); let button = Button::new(&mut self.button, Text::new("Submit")) .padding(10) @@ -194,11 +194,11 @@ mod style { } } - impl From for &'static dyn text_input::StyleSheet { + impl<'a> From for Box { fn from(theme: Theme) -> Self { match theme { Theme::Light => Default::default(), - Theme::Dark => &dark::TextInput, + Theme::Dark => dark::TextInput.into(), } } } -- cgit From 023aded2772f0cd6abd716fe5c8624d5d22e21fa Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 4 Nov 2021 19:22:29 +0700 Subject: Rename `fill_rectangle` to `fill_quad` in `Renderer` --- examples/custom_widget/src/main.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'examples') diff --git a/examples/custom_widget/src/main.rs b/examples/custom_widget/src/main.rs index 78a4339e..b32cb83d 100644 --- a/examples/custom_widget/src/main.rs +++ b/examples/custom_widget/src/main.rs @@ -12,8 +12,7 @@ mod circle { use iced_native::layout::{self, Layout}; use iced_native::renderer; use iced_native::{ - Background, Color, Element, Hasher, Length, Point, Rectangle, Size, - Widget, + Color, Element, Hasher, Length, Point, Rectangle, Size, Widget, }; pub struct Circle { @@ -60,13 +59,15 @@ mod circle { _cursor_position: Point, _viewport: &Rectangle, ) { - renderer.fill_rectangle(renderer::Quad { - bounds: layout.bounds(), - background: Background::Color(Color::BLACK), - border_radius: self.radius, - border_width: 0.0, - border_color: Color::TRANSPARENT, - }); + renderer.fill_quad( + renderer::Quad { + bounds: layout.bounds(), + border_radius: self.radius, + border_width: 0.0, + border_color: Color::TRANSPARENT, + }, + Color::BLACK, + ); } } -- cgit From 9fe65ed729c75a8401765cf373345aaba93352ca Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 5 Nov 2021 15:38:27 +0700 Subject: Rename `Renderer::present` to `with_primitives` --- examples/integration_opengl/src/main.rs | 2 +- examples/integration_wgpu/src/main.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'examples') diff --git a/examples/integration_opengl/src/main.rs b/examples/integration_opengl/src/main.rs index f0ff2076..3b63f22e 100644 --- a/examples/integration_opengl/src/main.rs +++ b/examples/integration_opengl/src/main.rs @@ -159,7 +159,7 @@ pub fn main() { } // And then iced on top - renderer.present(|backend, primitive| { + renderer.with_primitives(|backend, primitive| { backend.present( &gl, primitive, diff --git a/examples/integration_wgpu/src/main.rs b/examples/integration_wgpu/src/main.rs index d1000748..35a69a7d 100644 --- a/examples/integration_wgpu/src/main.rs +++ b/examples/integration_wgpu/src/main.rs @@ -195,7 +195,7 @@ pub fn main() { } // And then iced on top - renderer.present(|backend, primitive| { + renderer.with_primitives(|backend, primitive| { backend.present( &mut device, &mut staging_belt, -- cgit