Make rule API consistent with space
This commit is contained in:
parent
afac7be7d1
commit
8f87a2bc2e
7 changed files with 37 additions and 54 deletions
|
|
@ -290,7 +290,7 @@ fn quotes<'a>() -> Element<'a, Message> {
|
|||
fn quote<'a>(
|
||||
content: impl Into<Element<'a, Message>>,
|
||||
) -> 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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
]
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -630,7 +630,7 @@ impl<P: Program + 'static> Tester<P> {
|
|||
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)
|
||||
|
|
|
|||
|
|
@ -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<Pixels>) -> 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<Pixels>,
|
||||
text_size: impl Into<core::Pixels>,
|
||||
) -> Element<'a, Message, Theme, Renderer>
|
||||
where
|
||||
Message: 'a,
|
||||
|
|
|
|||
|
|
@ -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<Font = Font> + 'a,
|
||||
{
|
||||
row![
|
||||
crate::rule(4).vertical(),
|
||||
rule::vertical(4),
|
||||
column(
|
||||
contents
|
||||
.iter()
|
||||
|
|
@ -1410,7 +1410,7 @@ where
|
|||
Theme: Catalog + 'a,
|
||||
Renderer: core::text::Renderer<Font = Font> + 'a,
|
||||
{
|
||||
crate::rule(2).into()
|
||||
rule::horizontal(2).into()
|
||||
}
|
||||
|
||||
/// Displays a table using the default look.
|
||||
|
|
|
|||
|
|
@ -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<Pixels>) -> 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<Pixels>) -> 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<Pixels>) -> 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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue