diff options
Diffstat (limited to 'examples/pure/tooltip/src')
-rw-r--r-- | examples/pure/tooltip/src/main.rs | 76 |
1 files changed, 0 insertions, 76 deletions
diff --git a/examples/pure/tooltip/src/main.rs b/examples/pure/tooltip/src/main.rs deleted file mode 100644 index e9a6c111..00000000 --- a/examples/pure/tooltip/src/main.rs +++ /dev/null @@ -1,76 +0,0 @@ -use iced::pure::widget::tooltip::Position; -use iced::pure::{button, container, tooltip}; -use iced::pure::{Element, Sandbox}; -use iced::theme; -use iced::{Length, Settings}; - -pub fn main() -> iced::Result { - Example::run(Settings::default()) -} - -struct Example { - position: Position, -} - -#[derive(Debug, Clone)] -enum Message { - ChangePosition, -} - -impl Sandbox for Example { - type Message = Message; - - fn new() -> Self { - Self { - position: Position::Bottom, - } - } - - fn title(&self) -> String { - String::from("Tooltip - Iced") - } - - fn update(&mut self, message: Message) { - match message { - Message::ChangePosition => { - let position = match &self.position { - Position::FollowCursor => Position::Top, - Position::Top => Position::Bottom, - Position::Bottom => Position::Left, - Position::Left => Position::Right, - Position::Right => Position::FollowCursor, - }; - - self.position = position - } - } - } - - fn view(&self) -> Element<Message> { - let tooltip = tooltip( - button("Press to change position") - .on_press(Message::ChangePosition), - position_to_text(self.position), - self.position, - ) - .gap(10) - .style(theme::Container::Box); - - container(tooltip) - .width(Length::Fill) - .height(Length::Fill) - .center_x() - .center_y() - .into() - } -} - -fn position_to_text<'a>(position: Position) -> &'a str { - match position { - Position::FollowCursor => "Follow Cursor", - Position::Top => "Top", - Position::Bottom => "Bottom", - Position::Left => "Left", - Position::Right => "Right", - } -} |