Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A cross-platform GUI library for Rust, inspired by Elm

License

NotificationsYou must be signed in to change notification settings

iced-rs/iced

Repository files navigation

Iced

DocumentationCrates.ioLicenseDownloadsTest StatusDiscourseDiscord Server

A cross-platform GUI library for Rust focused on simplicity and type-safety.Inspired byElm.

Features

Iced is currently experimental software.Take a look at the roadmap andcheck out the issues.

Overview

Inspired byThe Elm Architecture, Iced expects you to split user interfacesinto four different concepts:

  • State — the state of your application
  • Messages — user interactions or meaningful events that you careabout
  • View logic — a way to display yourstate as widgets thatmay producemessages on user interaction
  • Update logic — a way to react tomessages and update yourstate

We can build something to see how this works! Let's say we want a simple counterthat can be incremented and decremented using two buttons.

We start by modelling thestate of our application:

#[derive(Default)]structCounter{value:i32,}

Next, we need to define the possible user interactions of our counter:the button presses. These interactions are ourmessages:

#[derive(Debug,Clone,Copy)]pubenumMessage{Increment,Decrement,}

Now, let's show the actual counter by putting it all together in ourview logic:

use iced::widget::{button, column, text,Column};implCounter{pubfnview(&self) ->Column<Message>{// We use a column: a simple vertical layoutcolumn![// The increment button. We tell it to produce an// `Increment` message when pressed            button("+").on_press(Message::Increment),// We show the value of the counter here            text(self.value).size(50),// The decrement button. We tell it to produce a// `Decrement` message when pressed            button("-").on_press(Message::Decrement),]}}

Finally, we need to be able to react to any producedmessages and change ourstate accordingly in ourupdate logic:

implCounter{// ...pubfnupdate(&mutself,message:Message){match message{Message::Increment =>{self.value +=1;}Message::Decrement =>{self.value -=1;}}}}

And that's everything! We just wrote a whole user interface. Let's run it:

fnmain() -> iced::Result{    iced::run("A cool counter",Counter::update,Counter::view)}

Iced will automatically:

  1. Take the result of ourview logic and layout its widgets.
  2. Process events from our system and producemessages for ourupdate logic.
  3. Draw the resulting user interface.

Read thebook, thedocumentation, and theexamples to learn more!

Implementation details

Iced was originally born as an attempt at bringing the simplicity ofElm andThe Elm Architecture intoCoffee, a 2D game library I am working on.

The core of the library was implemented during May 2019 inthis pull request.The first alpha version was eventually released asa renderer-agnostic GUI library. The library did not provide a renderer andimplemented the currenttour example on top ofggez, a game library.

Since then, the focus has shifted towards providing a batteries-included,end-user-oriented GUI library, while keeping the ecosystem modular.

Contributing / Feedback

If you want to contribute, please read ourcontributing guidelines for more details.

Feedback is also welcome! You can create a new topic inour Discourse forum orcome chat toour Discord server.

Sponsors

The development of Iced is sponsored by theCryptowatch team atKraken.com


[8]ページ先頭

©2009-2025 Movatter.jp