Introduce Program API

This commit is contained in:
Héctor Ramón Jiménez 2024-03-16 05:33:47 +01:00
parent 0524e9b457
commit c22269bff3
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
43 changed files with 1141 additions and 831 deletions

View file

@ -1,12 +1,13 @@
use iced::widget::tooltip::Position;
use iced::widget::{button, container, tooltip};
use iced::{Element, Length, Sandbox, Settings};
use iced::{Element, Length};
pub fn main() -> iced::Result {
Example::run(Settings::default())
iced::run("Tooltip - Iced", Tooltip::update, Tooltip::view)
}
struct Example {
#[derive(Default)]
struct Tooltip {
position: Position,
}
@ -15,28 +16,16 @@ 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")
}
impl Tooltip {
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,
Position::FollowCursor => Position::Top,
};
self.position = position;