diff --git a/examples/layout/src/main.rs b/examples/layout/src/main.rs index 210f745d..c4faf319 100644 --- a/examples/layout/src/main.rs +++ b/examples/layout/src/main.rs @@ -290,7 +290,7 @@ fn quotes<'a>() -> Element<'a, Message> { fn quote<'a>( content: impl Into>, ) -> Element<'a, Message> { - row![rule(1).vertical(), content.into()] + row![rule::vertical(1), content.into()] .spacing(10) .height(Shrink) .into() @@ -308,7 +308,7 @@ fn quotes<'a>() -> Element<'a, Message> { reply("This is the original message", "This is a reply"), "This is another reply", ), - rule(1), + rule::horizontal(1), text("A separator ↑"), ] .width(Shrink) diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index 56e5bb27..f979f6f2 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -162,14 +162,14 @@ impl Styling { let content = column![ choose_theme, - rule(1), + rule::horizontal(1), text_input, buttons, slider(), progress_bar(), row![ scroll_me, - rule(1).vertical(), + rule::vertical(1), column![check, check_disabled, toggle, disabled_toggle] .spacing(10) ] diff --git a/examples/toast/src/main.rs b/examples/toast/src/main.rs index b3f09dd6..cca0e789 100644 --- a/examples/toast/src/main.rs +++ b/examples/toast/src/main.rs @@ -252,7 +252,7 @@ mod toast { Status::Success => success, Status::Danger => danger, }), - rule(1), + rule::horizontal(1), container(text(toast.body.as_str())) .width(Fill) .padding(5) diff --git a/tester/src/lib.rs b/tester/src/lib.rs index 5ac77968..724aa28f 100644 --- a/tester/src/lib.rs +++ b/tester/src/lib.rs @@ -630,7 +630,7 @@ impl Tester

{ row![ center(column![status, viewport].spacing(10).align_x(Right)) .padding(10), - rule(1).vertical().style(rule::weak), + rule::vertical(1).style(rule::weak), container(self.controls().map(Tick::Tester)) .width(250) .padding(10) diff --git a/widget/src/helpers.rs b/widget/src/helpers.rs index 4afb8cee..2d696c84 100644 --- a/widget/src/helpers.rs +++ b/widget/src/helpers.rs @@ -7,7 +7,7 @@ use crate::core; use crate::core::theme; use crate::core::widget::operation::{self, Operation}; use crate::core::window; -use crate::core::{Element, Length, Pixels, Size, Widget}; +use crate::core::{Element, Length, Size, Widget}; use crate::float::{self, Float}; use crate::keyed; use crate::overlay; @@ -15,7 +15,6 @@ use crate::pane_grid::{self, PaneGrid}; use crate::pick_list::{self, PickList}; use crate::progress_bar::{self, ProgressBar}; use crate::radio::{self, Radio}; -use crate::rule::{self, Rule}; use crate::scrollable::{self, Scrollable}; use crate::slider::{self, Slider}; use crate::text::{self, Text}; @@ -1737,31 +1736,6 @@ pub fn space() -> Space { Space::new() } -/// Creates a horizontal [`Rule`] with the given height. -/// -/// # Example -/// ```no_run -/// # mod iced { pub mod widget { pub use iced_widget::*; } } -/// # pub type State = (); -/// # pub type Element<'a, Message> = iced_widget::core::Element<'a, Message, iced_widget::Theme, iced_widget::Renderer>; -/// use iced::widget::rule; -/// -/// #[derive(Clone)] -/// enum Message { -/// // ..., -/// } -/// -/// fn view(state: &State) -> Element<'_, Message> { -/// rule(2).into() -/// } -/// ``` -pub fn rule<'a, Theme>(height: impl Into) -> Rule<'a, Theme> -where - Theme: rule::Catalog + 'a, -{ - Rule::new(height) -} - /// Creates a new [`ProgressBar`]. /// /// Progress bars visualize the progression of an extended computer operation, such as a download, file transfer, or installation. @@ -1864,7 +1838,7 @@ where /// for instance. #[cfg(feature = "svg")] pub fn iced<'a, Message, Theme, Renderer>( - text_size: impl Into, + text_size: impl Into, ) -> Element<'a, Message, Theme, Renderer> where Message: 'a, diff --git a/widget/src/markdown.rs b/widget/src/markdown.rs index f2114f1d..d778dd6a 100644 --- a/widget/src/markdown.rs +++ b/widget/src/markdown.rs @@ -51,7 +51,7 @@ use crate::core::theme; use crate::core::{ self, Color, Element, Length, Padding, Pixels, Theme, color, }; -use crate::{column, container, rich_text, row, scrollable, span, text}; +use crate::{column, container, rich_text, row, rule, scrollable, span, text}; use std::borrow::BorrowMut; use std::cell::{Cell, RefCell}; @@ -1388,7 +1388,7 @@ where Renderer: core::text::Renderer + 'a, { row![ - crate::rule(4).vertical(), + rule::vertical(4), column( contents .iter() @@ -1410,7 +1410,7 @@ where Theme: Catalog + 'a, Renderer: core::text::Renderer + 'a, { - crate::rule(2).into() + rule::horizontal(2).into() } /// Displays a table using the default look. diff --git a/widget/src/rule.rs b/widget/src/rule.rs index 5ba2a6f0..1472caed 100644 --- a/widget/src/rule.rs +++ b/widget/src/rule.rs @@ -13,7 +13,7 @@ //! } //! //! fn view(state: &State) -> Element<'_, Message> { -//! rule(2).into() +//! rule::horizontal(2).into() //! } //! ``` use crate::core; @@ -26,6 +26,30 @@ use crate::core::{ Color, Element, Layout, Length, Pixels, Rectangle, Size, Theme, Widget, }; +/// Creates a new horizontal [`Rule`] with the given height. +pub fn horizontal<'a, Theme>(height: impl Into) -> Rule<'a, Theme> +where + Theme: Catalog, +{ + Rule { + thickness: Length::Fixed(height.into().0), + is_vertical: false, + class: Theme::default(), + } +} + +/// Creates a new vertical [`Rule`] with the given width. +pub fn vertical<'a, Theme>(width: impl Into) -> Rule<'a, Theme> +where + Theme: Catalog, +{ + Rule { + thickness: Length::Fixed(width.into().0), + is_vertical: true, + class: Theme::default(), + } +} + /// Display a horizontal or vertical rule for dividing content. /// /// # Example @@ -41,7 +65,7 @@ use crate::core::{ /// } /// /// fn view(state: &State) -> Element<'_, Message> { -/// rule(2).into() +/// rule::horizontal(2).into() /// } /// ``` pub struct Rule<'a, Theme = crate::Theme> @@ -57,21 +81,6 @@ impl<'a, Theme> Rule<'a, Theme> where Theme: Catalog, { - /// Creates a horizontal [`Rule`] with the given thickness. - pub fn new(thickness: impl Into) -> Self { - Rule { - thickness: Length::Fixed(thickness.into().0), - is_vertical: false, - class: Theme::default(), - } - } - - /// Turns the [`Rule`] into a vertical one. - pub fn vertical(mut self) -> Self { - self.is_vertical = true; - self - } - /// Sets the style of the [`Rule`]. #[must_use] pub fn style(mut self, style: impl Fn(&Theme) -> Style + 'a) -> Self