diff options
author | 2020-05-19 21:00:40 +0200 | |
---|---|---|
committer | 2020-05-19 21:00:40 +0200 | |
commit | e6180912488db4d59fbffcb46c5930282306cb92 (patch) | |
tree | f41c7ee830a8765b3795c8b6d012c7c621927cca /graphics/src/widget/progress_bar.rs | |
parent | c2e0c52ce031ffe1c300b3cfa362b0e445ac5afd (diff) | |
download | iced-e6180912488db4d59fbffcb46c5930282306cb92.tar.gz iced-e6180912488db4d59fbffcb46c5930282306cb92.tar.bz2 iced-e6180912488db4d59fbffcb46c5930282306cb92.zip |
Merge unnecessary split widget modules
Diffstat (limited to 'graphics/src/widget/progress_bar.rs')
-rw-r--r-- | graphics/src/widget/progress_bar.rs | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/graphics/src/widget/progress_bar.rs b/graphics/src/widget/progress_bar.rs index c1e5702e..48acb3c1 100644 --- a/graphics/src/widget/progress_bar.rs +++ b/graphics/src/widget/progress_bar.rs @@ -4,7 +4,10 @@ //! as well as a length, height and style. //! //! [`ProgressBar`]: type.ProgressBar.html -use crate::Renderer; +use crate::{Backend, Primitive, Renderer}; +use iced_native::mouse; +use iced_native::progress_bar; +use iced_native::{Color, Rectangle}; pub use iced_style::progress_bar::{Style, StyleSheet}; @@ -13,3 +16,58 @@ pub use iced_style::progress_bar::{Style, StyleSheet}; /// This is an alias of an `iced_native` progress bar with an /// `iced_wgpu::Renderer`. pub type ProgressBar<Backend> = iced_native::ProgressBar<Renderer<Backend>>; + +impl<B> progress_bar::Renderer for Renderer<B> +where + B: Backend, +{ + type Style = Box<dyn StyleSheet>; + + const DEFAULT_HEIGHT: u16 = 30; + + fn draw( + &self, + bounds: Rectangle, + range: std::ops::RangeInclusive<f32>, + value: f32, + style_sheet: &Self::Style, + ) -> Self::Output { + let style = style_sheet.style(); + + let (range_start, range_end) = range.into_inner(); + let active_progress_width = bounds.width + * ((value - range_start) / (range_end - range_start).max(1.0)); + + let background = Primitive::Group { + primitives: vec![Primitive::Quad { + bounds: Rectangle { ..bounds }, + background: style.background, + border_radius: style.border_radius, + border_width: 0, + border_color: Color::TRANSPARENT, + }], + }; + + ( + if active_progress_width > 0.0 { + let bar = Primitive::Quad { + bounds: Rectangle { + width: active_progress_width, + ..bounds + }, + background: style.bar, + border_radius: style.border_radius, + border_width: 0, + border_color: Color::TRANSPARENT, + }; + + Primitive::Group { + primitives: vec![background, bar], + } + } else { + background + }, + mouse::Interaction::default(), + ) + } +} |