summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--native/src/widget/rule.rs12
-rw-r--r--pure/src/widget.rs12
-rw-r--r--pure/src/widget/rule.rs98
3 files changed, 116 insertions, 6 deletions
diff --git a/native/src/widget/rule.rs b/native/src/widget/rule.rs
index b0cc3768..69619583 100644
--- a/native/src/widget/rule.rs
+++ b/native/src/widget/rule.rs
@@ -15,20 +15,20 @@ pub struct Rule<'a> {
}
impl<'a> Rule<'a> {
- /// Creates a horizontal [`Rule`] for dividing content by the given vertical spacing.
- pub fn horizontal(spacing: u16) -> Self {
+ /// Creates a horizontal [`Rule`] with the given height.
+ pub fn horizontal(height: u16) -> Self {
Rule {
width: Length::Fill,
- height: Length::from(Length::Units(spacing)),
+ height: Length::Units(height),
is_horizontal: true,
style_sheet: Default::default(),
}
}
- /// Creates a vertical [`Rule`] for dividing content by the given horizontal spacing.
- pub fn vertical(spacing: u16) -> Self {
+ /// Creates a vertical [`Rule`] with the given width.
+ pub fn vertical(width: u16) -> Self {
Rule {
- width: Length::from(Length::Units(spacing)),
+ width: Length::from(Length::Units(width)),
height: Length::Fill,
is_horizontal: false,
style_sheet: Default::default(),
diff --git a/pure/src/widget.rs b/pure/src/widget.rs
index c516c1f2..bee21633 100644
--- a/pure/src/widget.rs
+++ b/pure/src/widget.rs
@@ -1,4 +1,5 @@
pub mod image;
+pub mod rule;
pub mod tree;
mod button;
@@ -25,6 +26,7 @@ pub use image::Image;
pub use pick_list::PickList;
pub use radio::Radio;
pub use row::Row;
+pub use rule::Rule;
pub use scrollable::Scrollable;
pub use slider::Slider;
pub use space::Space;
@@ -234,3 +236,13 @@ pub fn horizontal_space(width: Length) -> Space {
pub fn vertical_space(height: Length) -> Space {
Space::with_height(height)
}
+
+/// Creates a horizontal [`Rule`] with the given height.
+pub fn horizontal_rule<'a>(height: u16) -> Rule<'a> {
+ Rule::horizontal(height)
+}
+
+/// Creates a vertical [`Rule`] with the given width.
+pub fn vertical_rule<'a>(width: u16) -> Rule<'a> {
+ Rule::horizontal(width)
+}
diff --git a/pure/src/widget/rule.rs b/pure/src/widget/rule.rs
new file mode 100644
index 00000000..375bed9e
--- /dev/null
+++ b/pure/src/widget/rule.rs
@@ -0,0 +1,98 @@
+use crate::{Element, Tree, Widget};
+
+use iced_native::event::{self, Event};
+use iced_native::layout::{self, Layout};
+use iced_native::mouse;
+use iced_native::renderer;
+use iced_native::{Clipboard, Length, Point, Rectangle, Shell};
+
+pub use iced_native::widget::rule::*;
+
+impl<'a, Message, Renderer> Widget<Message, Renderer> for Rule<'a>
+where
+ Renderer: iced_native::Renderer,
+{
+ fn width(&self) -> Length {
+ <Self as iced_native::Widget<Message, Renderer>>::width(self)
+ }
+
+ fn height(&self) -> Length {
+ <Self as iced_native::Widget<Message, Renderer>>::height(self)
+ }
+
+ fn layout(
+ &self,
+ renderer: &Renderer,
+ limits: &layout::Limits,
+ ) -> layout::Node {
+ <Self as iced_native::Widget<Message, Renderer>>::layout(
+ self, renderer, limits,
+ )
+ }
+
+ fn on_event(
+ &mut self,
+ _state: &mut Tree,
+ event: Event,
+ layout: Layout<'_>,
+ cursor_position: Point,
+ renderer: &Renderer,
+ clipboard: &mut dyn Clipboard,
+ shell: &mut Shell<'_, Message>,
+ ) -> event::Status {
+ <Self as iced_native::Widget<Message, Renderer>>::on_event(
+ self,
+ event,
+ layout,
+ cursor_position,
+ renderer,
+ clipboard,
+ shell,
+ )
+ }
+
+ fn draw(
+ &self,
+ _tree: &Tree,
+ renderer: &mut Renderer,
+ style: &renderer::Style,
+ layout: Layout<'_>,
+ cursor_position: Point,
+ viewport: &Rectangle,
+ ) {
+ <Self as iced_native::Widget<Message, Renderer>>::draw(
+ self,
+ renderer,
+ style,
+ layout,
+ cursor_position,
+ viewport,
+ )
+ }
+
+ fn mouse_interaction(
+ &self,
+ _state: &Tree,
+ layout: Layout<'_>,
+ cursor_position: Point,
+ viewport: &Rectangle,
+ renderer: &Renderer,
+ ) -> mouse::Interaction {
+ <Self as iced_native::Widget<Message, Renderer>>::mouse_interaction(
+ self,
+ layout,
+ cursor_position,
+ viewport,
+ renderer,
+ )
+ }
+}
+
+impl<'a, Message, Renderer> Into<Element<'a, Message, Renderer>> for Rule<'a>
+where
+ Renderer: iced_native::Renderer + 'a,
+{
+ fn into(self) -> Element<'a, Message, Renderer> {
+ Element::new(self)
+ }
+}