Implement pin widget

This commit is contained in:
Héctor Ramón Jiménez 2024-11-22 04:06:52 +01:00
parent 6ccc828607
commit 5be1d545d0
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
4 changed files with 333 additions and 2 deletions

View file

@ -24,7 +24,7 @@ use crate::text_input::{self, TextInput};
use crate::toggler::{self, Toggler};
use crate::tooltip::{self, Tooltip};
use crate::vertical_slider::{self, VerticalSlider};
use crate::{Column, MouseArea, Row, Space, Stack, Themer};
use crate::{Column, MouseArea, Pin, Row, Space, Stack, Themer};
use std::borrow::Borrow;
use std::ops::RangeInclusive;
@ -249,6 +249,40 @@ where
container(content).center(Length::Fill)
}
/// Creates a new [`Pin`] widget with the given content.
///
/// A [`Pin`] widget positions its contents at some fixed coordinates inside of its boundaries.
///
/// # Example
/// ```no_run
/// # mod iced { pub mod widget { pub use iced_widget::*; } pub use iced_widget::core::Length::Fill; }
/// # pub type State = ();
/// # pub type Element<'a, Message> = iced_widget::core::Element<'a, Message, iced_widget::Theme, iced_widget::Renderer>;
/// use iced::widget::pin;
/// use iced::Fill;
///
/// enum Message {
/// // ...
/// }
///
/// fn view(state: &State) -> Element<'_, Message> {
/// pin("This text is displayed at coordinates (50, 50)!")
/// .width(Fill)
/// .height(Fill)
/// .x(50)
/// .y(50)
/// .into()
/// }
/// ```
pub fn pin<'a, Message, Theme, Renderer>(
content: impl Into<Element<'a, Message, Theme, Renderer>>,
) -> Pin<'a, Message, Theme, Renderer>
where
Renderer: core::Renderer,
{
Pin::new(content)
}
/// Creates a new [`Column`] with the given children.
///
/// Columns distribute their children vertically.