summaryrefslogtreecommitdiffstats
path: root/graphics/src
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-08-22 21:25:06 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-08-22 21:25:06 +0200
commit2ce5df084456a92ed1a228738816cf8398b2e918 (patch)
tree57eae346361880dc9dbbc15a42a56e001e20c5ff /graphics/src
parentbbc6e91429ff94c3792de9d874999818b2c84a9b (diff)
parentfed30ef7753bbe33af026f1f46a09d8381682284 (diff)
downloadiced-2ce5df084456a92ed1a228738816cf8398b2e918.tar.gz
iced-2ce5df084456a92ed1a228738816cf8398b2e918.tar.bz2
iced-2ce5df084456a92ed1a228738816cf8398b2e918.zip
Merge branch 'feature/rule-widget' into master
Diffstat (limited to 'graphics/src')
-rw-r--r--graphics/src/widget.rs3
-rw-r--r--graphics/src/widget/rule.rs73
2 files changed, 76 insertions, 0 deletions
diff --git a/graphics/src/widget.rs b/graphics/src/widget.rs
index 94a65011..f87b558a 100644
--- a/graphics/src/widget.rs
+++ b/graphics/src/widget.rs
@@ -15,6 +15,7 @@ pub mod pane_grid;
pub mod pick_list;
pub mod progress_bar;
pub mod radio;
+pub mod rule;
pub mod scrollable;
pub mod slider;
pub mod svg;
@@ -40,6 +41,8 @@ pub use progress_bar::ProgressBar;
#[doc(no_inline)]
pub use radio::Radio;
#[doc(no_inline)]
+pub use rule::Rule;
+#[doc(no_inline)]
pub use scrollable::Scrollable;
#[doc(no_inline)]
pub use slider::Slider;
diff --git a/graphics/src/widget/rule.rs b/graphics/src/widget/rule.rs
new file mode 100644
index 00000000..a7a5d0e7
--- /dev/null
+++ b/graphics/src/widget/rule.rs
@@ -0,0 +1,73 @@
+//! Display a horizontal or vertical rule for dividing content.
+
+use crate::{Backend, Primitive, Renderer};
+use iced_native::mouse;
+use iced_native::rule;
+use iced_native::{Background, Color, Rectangle};
+
+pub use iced_style::rule::{FillMode, Style, StyleSheet};
+
+/// Display a horizontal or vertical rule for dividing content.
+///
+/// This is an alias of an `iced_native` rule with an `iced_graphics::Renderer`.
+pub type Rule<Backend> = iced_native::Rule<Renderer<Backend>>;
+
+impl<B> rule::Renderer for Renderer<B>
+where
+ B: Backend,
+{
+ type Style = Box<dyn StyleSheet>;
+
+ fn draw(
+ &mut self,
+ bounds: Rectangle,
+ style_sheet: &Self::Style,
+ is_horizontal: bool,
+ ) -> Self::Output {
+ let style = style_sheet.style();
+
+ let line = if is_horizontal {
+ let line_y = (bounds.y + (bounds.height / 2.0)
+ - (style.width as f32 / 2.0))
+ .round();
+
+ let (offset, line_width) = style.fill_mode.fill(bounds.width);
+ let line_x = bounds.x + offset;
+
+ Primitive::Quad {
+ bounds: Rectangle {
+ x: line_x,
+ y: line_y,
+ width: line_width,
+ height: style.width as f32,
+ },
+ background: Background::Color(style.color),
+ border_radius: style.radius,
+ border_width: 0,
+ border_color: Color::TRANSPARENT,
+ }
+ } else {
+ let line_x = (bounds.x + (bounds.width / 2.0)
+ - (style.width as f32 / 2.0))
+ .round();
+
+ let (offset, line_height) = style.fill_mode.fill(bounds.height);
+ let line_y = bounds.y + offset;
+
+ Primitive::Quad {
+ bounds: Rectangle {
+ x: line_x,
+ y: line_y,
+ width: style.width as f32,
+ height: line_height,
+ },
+ background: Background::Color(style.color),
+ border_radius: style.radius,
+ border_width: 0,
+ border_color: Color::TRANSPARENT,
+ }
+ };
+
+ (line, mouse::Interaction::default())
+ }
+}