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

@ -3,7 +3,8 @@ use iced::keyboard;
use iced::mouse;
use iced::widget::{
button, canvas, center, checkbox, column, container, horizontal_rule,
horizontal_space, pick_list, row, scrollable, text, vertical_rule,
horizontal_space, pick_list, pin, row, scrollable, stack, text,
vertical_rule,
};
use iced::{
color, Center, Element, Fill, Font, Length, Point, Rectangle, Renderer,
@ -151,6 +152,10 @@ impl Example {
title: "Quotes",
view: quotes,
},
Self {
title: "Pinning",
view: pinning,
},
];
fn is_first(self) -> bool {
@ -309,6 +314,23 @@ fn quotes<'a>() -> Element<'a, Message> {
.into()
}
fn pinning<'a>() -> Element<'a, Message> {
column![
"The pin widget can be used to position a widget \
at some fixed coordinates inside some other widget.",
stack![
container(pin("• (50, 50)").width(Fill).height(Fill).x(50).y(50))
.width(500)
.height(500)
.style(container::bordered_box),
pin("• (300, 300)").width(Fill).height(Fill).x(300).y(300),
]
]
.align_x(Center)
.spacing(10)
.into()
}
fn square<'a>(size: impl Into<Length> + Copy) -> Element<'a, Message> {
struct Square;