Use recently stabilized intra-doc links
See RFC: https://github.com/rust-lang/rfcs/blob/master/text/1946-intra-rustdoc-links.md
This commit is contained in:
parent
d612bf5678
commit
01322f69a4
135 changed files with 135 additions and 1769 deletions
|
|
@ -1,9 +1,6 @@
|
|||
//! Allow your users to perform actions by pressing a button.
|
||||
//!
|
||||
//! A [`Button`] has some local [`State`].
|
||||
//!
|
||||
//! [`Button`]: struct.Button.html
|
||||
//! [`State`]: struct.State.html
|
||||
use crate::event::{self, Event};
|
||||
use crate::layout;
|
||||
use crate::mouse;
|
||||
|
|
@ -49,9 +46,6 @@ where
|
|||
{
|
||||
/// Creates a new [`Button`] with some local [`State`] and the given
|
||||
/// content.
|
||||
///
|
||||
/// [`Button`]: struct.Button.html
|
||||
/// [`State`]: struct.State.html
|
||||
pub fn new<E>(state: &'a mut State, content: E) -> Self
|
||||
where
|
||||
E: Into<Element<'a, Message, Renderer>>,
|
||||
|
|
@ -70,56 +64,42 @@ where
|
|||
}
|
||||
|
||||
/// Sets the width of the [`Button`].
|
||||
///
|
||||
/// [`Button`]: struct.Button.html
|
||||
pub fn width(mut self, width: Length) -> Self {
|
||||
self.width = width;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the height of the [`Button`].
|
||||
///
|
||||
/// [`Button`]: struct.Button.html
|
||||
pub fn height(mut self, height: Length) -> Self {
|
||||
self.height = height;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the minimum width of the [`Button`].
|
||||
///
|
||||
/// [`Button`]: struct.Button.html
|
||||
pub fn min_width(mut self, min_width: u32) -> Self {
|
||||
self.min_width = min_width;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the minimum height of the [`Button`].
|
||||
///
|
||||
/// [`Button`]: struct.Button.html
|
||||
pub fn min_height(mut self, min_height: u32) -> Self {
|
||||
self.min_height = min_height;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the padding of the [`Button`].
|
||||
///
|
||||
/// [`Button`]: struct.Button.html
|
||||
pub fn padding(mut self, padding: u16) -> Self {
|
||||
self.padding = padding;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the message that will be produced when the [`Button`] is pressed.
|
||||
///
|
||||
/// [`Button`]: struct.Button.html
|
||||
pub fn on_press(mut self, msg: Message) -> Self {
|
||||
self.on_press = Some(msg);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the style of the [`Button`].
|
||||
///
|
||||
/// [`Button`]: struct.Button.html
|
||||
pub fn style(mut self, style: impl Into<Renderer::Style>) -> Self {
|
||||
self.style = style.into();
|
||||
self
|
||||
|
|
@ -127,8 +107,6 @@ where
|
|||
}
|
||||
|
||||
/// The local state of a [`Button`].
|
||||
///
|
||||
/// [`Button`]: struct.Button.html
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
||||
pub struct State {
|
||||
is_pressed: bool,
|
||||
|
|
@ -136,8 +114,6 @@ pub struct State {
|
|||
|
||||
impl State {
|
||||
/// Creates a new [`State`].
|
||||
///
|
||||
/// [`State`]: struct.State.html
|
||||
pub fn new() -> State {
|
||||
State::default()
|
||||
}
|
||||
|
|
@ -254,20 +230,15 @@ where
|
|||
/// Your [renderer] will need to implement this trait before being
|
||||
/// able to use a [`Button`] in your user interface.
|
||||
///
|
||||
/// [`Button`]: struct.Button.html
|
||||
/// [renderer]: ../../renderer/index.html
|
||||
/// [renderer]: crate::renderer
|
||||
pub trait Renderer: crate::Renderer + Sized {
|
||||
/// The default padding of a [`Button`].
|
||||
///
|
||||
/// [`Button`]: struct.Button.html
|
||||
const DEFAULT_PADDING: u16;
|
||||
|
||||
/// The style supported by this renderer.
|
||||
type Style: Default;
|
||||
|
||||
/// Draws a [`Button`].
|
||||
///
|
||||
/// [`Button`]: struct.Button.html
|
||||
fn draw<Message>(
|
||||
&mut self,
|
||||
defaults: &Self::Defaults,
|
||||
|
|
|
|||
|
|
@ -52,8 +52,6 @@ impl<Message, Renderer: self::Renderer + text::Renderer>
|
|||
/// * a function that will be called when the [`Checkbox`] is toggled. It
|
||||
/// will receive the new state of the [`Checkbox`] and must produce a
|
||||
/// `Message`.
|
||||
///
|
||||
/// [`Checkbox`]: struct.Checkbox.html
|
||||
pub fn new<F>(is_checked: bool, label: impl Into<String>, f: F) -> Self
|
||||
where
|
||||
F: 'static + Fn(bool) -> Message,
|
||||
|
|
@ -72,32 +70,24 @@ impl<Message, Renderer: self::Renderer + text::Renderer>
|
|||
}
|
||||
|
||||
/// Sets the size of the [`Checkbox`].
|
||||
///
|
||||
/// [`Checkbox`]: struct.Checkbox.html
|
||||
pub fn size(mut self, size: u16) -> Self {
|
||||
self.size = size;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the width of the [`Checkbox`].
|
||||
///
|
||||
/// [`Checkbox`]: struct.Checkbox.html
|
||||
pub fn width(mut self, width: Length) -> Self {
|
||||
self.width = width;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the spacing between the [`Checkbox`] and the text.
|
||||
///
|
||||
/// [`Checkbox`]: struct.Checkbox.html
|
||||
pub fn spacing(mut self, spacing: u16) -> Self {
|
||||
self.spacing = spacing;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the text size of the [`Checkbox`].
|
||||
///
|
||||
/// [`Checkbox`]: struct.Checkbox.html
|
||||
pub fn text_size(mut self, text_size: u16) -> Self {
|
||||
self.text_size = Some(text_size);
|
||||
self
|
||||
|
|
@ -105,16 +95,13 @@ impl<Message, Renderer: self::Renderer + text::Renderer>
|
|||
|
||||
/// Sets the [`Font`] of the text of the [`Checkbox`].
|
||||
///
|
||||
/// [`Checkbox`]: struct.Checkbox.html
|
||||
/// [`Font`]: ../../struct.Font.html
|
||||
/// [`Font`]: crate::widget::text::Renderer::Font
|
||||
pub fn font(mut self, font: Renderer::Font) -> Self {
|
||||
self.font = font;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the style of the [`Checkbox`].
|
||||
///
|
||||
/// [`Checkbox`]: struct.Checkbox.html
|
||||
pub fn style(mut self, style: impl Into<Renderer::Style>) -> Self {
|
||||
self.style = style.into();
|
||||
self
|
||||
|
|
@ -234,20 +221,15 @@ where
|
|||
/// Your [renderer] will need to implement this trait before being
|
||||
/// able to use a [`Checkbox`] in your user interface.
|
||||
///
|
||||
/// [`Checkbox`]: struct.Checkbox.html
|
||||
/// [renderer]: ../../renderer/index.html
|
||||
/// [renderer]: crate::Renderer
|
||||
pub trait Renderer: crate::Renderer {
|
||||
/// The style supported by this renderer.
|
||||
type Style: Default;
|
||||
|
||||
/// The default size of a [`Checkbox`].
|
||||
///
|
||||
/// [`Checkbox`]: struct.Checkbox.html
|
||||
const DEFAULT_SIZE: u16;
|
||||
|
||||
/// The default spacing of a [`Checkbox`].
|
||||
///
|
||||
/// [`Checkbox`]: struct.Checkbox.html
|
||||
const DEFAULT_SPACING: u16;
|
||||
|
||||
/// Draws a [`Checkbox`].
|
||||
|
|
@ -257,8 +239,6 @@ pub trait Renderer: crate::Renderer {
|
|||
/// * whether the [`Checkbox`] is selected or not
|
||||
/// * whether the mouse is over the [`Checkbox`] or not
|
||||
/// * the drawn label of the [`Checkbox`]
|
||||
///
|
||||
/// [`Checkbox`]: struct.Checkbox.html
|
||||
fn draw(
|
||||
&mut self,
|
||||
bounds: Rectangle,
|
||||
|
|
|
|||
|
|
@ -25,15 +25,11 @@ pub struct Column<'a, Message, Renderer> {
|
|||
|
||||
impl<'a, Message, Renderer> Column<'a, Message, Renderer> {
|
||||
/// Creates an empty [`Column`].
|
||||
///
|
||||
/// [`Column`]: struct.Column.html
|
||||
pub fn new() -> Self {
|
||||
Self::with_children(Vec::new())
|
||||
}
|
||||
|
||||
/// Creates a [`Column`] with the given elements.
|
||||
///
|
||||
/// [`Column`]: struct.Column.html
|
||||
pub fn with_children(
|
||||
children: Vec<Element<'a, Message, Renderer>>,
|
||||
) -> Self {
|
||||
|
|
@ -60,56 +56,42 @@ impl<'a, Message, Renderer> Column<'a, Message, Renderer> {
|
|||
}
|
||||
|
||||
/// Sets the padding of the [`Column`].
|
||||
///
|
||||
/// [`Column`]: struct.Column.html
|
||||
pub fn padding(mut self, units: u16) -> Self {
|
||||
self.padding = units;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the width of the [`Column`].
|
||||
///
|
||||
/// [`Column`]: struct.Column.html
|
||||
pub fn width(mut self, width: Length) -> Self {
|
||||
self.width = width;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the height of the [`Column`].
|
||||
///
|
||||
/// [`Column`]: struct.Column.html
|
||||
pub fn height(mut self, height: Length) -> Self {
|
||||
self.height = height;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the maximum width of the [`Column`].
|
||||
///
|
||||
/// [`Column`]: struct.Column.html
|
||||
pub fn max_width(mut self, max_width: u32) -> Self {
|
||||
self.max_width = max_width;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the maximum height of the [`Column`] in pixels.
|
||||
///
|
||||
/// [`Column`]: struct.Column.html
|
||||
pub fn max_height(mut self, max_height: u32) -> Self {
|
||||
self.max_height = max_height;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the horizontal alignment of the contents of the [`Column`] .
|
||||
///
|
||||
/// [`Column`]: struct.Column.html
|
||||
pub fn align_items(mut self, align: Align) -> Self {
|
||||
self.align_items = align;
|
||||
self
|
||||
}
|
||||
|
||||
/// Adds an element to the [`Column`].
|
||||
///
|
||||
/// [`Column`]: struct.Column.html
|
||||
pub fn push<E>(mut self, child: E) -> Self
|
||||
where
|
||||
E: Into<Element<'a, Message, Renderer>>,
|
||||
|
|
@ -230,8 +212,7 @@ where
|
|||
/// Your [renderer] will need to implement this trait before being
|
||||
/// able to use a [`Column`] in your user interface.
|
||||
///
|
||||
/// [`Column`]: struct.Column.html
|
||||
/// [renderer]: ../../renderer/index.html
|
||||
/// [renderer]: crate::renderer
|
||||
pub trait Renderer: crate::Renderer + Sized {
|
||||
/// Draws a [`Column`].
|
||||
///
|
||||
|
|
@ -239,9 +220,6 @@ pub trait Renderer: crate::Renderer + Sized {
|
|||
/// - the children of the [`Column`]
|
||||
/// - the [`Layout`] of the [`Column`] and its children
|
||||
/// - the cursor position
|
||||
///
|
||||
/// [`Column`]: struct.Column.html
|
||||
/// [`Layout`]: ../layout/struct.Layout.html
|
||||
fn draw<Message>(
|
||||
&mut self,
|
||||
defaults: &Self::Defaults,
|
||||
|
|
|
|||
|
|
@ -31,8 +31,6 @@ where
|
|||
Renderer: self::Renderer,
|
||||
{
|
||||
/// Creates an empty [`Container`].
|
||||
///
|
||||
/// [`Container`]: struct.Container.html
|
||||
pub fn new<T>(content: T) -> Self
|
||||
where
|
||||
T: Into<Element<'a, Message, Renderer>>,
|
||||
|
|
@ -51,80 +49,60 @@ where
|
|||
}
|
||||
|
||||
/// Sets the padding of the [`Container`].
|
||||
///
|
||||
/// [`Container`]: struct.Column.html
|
||||
pub fn padding(mut self, units: u16) -> Self {
|
||||
self.padding = units;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the width of the [`Container`].
|
||||
///
|
||||
/// [`Container`]: struct.Container.html
|
||||
pub fn width(mut self, width: Length) -> Self {
|
||||
self.width = width;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the height of the [`Container`].
|
||||
///
|
||||
/// [`Container`]: struct.Container.html
|
||||
pub fn height(mut self, height: Length) -> Self {
|
||||
self.height = height;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the maximum width of the [`Container`].
|
||||
///
|
||||
/// [`Container`]: struct.Container.html
|
||||
pub fn max_width(mut self, max_width: u32) -> Self {
|
||||
self.max_width = max_width;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the maximum height of the [`Container`] in pixels.
|
||||
///
|
||||
/// [`Container`]: struct.Container.html
|
||||
pub fn max_height(mut self, max_height: u32) -> Self {
|
||||
self.max_height = max_height;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the content alignment for the horizontal axis of the [`Container`].
|
||||
///
|
||||
/// [`Container`]: struct.Container.html
|
||||
pub fn align_x(mut self, alignment: Align) -> Self {
|
||||
self.horizontal_alignment = alignment;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the content alignment for the vertical axis of the [`Container`].
|
||||
///
|
||||
/// [`Container`]: struct.Container.html
|
||||
pub fn align_y(mut self, alignment: Align) -> Self {
|
||||
self.vertical_alignment = alignment;
|
||||
self
|
||||
}
|
||||
|
||||
/// Centers the contents in the horizontal axis of the [`Container`].
|
||||
///
|
||||
/// [`Container`]: struct.Container.html
|
||||
pub fn center_x(mut self) -> Self {
|
||||
self.horizontal_alignment = Align::Center;
|
||||
self
|
||||
}
|
||||
|
||||
/// Centers the contents in the vertical axis of the [`Container`].
|
||||
///
|
||||
/// [`Container`]: struct.Container.html
|
||||
pub fn center_y(mut self) -> Self {
|
||||
self.vertical_alignment = Align::Center;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the style of the [`Container`].
|
||||
///
|
||||
/// [`Container`]: struct.Container.html
|
||||
pub fn style(mut self, style: impl Into<Renderer::Style>) -> Self {
|
||||
self.style = style.into();
|
||||
self
|
||||
|
|
@ -232,15 +210,12 @@ where
|
|||
/// Your [renderer] will need to implement this trait before being
|
||||
/// able to use a [`Container`] in your user interface.
|
||||
///
|
||||
/// [`Container`]: struct.Container.html
|
||||
/// [renderer]: ../../renderer/index.html
|
||||
/// [renderer]: crate::renderer
|
||||
pub trait Renderer: crate::Renderer {
|
||||
/// The style supported by this renderer.
|
||||
type Style: Default;
|
||||
|
||||
/// Draws a [`Container`].
|
||||
///
|
||||
/// [`Container`]: struct.Container.html
|
||||
fn draw<Message>(
|
||||
&mut self,
|
||||
defaults: &Self::Defaults,
|
||||
|
|
|
|||
|
|
@ -28,8 +28,6 @@ pub struct Image {
|
|||
|
||||
impl Image {
|
||||
/// Creates a new [`Image`] with the given path.
|
||||
///
|
||||
/// [`Image`]: struct.Image.html
|
||||
pub fn new<T: Into<Handle>>(handle: T) -> Self {
|
||||
Image {
|
||||
handle: handle.into(),
|
||||
|
|
@ -39,16 +37,12 @@ impl Image {
|
|||
}
|
||||
|
||||
/// Sets the width of the [`Image`] boundaries.
|
||||
///
|
||||
/// [`Image`]: struct.Image.html
|
||||
pub fn width(mut self, width: Length) -> Self {
|
||||
self.width = width;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the height of the [`Image`] boundaries.
|
||||
///
|
||||
/// [`Image`]: struct.Image.html
|
||||
pub fn height(mut self, height: Length) -> Self {
|
||||
self.height = height;
|
||||
self
|
||||
|
|
@ -114,8 +108,6 @@ where
|
|||
}
|
||||
|
||||
/// An [`Image`] handle.
|
||||
///
|
||||
/// [`Image`]: struct.Image.html
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Handle {
|
||||
id: u64,
|
||||
|
|
@ -126,8 +118,6 @@ impl Handle {
|
|||
/// Creates an image [`Handle`] pointing to the image of the given path.
|
||||
///
|
||||
/// Makes an educated guess about the image format by examining the data in the file.
|
||||
///
|
||||
/// [`Handle`]: struct.Handle.html
|
||||
pub fn from_path<T: Into<PathBuf>>(path: T) -> Handle {
|
||||
Self::from_data(Data::Path(path.into()))
|
||||
}
|
||||
|
|
@ -137,8 +127,6 @@ impl Handle {
|
|||
/// pixels.
|
||||
///
|
||||
/// This is useful if you have already decoded your image.
|
||||
///
|
||||
/// [`Handle`]: struct.Handle.html
|
||||
pub fn from_pixels(width: u32, height: u32, pixels: Vec<u8>) -> Handle {
|
||||
Self::from_data(Data::Pixels {
|
||||
width,
|
||||
|
|
@ -153,8 +141,6 @@ impl Handle {
|
|||
///
|
||||
/// This is useful if you already have your image loaded in-memory, maybe
|
||||
/// because you downloaded or generated it procedurally.
|
||||
///
|
||||
/// [`Handle`]: struct.Handle.html
|
||||
pub fn from_memory(bytes: Vec<u8>) -> Handle {
|
||||
Self::from_data(Data::Bytes(bytes))
|
||||
}
|
||||
|
|
@ -170,15 +156,11 @@ impl Handle {
|
|||
}
|
||||
|
||||
/// Returns the unique identifier of the [`Handle`].
|
||||
///
|
||||
/// [`Handle`]: struct.Handle.html
|
||||
pub fn id(&self) -> u64 {
|
||||
self.id
|
||||
}
|
||||
|
||||
/// Returns a reference to the image [`Data`].
|
||||
///
|
||||
/// [`Data`]: enum.Data.html
|
||||
pub fn data(&self) -> &Data {
|
||||
&self.data
|
||||
}
|
||||
|
|
@ -200,8 +182,6 @@ impl Hash for Handle {
|
|||
}
|
||||
|
||||
/// The data of an [`Image`].
|
||||
///
|
||||
/// [`Image`]: struct.Image.html
|
||||
#[derive(Clone, Hash)]
|
||||
pub enum Data {
|
||||
/// File data
|
||||
|
|
@ -238,17 +218,12 @@ impl std::fmt::Debug for Data {
|
|||
/// Your [renderer] will need to implement this trait before being able to use
|
||||
/// an [`Image`] in your user interface.
|
||||
///
|
||||
/// [`Image`]: struct.Image.html
|
||||
/// [renderer]: ../../renderer/index.html
|
||||
/// [renderer]: crate::renderer
|
||||
pub trait Renderer: crate::Renderer {
|
||||
/// Returns the dimensions of an [`Image`] located on the given path.
|
||||
///
|
||||
/// [`Image`]: struct.Image.html
|
||||
fn dimensions(&self, handle: &Handle) -> (u32, u32);
|
||||
|
||||
/// Draws an [`Image`].
|
||||
///
|
||||
/// [`Image`]: struct.Image.html
|
||||
fn draw(&mut self, handle: Handle, layout: Layout<'_>) -> Self::Output;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,8 +6,7 @@
|
|||
//! The [`pane_grid` example] showcases how to use a [`PaneGrid`] with resizing,
|
||||
//! drag and drop, and hotkey support.
|
||||
//!
|
||||
//! [`pane_grid` example]: https://github.com/hecrj/iced/tree/0.1/examples/pane_grid
|
||||
//! [`PaneGrid`]: struct.PaneGrid.html
|
||||
//! [`pane_grid` example]: https://github.com/hecrj/iced/tree/0.2/examples/pane_grid
|
||||
mod axis;
|
||||
mod configuration;
|
||||
mod content;
|
||||
|
|
@ -89,9 +88,6 @@ use crate::{
|
|||
/// .on_drag(Message::PaneDragged)
|
||||
/// .on_resize(10, Message::PaneResized);
|
||||
/// ```
|
||||
///
|
||||
/// [`PaneGrid`]: struct.PaneGrid.html
|
||||
/// [`State`]: struct.State.html
|
||||
#[allow(missing_debug_implementations)]
|
||||
pub struct PaneGrid<'a, Message, Renderer: self::Renderer> {
|
||||
state: &'a mut state::Internal,
|
||||
|
|
@ -112,10 +108,6 @@ where
|
|||
///
|
||||
/// The view function will be called to display each [`Pane`] present in the
|
||||
/// [`State`].
|
||||
///
|
||||
/// [`PaneGrid`]: struct.PaneGrid.html
|
||||
/// [`State`]: struct.State.html
|
||||
/// [`Pane`]: struct.Pane.html
|
||||
pub fn new<T>(
|
||||
state: &'a mut State<T>,
|
||||
view: impl Fn(Pane, &'a mut T) -> Content<'a, Message, Renderer>,
|
||||
|
|
@ -141,24 +133,18 @@ where
|
|||
}
|
||||
|
||||
/// Sets the width of the [`PaneGrid`].
|
||||
///
|
||||
/// [`PaneGrid`]: struct.PaneGrid.html
|
||||
pub fn width(mut self, width: Length) -> Self {
|
||||
self.width = width;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the height of the [`PaneGrid`].
|
||||
///
|
||||
/// [`PaneGrid`]: struct.PaneGrid.html
|
||||
pub fn height(mut self, height: Length) -> Self {
|
||||
self.height = height;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the spacing _between_ the panes of the [`PaneGrid`].
|
||||
///
|
||||
/// [`PaneGrid`]: struct.PaneGrid.html
|
||||
pub fn spacing(mut self, units: u16) -> Self {
|
||||
self.spacing = units;
|
||||
self
|
||||
|
|
@ -166,9 +152,6 @@ where
|
|||
|
||||
/// Sets the message that will be produced when a [`Pane`] of the
|
||||
/// [`PaneGrid`] is clicked.
|
||||
///
|
||||
/// [`Pane`]: struct.Pane.html
|
||||
/// [`PaneGrid`]: struct.PaneGrid.html
|
||||
pub fn on_click<F>(mut self, f: F) -> Self
|
||||
where
|
||||
F: 'a + Fn(Pane) -> Message,
|
||||
|
|
@ -179,8 +162,6 @@ where
|
|||
|
||||
/// Enables the drag and drop interactions of the [`PaneGrid`], which will
|
||||
/// use the provided function to produce messages.
|
||||
///
|
||||
/// [`PaneGrid`]: struct.PaneGrid.html
|
||||
pub fn on_drag<F>(mut self, f: F) -> Self
|
||||
where
|
||||
F: 'a + Fn(DragEvent) -> Message,
|
||||
|
|
@ -198,8 +179,6 @@ where
|
|||
/// The grabbable area of a split will have a length of `spacing + leeway`,
|
||||
/// properly centered. In other words, a length of
|
||||
/// `(spacing + leeway) / 2.0` on either side of the split line.
|
||||
///
|
||||
/// [`PaneGrid`]: struct.PaneGrid.html
|
||||
pub fn on_resize<F>(mut self, leeway: u16, f: F) -> Self
|
||||
where
|
||||
F: 'a + Fn(ResizeEvent) -> Message,
|
||||
|
|
@ -287,63 +266,41 @@ where
|
|||
}
|
||||
|
||||
/// An event produced during a drag and drop interaction of a [`PaneGrid`].
|
||||
///
|
||||
/// [`PaneGrid`]: struct.PaneGrid.html
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum DragEvent {
|
||||
/// A [`Pane`] was picked for dragging.
|
||||
///
|
||||
/// [`Pane`]: struct.Pane.html
|
||||
Picked {
|
||||
/// The picked [`Pane`].
|
||||
///
|
||||
/// [`Pane`]: struct.Pane.html
|
||||
pane: Pane,
|
||||
},
|
||||
|
||||
/// A [`Pane`] was dropped on top of another [`Pane`].
|
||||
///
|
||||
/// [`Pane`]: struct.Pane.html
|
||||
Dropped {
|
||||
/// The picked [`Pane`].
|
||||
///
|
||||
/// [`Pane`]: struct.Pane.html
|
||||
pane: Pane,
|
||||
|
||||
/// The [`Pane`] where the picked one was dropped on.
|
||||
///
|
||||
/// [`Pane`]: struct.Pane.html
|
||||
target: Pane,
|
||||
},
|
||||
|
||||
/// A [`Pane`] was picked and then dropped outside of other [`Pane`]
|
||||
/// boundaries.
|
||||
///
|
||||
/// [`Pane`]: struct.Pane.html
|
||||
Canceled {
|
||||
/// The picked [`Pane`].
|
||||
///
|
||||
/// [`Pane`]: struct.Pane.html
|
||||
pane: Pane,
|
||||
},
|
||||
}
|
||||
|
||||
/// An event produced during a resize interaction of a [`PaneGrid`].
|
||||
///
|
||||
/// [`PaneGrid`]: struct.PaneGrid.html
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct ResizeEvent {
|
||||
/// The [`Split`] that is being dragged for resizing.
|
||||
///
|
||||
/// [`Split`]: struct.Split.html
|
||||
pub split: Split,
|
||||
|
||||
/// The new ratio of the [`Split`].
|
||||
///
|
||||
/// The ratio is a value in [0, 1], representing the exact position of a
|
||||
/// [`Split`] between two panes.
|
||||
///
|
||||
/// [`Split`]: struct.Split.html
|
||||
pub ratio: f32,
|
||||
}
|
||||
|
||||
|
|
@ -585,8 +542,7 @@ where
|
|||
/// Your [renderer] will need to implement this trait before being
|
||||
/// able to use a [`PaneGrid`] in your user interface.
|
||||
///
|
||||
/// [`PaneGrid`]: struct.PaneGrid.html
|
||||
/// [renderer]: ../../renderer/index.html
|
||||
/// [renderer]: crate::renderer
|
||||
pub trait Renderer:
|
||||
crate::Renderer + container::Renderer + text::Renderer + Sized
|
||||
{
|
||||
|
|
@ -598,10 +554,6 @@ pub trait Renderer:
|
|||
/// - the [`Axis`] that is currently being resized
|
||||
/// - the [`Layout`] of the [`PaneGrid`] and its elements
|
||||
/// - the cursor position
|
||||
///
|
||||
/// [`PaneGrid`]: struct.PaneGrid.html
|
||||
/// [`Pane`]: struct.Pane.html
|
||||
/// [`Layout`]: ../layout/struct.Layout.html
|
||||
fn draw<Message>(
|
||||
&mut self,
|
||||
defaults: &Self::Defaults,
|
||||
|
|
@ -619,9 +571,6 @@ pub trait Renderer:
|
|||
/// - the [`Content`] of the [`Pane`]
|
||||
/// - the [`Layout`] of the [`Pane`] and its elements
|
||||
/// - the cursor position
|
||||
///
|
||||
/// [`Pane`]: struct.Pane.html
|
||||
/// [`Layout`]: ../layout/struct.Layout.html
|
||||
fn draw_pane<Message>(
|
||||
&mut self,
|
||||
defaults: &Self::Defaults,
|
||||
|
|
@ -640,9 +589,6 @@ pub trait Renderer:
|
|||
/// - the title of the [`TitleBar`] with its size, font, and bounds
|
||||
/// - the controls of the [`TitleBar`] with their [`Layout`+, if any
|
||||
/// - the cursor position
|
||||
///
|
||||
/// [`TitleBar`]: struct.TitleBar.html
|
||||
/// [`Layout`]: ../layout/struct.Layout.html
|
||||
fn draw_title_bar<Message>(
|
||||
&mut self,
|
||||
defaults: &Self::Defaults,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use crate::{Clipboard, Element, Hasher, Layout, Point, Size};
|
|||
|
||||
/// The content of a [`Pane`].
|
||||
///
|
||||
/// [`Pane`]: struct.Pane.html
|
||||
/// [`Pane`]: crate::widget::pane_grid::Pane
|
||||
#[allow(missing_debug_implementations)]
|
||||
pub struct Content<'a, Message, Renderer: pane_grid::Renderer> {
|
||||
title_bar: Option<TitleBar<'a, Message, Renderer>>,
|
||||
|
|
@ -20,8 +20,6 @@ where
|
|||
Renderer: pane_grid::Renderer,
|
||||
{
|
||||
/// Creates a new [`Content`] with the provided body.
|
||||
///
|
||||
/// [`Content`]: struct.Content.html
|
||||
pub fn new(body: impl Into<Element<'a, Message, Renderer>>) -> Self {
|
||||
Self {
|
||||
title_bar: None,
|
||||
|
|
@ -31,9 +29,6 @@ where
|
|||
}
|
||||
|
||||
/// Sets the [`TitleBar`] of this [`Content`].
|
||||
///
|
||||
/// [`TitleBar`]: struct.TitleBar.html
|
||||
/// [`Content`]: struct.Content.html
|
||||
pub fn title_bar(
|
||||
mut self,
|
||||
title_bar: TitleBar<'a, Message, Renderer>,
|
||||
|
|
@ -43,8 +38,6 @@ where
|
|||
}
|
||||
|
||||
/// Sets the style of the [`Content`].
|
||||
///
|
||||
/// [`Content`]: struct.Content.html
|
||||
pub fn style(mut self, style: impl Into<Renderer::Style>) -> Self {
|
||||
self.style = style.into();
|
||||
self
|
||||
|
|
@ -57,9 +50,7 @@ where
|
|||
{
|
||||
/// Draws the [`Content`] with the provided [`Renderer`] and [`Layout`].
|
||||
///
|
||||
/// [`Content`]: struct.Content.html
|
||||
/// [`Renderer`]: trait.Renderer.html
|
||||
/// [`Layout`]: ../layout/struct.Layout.html
|
||||
/// [`Renderer`]: crate::widget::pane_grid::Renderer
|
||||
pub fn draw(
|
||||
&self,
|
||||
renderer: &mut Renderer,
|
||||
|
|
@ -94,9 +85,6 @@ where
|
|||
|
||||
/// Returns whether the [`Content`] with the given [`Layout`] can be picked
|
||||
/// at the provided cursor position.
|
||||
///
|
||||
/// [`Content`]: struct.Content.html
|
||||
/// [`Layout`]: ../layout/struct.Layout.html
|
||||
pub fn can_be_picked_at(
|
||||
&self,
|
||||
layout: Layout<'_>,
|
||||
|
|
|
|||
|
|
@ -7,17 +7,12 @@ use std::collections::HashMap;
|
|||
|
||||
/// A layout node of a [`PaneGrid`].
|
||||
///
|
||||
/// [`PaneGrid`]: struct.PaneGrid.html
|
||||
/// [`PaneGrid`]: crate::widget::PaneGrid
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Node {
|
||||
/// The region of this [`Node`] is split into two.
|
||||
///
|
||||
/// [`Node`]: enum.Node.html
|
||||
Split {
|
||||
/// The [`Split`] of this [`Node`].
|
||||
///
|
||||
/// [`Split`]: struct.Split.html
|
||||
/// [`Node`]: enum.Node.html
|
||||
id: Split,
|
||||
|
||||
/// The direction of the split.
|
||||
|
|
@ -27,26 +22,17 @@ pub enum Node {
|
|||
ratio: f32,
|
||||
|
||||
/// The left/top [`Node`] of the split.
|
||||
///
|
||||
/// [`Node`]: enum.Node.html
|
||||
a: Box<Node>,
|
||||
|
||||
/// The right/bottom [`Node`] of the split.
|
||||
///
|
||||
/// [`Node`]: enum.Node.html
|
||||
b: Box<Node>,
|
||||
},
|
||||
/// The region of this [`Node`] is taken by a [`Pane`].
|
||||
///
|
||||
/// [`Pane`]: struct.Pane.html
|
||||
Pane(Pane),
|
||||
}
|
||||
|
||||
impl Node {
|
||||
/// Returns an iterator over each [`Split`] in this [`Node`].
|
||||
///
|
||||
/// [`Split`]: struct.Split.html
|
||||
/// [`Node`]: enum.Node.html
|
||||
pub fn splits(&self) -> impl Iterator<Item = &Split> {
|
||||
let mut unvisited_nodes = vec![self];
|
||||
|
||||
|
|
@ -69,9 +55,6 @@ impl Node {
|
|||
|
||||
/// Returns the rectangular region for each [`Pane`] in the [`Node`] given
|
||||
/// the spacing between panes and the total available space.
|
||||
///
|
||||
/// [`Pane`]: struct.Pane.html
|
||||
/// [`Node`]: enum.Node.html
|
||||
pub fn pane_regions(
|
||||
&self,
|
||||
spacing: f32,
|
||||
|
|
@ -96,9 +79,6 @@ impl Node {
|
|||
/// Returns the axis, rectangular region, and ratio for each [`Split`] in
|
||||
/// the [`Node`] given the spacing between panes and the total available
|
||||
/// space.
|
||||
///
|
||||
/// [`Split`]: struct.Split.html
|
||||
/// [`Node`]: enum.Node.html
|
||||
pub fn split_regions(
|
||||
&self,
|
||||
spacing: f32,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/// A rectangular region in a [`PaneGrid`] used to display widgets.
|
||||
///
|
||||
/// [`PaneGrid`]: struct.PaneGrid.html
|
||||
/// [`PaneGrid`]: crate::widget::PaneGrid
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct Pane(pub(super) usize);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/// A divider that splits a region in a [`PaneGrid`] into two different panes.
|
||||
///
|
||||
/// [`PaneGrid`]: struct.PaneGrid.html
|
||||
/// [`PaneGrid`]: crate::widget::PaneGrid
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct Split(pub(super) usize);
|
||||
|
|
|
|||
|
|
@ -15,11 +15,8 @@ use std::collections::HashMap;
|
|||
/// provided to the view function of [`PaneGrid::new`] for displaying each
|
||||
/// [`Pane`].
|
||||
///
|
||||
/// [`PaneGrid`]: struct.PaneGrid.html
|
||||
/// [`PaneGrid::new`]: struct.PaneGrid.html#method.new
|
||||
/// [`Pane`]: struct.Pane.html
|
||||
/// [`Split`]: struct.Split.html
|
||||
/// [`State`]: struct.State.html
|
||||
/// [`PaneGrid`]: crate::widget::PaneGrid
|
||||
/// [`PaneGrid::new`]: crate::widget::PaneGrid::new
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct State<T> {
|
||||
pub(super) panes: HashMap<Pane, T>,
|
||||
|
|
@ -31,9 +28,6 @@ impl<T> State<T> {
|
|||
/// state.
|
||||
///
|
||||
/// Alongside the [`State`], it returns the first [`Pane`] identifier.
|
||||
///
|
||||
/// [`State`]: struct.State.html
|
||||
/// [`Pane`]: struct.Pane.html
|
||||
pub fn new(first_pane_state: T) -> (Self, Pane) {
|
||||
(
|
||||
Self::with_configuration(Configuration::Pane(first_pane_state)),
|
||||
|
|
@ -42,9 +36,6 @@ impl<T> State<T> {
|
|||
}
|
||||
|
||||
/// Creates a new [`State`] with the given [`Configuration`].
|
||||
///
|
||||
/// [`State`]: struct.State.html
|
||||
/// [`Configuration`]: enum.Configuration.html
|
||||
pub fn with_configuration(config: impl Into<Configuration<T>>) -> Self {
|
||||
let mut panes = HashMap::new();
|
||||
|
||||
|
|
@ -62,54 +53,40 @@ impl<T> State<T> {
|
|||
}
|
||||
|
||||
/// Returns the total amount of panes in the [`State`].
|
||||
///
|
||||
/// [`State`]: struct.State.html
|
||||
pub fn len(&self) -> usize {
|
||||
self.panes.len()
|
||||
}
|
||||
|
||||
/// Returns the internal state of the given [`Pane`], if it exists.
|
||||
///
|
||||
/// [`Pane`]: struct.Pane.html
|
||||
pub fn get(&self, pane: &Pane) -> Option<&T> {
|
||||
self.panes.get(pane)
|
||||
}
|
||||
|
||||
/// Returns the internal state of the given [`Pane`] with mutability, if it
|
||||
/// exists.
|
||||
///
|
||||
/// [`Pane`]: struct.Pane.html
|
||||
pub fn get_mut(&mut self, pane: &Pane) -> Option<&mut T> {
|
||||
self.panes.get_mut(pane)
|
||||
}
|
||||
|
||||
/// Returns an iterator over all the panes of the [`State`], alongside its
|
||||
/// internal state.
|
||||
///
|
||||
/// [`State`]: struct.State.html
|
||||
pub fn iter(&self) -> impl Iterator<Item = (&Pane, &T)> {
|
||||
self.panes.iter()
|
||||
}
|
||||
|
||||
/// Returns a mutable iterator over all the panes of the [`State`],
|
||||
/// alongside its internal state.
|
||||
///
|
||||
/// [`State`]: struct.State.html
|
||||
pub fn iter_mut(&mut self) -> impl Iterator<Item = (&Pane, &mut T)> {
|
||||
self.panes.iter_mut()
|
||||
}
|
||||
|
||||
/// Returns the layout of the [`State`].
|
||||
///
|
||||
/// [`State`]: struct.State.html
|
||||
pub fn layout(&self) -> &Node {
|
||||
&self.internal.layout
|
||||
}
|
||||
|
||||
/// Returns the adjacent [`Pane`] of another [`Pane`] in the given
|
||||
/// direction, if there is one.
|
||||
///
|
||||
/// [`Pane`]: struct.Pane.html
|
||||
pub fn adjacent(&self, pane: &Pane, direction: Direction) -> Option<Pane> {
|
||||
let regions = self
|
||||
.internal
|
||||
|
|
@ -145,9 +122,6 @@ impl<T> State<T> {
|
|||
|
||||
/// Splits the given [`Pane`] into two in the given [`Axis`] and
|
||||
/// initializing the new [`Pane`] with the provided internal state.
|
||||
///
|
||||
/// [`Pane`]: struct.Pane.html
|
||||
/// [`Axis`]: enum.Axis.html
|
||||
pub fn split(
|
||||
&mut self,
|
||||
axis: Axis,
|
||||
|
|
@ -180,9 +154,8 @@ impl<T> State<T> {
|
|||
/// If you want to swap panes on drag and drop in your [`PaneGrid`], you
|
||||
/// will need to call this method when handling a [`DragEvent`].
|
||||
///
|
||||
/// [`State`]: struct.State.html
|
||||
/// [`PaneGrid`]: struct.PaneGrid.html
|
||||
/// [`DragEvent`]: struct.DragEvent.html
|
||||
/// [`PaneGrid`]: crate::widget::PaneGrid
|
||||
/// [`DragEvent`]: crate::widget::pane_grid::DragEvent
|
||||
pub fn swap(&mut self, a: &Pane, b: &Pane) {
|
||||
self.internal.layout.update(&|node| match node {
|
||||
Node::Split { .. } => {}
|
||||
|
|
@ -204,17 +177,14 @@ impl<T> State<T> {
|
|||
/// If you want to enable resize interactions in your [`PaneGrid`], you will
|
||||
/// need to call this method when handling a [`ResizeEvent`].
|
||||
///
|
||||
/// [`Split`]: struct.Split.html
|
||||
/// [`PaneGrid`]: struct.PaneGrid.html
|
||||
/// [`ResizeEvent`]: struct.ResizeEvent.html
|
||||
/// [`PaneGrid`]: crate::widget::PaneGrid
|
||||
/// [`ResizeEvent`]: crate::widget::pane_grid::ResizeEvent
|
||||
pub fn resize(&mut self, split: &Split, ratio: f32) {
|
||||
let _ = self.internal.layout.resize(split, ratio);
|
||||
}
|
||||
|
||||
/// Closes the given [`Pane`] and returns its internal state and its closest
|
||||
/// sibling, if it exists.
|
||||
///
|
||||
/// [`Pane`]: struct.Pane.html
|
||||
pub fn close(&mut self, pane: &Pane) -> Option<(T, Pane)> {
|
||||
if let Some(sibling) = self.internal.layout.remove(pane) {
|
||||
self.panes.remove(pane).map(|state| (state, sibling))
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use crate::{Clipboard, Element, Hasher, Layout, Point, Rectangle, Size};
|
|||
|
||||
/// The title bar of a [`Pane`].
|
||||
///
|
||||
/// [`Pane`]: struct.Pane.html
|
||||
/// [`Pane`]: crate::widget::pane_grid::Pane
|
||||
#[allow(missing_debug_implementations)]
|
||||
pub struct TitleBar<'a, Message, Renderer: pane_grid::Renderer> {
|
||||
title: String,
|
||||
|
|
@ -21,8 +21,6 @@ where
|
|||
Renderer: pane_grid::Renderer,
|
||||
{
|
||||
/// Creates a new [`TitleBar`] with the given title.
|
||||
///
|
||||
/// [`TitleBar`]: struct.TitleBar.html
|
||||
pub fn new(title: impl Into<String>) -> Self {
|
||||
Self {
|
||||
title: title.into(),
|
||||
|
|
@ -35,16 +33,12 @@ where
|
|||
}
|
||||
|
||||
/// Sets the size of the title of the [`TitleBar`].
|
||||
///
|
||||
/// [`TitleBar`]: struct.TitleBar.html
|
||||
pub fn title_size(mut self, size: u16) -> Self {
|
||||
self.title_size = Some(size);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the controls of the [`TitleBar`].
|
||||
///
|
||||
/// [`TitleBar`]: struct.TitleBar.html
|
||||
pub fn controls(
|
||||
mut self,
|
||||
controls: impl Into<Element<'a, Message, Renderer>>,
|
||||
|
|
@ -54,16 +48,12 @@ where
|
|||
}
|
||||
|
||||
/// Sets the padding of the [`TitleBar`].
|
||||
///
|
||||
/// [`TitleBar`]: struct.TitleBar.html
|
||||
pub fn padding(mut self, units: u16) -> Self {
|
||||
self.padding = units;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the style of the [`TitleBar`].
|
||||
///
|
||||
/// [`TitleBar`]: struct.TitleBar.html
|
||||
pub fn style(mut self, style: impl Into<Renderer::Style>) -> Self {
|
||||
self.style = style.into();
|
||||
self
|
||||
|
|
@ -75,9 +65,8 @@ where
|
|||
/// By default, the controls are only visible when the [`Pane`] of this
|
||||
/// [`TitleBar`] is hovered.
|
||||
///
|
||||
/// [`TitleBar`]: struct.TitleBar.html
|
||||
/// [`controls`]: struct.TitleBar.html#method.controls
|
||||
/// [`Pane`]: struct.Pane.html
|
||||
/// [`controls`]: Self::controls
|
||||
/// [`Pane`]: crate::widget::pane_grid::Pane
|
||||
pub fn always_show_controls(mut self) -> Self {
|
||||
self.always_show_controls = true;
|
||||
self
|
||||
|
|
@ -90,9 +79,7 @@ where
|
|||
{
|
||||
/// Draws the [`TitleBar`] with the provided [`Renderer`] and [`Layout`].
|
||||
///
|
||||
/// [`TitleBar`]: struct.TitleBar.html
|
||||
/// [`Renderer`]: trait.Renderer.html
|
||||
/// [`Layout`]: ../layout/struct.Layout.html
|
||||
/// [`Renderer`]: crate::widget::pane_grid::Renderer
|
||||
pub fn draw(
|
||||
&self,
|
||||
renderer: &mut Renderer,
|
||||
|
|
@ -152,8 +139,6 @@ where
|
|||
/// [`TitleBar`] or not.
|
||||
///
|
||||
/// The whole [`TitleBar`] is a pick area, except its controls.
|
||||
///
|
||||
/// [`TitleBar`]: struct.TitleBar.html
|
||||
pub fn is_over_pick_area(
|
||||
&self,
|
||||
layout: Layout<'_>,
|
||||
|
|
|
|||
|
|
@ -32,8 +32,6 @@ where
|
|||
}
|
||||
|
||||
/// The local state of a [`PickList`].
|
||||
///
|
||||
/// [`PickList`]: struct.PickList.html
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct State<T> {
|
||||
menu: menu::State,
|
||||
|
|
@ -62,9 +60,6 @@ where
|
|||
/// Creates a new [`PickList`] with the given [`State`], a list of options,
|
||||
/// the current selected value, and the message to produce when an option is
|
||||
/// selected.
|
||||
///
|
||||
/// [`PickList`]: struct.PickList.html
|
||||
/// [`State`]: struct.State.html
|
||||
pub fn new(
|
||||
state: &'a mut State<T>,
|
||||
options: impl Into<Cow<'a, [T]>>,
|
||||
|
|
@ -95,40 +90,30 @@ where
|
|||
}
|
||||
|
||||
/// Sets the width of the [`PickList`].
|
||||
///
|
||||
/// [`PickList`]: struct.PickList.html
|
||||
pub fn width(mut self, width: Length) -> Self {
|
||||
self.width = width;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the padding of the [`PickList`].
|
||||
///
|
||||
/// [`PickList`]: struct.PickList.html
|
||||
pub fn padding(mut self, padding: u16) -> Self {
|
||||
self.padding = padding;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the text size of the [`PickList`].
|
||||
///
|
||||
/// [`PickList`]: struct.PickList.html
|
||||
pub fn text_size(mut self, size: u16) -> Self {
|
||||
self.text_size = Some(size);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the font of the [`PickList`].
|
||||
///
|
||||
/// [`PickList`]: struct.PickList.html
|
||||
pub fn font(mut self, font: Renderer::Font) -> Self {
|
||||
self.font = font;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the style of the [`PickList`].
|
||||
///
|
||||
/// [`PickList`]: struct.PickList.html
|
||||
pub fn style(
|
||||
mut self,
|
||||
style: impl Into<<Renderer as self::Renderer>::Style>,
|
||||
|
|
@ -318,30 +303,20 @@ where
|
|||
/// Your [renderer] will need to implement this trait before being
|
||||
/// able to use a [`PickList`] in your user interface.
|
||||
///
|
||||
/// [`PickList`]: struct.PickList.html
|
||||
/// [renderer]: ../../renderer/index.html
|
||||
/// [renderer]: crate::renderer
|
||||
pub trait Renderer: text::Renderer + menu::Renderer {
|
||||
/// The default padding of a [`PickList`].
|
||||
///
|
||||
/// [`PickList`]: struct.PickList.html
|
||||
const DEFAULT_PADDING: u16;
|
||||
|
||||
/// The [`PickList`] style supported by this renderer.
|
||||
///
|
||||
/// [`PickList`]: struct.PickList.html
|
||||
type Style: Default;
|
||||
|
||||
/// Returns the style of the [`Menu`] of the [`PickList`].
|
||||
///
|
||||
/// [`Menu`]: ../../overlay/menu/struct.Menu.html
|
||||
/// [`PickList`]: struct.PickList.html
|
||||
fn menu_style(
|
||||
style: &<Self as Renderer>::Style,
|
||||
) -> <Self as menu::Renderer>::Style;
|
||||
|
||||
/// Draws a [`PickList`].
|
||||
///
|
||||
/// [`PickList`]: struct.PickList.html
|
||||
fn draw(
|
||||
&mut self,
|
||||
bounds: Rectangle,
|
||||
|
|
|
|||
|
|
@ -33,8 +33,6 @@ impl<Renderer: self::Renderer> ProgressBar<Renderer> {
|
|||
/// It expects:
|
||||
/// * an inclusive range of possible values
|
||||
/// * the current value of the [`ProgressBar`]
|
||||
///
|
||||
/// [`ProgressBar`]: struct.ProgressBar.html
|
||||
pub fn new(range: RangeInclusive<f32>, value: f32) -> Self {
|
||||
ProgressBar {
|
||||
value: value.max(*range.start()).min(*range.end()),
|
||||
|
|
@ -46,24 +44,18 @@ impl<Renderer: self::Renderer> ProgressBar<Renderer> {
|
|||
}
|
||||
|
||||
/// Sets the width of the [`ProgressBar`].
|
||||
///
|
||||
/// [`ProgressBar`]: struct.ProgressBar.html
|
||||
pub fn width(mut self, width: Length) -> Self {
|
||||
self.width = width;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the height of the [`ProgressBar`].
|
||||
///
|
||||
/// [`ProgressBar`]: struct.ProgressBar.html
|
||||
pub fn height(mut self, height: Length) -> Self {
|
||||
self.height = Some(height);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the style of the [`ProgressBar`].
|
||||
///
|
||||
/// [`ProgressBar`]: struct.ProgressBar.html
|
||||
pub fn style(mut self, style: impl Into<Renderer::Style>) -> Self {
|
||||
self.style = style.into();
|
||||
self
|
||||
|
|
@ -128,15 +120,12 @@ where
|
|||
/// Your [renderer] will need to implement this trait before being
|
||||
/// able to use a [`ProgressBar`] in your user interface.
|
||||
///
|
||||
/// [`ProgressBar`]: struct.ProgressBar.html
|
||||
/// [renderer]: ../../renderer/index.html
|
||||
/// [renderer]: crate::renderer
|
||||
pub trait Renderer: crate::Renderer {
|
||||
/// The style supported by this renderer.
|
||||
type Style: Default;
|
||||
|
||||
/// The default height of a [`ProgressBar`].
|
||||
///
|
||||
/// [`ProgressBar`]: struct.ProgressBar.html
|
||||
const DEFAULT_HEIGHT: u16;
|
||||
|
||||
/// Draws a [`ProgressBar`].
|
||||
|
|
@ -147,8 +136,6 @@ pub trait Renderer: crate::Renderer {
|
|||
/// * the current value of the [`ProgressBar`]
|
||||
/// * maybe a specific background of the [`ProgressBar`]
|
||||
/// * maybe a specific active color of the [`ProgressBar`]
|
||||
///
|
||||
/// [`ProgressBar`]: struct.ProgressBar.html
|
||||
fn draw(
|
||||
&self,
|
||||
bounds: Rectangle,
|
||||
|
|
|
|||
|
|
@ -62,8 +62,6 @@ where
|
|||
/// * the current selected value
|
||||
/// * a function that will be called when the [`Radio`] is selected. It
|
||||
/// receives the value of the radio and must produce a `Message`.
|
||||
///
|
||||
/// [`Radio`]: struct.Radio.html
|
||||
pub fn new<F, V>(
|
||||
value: V,
|
||||
label: impl Into<String>,
|
||||
|
|
@ -87,40 +85,30 @@ where
|
|||
}
|
||||
|
||||
/// Sets the size of the [`Radio`] button.
|
||||
///
|
||||
/// [`Radio`]: struct.Radio.html
|
||||
pub fn size(mut self, size: u16) -> Self {
|
||||
self.size = size;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the width of the [`Radio`] button.
|
||||
///
|
||||
/// [`Radio`]: struct.Radio.html
|
||||
pub fn width(mut self, width: Length) -> Self {
|
||||
self.width = width;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the spacing between the [`Radio`] button and the text.
|
||||
///
|
||||
/// [`Radio`]: struct.Radio.html
|
||||
pub fn spacing(mut self, spacing: u16) -> Self {
|
||||
self.spacing = spacing;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the text size of the [`Radio`] button.
|
||||
///
|
||||
/// [`Radio`]: struct.Radio.html
|
||||
pub fn text_size(mut self, text_size: u16) -> Self {
|
||||
self.text_size = Some(text_size);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the style of the [`Radio`] button.
|
||||
///
|
||||
/// [`Radio`]: struct.Radio.html
|
||||
pub fn style(mut self, style: impl Into<Renderer::Style>) -> Self {
|
||||
self.style = style.into();
|
||||
self
|
||||
|
|
@ -237,20 +225,15 @@ where
|
|||
/// Your [renderer] will need to implement this trait before being
|
||||
/// able to use a [`Radio`] button in your user interface.
|
||||
///
|
||||
/// [`Radio`]: struct.Radio.html
|
||||
/// [renderer]: ../../renderer/index.html
|
||||
/// [renderer]: crate::renderer
|
||||
pub trait Renderer: crate::Renderer {
|
||||
/// The style supported by this renderer.
|
||||
type Style: Default;
|
||||
|
||||
/// The default size of a [`Radio`] button.
|
||||
///
|
||||
/// [`Radio`]: struct.Radio.html
|
||||
const DEFAULT_SIZE: u16;
|
||||
|
||||
/// The default spacing of a [`Radio`] button.
|
||||
///
|
||||
/// [`Radio`]: struct.Radio.html
|
||||
const DEFAULT_SPACING: u16;
|
||||
|
||||
/// Draws a [`Radio`] button.
|
||||
|
|
@ -260,8 +243,6 @@ pub trait Renderer: crate::Renderer {
|
|||
/// * whether the [`Radio`] is selected or not
|
||||
/// * whether the mouse is over the [`Radio`] or not
|
||||
/// * the drawn label of the [`Radio`]
|
||||
///
|
||||
/// [`Radio`]: struct.Radio.html
|
||||
fn draw(
|
||||
&mut self,
|
||||
bounds: Rectangle,
|
||||
|
|
|
|||
|
|
@ -24,15 +24,11 @@ pub struct Row<'a, Message, Renderer> {
|
|||
|
||||
impl<'a, Message, Renderer> Row<'a, Message, Renderer> {
|
||||
/// Creates an empty [`Row`].
|
||||
///
|
||||
/// [`Row`]: struct.Row.html
|
||||
pub fn new() -> Self {
|
||||
Self::with_children(Vec::new())
|
||||
}
|
||||
|
||||
/// Creates a [`Row`] with the given elements.
|
||||
///
|
||||
/// [`Row`]: struct.Row.html
|
||||
pub fn with_children(
|
||||
children: Vec<Element<'a, Message, Renderer>>,
|
||||
) -> Self {
|
||||
|
|
@ -59,57 +55,42 @@ impl<'a, Message, Renderer> Row<'a, Message, Renderer> {
|
|||
}
|
||||
|
||||
/// Sets the padding of the [`Row`].
|
||||
///
|
||||
/// [`Row`]: struct.Row.html
|
||||
pub fn padding(mut self, units: u16) -> Self {
|
||||
self.padding = units;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the width of the [`Row`].
|
||||
///
|
||||
/// [`Row`]: struct.Row.html
|
||||
pub fn width(mut self, width: Length) -> Self {
|
||||
self.width = width;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the height of the [`Row`].
|
||||
///
|
||||
/// [`Row`]: struct.Row.html
|
||||
pub fn height(mut self, height: Length) -> Self {
|
||||
self.height = height;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the maximum width of the [`Row`].
|
||||
///
|
||||
/// [`Row`]: struct.Row.html
|
||||
pub fn max_width(mut self, max_width: u32) -> Self {
|
||||
self.max_width = max_width;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the maximum height of the [`Row`].
|
||||
///
|
||||
/// [`Row`]: struct.Row.html
|
||||
pub fn max_height(mut self, max_height: u32) -> Self {
|
||||
self.max_height = max_height;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the vertical alignment of the contents of the [`Row`] .
|
||||
///
|
||||
/// [`Row`]: struct.Row.html
|
||||
pub fn align_items(mut self, align: Align) -> Self {
|
||||
self.align_items = align;
|
||||
self
|
||||
}
|
||||
|
||||
/// Adds an [`Element`] to the [`Row`].
|
||||
///
|
||||
/// [`Element`]: ../struct.Element.html
|
||||
/// [`Row`]: struct.Row.html
|
||||
pub fn push<E>(mut self, child: E) -> Self
|
||||
where
|
||||
E: Into<Element<'a, Message, Renderer>>,
|
||||
|
|
@ -230,8 +211,7 @@ where
|
|||
/// Your [renderer] will need to implement this trait before being
|
||||
/// able to use a [`Row`] in your user interface.
|
||||
///
|
||||
/// [`Row`]: struct.Row.html
|
||||
/// [renderer]: ../../renderer/index.html
|
||||
/// [renderer]: crate::renderer
|
||||
pub trait Renderer: crate::Renderer + Sized {
|
||||
/// Draws a [`Row`].
|
||||
///
|
||||
|
|
@ -239,9 +219,6 @@ pub trait Renderer: crate::Renderer + Sized {
|
|||
/// - the children of the [`Row`]
|
||||
/// - the [`Layout`] of the [`Row`] and its children
|
||||
/// - the cursor position
|
||||
///
|
||||
/// [`Row`]: struct.Row.html
|
||||
/// [`Layout`]: ../layout/struct.Layout.html
|
||||
fn draw<Message>(
|
||||
&mut self,
|
||||
defaults: &Self::Defaults,
|
||||
|
|
|
|||
|
|
@ -17,8 +17,6 @@ pub struct Rule<Renderer: self::Renderer> {
|
|||
|
||||
impl<Renderer: self::Renderer> Rule<Renderer> {
|
||||
/// Creates a horizontal [`Rule`] for dividing content by the given vertical spacing.
|
||||
///
|
||||
/// [`Rule`]: struct.Rule.html
|
||||
pub fn horizontal(spacing: u16) -> Self {
|
||||
Rule {
|
||||
width: Length::Fill,
|
||||
|
|
@ -29,8 +27,6 @@ impl<Renderer: self::Renderer> Rule<Renderer> {
|
|||
}
|
||||
|
||||
/// Creates a vertical [`Rule`] for dividing content by the given horizontal spacing.
|
||||
///
|
||||
/// [`Rule`]: struct.Rule.html
|
||||
pub fn vertical(spacing: u16) -> Self {
|
||||
Rule {
|
||||
width: Length::from(Length::Units(spacing)),
|
||||
|
|
@ -41,8 +37,6 @@ impl<Renderer: self::Renderer> Rule<Renderer> {
|
|||
}
|
||||
|
||||
/// Sets the style of the [`Rule`].
|
||||
///
|
||||
/// [`Rule`]: struct.Rule.html
|
||||
pub fn style(mut self, style: impl Into<Renderer::Style>) -> Self {
|
||||
self.style = style.into();
|
||||
self
|
||||
|
|
@ -92,8 +86,6 @@ where
|
|||
}
|
||||
|
||||
/// The renderer of a [`Rule`].
|
||||
///
|
||||
/// [`Rule`]: struct.Rule.html
|
||||
pub trait Renderer: crate::Renderer {
|
||||
/// The style supported by this renderer.
|
||||
type Style: Default;
|
||||
|
|
@ -104,8 +96,6 @@ pub trait Renderer: crate::Renderer {
|
|||
/// * the bounds of the [`Rule`]
|
||||
/// * the style of the [`Rule`]
|
||||
/// * whether the [`Rule`] is horizontal (true) or vertical (false)
|
||||
///
|
||||
/// [`Rule`]: struct.Rule.html
|
||||
fn draw(
|
||||
&mut self,
|
||||
bounds: Rectangle,
|
||||
|
|
|
|||
|
|
@ -27,9 +27,6 @@ pub struct Scrollable<'a, Message, Renderer: self::Renderer> {
|
|||
|
||||
impl<'a, Message, Renderer: self::Renderer> Scrollable<'a, Message, Renderer> {
|
||||
/// Creates a new [`Scrollable`] with the given [`State`].
|
||||
///
|
||||
/// [`Scrollable`]: struct.Scrollable.html
|
||||
/// [`State`]: struct.State.html
|
||||
pub fn new(state: &'a mut State) -> Self {
|
||||
Scrollable {
|
||||
state,
|
||||
|
|
@ -54,48 +51,36 @@ impl<'a, Message, Renderer: self::Renderer> Scrollable<'a, Message, Renderer> {
|
|||
}
|
||||
|
||||
/// Sets the padding of the [`Scrollable`].
|
||||
///
|
||||
/// [`Scrollable`]: struct.Scrollable.html
|
||||
pub fn padding(mut self, units: u16) -> Self {
|
||||
self.content = self.content.padding(units);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the width of the [`Scrollable`].
|
||||
///
|
||||
/// [`Scrollable`]: struct.Scrollable.html
|
||||
pub fn width(mut self, width: Length) -> Self {
|
||||
self.content = self.content.width(width);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the height of the [`Scrollable`].
|
||||
///
|
||||
/// [`Scrollable`]: struct.Scrollable.html
|
||||
pub fn height(mut self, height: Length) -> Self {
|
||||
self.height = height;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the maximum width of the [`Scrollable`].
|
||||
///
|
||||
/// [`Scrollable`]: struct.Scrollable.html
|
||||
pub fn max_width(mut self, max_width: u32) -> Self {
|
||||
self.content = self.content.max_width(max_width);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the maximum height of the [`Scrollable`] in pixels.
|
||||
///
|
||||
/// [`Scrollable`]: struct.Scrollable.html
|
||||
pub fn max_height(mut self, max_height: u32) -> Self {
|
||||
self.max_height = max_height;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the horizontal alignment of the contents of the [`Scrollable`] .
|
||||
///
|
||||
/// [`Scrollable`]: struct.Scrollable.html
|
||||
pub fn align_items(mut self, align_items: Align) -> Self {
|
||||
self.content = self.content.align_items(align_items);
|
||||
self
|
||||
|
|
@ -103,16 +88,12 @@ impl<'a, Message, Renderer: self::Renderer> Scrollable<'a, Message, Renderer> {
|
|||
|
||||
/// Sets the scrollbar width of the [`Scrollable`] .
|
||||
/// Silently enforces a minimum value of 1.
|
||||
///
|
||||
/// [`Scrollable`]: struct.Scrollable.html
|
||||
pub fn scrollbar_width(mut self, scrollbar_width: u16) -> Self {
|
||||
self.scrollbar_width = scrollbar_width.max(1);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the scrollbar margin of the [`Scrollable`] .
|
||||
///
|
||||
/// [`Scrollable`]: struct.Scrollable.html
|
||||
pub fn scrollbar_margin(mut self, scrollbar_margin: u16) -> Self {
|
||||
self.scrollbar_margin = scrollbar_margin;
|
||||
self
|
||||
|
|
@ -120,24 +101,18 @@ impl<'a, Message, Renderer: self::Renderer> Scrollable<'a, Message, Renderer> {
|
|||
|
||||
/// Sets the scroller width of the [`Scrollable`] .
|
||||
/// Silently enforces a minimum value of 1.
|
||||
///
|
||||
/// [`Scrollable`]: struct.Scrollable.html
|
||||
pub fn scroller_width(mut self, scroller_width: u16) -> Self {
|
||||
self.scroller_width = scroller_width.max(1);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the style of the [`Scrollable`] .
|
||||
///
|
||||
/// [`Scrollable`]: struct.Scrollable.html
|
||||
pub fn style(mut self, style: impl Into<Renderer::Style>) -> Self {
|
||||
self.style = style.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Adds an element to the [`Scrollable`].
|
||||
///
|
||||
/// [`Scrollable`]: struct.Scrollable.html
|
||||
pub fn push<E>(mut self, child: E) -> Self
|
||||
where
|
||||
E: Into<Element<'a, Message, Renderer>>,
|
||||
|
|
@ -407,8 +382,6 @@ where
|
|||
}
|
||||
|
||||
/// The local state of a [`Scrollable`].
|
||||
///
|
||||
/// [`Scrollable`]: struct.Scrollable.html
|
||||
#[derive(Debug, Clone, Copy, Default)]
|
||||
pub struct State {
|
||||
scroller_grabbed_at: Option<f32>,
|
||||
|
|
@ -417,17 +390,12 @@ pub struct State {
|
|||
|
||||
impl State {
|
||||
/// Creates a new [`State`] with the scrollbar located at the top.
|
||||
///
|
||||
/// [`State`]: struct.State.html
|
||||
pub fn new() -> Self {
|
||||
State::default()
|
||||
}
|
||||
|
||||
/// Apply a scrolling offset to the current [`State`], given the bounds of
|
||||
/// the [`Scrollable`] and its contents.
|
||||
///
|
||||
/// [`Scrollable`]: struct.Scrollable.html
|
||||
/// [`State`]: struct.State.html
|
||||
pub fn scroll(
|
||||
&mut self,
|
||||
delta_y: f32,
|
||||
|
|
@ -448,9 +416,6 @@ impl State {
|
|||
///
|
||||
/// `0` represents scrollbar at the top, while `1` represents scrollbar at
|
||||
/// the bottom.
|
||||
///
|
||||
/// [`Scrollable`]: struct.Scrollable.html
|
||||
/// [`State`]: struct.State.html
|
||||
pub fn scroll_to(
|
||||
&mut self,
|
||||
percentage: f32,
|
||||
|
|
@ -463,9 +428,6 @@ impl State {
|
|||
|
||||
/// Returns the current scrolling offset of the [`State`], given the bounds
|
||||
/// of the [`Scrollable`] and its contents.
|
||||
///
|
||||
/// [`Scrollable`]: struct.Scrollable.html
|
||||
/// [`State`]: struct.State.html
|
||||
pub fn offset(&self, bounds: Rectangle, content_bounds: Rectangle) -> u32 {
|
||||
let hidden_content =
|
||||
(content_bounds.height - bounds.height).max(0.0).round() as u32;
|
||||
|
|
@ -480,30 +442,19 @@ impl State {
|
|||
}
|
||||
|
||||
/// The scrollbar of a [`Scrollable`].
|
||||
///
|
||||
/// [`Scrollable`]: struct.Scrollable.html
|
||||
#[derive(Debug)]
|
||||
pub struct Scrollbar {
|
||||
/// The outer bounds of the scrollable, including the [`Scrollbar`] and
|
||||
/// [`Scroller`].
|
||||
///
|
||||
/// [`Scrollbar`]: struct.Scrollbar.html
|
||||
/// [`Scroller`]: struct.Scroller.html
|
||||
pub outer_bounds: Rectangle,
|
||||
|
||||
/// The bounds of the [`Scrollbar`].
|
||||
///
|
||||
/// [`Scrollbar`]: struct.Scrollbar.html
|
||||
pub bounds: Rectangle,
|
||||
|
||||
/// The margin within the [`Scrollbar`].
|
||||
///
|
||||
/// [`Scrollbar`]: struct.Scrollbar.html
|
||||
pub margin: u16,
|
||||
|
||||
/// The bounds of the [`Scroller`].
|
||||
///
|
||||
/// [`Scroller`]: struct.Scroller.html
|
||||
pub scroller: Scroller,
|
||||
}
|
||||
|
||||
|
|
@ -538,13 +489,9 @@ impl Scrollbar {
|
|||
}
|
||||
|
||||
/// The handle of a [`Scrollbar`].
|
||||
///
|
||||
/// [`Scrollbar`]: struct.Scrollbar.html
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Scroller {
|
||||
/// The bounds of the [`Scroller`].
|
||||
///
|
||||
/// [`Scroller`]: struct.Scrollbar.html
|
||||
pub bounds: Rectangle,
|
||||
}
|
||||
|
||||
|
|
@ -553,17 +500,13 @@ pub struct Scroller {
|
|||
/// Your [renderer] will need to implement this trait before being
|
||||
/// able to use a [`Scrollable`] in your user interface.
|
||||
///
|
||||
/// [`Scrollable`]: struct.Scrollable.html
|
||||
/// [renderer]: ../../renderer/index.html
|
||||
/// [renderer]: crate::renderer
|
||||
pub trait Renderer: column::Renderer + Sized {
|
||||
/// The style supported by this renderer.
|
||||
type Style: Default;
|
||||
|
||||
/// Returns the [`Scrollbar`] given the bounds and content bounds of a
|
||||
/// [`Scrollable`].
|
||||
///
|
||||
/// [`Scrollbar`]: struct.Scrollbar.html
|
||||
/// [`Scrollable`]: struct.Scrollable.html
|
||||
fn scrollbar(
|
||||
&self,
|
||||
bounds: Rectangle,
|
||||
|
|
@ -585,10 +528,6 @@ pub trait Renderer: column::Renderer + Sized {
|
|||
/// - a optional [`Scrollbar`] to be rendered
|
||||
/// - the scrolling offset
|
||||
/// - the drawn content
|
||||
///
|
||||
/// [`Scrollbar`]: struct.Scrollbar.html
|
||||
/// [`Scrollable`]: struct.Scrollable.html
|
||||
/// [`State`]: struct.State.html
|
||||
fn draw(
|
||||
&mut self,
|
||||
scrollable: &State,
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
//! Display an interactive selector of a single value from a range of values.
|
||||
//!
|
||||
//! A [`Slider`] has some local [`State`].
|
||||
//!
|
||||
//! [`Slider`]: struct.Slider.html
|
||||
//! [`State`]: struct.State.html
|
||||
use crate::event::{self, Event};
|
||||
use crate::layout;
|
||||
use crate::mouse;
|
||||
|
|
@ -21,8 +18,6 @@ use std::{hash::Hash, ops::RangeInclusive};
|
|||
/// The [`Slider`] range of numeric values is generic and its step size defaults
|
||||
/// to 1 unit.
|
||||
///
|
||||
/// [`Slider`]: struct.Slider.html
|
||||
///
|
||||
/// # Example
|
||||
/// ```
|
||||
/// # use iced_native::{slider, renderer::Null};
|
||||
|
|
@ -68,9 +63,6 @@ where
|
|||
/// * a function that will be called when the [`Slider`] is dragged.
|
||||
/// It receives the new value of the [`Slider`] and must produce a
|
||||
/// `Message`.
|
||||
///
|
||||
/// [`Slider`]: struct.Slider.html
|
||||
/// [`State`]: struct.State.html
|
||||
pub fn new<F>(
|
||||
state: &'a mut State,
|
||||
range: RangeInclusive<T>,
|
||||
|
|
@ -111,40 +103,30 @@ where
|
|||
/// Typically, the user's interaction with the slider is finished when this message is produced.
|
||||
/// This is useful if you need to spawn a long-running task from the slider's result, where
|
||||
/// the default on_change message could create too many events.
|
||||
///
|
||||
/// [`Slider`]: struct.Slider.html
|
||||
pub fn on_release(mut self, on_release: Message) -> Self {
|
||||
self.on_release = Some(on_release);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the width of the [`Slider`].
|
||||
///
|
||||
/// [`Slider`]: struct.Slider.html
|
||||
pub fn width(mut self, width: Length) -> Self {
|
||||
self.width = width;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the height of the [`Slider`].
|
||||
///
|
||||
/// [`Slider`]: struct.Slider.html
|
||||
pub fn height(mut self, height: u16) -> Self {
|
||||
self.height = height;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the style of the [`Slider`].
|
||||
///
|
||||
/// [`Slider`]: struct.Slider.html
|
||||
pub fn style(mut self, style: impl Into<Renderer::Style>) -> Self {
|
||||
self.style = style.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the step size of the [`Slider`].
|
||||
///
|
||||
/// [`Slider`]: struct.Slider.html
|
||||
pub fn step(mut self, step: T) -> Self {
|
||||
self.step = step;
|
||||
self
|
||||
|
|
@ -152,8 +134,6 @@ where
|
|||
}
|
||||
|
||||
/// The local state of a [`Slider`].
|
||||
///
|
||||
/// [`Slider`]: struct.Slider.html
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
||||
pub struct State {
|
||||
is_dragging: bool,
|
||||
|
|
@ -161,8 +141,6 @@ pub struct State {
|
|||
|
||||
impl State {
|
||||
/// Creates a new [`State`].
|
||||
///
|
||||
/// [`State`]: struct.State.html
|
||||
pub fn new() -> State {
|
||||
State::default()
|
||||
}
|
||||
|
|
@ -297,15 +275,12 @@ where
|
|||
/// Your [renderer] will need to implement this trait before being
|
||||
/// able to use a [`Slider`] in your user interface.
|
||||
///
|
||||
/// [`Slider`]: struct.Slider.html
|
||||
/// [renderer]: ../../renderer/index.html
|
||||
/// [renderer]: crate::renderer
|
||||
pub trait Renderer: crate::Renderer {
|
||||
/// The style supported by this renderer.
|
||||
type Style: Default;
|
||||
|
||||
/// The default height of a [`Slider`].
|
||||
///
|
||||
/// [`Slider`]: struct.Slider.html
|
||||
const DEFAULT_HEIGHT: u16;
|
||||
|
||||
/// Draws a [`Slider`].
|
||||
|
|
@ -316,10 +291,6 @@ pub trait Renderer: crate::Renderer {
|
|||
/// * the local state of the [`Slider`]
|
||||
/// * the range of values of the [`Slider`]
|
||||
/// * the current value of the [`Slider`]
|
||||
///
|
||||
/// [`Slider`]: struct.Slider.html
|
||||
/// [`State`]: struct.State.html
|
||||
/// [`Class`]: enum.Class.html
|
||||
fn draw(
|
||||
&mut self,
|
||||
bounds: Rectangle,
|
||||
|
|
|
|||
|
|
@ -16,15 +16,11 @@ pub struct Space {
|
|||
|
||||
impl Space {
|
||||
/// Creates an amount of empty [`Space`] with the given width and height.
|
||||
///
|
||||
/// [`Space`]: struct.Space.html
|
||||
pub fn new(width: Length, height: Length) -> Self {
|
||||
Space { width, height }
|
||||
}
|
||||
|
||||
/// Creates an amount of horizontal [`Space`].
|
||||
///
|
||||
/// [`Space`]: struct.Space.html
|
||||
pub fn with_width(width: Length) -> Self {
|
||||
Space {
|
||||
width,
|
||||
|
|
@ -33,8 +29,6 @@ impl Space {
|
|||
}
|
||||
|
||||
/// Creates an amount of vertical [`Space`].
|
||||
///
|
||||
/// [`Space`]: struct.Space.html
|
||||
pub fn with_height(height: Length) -> Self {
|
||||
Space {
|
||||
width: Length::Shrink,
|
||||
|
|
@ -85,14 +79,10 @@ where
|
|||
}
|
||||
|
||||
/// The renderer of an amount of [`Space`].
|
||||
///
|
||||
/// [`Space`]: struct.Space.html
|
||||
pub trait Renderer: crate::Renderer {
|
||||
/// Draws an amount of empty [`Space`].
|
||||
///
|
||||
/// You should most likely return an empty primitive here.
|
||||
///
|
||||
/// [`Space`]: struct.Space.html
|
||||
fn draw(&mut self, bounds: Rectangle) -> Self::Output;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,8 +14,6 @@ use std::{
|
|||
///
|
||||
/// [`Svg`] images can have a considerable rendering cost when resized,
|
||||
/// specially when they are complex.
|
||||
///
|
||||
/// [`Svg`]: struct.Svg.html
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Svg {
|
||||
handle: Handle,
|
||||
|
|
@ -25,9 +23,6 @@ pub struct Svg {
|
|||
|
||||
impl Svg {
|
||||
/// Creates a new [`Svg`] from the given [`Handle`].
|
||||
///
|
||||
/// [`Svg`]: struct.Svg.html
|
||||
/// [`Handle`]: struct.Handle.html
|
||||
pub fn new(handle: impl Into<Handle>) -> Self {
|
||||
Svg {
|
||||
handle: handle.into(),
|
||||
|
|
@ -38,23 +33,17 @@ impl Svg {
|
|||
|
||||
/// Creates a new [`Svg`] that will display the contents of the file at the
|
||||
/// provided path.
|
||||
///
|
||||
/// [`Svg`]: struct.Svg.html
|
||||
pub fn from_path(path: impl Into<PathBuf>) -> Self {
|
||||
Self::new(Handle::from_path(path))
|
||||
}
|
||||
|
||||
/// Sets the width of the [`Svg`].
|
||||
///
|
||||
/// [`Svg`]: struct.Svg.html
|
||||
pub fn width(mut self, width: Length) -> Self {
|
||||
self.width = width;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the height of the [`Svg`].
|
||||
///
|
||||
/// [`Svg`]: struct.Svg.html
|
||||
pub fn height(mut self, height: Length) -> Self {
|
||||
self.height = height;
|
||||
self
|
||||
|
|
@ -119,8 +108,6 @@ where
|
|||
}
|
||||
|
||||
/// An [`Svg`] handle.
|
||||
///
|
||||
/// [`Svg`]: struct.Svg.html
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Handle {
|
||||
id: u64,
|
||||
|
|
@ -130,8 +117,6 @@ pub struct Handle {
|
|||
impl Handle {
|
||||
/// Creates an SVG [`Handle`] pointing to the vector image of the given
|
||||
/// path.
|
||||
///
|
||||
/// [`Handle`]: struct.Handle.html
|
||||
pub fn from_path(path: impl Into<PathBuf>) -> Handle {
|
||||
Self::from_data(Data::Path(path.into()))
|
||||
}
|
||||
|
|
@ -141,8 +126,6 @@ impl Handle {
|
|||
///
|
||||
/// This is useful if you already have your SVG data in-memory, maybe
|
||||
/// because you downloaded or generated it procedurally.
|
||||
///
|
||||
/// [`Handle`]: struct.Handle.html
|
||||
pub fn from_memory(bytes: impl Into<Vec<u8>>) -> Handle {
|
||||
Self::from_data(Data::Bytes(bytes.into()))
|
||||
}
|
||||
|
|
@ -158,15 +141,11 @@ impl Handle {
|
|||
}
|
||||
|
||||
/// Returns the unique identifier of the [`Handle`].
|
||||
///
|
||||
/// [`Handle`]: struct.Handle.html
|
||||
pub fn id(&self) -> u64 {
|
||||
self.id
|
||||
}
|
||||
|
||||
/// Returns a reference to the SVG [`Data`].
|
||||
///
|
||||
/// [`Data`]: enum.Data.html
|
||||
pub fn data(&self) -> &Data {
|
||||
&self.data
|
||||
}
|
||||
|
|
@ -179,8 +158,6 @@ impl Hash for Handle {
|
|||
}
|
||||
|
||||
/// The data of an [`Svg`].
|
||||
///
|
||||
/// [`Svg`]: struct.Svg.html
|
||||
#[derive(Clone, Hash)]
|
||||
pub enum Data {
|
||||
/// File data
|
||||
|
|
@ -206,18 +183,12 @@ impl std::fmt::Debug for Data {
|
|||
/// Your [renderer] will need to implement this trait before being able to use
|
||||
/// an [`Svg`] in your user interface.
|
||||
///
|
||||
/// [`Svg`]: struct.Svg.html
|
||||
/// [renderer]: ../../renderer/index.html
|
||||
/// [renderer]: crate::renderer
|
||||
pub trait Renderer: crate::Renderer {
|
||||
/// Returns the default dimensions of an [`Svg`] for the given [`Handle`].
|
||||
///
|
||||
/// [`Svg`]: struct.Svg.html
|
||||
/// [`Handle`]: struct.Handle.html
|
||||
fn dimensions(&self, handle: &Handle) -> (u32, u32);
|
||||
|
||||
/// Draws an [`Svg`].
|
||||
///
|
||||
/// [`Svg`]: struct.Svg.html
|
||||
fn draw(&mut self, handle: Handle, layout: Layout<'_>) -> Self::Output;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,8 +33,6 @@ pub struct Text<Renderer: self::Renderer> {
|
|||
|
||||
impl<Renderer: self::Renderer> Text<Renderer> {
|
||||
/// Create a new fragment of [`Text`] with the given contents.
|
||||
///
|
||||
/// [`Text`]: struct.Text.html
|
||||
pub fn new<T: Into<String>>(label: T) -> Self {
|
||||
Text {
|
||||
content: label.into(),
|
||||
|
|
@ -49,17 +47,12 @@ impl<Renderer: self::Renderer> Text<Renderer> {
|
|||
}
|
||||
|
||||
/// Sets the size of the [`Text`].
|
||||
///
|
||||
/// [`Text`]: struct.Text.html
|
||||
pub fn size(mut self, size: u16) -> Self {
|
||||
self.size = Some(size);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the [`Color`] of the [`Text`].
|
||||
///
|
||||
/// [`Text`]: struct.Text.html
|
||||
/// [`Color`]: ../../struct.Color.html
|
||||
pub fn color<C: Into<Color>>(mut self, color: C) -> Self {
|
||||
self.color = Some(color.into());
|
||||
self
|
||||
|
|
@ -67,33 +60,25 @@ impl<Renderer: self::Renderer> Text<Renderer> {
|
|||
|
||||
/// Sets the [`Font`] of the [`Text`].
|
||||
///
|
||||
/// [`Text`]: struct.Text.html
|
||||
/// [`Font`]: ../../struct.Font.html
|
||||
/// [`Font`]: Renderer::Font
|
||||
pub fn font(mut self, font: impl Into<Renderer::Font>) -> Self {
|
||||
self.font = font.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the width of the [`Text`] boundaries.
|
||||
///
|
||||
/// [`Text`]: struct.Text.html
|
||||
pub fn width(mut self, width: Length) -> Self {
|
||||
self.width = width;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the height of the [`Text`] boundaries.
|
||||
///
|
||||
/// [`Text`]: struct.Text.html
|
||||
pub fn height(mut self, height: Length) -> Self {
|
||||
self.height = height;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the [`HorizontalAlignment`] of the [`Text`].
|
||||
///
|
||||
/// [`Text`]: struct.Text.html
|
||||
/// [`HorizontalAlignment`]: enum.HorizontalAlignment.html
|
||||
pub fn horizontal_alignment(
|
||||
mut self,
|
||||
alignment: HorizontalAlignment,
|
||||
|
|
@ -103,9 +88,6 @@ impl<Renderer: self::Renderer> Text<Renderer> {
|
|||
}
|
||||
|
||||
/// Sets the [`VerticalAlignment`] of the [`Text`].
|
||||
///
|
||||
/// [`Text`]: struct.Text.html
|
||||
/// [`VerticalAlignment`]: enum.VerticalAlignment.html
|
||||
pub fn vertical_alignment(mut self, alignment: VerticalAlignment) -> Self {
|
||||
self.vertical_alignment = alignment;
|
||||
self
|
||||
|
|
@ -177,26 +159,18 @@ where
|
|||
/// The renderer of a [`Text`] fragment.
|
||||
///
|
||||
/// Your [renderer] will need to implement this trait before being
|
||||
/// able to use [`Text`] in your [`UserInterface`].
|
||||
/// able to use [`Text`] in your user interface.
|
||||
///
|
||||
/// [`Text`]: struct.Text.html
|
||||
/// [renderer]: ../../renderer/index.html
|
||||
/// [`UserInterface`]: ../../struct.UserInterface.html
|
||||
/// [renderer]: crate::Renderer
|
||||
pub trait Renderer: crate::Renderer {
|
||||
/// The font type used for [`Text`].
|
||||
///
|
||||
/// [`Text`]: struct.Text.html
|
||||
type Font: Default + Copy;
|
||||
|
||||
/// Returns the default size of [`Text`].
|
||||
///
|
||||
/// [`Text`]: struct.Text.html
|
||||
fn default_size(&self) -> u16;
|
||||
|
||||
/// Measures the [`Text`] in the given bounds and returns the minimum
|
||||
/// boundaries that can fit the contents.
|
||||
///
|
||||
/// [`Text`]: struct.Text.html
|
||||
fn measure(
|
||||
&self,
|
||||
content: &str,
|
||||
|
|
@ -214,10 +188,6 @@ pub trait Renderer: crate::Renderer {
|
|||
/// * the color of the [`Text`]
|
||||
/// * the [`HorizontalAlignment`] of the [`Text`]
|
||||
/// * the [`VerticalAlignment`] of the [`Text`]
|
||||
///
|
||||
/// [`Text`]: struct.Text.html
|
||||
/// [`HorizontalAlignment`]: enum.HorizontalAlignment.html
|
||||
/// [`VerticalAlignment`]: enum.VerticalAlignment.html
|
||||
fn draw(
|
||||
&mut self,
|
||||
defaults: &Self::Defaults,
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
//! Display fields that can be filled with text.
|
||||
//!
|
||||
//! A [`TextInput`] has some local [`State`].
|
||||
//!
|
||||
//! [`TextInput`]: struct.TextInput.html
|
||||
//! [`State`]: struct.State.html
|
||||
mod editor;
|
||||
mod value;
|
||||
|
||||
|
|
@ -77,9 +74,6 @@ where
|
|||
/// - a placeholder
|
||||
/// - the current value
|
||||
/// - a function that produces a message when the [`TextInput`] changes
|
||||
///
|
||||
/// [`TextInput`]: struct.TextInput.html
|
||||
/// [`State`]: struct.State.html
|
||||
pub fn new<F>(
|
||||
state: &'a mut State,
|
||||
placeholder: &str,
|
||||
|
|
@ -106,8 +100,6 @@ where
|
|||
}
|
||||
|
||||
/// Converts the [`TextInput`] into a secure password input.
|
||||
///
|
||||
/// [`TextInput`]: struct.TextInput.html
|
||||
pub fn password(mut self) -> Self {
|
||||
self.is_secure = true;
|
||||
self
|
||||
|
|
@ -115,39 +107,31 @@ where
|
|||
|
||||
/// Sets the [`Font`] of the [`Text`].
|
||||
///
|
||||
/// [`Text`]: struct.Text.html
|
||||
/// [`Font`]: ../../struct.Font.html
|
||||
/// [`Font`]: crate::widget::text::Renderer::Font
|
||||
/// [`Text`]: crate::widget::Text
|
||||
pub fn font(mut self, font: Renderer::Font) -> Self {
|
||||
self.font = font;
|
||||
self
|
||||
}
|
||||
/// Sets the width of the [`TextInput`].
|
||||
///
|
||||
/// [`TextInput`]: struct.TextInput.html
|
||||
pub fn width(mut self, width: Length) -> Self {
|
||||
self.width = width;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the maximum width of the [`TextInput`].
|
||||
///
|
||||
/// [`TextInput`]: struct.TextInput.html
|
||||
pub fn max_width(mut self, max_width: u32) -> Self {
|
||||
self.max_width = max_width;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the padding of the [`TextInput`].
|
||||
///
|
||||
/// [`TextInput`]: struct.TextInput.html
|
||||
pub fn padding(mut self, units: u16) -> Self {
|
||||
self.padding = units;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the text size of the [`TextInput`].
|
||||
///
|
||||
/// [`TextInput`]: struct.TextInput.html
|
||||
pub fn size(mut self, size: u16) -> Self {
|
||||
self.size = Some(size);
|
||||
self
|
||||
|
|
@ -155,26 +139,18 @@ where
|
|||
|
||||
/// Sets the message that should be produced when the [`TextInput`] is
|
||||
/// focused and the enter key is pressed.
|
||||
///
|
||||
/// [`TextInput`]: struct.TextInput.html
|
||||
pub fn on_submit(mut self, message: Message) -> Self {
|
||||
self.on_submit = Some(message);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the style of the [`TextInput`].
|
||||
///
|
||||
/// [`TextInput`]: struct.TextInput.html
|
||||
/// [`State`]: struct.State.html
|
||||
pub fn style(mut self, style: impl Into<Renderer::Style>) -> Self {
|
||||
self.style = style.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Returns the current [`State`] of the [`TextInput`].
|
||||
///
|
||||
/// [`TextInput`]: struct.TextInput.html
|
||||
/// [`State`]: struct.State.html
|
||||
pub fn state(&self) -> &State {
|
||||
self.state
|
||||
}
|
||||
|
|
@ -186,10 +162,6 @@ where
|
|||
{
|
||||
/// Draws the [`TextInput`] with the given [`Renderer`], overriding its
|
||||
/// [`Value`] if provided.
|
||||
///
|
||||
/// [`TextInput`]: struct.TextInput.html
|
||||
/// [`Renderer`]: trait.Render.html
|
||||
/// [`Value`]: struct.Value.html
|
||||
pub fn draw(
|
||||
&self,
|
||||
renderer: &mut Renderer,
|
||||
|
|
@ -628,15 +600,12 @@ where
|
|||
/// Your [renderer] will need to implement this trait before being
|
||||
/// able to use a [`TextInput`] in your user interface.
|
||||
///
|
||||
/// [`TextInput`]: struct.TextInput.html
|
||||
/// [renderer]: ../../renderer/index.html
|
||||
/// [renderer]: crate::renderer
|
||||
pub trait Renderer: text::Renderer + Sized {
|
||||
/// The style supported by this renderer.
|
||||
type Style: Default;
|
||||
|
||||
/// Returns the width of the value of the [`TextInput`].
|
||||
///
|
||||
/// [`TextInput`]: struct.TextInput.html
|
||||
fn measure_value(&self, value: &str, size: u16, font: Self::Font) -> f32;
|
||||
|
||||
/// Returns the current horizontal offset of the value of the
|
||||
|
|
@ -644,9 +613,6 @@ pub trait Renderer: text::Renderer + Sized {
|
|||
///
|
||||
/// This is the amount of horizontal scrolling applied when the [`Value`]
|
||||
/// does not fit the [`TextInput`].
|
||||
///
|
||||
/// [`TextInput`]: struct.TextInput.html
|
||||
/// [`Value`]: struct.Value.html
|
||||
fn offset(
|
||||
&self,
|
||||
text_bounds: Rectangle,
|
||||
|
|
@ -665,10 +631,6 @@ pub trait Renderer: text::Renderer + Sized {
|
|||
/// - the placeholder to show when the value is empty
|
||||
/// - the current [`Value`]
|
||||
/// - the current [`State`]
|
||||
///
|
||||
/// [`TextInput`]: struct.TextInput.html
|
||||
/// [`Value`]: struct.Value.html
|
||||
/// [`State`]: struct.State.html
|
||||
fn draw(
|
||||
&mut self,
|
||||
bounds: Rectangle,
|
||||
|
|
@ -684,8 +646,6 @@ pub trait Renderer: text::Renderer + Sized {
|
|||
|
||||
/// Computes the position of the text cursor at the given X coordinate of
|
||||
/// a [`TextInput`].
|
||||
///
|
||||
/// [`TextInput`]: struct.TextInput.html
|
||||
fn find_cursor_position(
|
||||
&self,
|
||||
text_bounds: Rectangle,
|
||||
|
|
@ -725,8 +685,6 @@ where
|
|||
}
|
||||
|
||||
/// The state of a [`TextInput`].
|
||||
///
|
||||
/// [`TextInput`]: struct.TextInput.html
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct State {
|
||||
is_focused: bool,
|
||||
|
|
@ -740,15 +698,11 @@ pub struct State {
|
|||
|
||||
impl State {
|
||||
/// Creates a new [`State`], representing an unfocused [`TextInput`].
|
||||
///
|
||||
/// [`State`]: struct.State.html
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
/// Creates a new [`State`], representing a focused [`TextInput`].
|
||||
///
|
||||
/// [`State`]: struct.State.html
|
||||
pub fn focused() -> Self {
|
||||
Self {
|
||||
is_focused: true,
|
||||
|
|
@ -761,54 +715,36 @@ impl State {
|
|||
}
|
||||
|
||||
/// Returns whether the [`TextInput`] is currently focused or not.
|
||||
///
|
||||
/// [`TextInput`]: struct.TextInput.html
|
||||
pub fn is_focused(&self) -> bool {
|
||||
self.is_focused
|
||||
}
|
||||
|
||||
/// Returns the [`Cursor`] of the [`TextInput`].
|
||||
///
|
||||
/// [`Cursor`]: struct.Cursor.html
|
||||
/// [`TextInput`]: struct.TextInput.html
|
||||
pub fn cursor(&self) -> Cursor {
|
||||
self.cursor
|
||||
}
|
||||
|
||||
/// Focuses the [`TextInput`].
|
||||
///
|
||||
/// [`TextInput`]: struct.TextInput.html
|
||||
pub fn focus(&mut self) {
|
||||
self.is_focused = true;
|
||||
}
|
||||
|
||||
/// Unfocuses the [`TextInput`].
|
||||
///
|
||||
/// [`TextInput`]: struct.TextInput.html
|
||||
pub fn unfocus(&mut self) {
|
||||
self.is_focused = false;
|
||||
}
|
||||
|
||||
/// Moves the [`Cursor`] of the [`TextInput`] to the front of the input text.
|
||||
///
|
||||
/// [`Cursor`]: struct.Cursor.html
|
||||
/// [`TextInput`]: struct.TextInput.html
|
||||
pub fn move_cursor_to_front(&mut self) {
|
||||
self.cursor.move_to(0);
|
||||
}
|
||||
|
||||
/// Moves the [`Cursor`] of the [`TextInput`] to the end of the input text.
|
||||
///
|
||||
/// [`Cursor`]: struct.Cursor.html
|
||||
/// [`TextInput`]: struct.TextInput.html
|
||||
pub fn move_cursor_to_end(&mut self) {
|
||||
self.cursor.move_to(usize::MAX);
|
||||
}
|
||||
|
||||
/// Moves the [`Cursor`] of the [`TextInput`] to an arbitrary location.
|
||||
///
|
||||
/// [`Cursor`]: struct.Cursor.html
|
||||
/// [`TextInput`]: struct.TextInput.html
|
||||
pub fn move_cursor_to(&mut self, position: usize) {
|
||||
self.cursor.move_to(position);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,8 +8,6 @@ pub struct Cursor {
|
|||
}
|
||||
|
||||
/// The state of a [`Cursor`].
|
||||
///
|
||||
/// [`Cursor`]: struct.Cursor.html
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub enum State {
|
||||
/// Cursor without a selection
|
||||
|
|
@ -34,9 +32,6 @@ impl Default for Cursor {
|
|||
|
||||
impl Cursor {
|
||||
/// Returns the [`State`] of the [`Cursor`].
|
||||
///
|
||||
/// [`State`]: struct.State.html
|
||||
/// [`Cursor`]: struct.Cursor.html
|
||||
pub fn state(&self, value: &Value) -> State {
|
||||
match self.state {
|
||||
State::Index(index) => State::Index(index.min(value.len())),
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use unicode_segmentation::UnicodeSegmentation;
|
|||
|
||||
/// The value of a [`TextInput`].
|
||||
///
|
||||
/// [`TextInput`]: struct.TextInput.html
|
||||
/// [`TextInput`]: crate::widget::TextInput
|
||||
// TODO: Reduce allocations, cache results (?)
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Value {
|
||||
|
|
@ -11,8 +11,6 @@ pub struct Value {
|
|||
|
||||
impl Value {
|
||||
/// Creates a new [`Value`] from a string slice.
|
||||
///
|
||||
/// [`Value`]: struct.Value.html
|
||||
pub fn new(string: &str) -> Self {
|
||||
let graphemes = UnicodeSegmentation::graphemes(string, true)
|
||||
.map(String::from)
|
||||
|
|
@ -24,23 +22,17 @@ impl Value {
|
|||
/// Returns whether the [`Value`] is empty or not.
|
||||
///
|
||||
/// A [`Value`] is empty when it contains no graphemes.
|
||||
///
|
||||
/// [`Value`]: struct.Value.html
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.len() == 0
|
||||
}
|
||||
|
||||
/// Returns the total amount of graphemes in the [`Value`].
|
||||
///
|
||||
/// [`Value`]: struct.Value.html
|
||||
pub fn len(&self) -> usize {
|
||||
self.graphemes.len()
|
||||
}
|
||||
|
||||
/// Returns the position of the previous start of a word from the given
|
||||
/// grapheme `index`.
|
||||
///
|
||||
/// [`Value`]: struct.Value.html
|
||||
pub fn previous_start_of_word(&self, index: usize) -> usize {
|
||||
let previous_string =
|
||||
&self.graphemes[..index.min(self.graphemes.len())].concat();
|
||||
|
|
@ -63,8 +55,6 @@ impl Value {
|
|||
|
||||
/// Returns the position of the next end of a word from the given grapheme
|
||||
/// `index`.
|
||||
///
|
||||
/// [`Value`]: struct.Value.html
|
||||
pub fn next_end_of_word(&self, index: usize) -> usize {
|
||||
let next_string = &self.graphemes[index..].concat();
|
||||
|
||||
|
|
@ -85,8 +75,6 @@ impl Value {
|
|||
|
||||
/// Returns a new [`Value`] containing the graphemes until the given
|
||||
/// `index`.
|
||||
///
|
||||
/// [`Value`]: struct.Value.html
|
||||
pub fn until(&self, index: usize) -> Self {
|
||||
let graphemes = self.graphemes[..index.min(self.len())].to_vec();
|
||||
|
||||
|
|
@ -94,8 +82,6 @@ impl Value {
|
|||
}
|
||||
|
||||
/// Converts the [`Value`] into a `String`.
|
||||
///
|
||||
/// [`Value`]: struct.Value.html
|
||||
pub fn to_string(&self) -> String {
|
||||
self.graphemes.concat()
|
||||
}
|
||||
|
|
@ -118,8 +104,6 @@ impl Value {
|
|||
}
|
||||
|
||||
/// Removes the grapheme at the given `index`.
|
||||
///
|
||||
/// [`Value`]: struct.Value.html
|
||||
pub fn remove(&mut self, index: usize) {
|
||||
let _ = self.graphemes.remove(index);
|
||||
}
|
||||
|
|
@ -131,8 +115,6 @@ impl Value {
|
|||
|
||||
/// Returns a new [`Value`] with all its graphemes replaced with the
|
||||
/// dot ('•') character.
|
||||
///
|
||||
/// [`Value`]: struct.Value.html
|
||||
pub fn secure(&self) -> Self {
|
||||
Self {
|
||||
graphemes: std::iter::repeat(String::from("•"))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue