Implement pure version of Rule widget
This commit is contained in:
parent
31d814b43c
commit
0fbd1d98b5
3 changed files with 116 additions and 6 deletions
|
|
@ -15,20 +15,20 @@ pub struct Rule<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Rule<'a> {
|
impl<'a> Rule<'a> {
|
||||||
/// Creates a horizontal [`Rule`] for dividing content by the given vertical spacing.
|
/// Creates a horizontal [`Rule`] with the given height.
|
||||||
pub fn horizontal(spacing: u16) -> Self {
|
pub fn horizontal(height: u16) -> Self {
|
||||||
Rule {
|
Rule {
|
||||||
width: Length::Fill,
|
width: Length::Fill,
|
||||||
height: Length::from(Length::Units(spacing)),
|
height: Length::Units(height),
|
||||||
is_horizontal: true,
|
is_horizontal: true,
|
||||||
style_sheet: Default::default(),
|
style_sheet: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a vertical [`Rule`] for dividing content by the given horizontal spacing.
|
/// Creates a vertical [`Rule`] with the given width.
|
||||||
pub fn vertical(spacing: u16) -> Self {
|
pub fn vertical(width: u16) -> Self {
|
||||||
Rule {
|
Rule {
|
||||||
width: Length::from(Length::Units(spacing)),
|
width: Length::from(Length::Units(width)),
|
||||||
height: Length::Fill,
|
height: Length::Fill,
|
||||||
is_horizontal: false,
|
is_horizontal: false,
|
||||||
style_sheet: Default::default(),
|
style_sheet: Default::default(),
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
pub mod image;
|
pub mod image;
|
||||||
|
pub mod rule;
|
||||||
pub mod tree;
|
pub mod tree;
|
||||||
|
|
||||||
mod button;
|
mod button;
|
||||||
|
|
@ -25,6 +26,7 @@ pub use image::Image;
|
||||||
pub use pick_list::PickList;
|
pub use pick_list::PickList;
|
||||||
pub use radio::Radio;
|
pub use radio::Radio;
|
||||||
pub use row::Row;
|
pub use row::Row;
|
||||||
|
pub use rule::Rule;
|
||||||
pub use scrollable::Scrollable;
|
pub use scrollable::Scrollable;
|
||||||
pub use slider::Slider;
|
pub use slider::Slider;
|
||||||
pub use space::Space;
|
pub use space::Space;
|
||||||
|
|
@ -234,3 +236,13 @@ pub fn horizontal_space(width: Length) -> Space {
|
||||||
pub fn vertical_space(height: Length) -> Space {
|
pub fn vertical_space(height: Length) -> Space {
|
||||||
Space::with_height(height)
|
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)
|
||||||
|
}
|
||||||
|
|
|
||||||
98
pure/src/widget/rule.rs
Normal file
98
pure/src/widget/rule.rs
Normal file
|
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue