Use f32 in Length::Units and rename it to Fixed
This commit is contained in:
parent
f75e020257
commit
7b8b01f560
43 changed files with 269 additions and 262 deletions
|
|
@ -82,14 +82,14 @@ where
|
|||
}
|
||||
|
||||
/// Sets the width of the [`Button`].
|
||||
pub fn width(mut self, width: Length) -> Self {
|
||||
self.width = width;
|
||||
pub fn width(mut self, width: impl Into<Length>) -> Self {
|
||||
self.width = width.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the height of the [`Button`].
|
||||
pub fn height(mut self, height: Length) -> Self {
|
||||
self.height = height;
|
||||
pub fn height(mut self, height: impl Into<Length>) -> Self {
|
||||
self.height = height.into();
|
||||
self
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ use crate::text;
|
|||
use crate::touch;
|
||||
use crate::widget::{self, Row, Text, Tree};
|
||||
use crate::{
|
||||
Alignment, Clipboard, Element, Layout, Length, Point, Rectangle, Shell,
|
||||
Widget,
|
||||
Alignment, Clipboard, Element, Layout, Length, Pixels, Point, Rectangle,
|
||||
Shell, Widget,
|
||||
};
|
||||
|
||||
pub use iced_style::checkbox::{Appearance, StyleSheet};
|
||||
|
|
@ -52,7 +52,7 @@ where
|
|||
on_toggle: Box<dyn Fn(bool) -> Message + 'a>,
|
||||
label: String,
|
||||
width: Length,
|
||||
size: u16,
|
||||
size: f32,
|
||||
spacing: u16,
|
||||
text_size: Option<u16>,
|
||||
font: Renderer::Font,
|
||||
|
|
@ -66,7 +66,7 @@ where
|
|||
Renderer::Theme: StyleSheet + widget::text::StyleSheet,
|
||||
{
|
||||
/// The default size of a [`Checkbox`].
|
||||
const DEFAULT_SIZE: u16 = 20;
|
||||
const DEFAULT_SIZE: f32 = 20.0;
|
||||
|
||||
/// The default spacing of a [`Checkbox`].
|
||||
const DEFAULT_SPACING: u16 = 15;
|
||||
|
|
@ -102,14 +102,14 @@ where
|
|||
}
|
||||
|
||||
/// Sets the size of the [`Checkbox`].
|
||||
pub fn size(mut self, size: u16) -> Self {
|
||||
self.size = size;
|
||||
pub fn size(mut self, size: impl Into<Pixels>) -> Self {
|
||||
self.size = size.into().0;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the width of the [`Checkbox`].
|
||||
pub fn width(mut self, width: Length) -> Self {
|
||||
self.width = width;
|
||||
pub fn width(mut self, width: impl Into<Length>) -> Self {
|
||||
self.width = width.into();
|
||||
self
|
||||
}
|
||||
|
||||
|
|
@ -172,11 +172,7 @@ where
|
|||
.width(self.width)
|
||||
.spacing(self.spacing)
|
||||
.align_items(Alignment::Center)
|
||||
.push(
|
||||
Row::new()
|
||||
.width(Length::Units(self.size))
|
||||
.height(Length::Units(self.size)),
|
||||
)
|
||||
.push(Row::new().width(self.size).height(self.size))
|
||||
.push(
|
||||
Text::new(&self.label)
|
||||
.font(self.font.clone())
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ use crate::overlay;
|
|||
use crate::renderer;
|
||||
use crate::widget::{Operation, Tree};
|
||||
use crate::{
|
||||
Alignment, Clipboard, Element, Layout, Length, Padding, Point, Rectangle,
|
||||
Shell, Widget,
|
||||
Alignment, Clipboard, Element, Layout, Length, Padding, Pixels, Point,
|
||||
Rectangle, Shell, Widget,
|
||||
};
|
||||
|
||||
/// A container that distributes its contents vertically.
|
||||
|
|
@ -17,7 +17,7 @@ pub struct Column<'a, Message, Renderer> {
|
|||
padding: Padding,
|
||||
width: Length,
|
||||
height: Length,
|
||||
max_width: u32,
|
||||
max_width: f32,
|
||||
align_items: Alignment,
|
||||
children: Vec<Element<'a, Message, Renderer>>,
|
||||
}
|
||||
|
|
@ -37,7 +37,7 @@ impl<'a, Message, Renderer> Column<'a, Message, Renderer> {
|
|||
padding: Padding::ZERO,
|
||||
width: Length::Shrink,
|
||||
height: Length::Shrink,
|
||||
max_width: u32::MAX,
|
||||
max_width: f32::INFINITY,
|
||||
align_items: Alignment::Start,
|
||||
children,
|
||||
}
|
||||
|
|
@ -60,20 +60,20 @@ impl<'a, Message, Renderer> Column<'a, Message, Renderer> {
|
|||
}
|
||||
|
||||
/// Sets the width of the [`Column`].
|
||||
pub fn width(mut self, width: Length) -> Self {
|
||||
self.width = width;
|
||||
pub fn width(mut self, width: impl Into<Length>) -> Self {
|
||||
self.width = width.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the height of the [`Column`].
|
||||
pub fn height(mut self, height: Length) -> Self {
|
||||
self.height = height;
|
||||
pub fn height(mut self, height: impl Into<Length>) -> Self {
|
||||
self.height = height.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the maximum width of the [`Column`].
|
||||
pub fn max_width(mut self, max_width: u32) -> Self {
|
||||
self.max_width = max_width;
|
||||
pub fn max_width(mut self, max_width: impl Into<Pixels>) -> Self {
|
||||
self.max_width = max_width.into().0;
|
||||
self
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,12 +7,10 @@ use crate::overlay;
|
|||
use crate::renderer;
|
||||
use crate::widget::{self, Operation, Tree};
|
||||
use crate::{
|
||||
Background, Clipboard, Color, Element, Layout, Length, Padding, Point,
|
||||
Rectangle, Shell, Widget,
|
||||
Background, Clipboard, Color, Element, Layout, Length, Padding, Pixels,
|
||||
Point, Rectangle, Shell, Widget,
|
||||
};
|
||||
|
||||
use std::u32;
|
||||
|
||||
pub use iced_style::container::{Appearance, StyleSheet};
|
||||
|
||||
/// An element decorating some content.
|
||||
|
|
@ -28,8 +26,8 @@ where
|
|||
padding: Padding,
|
||||
width: Length,
|
||||
height: Length,
|
||||
max_width: u32,
|
||||
max_height: u32,
|
||||
max_width: f32,
|
||||
max_height: f32,
|
||||
horizontal_alignment: alignment::Horizontal,
|
||||
vertical_alignment: alignment::Vertical,
|
||||
style: <Renderer::Theme as StyleSheet>::Style,
|
||||
|
|
@ -51,8 +49,8 @@ where
|
|||
padding: Padding::ZERO,
|
||||
width: Length::Shrink,
|
||||
height: Length::Shrink,
|
||||
max_width: u32::MAX,
|
||||
max_height: u32::MAX,
|
||||
max_width: f32::INFINITY,
|
||||
max_height: f32::INFINITY,
|
||||
horizontal_alignment: alignment::Horizontal::Left,
|
||||
vertical_alignment: alignment::Vertical::Top,
|
||||
style: Default::default(),
|
||||
|
|
@ -73,26 +71,26 @@ where
|
|||
}
|
||||
|
||||
/// Sets the width of the [`Container`].
|
||||
pub fn width(mut self, width: Length) -> Self {
|
||||
self.width = width;
|
||||
pub fn width(mut self, width: impl Into<Length>) -> Self {
|
||||
self.width = width.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the height of the [`Container`].
|
||||
pub fn height(mut self, height: Length) -> Self {
|
||||
self.height = height;
|
||||
pub fn height(mut self, height: impl Into<Length>) -> Self {
|
||||
self.height = height.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the maximum width of the [`Container`].
|
||||
pub fn max_width(mut self, max_width: u32) -> Self {
|
||||
self.max_width = max_width;
|
||||
pub fn max_width(mut self, max_width: impl Into<Pixels>) -> Self {
|
||||
self.max_width = max_width.into().0;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the maximum height of the [`Container`] in pixels.
|
||||
pub fn max_height(mut self, max_height: u32) -> Self {
|
||||
self.max_height = max_height;
|
||||
/// Sets the maximum height of the [`Container`].
|
||||
pub fn max_height(mut self, max_height: impl Into<Pixels>) -> Self {
|
||||
self.max_height = max_height.into().0;
|
||||
self
|
||||
}
|
||||
|
||||
|
|
@ -294,8 +292,8 @@ pub fn layout<Renderer>(
|
|||
limits: &layout::Limits,
|
||||
width: Length,
|
||||
height: Length,
|
||||
max_width: u32,
|
||||
max_height: u32,
|
||||
max_width: f32,
|
||||
max_height: f32,
|
||||
padding: Padding,
|
||||
horizontal_alignment: alignment::Horizontal,
|
||||
vertical_alignment: alignment::Vertical,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
//! Helper functions to create pure widgets.
|
||||
use crate::overlay;
|
||||
use crate::widget;
|
||||
use crate::{Element, Length};
|
||||
use crate::{Element, Length, Pixels};
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::ops::RangeInclusive;
|
||||
|
|
@ -247,21 +247,23 @@ pub fn image<Handle>(handle: impl Into<Handle>) -> widget::Image<Handle> {
|
|||
/// Creates a new horizontal [`Space`] with the given [`Length`].
|
||||
///
|
||||
/// [`Space`]: widget::Space
|
||||
pub fn horizontal_space(width: Length) -> widget::Space {
|
||||
pub fn horizontal_space(width: impl Into<Length>) -> widget::Space {
|
||||
widget::Space::with_width(width)
|
||||
}
|
||||
|
||||
/// Creates a new vertical [`Space`] with the given [`Length`].
|
||||
///
|
||||
/// [`Space`]: widget::Space
|
||||
pub fn vertical_space(height: Length) -> widget::Space {
|
||||
pub fn vertical_space(height: impl Into<Length>) -> widget::Space {
|
||||
widget::Space::with_height(height)
|
||||
}
|
||||
|
||||
/// Creates a horizontal [`Rule`] with the given height.
|
||||
///
|
||||
/// [`Rule`]: widget::Rule
|
||||
pub fn horizontal_rule<Renderer>(height: u16) -> widget::Rule<Renderer>
|
||||
pub fn horizontal_rule<Renderer>(
|
||||
height: impl Into<Pixels>,
|
||||
) -> widget::Rule<Renderer>
|
||||
where
|
||||
Renderer: crate::Renderer,
|
||||
Renderer::Theme: widget::rule::StyleSheet,
|
||||
|
|
@ -272,7 +274,9 @@ where
|
|||
/// Creates a vertical [`Rule`] with the given width.
|
||||
///
|
||||
/// [`Rule`]: widget::Rule
|
||||
pub fn vertical_rule<Renderer>(width: u16) -> widget::Rule<Renderer>
|
||||
pub fn vertical_rule<Renderer>(
|
||||
width: impl Into<Pixels>,
|
||||
) -> widget::Rule<Renderer>
|
||||
where
|
||||
Renderer: crate::Renderer,
|
||||
Renderer::Theme: widget::rule::StyleSheet,
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ pub fn viewer<Handle>(handle: Handle) -> Viewer<Handle> {
|
|||
/// ```
|
||||
///
|
||||
/// <img src="https://github.com/iced-rs/iced/blob/9712b319bb7a32848001b96bd84977430f14b623/examples/resources/ferris.png?raw=true" width="300">
|
||||
#[derive(Debug, Hash)]
|
||||
#[derive(Debug)]
|
||||
pub struct Image<Handle> {
|
||||
handle: Handle,
|
||||
width: Length,
|
||||
|
|
@ -49,14 +49,14 @@ impl<Handle> Image<Handle> {
|
|||
}
|
||||
|
||||
/// Sets the width of the [`Image`] boundaries.
|
||||
pub fn width(mut self, width: Length) -> Self {
|
||||
self.width = width;
|
||||
pub fn width(mut self, width: impl Into<Length>) -> Self {
|
||||
self.width = width.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the height of the [`Image`] boundaries.
|
||||
pub fn height(mut self, height: Length) -> Self {
|
||||
self.height = height;
|
||||
pub fn height(mut self, height: impl Into<Length>) -> Self {
|
||||
self.height = height.into();
|
||||
self
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,14 +45,14 @@ impl<Handle> Viewer<Handle> {
|
|||
}
|
||||
|
||||
/// Sets the width of the [`Viewer`].
|
||||
pub fn width(mut self, width: Length) -> Self {
|
||||
self.width = width;
|
||||
pub fn width(mut self, width: impl Into<Length>) -> Self {
|
||||
self.width = width.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the height of the [`Viewer`].
|
||||
pub fn height(mut self, height: Length) -> Self {
|
||||
self.height = height;
|
||||
pub fn height(mut self, height: impl Into<Length>) -> Self {
|
||||
self.height = height.into();
|
||||
self
|
||||
}
|
||||
|
||||
|
|
@ -124,7 +124,7 @@ where
|
|||
// Only calculate viewport sizes if the images are constrained to a limited space.
|
||||
// If they are Fill|Portion let them expand within their alotted space.
|
||||
match expansion_size {
|
||||
Length::Shrink | Length::Units(_) => {
|
||||
Length::Shrink | Length::Fixed(_) => {
|
||||
let aspect_ratio = width as f32 / height as f32;
|
||||
let viewport_aspect_ratio = size.width / size.height;
|
||||
if viewport_aspect_ratio > aspect_ratio {
|
||||
|
|
|
|||
|
|
@ -159,14 +159,14 @@ where
|
|||
}
|
||||
|
||||
/// Sets the width of the [`PaneGrid`].
|
||||
pub fn width(mut self, width: Length) -> Self {
|
||||
self.width = width;
|
||||
pub fn width(mut self, width: impl Into<Length>) -> Self {
|
||||
self.width = width.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the height of the [`PaneGrid`].
|
||||
pub fn height(mut self, height: Length) -> Self {
|
||||
self.height = height;
|
||||
pub fn height(mut self, height: impl Into<Length>) -> Self {
|
||||
self.height = height.into();
|
||||
self
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -83,8 +83,8 @@ where
|
|||
}
|
||||
|
||||
/// Sets the width of the [`PickList`].
|
||||
pub fn width(mut self, width: Length) -> Self {
|
||||
self.width = width;
|
||||
pub fn width(mut self, width: impl Into<Length>) -> Self {
|
||||
self.width = width.into();
|
||||
self
|
||||
}
|
||||
|
||||
|
|
@ -539,7 +539,7 @@ where
|
|||
&mut state.hovered_option,
|
||||
&mut state.last_selection,
|
||||
)
|
||||
.width(bounds.width.round() as u16)
|
||||
.width(bounds.width)
|
||||
.padding(padding)
|
||||
.font(font)
|
||||
.style(style);
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ where
|
|||
Renderer::Theme: StyleSheet,
|
||||
{
|
||||
/// The default height of a [`ProgressBar`].
|
||||
pub const DEFAULT_HEIGHT: u16 = 30;
|
||||
pub const DEFAULT_HEIGHT: f32 = 30.0;
|
||||
|
||||
/// Creates a new [`ProgressBar`].
|
||||
///
|
||||
|
|
@ -56,14 +56,14 @@ where
|
|||
}
|
||||
|
||||
/// Sets the width of the [`ProgressBar`].
|
||||
pub fn width(mut self, width: Length) -> Self {
|
||||
self.width = width;
|
||||
pub fn width(mut self, width: impl Into<Length>) -> Self {
|
||||
self.width = width.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the height of the [`ProgressBar`].
|
||||
pub fn height(mut self, height: Length) -> Self {
|
||||
self.height = Some(height);
|
||||
pub fn height(mut self, height: impl Into<Length>) -> Self {
|
||||
self.height = Some(height.into());
|
||||
self
|
||||
}
|
||||
|
||||
|
|
@ -87,7 +87,7 @@ where
|
|||
}
|
||||
|
||||
fn height(&self) -> Length {
|
||||
self.height.unwrap_or(Length::Units(Self::DEFAULT_HEIGHT))
|
||||
self.height.unwrap_or(Length::Fixed(Self::DEFAULT_HEIGHT))
|
||||
}
|
||||
|
||||
fn layout(
|
||||
|
|
@ -97,7 +97,7 @@ where
|
|||
) -> layout::Node {
|
||||
let limits = limits
|
||||
.width(self.width)
|
||||
.height(self.height.unwrap_or(Length::Units(Self::DEFAULT_HEIGHT)));
|
||||
.height(self.height.unwrap_or(Length::Fixed(Self::DEFAULT_HEIGHT)));
|
||||
|
||||
let size = limits.resolve(Size::ZERO);
|
||||
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ where
|
|||
on_click: Message,
|
||||
label: String,
|
||||
width: Length,
|
||||
size: u16,
|
||||
size: f32,
|
||||
spacing: u16,
|
||||
text_size: Option<u16>,
|
||||
font: Renderer::Font,
|
||||
|
|
@ -64,7 +64,7 @@ where
|
|||
Renderer::Theme: StyleSheet,
|
||||
{
|
||||
/// The default size of a [`Radio`] button.
|
||||
pub const DEFAULT_SIZE: u16 = 28;
|
||||
pub const DEFAULT_SIZE: f32 = 28.0;
|
||||
|
||||
/// The default spacing of a [`Radio`] button.
|
||||
pub const DEFAULT_SPACING: u16 = 15;
|
||||
|
|
@ -101,14 +101,14 @@ where
|
|||
}
|
||||
|
||||
/// Sets the size of the [`Radio`] button.
|
||||
pub fn size(mut self, size: u16) -> Self {
|
||||
pub fn size(mut self, size: f32) -> Self {
|
||||
self.size = size;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the width of the [`Radio`] button.
|
||||
pub fn width(mut self, width: Length) -> Self {
|
||||
self.width = width;
|
||||
pub fn width(mut self, width: impl Into<Length>) -> Self {
|
||||
self.width = width.into();
|
||||
self
|
||||
}
|
||||
|
||||
|
|
@ -163,11 +163,7 @@ where
|
|||
.width(self.width)
|
||||
.spacing(self.spacing)
|
||||
.align_items(Alignment::Center)
|
||||
.push(
|
||||
Row::new()
|
||||
.width(Length::Units(self.size))
|
||||
.height(Length::Units(self.size)),
|
||||
)
|
||||
.push(Row::new().width(self.size).height(self.size))
|
||||
.push(Text::new(&self.label).width(self.width).size(
|
||||
self.text_size.unwrap_or_else(|| renderer.default_size()),
|
||||
))
|
||||
|
|
|
|||
|
|
@ -58,14 +58,14 @@ impl<'a, Message, Renderer> Row<'a, Message, Renderer> {
|
|||
}
|
||||
|
||||
/// Sets the width of the [`Row`].
|
||||
pub fn width(mut self, width: Length) -> Self {
|
||||
self.width = width;
|
||||
pub fn width(mut self, width: impl Into<Length>) -> Self {
|
||||
self.width = width.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the height of the [`Row`].
|
||||
pub fn height(mut self, height: Length) -> Self {
|
||||
self.height = height;
|
||||
pub fn height(mut self, height: impl Into<Length>) -> Self {
|
||||
self.height = height.into();
|
||||
self
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@
|
|||
use crate::layout;
|
||||
use crate::renderer;
|
||||
use crate::widget::Tree;
|
||||
use crate::{Color, Element, Layout, Length, Point, Rectangle, Size, Widget};
|
||||
use crate::{
|
||||
Color, Element, Layout, Length, Pixels, Point, Rectangle, Size, Widget,
|
||||
};
|
||||
|
||||
pub use iced_style::rule::{Appearance, FillMode, StyleSheet};
|
||||
|
||||
|
|
@ -25,19 +27,19 @@ where
|
|||
Renderer::Theme: StyleSheet,
|
||||
{
|
||||
/// Creates a horizontal [`Rule`] with the given height.
|
||||
pub fn horizontal(height: u16) -> Self {
|
||||
pub fn horizontal(height: impl Into<Pixels>) -> Self {
|
||||
Rule {
|
||||
width: Length::Fill,
|
||||
height: Length::Units(height),
|
||||
height: Length::Fixed(height.into().0),
|
||||
is_horizontal: true,
|
||||
style: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a vertical [`Rule`] with the given width.
|
||||
pub fn vertical(width: u16) -> Self {
|
||||
pub fn vertical(width: impl Into<Pixels>) -> Self {
|
||||
Rule {
|
||||
width: Length::Units(width),
|
||||
width: Length::Fixed(width.into().0),
|
||||
height: Length::Fill,
|
||||
is_horizontal: false,
|
||||
style: Default::default(),
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ use crate::widget;
|
|||
use crate::widget::operation::{self, Operation};
|
||||
use crate::widget::tree::{self, Tree};
|
||||
use crate::{
|
||||
Background, Clipboard, Color, Command, Element, Layout, Length, Point,
|
||||
Rectangle, Shell, Size, Vector, Widget,
|
||||
Background, Clipboard, Color, Command, Element, Layout, Length, Pixels,
|
||||
Point, Rectangle, Shell, Size, Vector, Widget,
|
||||
};
|
||||
|
||||
pub use iced_style::scrollable::StyleSheet;
|
||||
|
|
@ -66,8 +66,8 @@ where
|
|||
}
|
||||
|
||||
/// Sets the height of the [`Scrollable`].
|
||||
pub fn height(mut self, height: Length) -> Self {
|
||||
self.height = height;
|
||||
pub fn height(mut self, height: impl Into<Length>) -> Self {
|
||||
self.height = height.into();
|
||||
self
|
||||
}
|
||||
|
||||
|
|
@ -108,17 +108,17 @@ where
|
|||
/// Properties of a scrollbar within a [`Scrollable`].
|
||||
#[derive(Debug)]
|
||||
pub struct Properties {
|
||||
width: u16,
|
||||
margin: u16,
|
||||
scroller_width: u16,
|
||||
width: f32,
|
||||
margin: f32,
|
||||
scroller_width: f32,
|
||||
}
|
||||
|
||||
impl Default for Properties {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
width: 10,
|
||||
margin: 0,
|
||||
scroller_width: 10,
|
||||
width: 10.0,
|
||||
margin: 0.0,
|
||||
scroller_width: 10.0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -131,21 +131,21 @@ impl Properties {
|
|||
|
||||
/// Sets the scrollbar width of the [`Scrollable`] .
|
||||
/// Silently enforces a minimum width of 1.
|
||||
pub fn width(mut self, width: u16) -> Self {
|
||||
self.width = width.max(1);
|
||||
pub fn width(mut self, width: impl Into<Pixels>) -> Self {
|
||||
self.width = width.into().0.max(1.0);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the scrollbar margin of the [`Scrollable`] .
|
||||
pub fn margin(mut self, margin: u16) -> Self {
|
||||
self.margin = margin;
|
||||
pub fn margin(mut self, margin: impl Into<Pixels>) -> Self {
|
||||
self.margin = margin.into().0;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the scroller width of the [`Scrollable`] .
|
||||
/// Silently enforces a minimum width of 1.
|
||||
pub fn scroller_width(mut self, scroller_width: u16) -> Self {
|
||||
self.scroller_width = scroller_width.max(1);
|
||||
pub fn scroller_width(mut self, scroller_width: impl Into<Pixels>) -> Self {
|
||||
self.scroller_width = scroller_width.into().0.max(1.0);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
|
@ -398,11 +398,11 @@ pub fn layout<Renderer>(
|
|||
layout_content: impl FnOnce(&Renderer, &layout::Limits) -> layout::Node,
|
||||
) -> layout::Node {
|
||||
let limits = limits
|
||||
.max_height(u32::MAX)
|
||||
.max_height(f32::INFINITY)
|
||||
.max_width(if horizontal_enabled {
|
||||
u32::MAX
|
||||
f32::INFINITY
|
||||
} else {
|
||||
limits.max().width as u32
|
||||
limits.max().width
|
||||
})
|
||||
.width(width)
|
||||
.height(height);
|
||||
|
|
@ -1100,26 +1100,26 @@ impl Scrollbars {
|
|||
|
||||
// Adjust the height of the vertical scrollbar if the horizontal scrollbar
|
||||
// is present
|
||||
let x_scrollbar_height = show_scrollbar_x.map_or(0.0, |h| {
|
||||
(h.width.max(h.scroller_width) + h.margin) as f32
|
||||
});
|
||||
let x_scrollbar_height = show_scrollbar_x
|
||||
.map_or(0.0, |h| h.width.max(h.scroller_width) + h.margin);
|
||||
|
||||
let total_scrollbar_width = width.max(scroller_width) + 2 * margin;
|
||||
let total_scrollbar_width =
|
||||
width.max(scroller_width) + 2.0 * margin;
|
||||
|
||||
// Total bounds of the scrollbar + margin + scroller width
|
||||
let total_scrollbar_bounds = Rectangle {
|
||||
x: bounds.x + bounds.width - total_scrollbar_width as f32,
|
||||
x: bounds.x + bounds.width - total_scrollbar_width,
|
||||
y: bounds.y,
|
||||
width: total_scrollbar_width as f32,
|
||||
width: total_scrollbar_width,
|
||||
height: (bounds.height - x_scrollbar_height).max(0.0),
|
||||
};
|
||||
|
||||
// Bounds of just the scrollbar
|
||||
let scrollbar_bounds = Rectangle {
|
||||
x: bounds.x + bounds.width
|
||||
- f32::from(total_scrollbar_width / 2 + width / 2),
|
||||
x: bounds.x + bounds.width - total_scrollbar_width / 2.0
|
||||
+ width / 2.0,
|
||||
y: bounds.y,
|
||||
width: width as f32,
|
||||
width,
|
||||
height: (bounds.height - x_scrollbar_height).max(0.0),
|
||||
};
|
||||
|
||||
|
|
@ -1129,11 +1129,11 @@ impl Scrollbars {
|
|||
let scroller_offset = offset.y * ratio;
|
||||
|
||||
let scroller_bounds = Rectangle {
|
||||
x: bounds.x + bounds.width
|
||||
- f32::from(total_scrollbar_width / 2 + scroller_width / 2),
|
||||
x: bounds.x + bounds.width - total_scrollbar_width / 2.0
|
||||
+ scroller_width / 2.0,
|
||||
y: (scrollbar_bounds.y + scroller_offset - x_scrollbar_height)
|
||||
.max(0.0),
|
||||
width: scroller_width as f32,
|
||||
width: scroller_width,
|
||||
height: scroller_height,
|
||||
};
|
||||
|
||||
|
|
@ -1158,27 +1158,27 @@ impl Scrollbars {
|
|||
// Need to adjust the width of the horizontal scrollbar if the vertical scrollbar
|
||||
// is present
|
||||
let scrollbar_y_width = y_scrollbar.map_or(0.0, |_| {
|
||||
(vertical.width.max(vertical.scroller_width) + vertical.margin)
|
||||
as f32
|
||||
vertical.width.max(vertical.scroller_width) + vertical.margin
|
||||
});
|
||||
|
||||
let total_scrollbar_height = width.max(scroller_width) + 2 * margin;
|
||||
let total_scrollbar_height =
|
||||
width.max(scroller_width) + 2.0 * margin;
|
||||
|
||||
// Total bounds of the scrollbar + margin + scroller width
|
||||
let total_scrollbar_bounds = Rectangle {
|
||||
x: bounds.x,
|
||||
y: bounds.y + bounds.height - total_scrollbar_height as f32,
|
||||
y: bounds.y + bounds.height - total_scrollbar_height,
|
||||
width: (bounds.width - scrollbar_y_width).max(0.0),
|
||||
height: total_scrollbar_height as f32,
|
||||
height: total_scrollbar_height,
|
||||
};
|
||||
|
||||
// Bounds of just the scrollbar
|
||||
let scrollbar_bounds = Rectangle {
|
||||
x: bounds.x,
|
||||
y: bounds.y + bounds.height
|
||||
- f32::from(total_scrollbar_height / 2 + width / 2),
|
||||
y: bounds.y + bounds.height - total_scrollbar_height / 2.0
|
||||
+ width / 2.0,
|
||||
width: (bounds.width - scrollbar_y_width).max(0.0),
|
||||
height: width as f32,
|
||||
height: width,
|
||||
};
|
||||
|
||||
let ratio = bounds.width / content_bounds.width;
|
||||
|
|
@ -1189,12 +1189,11 @@ impl Scrollbars {
|
|||
let scroller_bounds = Rectangle {
|
||||
x: (scrollbar_bounds.x + scroller_offset - scrollbar_y_width)
|
||||
.max(0.0),
|
||||
y: bounds.y + bounds.height
|
||||
- f32::from(
|
||||
total_scrollbar_height / 2 + scroller_width / 2,
|
||||
),
|
||||
y: bounds.y + bounds.height - total_scrollbar_height / 2.0
|
||||
+ scroller_width / 2.0,
|
||||
|
||||
width: scroller_length,
|
||||
height: scroller_width as f32,
|
||||
height: scroller_width,
|
||||
};
|
||||
|
||||
Some(Scrollbar {
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ where
|
|||
on_change: Box<dyn Fn(T) -> Message + 'a>,
|
||||
on_release: Option<Message>,
|
||||
width: Length,
|
||||
height: u16,
|
||||
height: f32,
|
||||
style: <Renderer::Theme as StyleSheet>::Style,
|
||||
}
|
||||
|
||||
|
|
@ -66,7 +66,7 @@ where
|
|||
Renderer::Theme: StyleSheet,
|
||||
{
|
||||
/// The default height of a [`Slider`].
|
||||
pub const DEFAULT_HEIGHT: u16 = 22;
|
||||
pub const DEFAULT_HEIGHT: f32 = 22.0;
|
||||
|
||||
/// Creates a new [`Slider`].
|
||||
///
|
||||
|
|
@ -116,13 +116,13 @@ where
|
|||
}
|
||||
|
||||
/// Sets the width of the [`Slider`].
|
||||
pub fn width(mut self, width: Length) -> Self {
|
||||
self.width = width;
|
||||
pub fn width(mut self, width: impl Into<Length>) -> Self {
|
||||
self.width = width.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the height of the [`Slider`].
|
||||
pub fn height(mut self, height: u16) -> Self {
|
||||
pub fn height(mut self, height: f32) -> Self {
|
||||
self.height = height;
|
||||
self
|
||||
}
|
||||
|
|
@ -172,9 +172,7 @@ where
|
|||
_renderer: &Renderer,
|
||||
limits: &layout::Limits,
|
||||
) -> layout::Node {
|
||||
let limits =
|
||||
limits.width(self.width).height(Length::Units(self.height));
|
||||
|
||||
let limits = limits.width(self.width).height(self.height);
|
||||
let size = limits.resolve(Size::ZERO);
|
||||
|
||||
layout::Node::new(size)
|
||||
|
|
|
|||
|
|
@ -15,23 +15,26 @@ pub struct Space {
|
|||
|
||||
impl Space {
|
||||
/// Creates an amount of empty [`Space`] with the given width and height.
|
||||
pub fn new(width: Length, height: Length) -> Self {
|
||||
Space { width, height }
|
||||
pub fn new(width: impl Into<Length>, height: impl Into<Length>) -> Self {
|
||||
Space {
|
||||
width: width.into(),
|
||||
height: height.into(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates an amount of horizontal [`Space`].
|
||||
pub fn with_width(width: Length) -> Self {
|
||||
pub fn with_width(width: impl Into<Length>) -> Self {
|
||||
Space {
|
||||
width,
|
||||
width: width.into(),
|
||||
height: Length::Shrink,
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates an amount of vertical [`Space`].
|
||||
pub fn with_height(height: Length) -> Self {
|
||||
pub fn with_height(height: impl Into<Length>) -> Self {
|
||||
Space {
|
||||
width: Length::Shrink,
|
||||
height,
|
||||
height: height.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,15 +56,15 @@ where
|
|||
|
||||
/// Sets the width of the [`Svg`].
|
||||
#[must_use]
|
||||
pub fn width(mut self, width: Length) -> Self {
|
||||
self.width = width;
|
||||
pub fn width(mut self, width: impl Into<Length>) -> Self {
|
||||
self.width = width.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the height of the [`Svg`].
|
||||
#[must_use]
|
||||
pub fn height(mut self, height: Length) -> Self {
|
||||
self.height = height;
|
||||
pub fn height(mut self, height: impl Into<Length>) -> Self {
|
||||
self.height = height.into();
|
||||
self
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -84,14 +84,14 @@ where
|
|||
}
|
||||
|
||||
/// Sets the width of the [`Text`] boundaries.
|
||||
pub fn width(mut self, width: Length) -> Self {
|
||||
self.width = width;
|
||||
pub fn width(mut self, width: impl Into<Length>) -> Self {
|
||||
self.width = width.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the height of the [`Text`] boundaries.
|
||||
pub fn height(mut self, height: Length) -> Self {
|
||||
self.height = height;
|
||||
pub fn height(mut self, height: impl Into<Length>) -> Self {
|
||||
self.height = height.into();
|
||||
self
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -133,8 +133,8 @@ where
|
|||
self
|
||||
}
|
||||
/// Sets the width of the [`TextInput`].
|
||||
pub fn width(mut self, width: Length) -> Self {
|
||||
self.width = width;
|
||||
pub fn width(mut self, width: impl Into<Length>) -> Self {
|
||||
self.width = width.into();
|
||||
self
|
||||
}
|
||||
|
||||
|
|
@ -387,11 +387,7 @@ where
|
|||
let text_size = size.unwrap_or_else(|| renderer.default_size());
|
||||
|
||||
let padding = padding.fit(Size::ZERO, limits.max());
|
||||
|
||||
let limits = limits
|
||||
.width(width)
|
||||
.pad(padding)
|
||||
.height(Length::Units(text_size));
|
||||
let limits = limits.width(width).pad(padding).height(text_size);
|
||||
|
||||
let mut text = layout::Node::new(limits.resolve(Size::ZERO));
|
||||
text.move_to(Point::new(padding.left.into(), padding.top.into()));
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ where
|
|||
on_toggle: Box<dyn Fn(bool) -> Message + 'a>,
|
||||
label: Option<String>,
|
||||
width: Length,
|
||||
size: u16,
|
||||
size: f32,
|
||||
text_size: Option<u16>,
|
||||
text_alignment: alignment::Horizontal,
|
||||
spacing: u16,
|
||||
|
|
@ -52,7 +52,7 @@ where
|
|||
Renderer::Theme: StyleSheet,
|
||||
{
|
||||
/// The default size of a [`Toggler`].
|
||||
pub const DEFAULT_SIZE: u16 = 20;
|
||||
pub const DEFAULT_SIZE: f32 = 20.0;
|
||||
|
||||
/// Creates a new [`Toggler`].
|
||||
///
|
||||
|
|
@ -85,14 +85,14 @@ where
|
|||
}
|
||||
|
||||
/// Sets the size of the [`Toggler`].
|
||||
pub fn size(mut self, size: u16) -> Self {
|
||||
pub fn size(mut self, size: f32) -> Self {
|
||||
self.size = size;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the width of the [`Toggler`].
|
||||
pub fn width(mut self, width: Length) -> Self {
|
||||
self.width = width;
|
||||
pub fn width(mut self, width: impl Into<Length>) -> Self {
|
||||
self.width = width.into();
|
||||
self
|
||||
}
|
||||
|
||||
|
|
@ -169,11 +169,7 @@ where
|
|||
);
|
||||
}
|
||||
|
||||
row = row.push(
|
||||
Row::new()
|
||||
.width(Length::Units(2 * self.size))
|
||||
.height(Length::Units(self.size)),
|
||||
);
|
||||
row = row.push(Row::new().width(2.0 * self.size).height(self.size));
|
||||
|
||||
row.layout(renderer, limits)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ where
|
|||
value: T,
|
||||
on_change: Box<dyn Fn(T) -> Message + 'a>,
|
||||
on_release: Option<Message>,
|
||||
width: u16,
|
||||
width: f32,
|
||||
height: Length,
|
||||
style: <Renderer::Theme as StyleSheet>::Style,
|
||||
}
|
||||
|
|
@ -60,7 +60,7 @@ where
|
|||
Renderer::Theme: StyleSheet,
|
||||
{
|
||||
/// The default width of a [`VerticalSlider`].
|
||||
pub const DEFAULT_WIDTH: u16 = 22;
|
||||
pub const DEFAULT_WIDTH: f32 = 22.0;
|
||||
|
||||
/// Creates a new [`VerticalSlider`].
|
||||
///
|
||||
|
|
@ -110,14 +110,14 @@ where
|
|||
}
|
||||
|
||||
/// Sets the width of the [`VerticalSlider`].
|
||||
pub fn width(mut self, width: u16) -> Self {
|
||||
pub fn width(mut self, width: f32) -> Self {
|
||||
self.width = width;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the height of the [`VerticalSlider`].
|
||||
pub fn height(mut self, height: Length) -> Self {
|
||||
self.height = height;
|
||||
pub fn height(mut self, height: impl Into<Length>) -> Self {
|
||||
self.height = height.into();
|
||||
self
|
||||
}
|
||||
|
||||
|
|
@ -166,9 +166,7 @@ where
|
|||
_renderer: &Renderer,
|
||||
limits: &layout::Limits,
|
||||
) -> layout::Node {
|
||||
let limits =
|
||||
limits.width(Length::Units(self.width)).height(self.height);
|
||||
|
||||
let limits = limits.width(self.width).height(self.height);
|
||||
let size = limits.resolve(Size::ZERO);
|
||||
|
||||
layout::Node::new(size)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue