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` --- native/src/widget/scrollable.rs | 117 ++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 77 deletions(-) (limited to 'native/src/widget/scrollable.rs') diff --git a/native/src/widget/scrollable.rs b/native/src/widget/scrollable.rs index a8e467d3..1c897dc5 100644 --- a/native/src/widget/scrollable.rs +++ b/native/src/widget/scrollable.rs @@ -1,5 +1,4 @@ //! Navigate an endless amount of content with a scrollbar. -use crate::column; use crate::event::{self, Event}; use crate::layout; use crate::mouse; @@ -381,57 +380,45 @@ where layout: Layout<'_>, cursor_position: Point, _viewport: &Rectangle, - ) -> Renderer::Output { - let bounds = layout.bounds(); - let content_layout = layout.children().next().unwrap(); - let content_bounds = content_layout.bounds(); - let offset = self.state.offset(bounds, content_bounds); - let scrollbar = renderer.scrollbar( - bounds, - content_bounds, - offset, - self.scrollbar_width, - self.scrollbar_margin, - self.scroller_width, - ); - - let is_mouse_over = bounds.contains(cursor_position); - let is_mouse_over_scrollbar = scrollbar - .as_ref() - .map(|scrollbar| scrollbar.is_mouse_over(cursor_position)) - .unwrap_or(false); - - let content = { - let cursor_position = if is_mouse_over && !is_mouse_over_scrollbar { - Point::new(cursor_position.x, cursor_position.y + offset as f32) - } else { - Point::new(cursor_position.x, -1.0) - }; - - self.content.draw( - renderer, - defaults, - content_layout, - cursor_position, - &Rectangle { - y: bounds.y + offset as f32, - ..bounds - }, - ) - }; - - self::Renderer::draw( - renderer, - &self.state, - bounds, - content_layout.bounds(), - is_mouse_over, - is_mouse_over_scrollbar, - scrollbar, - offset, - &self.style, - content, - ) + ) { + // TODO + // let bounds = layout.bounds(); + // let content_layout = layout.children().next().unwrap(); + // let content_bounds = content_layout.bounds(); + // let offset = self.state.offset(bounds, content_bounds); + // let scrollbar = renderer.scrollbar( + // bounds, + // content_bounds, + // offset, + // self.scrollbar_width, + // self.scrollbar_margin, + // self.scroller_width, + // ); + + // let is_mouse_over = bounds.contains(cursor_position); + // let is_mouse_over_scrollbar = scrollbar + // .as_ref() + // .map(|scrollbar| scrollbar.is_mouse_over(cursor_position)) + // .unwrap_or(false); + + // let content = { + // let cursor_position = if is_mouse_over && !is_mouse_over_scrollbar { + // Point::new(cursor_position.x, cursor_position.y + offset as f32) + // } else { + // Point::new(cursor_position.x, -1.0) + // }; + + // self.content.draw( + // renderer, + // defaults, + // content_layout, + // cursor_position, + // &Rectangle { + // y: bounds.y + offset as f32, + // ..bounds + // }, + // ) + // }; } fn hash_layout(&self, state: &mut Hasher) { @@ -635,7 +622,7 @@ pub struct Scroller { /// able to use a [`Scrollable`] in your user interface. /// /// [renderer]: crate::renderer -pub trait Renderer: column::Renderer + Sized { +pub trait Renderer: crate::Renderer + Sized { /// The style supported by this renderer. type Style: Default; @@ -650,30 +637,6 @@ pub trait Renderer: column::Renderer + Sized { scrollbar_margin: u16, scroller_width: u16, ) -> Option; - - /// Draws the [`Scrollable`]. - /// - /// It receives: - /// - the [`State`] of the [`Scrollable`] - /// - the bounds of the [`Scrollable`] widget - /// - the bounds of the [`Scrollable`] content - /// - whether the mouse is over the [`Scrollable`] or not - /// - whether the mouse is over the [`Scrollbar`] or not - /// - a optional [`Scrollbar`] to be rendered - /// - the scrolling offset - /// - the drawn content - fn draw( - &mut self, - scrollable: &State, - bounds: Rectangle, - content_bounds: Rectangle, - is_mouse_over: bool, - is_mouse_over_scrollbar: bool, - scrollbar: Option, - offset: u32, - style: &Self::Style, - content: Self::Output, - ) -> Self::Output; } impl<'a, Message, Renderer> From> -- cgit From dfceee99aad9462f09ca61081e68e1decb2fed92 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 14 Oct 2021 17:15:29 +0700 Subject: Implement `Widget::draw` for `Scrollable` Rendering the scroller is still WIP --- native/src/widget/scrollable.rs | 126 ++++++++++++++++++++++++++++------------ 1 file changed, 88 insertions(+), 38 deletions(-) (limited to 'native/src/widget/scrollable.rs') diff --git a/native/src/widget/scrollable.rs b/native/src/widget/scrollable.rs index 1c897dc5..ba3d3dd6 100644 --- a/native/src/widget/scrollable.rs +++ b/native/src/widget/scrollable.rs @@ -381,44 +381,94 @@ where cursor_position: Point, _viewport: &Rectangle, ) { - // TODO - // let bounds = layout.bounds(); - // let content_layout = layout.children().next().unwrap(); - // let content_bounds = content_layout.bounds(); - // let offset = self.state.offset(bounds, content_bounds); - // let scrollbar = renderer.scrollbar( - // bounds, - // content_bounds, - // offset, - // self.scrollbar_width, - // self.scrollbar_margin, - // self.scroller_width, - // ); - - // let is_mouse_over = bounds.contains(cursor_position); - // let is_mouse_over_scrollbar = scrollbar - // .as_ref() - // .map(|scrollbar| scrollbar.is_mouse_over(cursor_position)) - // .unwrap_or(false); - - // let content = { - // let cursor_position = if is_mouse_over && !is_mouse_over_scrollbar { - // Point::new(cursor_position.x, cursor_position.y + offset as f32) - // } else { - // Point::new(cursor_position.x, -1.0) - // }; - - // self.content.draw( - // renderer, - // defaults, - // content_layout, - // cursor_position, - // &Rectangle { - // y: bounds.y + offset as f32, - // ..bounds - // }, - // ) - // }; + let bounds = layout.bounds(); + let content_layout = layout.children().next().unwrap(); + let content_bounds = content_layout.bounds(); + let offset = self.state.offset(bounds, content_bounds); + let scrollbar = renderer.scrollbar( + bounds, + content_bounds, + offset, + self.scrollbar_width, + self.scrollbar_margin, + self.scroller_width, + ); + + let is_mouse_over = bounds.contains(cursor_position); + let is_mouse_over_scrollbar = scrollbar + .as_ref() + .map(|scrollbar| scrollbar.is_mouse_over(cursor_position)) + .unwrap_or(false); + + let cursor_position = if is_mouse_over && !is_mouse_over_scrollbar { + Point::new(cursor_position.x, cursor_position.y + offset as f32) + } else { + Point::new(cursor_position.x, -1.0) + }; + + if let Some(scrollbar) = scrollbar { + renderer.with_layer(bounds, Vector::new(0, offset), |renderer| { + self.content.draw( + renderer, + defaults, + content_layout, + cursor_position, + &Rectangle { + y: bounds.y + offset as f32, + ..bounds + }, + ); + }); + + // TODO: Draw scroller + // let style = if self.state.is_scroller_grabbed() { + // style_sheet.dragging() + // } else if is_mouse_over_scrollbar { + // style_sheet.hovered() + // } else { + // style_sheet.active() + // }; + + // let is_scrollbar_visible = + // style.background.is_some() || style.border_width > 0.0; + + // if is_mouse_over + // || self.state.is_scroller_grabbed() + // || is_scrollbar_visible + // { + // // Primitive::Quad { + // // bounds: scrollbar.scroller.bounds, + // // background: Background::Color(style.scroller.color), + // // border_radius: style.scroller.border_radius, + // // border_width: style.scroller.border_width, + // // border_color: style.scroller.border_color, + // // } + // }; + + // TODO: Draw scrollbar + // if is_scrollbar_visible { + // Primitive::Quad { + // bounds: scrollbar.bounds, + // background: style + // .background + // .unwrap_or(Background::Color(Color::TRANSPARENT)), + // border_radius: style.border_radius, + // border_width: style.border_width, + // border_color: style.border_color, + // } + //} + } else { + self.content.draw( + renderer, + defaults, + content_layout, + cursor_position, + &Rectangle { + y: bounds.y + offset as f32, + ..bounds + }, + ); + } } fn hash_layout(&self, state: &mut Hasher) { -- 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` --- native/src/widget/scrollable.rs | 207 ++++++++++++++++++++++------------------ 1 file changed, 113 insertions(+), 94 deletions(-) (limited to 'native/src/widget/scrollable.rs') diff --git a/native/src/widget/scrollable.rs b/native/src/widget/scrollable.rs index ba3d3dd6..98357928 100644 --- a/native/src/widget/scrollable.rs +++ b/native/src/widget/scrollable.rs @@ -3,18 +3,21 @@ use crate::event::{self, Event}; use crate::layout; use crate::mouse; use crate::overlay; +use crate::renderer; use crate::touch; use crate::{ - Alignment, Clipboard, Column, Element, Hasher, Layout, Length, Padding, - Point, Rectangle, Size, Vector, Widget, + Alignment, Background, Clipboard, Color, Column, Element, Hasher, Layout, + Length, Padding, Point, Rectangle, Size, Vector, Widget, }; use std::{f32, hash::Hash, u32}; +pub use iced_style::scrollable::StyleSheet; + /// A widget that can vertically display an infinite amount of content with a /// scrollbar. #[allow(missing_debug_implementations)] -pub struct Scrollable<'a, Message, Renderer: self::Renderer> { +pub struct Scrollable<'a, Message, Renderer> { state: &'a mut State, height: Length, max_height: u32, @@ -23,10 +26,10 @@ pub struct Scrollable<'a, Message, Renderer: self::Renderer> { scroller_width: u16, content: Column<'a, Message, Renderer>, on_scroll: Option Message>>, - style: Renderer::Style, + style_sheet: &'a dyn StyleSheet, } -impl<'a, Message, Renderer: self::Renderer> Scrollable<'a, Message, Renderer> { +impl<'a, Message, Renderer: crate::Renderer> Scrollable<'a, Message, Renderer> { /// Creates a new [`Scrollable`] with the given [`State`]. pub fn new(state: &'a mut State) -> Self { Scrollable { @@ -38,7 +41,7 @@ impl<'a, Message, Renderer: self::Renderer> Scrollable<'a, Message, Renderer> { scroller_width: 10, content: Column::new(), on_scroll: None, - style: Renderer::Style::default(), + style_sheet: Default::default(), } } @@ -119,8 +122,11 @@ impl<'a, Message, Renderer: self::Renderer> Scrollable<'a, Message, Renderer> { } /// Sets the style of the [`Scrollable`] . - pub fn style(mut self, style: impl Into) -> Self { - self.style = style.into(); + pub fn style<'b>(mut self, style_sheet: &'b dyn StyleSheet) -> Self + where + 'b: 'a, + { + self.style_sheet = style_sheet; self } @@ -150,12 +156,63 @@ impl<'a, Message, Renderer: self::Renderer> Scrollable<'a, Message, Renderer> { )); } } + + fn scrollbar( + &self, + bounds: Rectangle, + content_bounds: Rectangle, + ) -> Option { + let offset = self.state.offset(bounds, content_bounds); + + if content_bounds.height > bounds.height { + let outer_width = self.scrollbar_width.max(self.scroller_width) + + 2 * self.scrollbar_margin; + + let outer_bounds = Rectangle { + x: bounds.x + bounds.width - outer_width as f32, + y: bounds.y, + width: outer_width as f32, + height: bounds.height, + }; + + let scrollbar_bounds = Rectangle { + x: bounds.x + bounds.width + - f32::from(outer_width / 2 + self.scrollbar_width / 2), + y: bounds.y, + width: self.scrollbar_width as f32, + height: bounds.height, + }; + + let ratio = bounds.height / content_bounds.height; + let scroller_height = bounds.height * ratio; + let y_offset = offset as f32 * ratio; + + let scroller_bounds = Rectangle { + x: bounds.x + bounds.width + - f32::from(outer_width / 2 + self.scroller_width / 2), + y: scrollbar_bounds.y + y_offset, + width: self.scroller_width as f32, + height: scroller_height, + }; + + Some(Scrollbar { + outer_bounds, + bounds: scrollbar_bounds, + margin: self.scrollbar_margin, + scroller: Scroller { + bounds: scroller_bounds, + }, + }) + } else { + None + } + } } impl<'a, Message, Renderer> Widget for Scrollable<'a, Message, Renderer> where - Renderer: self::Renderer, + Renderer: crate::Renderer, { fn width(&self) -> Length { Widget::::width(&self.content) @@ -201,15 +258,7 @@ where let content = layout.children().next().unwrap(); let content_bounds = content.bounds(); - let offset = self.state.offset(bounds, content_bounds); - let scrollbar = renderer.scrollbar( - bounds, - content_bounds, - offset, - self.scrollbar_width, - self.scrollbar_margin, - self.scroller_width, - ); + let scrollbar = self.scrollbar(bounds, content_bounds); let is_mouse_over_scrollbar = scrollbar .as_ref() .map(|scrollbar| scrollbar.is_mouse_over(cursor_position)) @@ -385,14 +434,7 @@ where let content_layout = layout.children().next().unwrap(); let content_bounds = content_layout.bounds(); let offset = self.state.offset(bounds, content_bounds); - let scrollbar = renderer.scrollbar( - bounds, - content_bounds, - offset, - self.scrollbar_width, - self.scrollbar_margin, - self.scroller_width, - ); + let scrollbar = self.scrollbar(bounds, content_bounds); let is_mouse_over = bounds.contains(cursor_position); let is_mouse_over_scrollbar = scrollbar @@ -420,43 +462,43 @@ where ); }); - // TODO: Draw scroller - // let style = if self.state.is_scroller_grabbed() { - // style_sheet.dragging() - // } else if is_mouse_over_scrollbar { - // style_sheet.hovered() - // } else { - // style_sheet.active() - // }; - - // let is_scrollbar_visible = - // style.background.is_some() || style.border_width > 0.0; - - // if is_mouse_over - // || self.state.is_scroller_grabbed() - // || is_scrollbar_visible - // { - // // Primitive::Quad { - // // bounds: scrollbar.scroller.bounds, - // // background: Background::Color(style.scroller.color), - // // border_radius: style.scroller.border_radius, - // // border_width: style.scroller.border_width, - // // border_color: style.scroller.border_color, - // // } - // }; - - // TODO: Draw scrollbar - // if is_scrollbar_visible { - // Primitive::Quad { - // bounds: scrollbar.bounds, - // background: style - // .background - // .unwrap_or(Background::Color(Color::TRANSPARENT)), - // border_radius: style.border_radius, - // border_width: style.border_width, - // border_color: style.border_color, - // } - //} + let style = if self.state.is_scroller_grabbed() { + self.style_sheet.dragging() + } else if is_mouse_over_scrollbar { + self.style_sheet.hovered() + } else { + self.style_sheet.active() + }; + + let is_scrollbar_visible = + style.background.is_some() || style.border_width > 0.0; + + renderer.with_layer(bounds, Vector::new(0, 0), |renderer| { + if is_scrollbar_visible { + renderer.fill_rectangle(renderer::Quad { + bounds: scrollbar.bounds, + background: style + .background + .unwrap_or(Background::Color(Color::TRANSPARENT)), + border_radius: style.border_radius, + border_width: style.border_width, + border_color: style.border_color, + }); + } + + if is_mouse_over + || self.state.is_scroller_grabbed() + || is_scrollbar_visible + { + renderer.fill_rectangle(renderer::Quad { + bounds: scrollbar.scroller.bounds, + background: Background::Color(style.scroller.color), + border_radius: style.scroller.border_radius, + border_width: style.scroller.border_width, + border_color: style.scroller.border_color, + }); + } + }); } else { self.content.draw( renderer, @@ -614,19 +656,19 @@ impl State { /// The scrollbar of a [`Scrollable`]. #[derive(Debug)] -pub struct Scrollbar { +struct Scrollbar { /// The outer bounds of the scrollable, including the [`Scrollbar`] and /// [`Scroller`]. - pub outer_bounds: Rectangle, + outer_bounds: Rectangle, /// The bounds of the [`Scrollbar`]. - pub bounds: Rectangle, + bounds: Rectangle, /// The margin within the [`Scrollbar`]. - pub margin: u16, + margin: u16, /// The bounds of the [`Scroller`]. - pub scroller: Scroller, + scroller: Scroller, } impl Scrollbar { @@ -661,38 +703,15 @@ impl Scrollbar { /// The handle of a [`Scrollbar`]. #[derive(Debug, Clone, Copy)] -pub struct Scroller { +struct Scroller { /// The bounds of the [`Scroller`]. - pub bounds: Rectangle, -} - -/// The renderer of a [`Scrollable`]. -/// -/// Your [renderer] will need to implement this trait before being -/// able to use a [`Scrollable`] in your user interface. -/// -/// [renderer]: crate::renderer -pub trait Renderer: crate::Renderer + Sized { - /// The style supported by this renderer. - type Style: Default; - - /// Returns the [`Scrollbar`] given the bounds and content bounds of a - /// [`Scrollable`]. - fn scrollbar( - &self, - bounds: Rectangle, - content_bounds: Rectangle, - offset: u32, - scrollbar_width: u16, - scrollbar_margin: u16, - scroller_width: u16, - ) -> Option; + bounds: Rectangle, } impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where - Renderer: 'a + self::Renderer, + Renderer: 'a + crate::Renderer, Message: 'a, { fn from( -- 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` --- native/src/widget/scrollable.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'native/src/widget/scrollable.rs') diff --git a/native/src/widget/scrollable.rs b/native/src/widget/scrollable.rs index 98357928..63da539f 100644 --- a/native/src/widget/scrollable.rs +++ b/native/src/widget/scrollable.rs @@ -425,7 +425,7 @@ where fn draw( &self, renderer: &mut Renderer, - defaults: &Renderer::Defaults, + style: &renderer::Style, layout: Layout<'_>, cursor_position: Point, _viewport: &Rectangle, @@ -452,7 +452,7 @@ where renderer.with_layer(bounds, Vector::new(0, offset), |renderer| { self.content.draw( renderer, - defaults, + style, content_layout, cursor_position, &Rectangle { @@ -502,7 +502,7 @@ where } else { self.content.draw( renderer, - defaults, + style, content_layout, cursor_position, &Rectangle { -- 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` --- native/src/widget/scrollable.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'native/src/widget/scrollable.rs') diff --git a/native/src/widget/scrollable.rs b/native/src/widget/scrollable.rs index 63da539f..ac5b3e4f 100644 --- a/native/src/widget/scrollable.rs +++ b/native/src/widget/scrollable.rs @@ -122,10 +122,7 @@ impl<'a, Message, Renderer: crate::Renderer> Scrollable<'a, Message, Renderer> { } /// Sets the style of the [`Scrollable`] . - pub fn style<'b>(mut self, style_sheet: &'b dyn StyleSheet) -> Self - where - 'b: 'a, - { + pub fn style(mut self, style_sheet: &'a dyn StyleSheet) -> Self { self.style_sheet = style_sheet; self } -- cgit From 9a4fb82b5818f10e96d2f185a7e5a1f1fce3305c Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 18 Oct 2021 16:53:50 +0700 Subject: Implement `Widget::mouse_interaction` for `Scrollable` --- native/src/widget/scrollable.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'native/src/widget/scrollable.rs') diff --git a/native/src/widget/scrollable.rs b/native/src/widget/scrollable.rs index ac5b3e4f..76badbde 100644 --- a/native/src/widget/scrollable.rs +++ b/native/src/widget/scrollable.rs @@ -419,6 +419,45 @@ where event::Status::Ignored } + fn mouse_interaction( + &self, + layout: Layout<'_>, + _viewport: &Rectangle, + cursor_position: Point, + ) -> mouse::Interaction { + let bounds = layout.bounds(); + let content_layout = layout.children().next().unwrap(); + let content_bounds = content_layout.bounds(); + let scrollbar = self.scrollbar(bounds, content_bounds); + + let is_mouse_over = bounds.contains(cursor_position); + let is_mouse_over_scrollbar = scrollbar + .as_ref() + .map(|scrollbar| scrollbar.is_mouse_over(cursor_position)) + .unwrap_or(false); + + if is_mouse_over_scrollbar || self.state.is_scroller_grabbed() { + mouse::Interaction::Idle + } else { + let offset = self.state.offset(bounds, content_bounds); + + let cursor_position = if is_mouse_over && !is_mouse_over_scrollbar { + Point::new(cursor_position.x, cursor_position.y + offset as f32) + } else { + Point::new(cursor_position.x, -1.0) + }; + + self.content.mouse_interaction( + content_layout, + &Rectangle { + y: bounds.y + offset as f32, + ..bounds + }, + cursor_position, + ) + } + } + fn draw( &self, renderer: &mut Renderer, -- cgit From 4a11cbd99445338619dfaf1f327dbc25b2983cb7 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 25 Oct 2021 16:16:35 +0700 Subject: Implement `Widget::mouse_interaction` for `PaneGrid` ... and fix rendering of drag interaction in `PaneGrid` by introducing an explicit `with_translation` method to `Renderer` and simplifying the `with_layer` and `Clip` primitive. --- native/src/widget/scrollable.rs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'native/src/widget/scrollable.rs') diff --git a/native/src/widget/scrollable.rs b/native/src/widget/scrollable.rs index 76badbde..563ea370 100644 --- a/native/src/widget/scrollable.rs +++ b/native/src/widget/scrollable.rs @@ -485,15 +485,20 @@ where }; if let Some(scrollbar) = scrollbar { - renderer.with_layer(bounds, Vector::new(0, offset), |renderer| { - self.content.draw( - renderer, - style, - content_layout, - cursor_position, - &Rectangle { - y: bounds.y + offset as f32, - ..bounds + renderer.with_layer(bounds, |renderer| { + renderer.with_translation( + Vector::new(0.0, -(offset as f32)), + |renderer| { + self.content.draw( + renderer, + style, + content_layout, + cursor_position, + &Rectangle { + y: bounds.y + offset as f32, + ..bounds + }, + ); }, ); }); @@ -509,7 +514,7 @@ where let is_scrollbar_visible = style.background.is_some() || style.border_width > 0.0; - renderer.with_layer(bounds, Vector::new(0, 0), |renderer| { + renderer.with_layer(bounds, |renderer| { if is_scrollbar_visible { renderer.fill_rectangle(renderer::Quad { bounds: scrollbar.bounds, -- cgit From d127dbd08ec314e6a2c65961134bdc7b28a1e4aa Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 28 Oct 2021 17:55:07 +0700 Subject: Fix scrollbar clipping in `Scrollable` draw logic --- native/src/widget/scrollable.rs | 57 +++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 25 deletions(-) (limited to 'native/src/widget/scrollable.rs') diff --git a/native/src/widget/scrollable.rs b/native/src/widget/scrollable.rs index 563ea370..4b514818 100644 --- a/native/src/widget/scrollable.rs +++ b/native/src/widget/scrollable.rs @@ -514,32 +514,39 @@ where let is_scrollbar_visible = style.background.is_some() || style.border_width > 0.0; - renderer.with_layer(bounds, |renderer| { - if is_scrollbar_visible { - renderer.fill_rectangle(renderer::Quad { - bounds: scrollbar.bounds, - background: style - .background - .unwrap_or(Background::Color(Color::TRANSPARENT)), - border_radius: style.border_radius, - border_width: style.border_width, - border_color: style.border_color, - }); - } + renderer.with_layer( + Rectangle { + width: bounds.width + 2.0, + height: bounds.height + 2.0, + ..bounds + }, + |renderer| { + if is_scrollbar_visible { + renderer.fill_rectangle(renderer::Quad { + bounds: scrollbar.bounds, + background: style.background.unwrap_or( + Background::Color(Color::TRANSPARENT), + ), + border_radius: style.border_radius, + border_width: style.border_width, + border_color: style.border_color, + }); + } - if is_mouse_over - || self.state.is_scroller_grabbed() - || is_scrollbar_visible - { - renderer.fill_rectangle(renderer::Quad { - bounds: scrollbar.scroller.bounds, - background: Background::Color(style.scroller.color), - border_radius: style.scroller.border_radius, - border_width: style.scroller.border_width, - border_color: style.scroller.border_color, - }); - } - }); + if is_mouse_over + || self.state.is_scroller_grabbed() + || is_scrollbar_visible + { + renderer.fill_rectangle(renderer::Quad { + bounds: scrollbar.scroller.bounds, + background: Background::Color(style.scroller.color), + border_radius: style.scroller.border_radius, + border_width: style.scroller.border_width, + border_color: style.scroller.border_color, + }); + } + }, + ); } else { self.content.draw( renderer, -- 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` --- native/src/widget/scrollable.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'native/src/widget/scrollable.rs') diff --git a/native/src/widget/scrollable.rs b/native/src/widget/scrollable.rs index 4b514818..781fe73e 100644 --- a/native/src/widget/scrollable.rs +++ b/native/src/widget/scrollable.rs @@ -5,9 +5,10 @@ use crate::mouse; use crate::overlay; use crate::renderer; use crate::touch; +use crate::widget::Column; use crate::{ - Alignment, Background, Clipboard, Color, Column, Element, Hasher, Layout, - Length, Padding, Point, Rectangle, Size, Vector, Widget, + Alignment, Background, Clipboard, Color, Element, Hasher, Layout, Length, + Padding, Point, Rectangle, Size, Vector, Widget, }; use std::{f32, hash::Hash, u32}; -- 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` --- native/src/widget/scrollable.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'native/src/widget/scrollable.rs') diff --git a/native/src/widget/scrollable.rs b/native/src/widget/scrollable.rs index 781fe73e..05e9b347 100644 --- a/native/src/widget/scrollable.rs +++ b/native/src/widget/scrollable.rs @@ -27,7 +27,7 @@ pub struct Scrollable<'a, Message, Renderer> { scroller_width: u16, content: Column<'a, Message, Renderer>, on_scroll: Option Message>>, - style_sheet: &'a dyn StyleSheet, + style_sheet: Box, } impl<'a, Message, Renderer: crate::Renderer> Scrollable<'a, Message, Renderer> { @@ -123,8 +123,11 @@ impl<'a, Message, Renderer: crate::Renderer> Scrollable<'a, Message, Renderer> { } /// Sets the style of the [`Scrollable`] . - pub fn style(mut self, style_sheet: &'a dyn StyleSheet) -> Self { - self.style_sheet = style_sheet; + pub fn style( + mut self, + style_sheet: impl Into>, + ) -> Self { + self.style_sheet = style_sheet.into(); self } -- cgit From 631e95ee0be01dc7f5e5183e1429972aee37787f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 2 Nov 2021 15:03:29 +0700 Subject: Move `viewport` argument to last position in `mouse_interaction` methods This keeps the order of the arguments consistent with `draw`. --- native/src/widget/scrollable.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'native/src/widget/scrollable.rs') diff --git a/native/src/widget/scrollable.rs b/native/src/widget/scrollable.rs index 05e9b347..00f80bc6 100644 --- a/native/src/widget/scrollable.rs +++ b/native/src/widget/scrollable.rs @@ -426,8 +426,8 @@ where fn mouse_interaction( &self, layout: Layout<'_>, - _viewport: &Rectangle, cursor_position: Point, + _viewport: &Rectangle, ) -> mouse::Interaction { let bounds = layout.bounds(); let content_layout = layout.children().next().unwrap(); @@ -453,11 +453,11 @@ where self.content.mouse_interaction( content_layout, + cursor_position, &Rectangle { y: bounds.y + offset as f32, ..bounds }, - cursor_position, ) } } -- 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` --- native/src/widget/scrollable.rs | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'native/src/widget/scrollable.rs') diff --git a/native/src/widget/scrollable.rs b/native/src/widget/scrollable.rs index 00f80bc6..2bf2ea5e 100644 --- a/native/src/widget/scrollable.rs +++ b/native/src/widget/scrollable.rs @@ -526,28 +526,32 @@ where }, |renderer| { if is_scrollbar_visible { - renderer.fill_rectangle(renderer::Quad { - bounds: scrollbar.bounds, - background: style.background.unwrap_or( - Background::Color(Color::TRANSPARENT), - ), - border_radius: style.border_radius, - border_width: style.border_width, - border_color: style.border_color, - }); + renderer.fill_quad( + renderer::Quad { + bounds: scrollbar.bounds, + border_radius: style.border_radius, + border_width: style.border_width, + border_color: style.border_color, + }, + style.background.unwrap_or(Background::Color( + Color::TRANSPARENT, + )), + ); } if is_mouse_over || self.state.is_scroller_grabbed() || is_scrollbar_visible { - renderer.fill_rectangle(renderer::Quad { - bounds: scrollbar.scroller.bounds, - background: Background::Color(style.scroller.color), - border_radius: style.scroller.border_radius, - border_width: style.scroller.border_width, - border_color: style.scroller.border_color, - }); + renderer.fill_quad( + renderer::Quad { + bounds: scrollbar.scroller.bounds, + border_radius: style.scroller.border_radius, + border_width: style.scroller.border_width, + border_color: style.scroller.border_color, + }, + style.scroller.color, + ); } }, ); -- cgit