Skip to content

Latest commit

 

History

History
57 lines (46 loc) · 1.25 KB

File metadata and controls

57 lines (46 loc) · 1.25 KB

First App - Hello World!

We need a struct to implement Sandbox, and call its run method from main. All widgets should be placed inside the view method.

use iced::{
    widget::{
        column, text
    },
    Element
};

fn main() -> iced::Result {
    iced::application("My First App", MyApp::update, MyApp::view)
        .run()
}

struct MyApp {
    _state: String,
}

impl Default for MyApp {
    fn default() -> Self {
        MyApp::new()
    }
}
  
#[derive(Debug, Clone)]
enum Message {
    _Message1,
}
  
impl MyApp {
    fn new() -> Self {
        Self {
            _state: String::new(),
        }
    }
  
    fn update(&mut self, _message: Message) {
        todo!()
    }
    
    fn view(&self) -> Element<Message> {
        column!(
            text("Hello World!".to_string()),
        ).into()
    }
}

First app

➡️ Next: Explanation of Sandbox Trait

📘 Back: Table of contents