summaryrefslogtreecommitdiffstats
path: root/widget/src/helpers.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-11-22 04:06:52 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-11-22 04:06:52 +0100
commit5be1d545d0baa09b82fe380d9246f66474cce302 (patch)
tree3493b8fecf17740ad67cc9d5fe6f9f9073206098 /widget/src/helpers.rs
parent6ccc828607b22a0583c12bad638ee2bc7e7310b8 (diff)
downloadiced-5be1d545d0baa09b82fe380d9246f66474cce302.tar.gz
iced-5be1d545d0baa09b82fe380d9246f66474cce302.tar.bz2
iced-5be1d545d0baa09b82fe380d9246f66474cce302.zip
Implement `pin` widget
Diffstat (limited to 'widget/src/helpers.rs')
-rw-r--r--widget/src/helpers.rs36
1 files changed, 35 insertions, 1 deletions
diff --git a/widget/src/helpers.rs b/widget/src/helpers.rs
index 33dff647..a669b290 100644
--- a/widget/src/helpers.rs
+++ b/widget/src/helpers.rs
@@ -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.