summaryrefslogtreecommitdiffstats
path: root/wgpu
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-01-07 01:53:26 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-01-07 01:53:26 +0100
commit48b3b78a3840778eef1035f4585d5ba9dd3d6291 (patch)
tree2df86a26f9961969b4f8da38c145b123162f0923 /wgpu
parentfce89d0ffe36111cdbf42480c28e67811afb42e6 (diff)
downloadiced-48b3b78a3840778eef1035f4585d5ba9dd3d6291.tar.gz
iced-48b3b78a3840778eef1035f4585d5ba9dd3d6291.tar.bz2
iced-48b3b78a3840778eef1035f4585d5ba9dd3d6291.zip
Implement styling for `ProgressBar`
Diffstat (limited to 'wgpu')
-rw-r--r--wgpu/src/renderer/widget/progress_bar.rs27
-rw-r--r--wgpu/src/widget.rs1
-rw-r--r--wgpu/src/widget/progress_bar.rs15
3 files changed, 29 insertions, 14 deletions
diff --git a/wgpu/src/renderer/widget/progress_bar.rs b/wgpu/src/renderer/widget/progress_bar.rs
index e9346fda..8bb9db03 100644
--- a/wgpu/src/renderer/widget/progress_bar.rs
+++ b/wgpu/src/renderer/widget/progress_bar.rs
@@ -1,7 +1,9 @@
-use crate::{Primitive, Renderer};
-use iced_native::{progress_bar, Background, Color, MouseCursor, Rectangle};
+use crate::{progress_bar::StyleSheet, Primitive, Renderer};
+use iced_native::{progress_bar, Color, MouseCursor, Rectangle};
impl progress_bar::Renderer for Renderer {
+ type Style = Box<dyn StyleSheet>;
+
const DEFAULT_HEIGHT: u16 = 30;
fn draw(
@@ -9,9 +11,10 @@ impl progress_bar::Renderer for Renderer {
bounds: Rectangle,
range: std::ops::RangeInclusive<f32>,
value: f32,
- background: Option<Background>,
- active_color: Option<Color>,
+ 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));
@@ -19,31 +22,27 @@ impl progress_bar::Renderer for Renderer {
let background = Primitive::Group {
primitives: vec![Primitive::Quad {
bounds: Rectangle { ..bounds },
- background: background
- .unwrap_or(Background::Color([0.6, 0.6, 0.6].into()))
- .into(),
- border_radius: 5,
+ background: style.background,
+ border_radius: style.border_radius,
border_width: 0,
border_color: Color::TRANSPARENT,
}],
};
- let active_progress = Primitive::Quad {
+ let bar = Primitive::Quad {
bounds: Rectangle {
width: active_progress_width,
..bounds
},
- background: Background::Color(
- active_color.unwrap_or([0.0, 0.95, 0.0].into()),
- ),
- border_radius: 5,
+ background: style.bar,
+ border_radius: style.border_radius,
border_width: 0,
border_color: Color::TRANSPARENT,
};
(
Primitive::Group {
- primitives: vec![background, active_progress],
+ primitives: vec![background, bar],
},
MouseCursor::OutOfBounds,
)
diff --git a/wgpu/src/widget.rs b/wgpu/src/widget.rs
index 4b8d339e..3f3dc0b0 100644
--- a/wgpu/src/widget.rs
+++ b/wgpu/src/widget.rs
@@ -1,5 +1,6 @@
pub mod button;
pub mod container;
+pub mod progress_bar;
pub mod scrollable;
pub mod slider;
pub mod text_input;
diff --git a/wgpu/src/widget/progress_bar.rs b/wgpu/src/widget/progress_bar.rs
new file mode 100644
index 00000000..34450b5e
--- /dev/null
+++ b/wgpu/src/widget/progress_bar.rs
@@ -0,0 +1,15 @@
+//! Allow your users to perform actions by pressing a button.
+//!
+//! A [`Button`] has some local [`State`].
+//!
+//! [`Button`]: type.Button.html
+//! [`State`]: struct.State.html
+use crate::Renderer;
+
+pub use iced_style::progress_bar::{Style, StyleSheet};
+
+/// A bar that displays progress.
+///
+/// This is an alias of an `iced_native` progress bar with an
+/// `iced_wgpu::Renderer`.
+pub type ProgressBar = iced_native::ProgressBar<Renderer>;