iced(비교)

r6 vs r7
......
77[clearfix]
88== 개요 ==
99러스트의 GUI 프레임워크이다.
10== 사용법 ==
11[[iced 구조.svg]]
12iced는 기본적으로 위의 구조를 갖고 있다. 먼저 UI에서 사용자가 상호작용하면 update 로직에 보낼 Message 열거를 만들어보자
13{{{#syntax rust
14enum Message {
15 Hello,
16 Bye
17}}}}
18그리고 데이터를 담을 state 구조체를 만들자
19{{{#syntax rust
20#[derive(Default)]
21struct State {
22 say:String
23}}}}
24say의 기본값을 "hello"로 지정해주고 싶으면 derive 메크로를 제거하고
25{{{#syntax rust
26impl Default for State {
27 fn default() Self {
28 Self {
29 say:String::from("hello");
30 }
31 }
32}}}}를 추가해주자.[* 사실 iced::application이라는 대응 함수도 있는데 부실한 문서화때문에 사용하기 어렵다]
33그리고 상호작용을 할 때 실행될 update 함수를 만들자
34{{{#syntax rust
35fn update(state:&mut State, message:Message) {
36 match Message {
37 Hello => {
38 state.say = String::from("Hello");
39 },
40 Bye => {
41 state.say = String::from("Bye");
42 }
43 }
44}}}}
45마지막으로 UI를 담당할 view 함수를 만들고
46{{{#syntax rust
47use iced::Element;
48use iced::widget::{button, column, text};
1049
50fn view(state: &State) -> Element<'_, Message> {
51 column![
52 text(state.say),
53 button("say hello").on_press(Message::Hello),
54 button("say bye").on_press(Message::Bye)
55 ].into()
56}}}}
57iced::run으로 실행하자
58{{{#syntax rust
59fn main () -> iced::Result {
60 iced::run(update, view)?
61}}}}
1162== 특징 ==
1263 * 마지막 릴리즈가 ,,25년 9월 기준,,1년 전에 나왔다![* cargo add iced 대신 깃헙 주소를 입력하는 것을 추천한다. 브랜치는 master로]
13
64* 비동기 처리를 자체 런타임을 이용해서 하는데 tokio[* 러스트에서 가장 많이쓰는 런타임] 런타임이랑 호환이 안되는듯 하다
1465== 사용하는 소프트웨어 ==
1566 * cosmic