iced(r14 Blame)

r14
r6
1[[분류:GUI 프레임워크]][[분류:Rust로 개발된 소프트웨어]]
2||<-2><tablealign=right><tablewidth=450><tablebordercolor=#30f><tablebgcolor=transparent><colbgcolor=#30f><colcolor=#fff> '''{{{+3 Iced}}}''' ||
3||<bgcolor=transparent><nopad><-2> [[파일:iced logo.svg|width=60%]] ||
4||<width=25%> '''개발자''' ||'''hecrj''' ||
5|| '''링크''' ||[[https://github.com/iced-rs/iced|[[파일:GitHub 아이콘 light.svg|width=25px&theme=light]][[파일:GitHub 아이콘 dark.svg|width=25px&theme=dark]]]] [[https://docs.rs/iced/latest/iced|[[파일:Docs.rs logo.png]]]] [[https://crates.io/crates/iced|[[파일:Crates.io logo.png|width=25px]]]]||
r3
6[목차]
7[clearfix]
r1

(새 문서)
8== 개요 ==
r6
9러스트의 GUI 프레임워크이다.
r7
10== 사용법 ==
r10
11[[파일:iced 구조.svg]]
r7
12iced는 기본적으로 위의 구조를 갖고 있다. 먼저 UI에서 사용자가 상호작용하면 update 로직에 보낼 Message 열거를 만들어보자
r8
13{{{#!syntax rust
r7
14enum Message {
15 Hello,
16 Bye
r9
17} }}}
r7
18그리고 데이터를 담을 state 구조체를 만들자
r8
19{{{#!syntax rust
r7
20#[derive(Default)]
21struct State {
22 say:String
r9
23} }}}
r7
24say의 기본값을 "hello"로 지정해주고 싶으면 derive 메크로를 제거하고
r8
25{{{#!syntax rust
r7
26impl Default for State {
27 fn default() Self {
28 Self {
29 say:String::from("hello");
30 }
31 }
r9
32} }}}를 추가해주자.[* 사실 iced::application이라는 대응 함수도 있는데 부실한 문서화때문에 사용하기 어렵다]
r7
33그리고 상호작용을 할 때 실행될 update 함수를 만들자
r8
34{{{#!syntax rust
r7
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 }
r9
44} }}}
r7
45마지막으로 UI를 담당할 view 함수를 만들고
r8
46{{{#!syntax rust
r7
47use iced::Element;
48use iced::widget::{button, column, text};
r6
49
r7
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()
r9
56} }}}
r7
57iced::run으로 실행하자
r8
58{{{#!syntax rust
r7
59fn main () -> iced::Result {
60 iced::run(update, view)?
r9
61} }}}
r11
62=== 비동기 ===
63update로직이 너무 오랫동안 실행되면 UI 전채가 멈춰지는 문제가 있다.[* rust의 함수는 기본적으로 블로킹 방식이기 때문이다] 그래서 내장 런타임을 활용하여 IO같은 지연이 오래걸리는 작업을 비동기로 처리해줘야한다.
64{{{#!syntax rust
65fn update(state:&mut State, message:Message) -> iced::Task<Message> {
66 match Message {
67 Message::SomeAsyncTask => {
68 return iced::Task::perform(asyncfunc(), Message::AfterAsyncTask);
69 //asyncfunc라는 함수를 실행하고 함수 실행이 완료되면 AfterAsyncTask를 update의 message로 넘긴다는 뜻.
70 }
71 Message::AfterAsyncTask => {
72 println!("비동기 작업 완료! ✌️");
73 Task::none(); //비동기 작업을 실행하지 않는다는 뜻
74 }
75 }
r12
76}
77async fn asyncfunc() {
78 sleep(1000).await;
r11
79} }}}
80이런식으로 업데이트 함수를 수정해주면 된다.
r2
81== 특징 ==
82 * 마지막 릴리즈가 ,,25년 9월 기준,,1년 전에 나왔다![* cargo add iced 대신 깃헙 주소를 입력하는 것을 추천한다. 브랜치는 master로]
r14
83 * 비동기 처리를 자체 런타임을 이용해서 하는데 tokio[* 러스트에서 가장 많이쓰는 런타임] 런타임이랑 호환이 안되는듯 하다[* 따라서 [[hyper]]같은 프레임워크를 쓰려면 iced::main 메크로를 사용하였다는 가정 하에 [[tokio]] 런타임속 iced 런타임속 tokio 런타임을 만들어야 한다! 따라서 [[poise]]같은 hyper를 종속하는 프레임워크를 쓸 때는 고려해보자]
r2
84== 사용하는 소프트웨어 ==
r6
85 * cosmic