Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork1.3k
A cross-platform GUI library for Rust, inspired by Elm
License
iced-rs/iced
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
- Simple, easy-to-use, batteries-included API
- Type-safe, reactive programming model
- Cross-platform support (Windows, macOS, Linux, and the Web)
- Responsive layout
- Built-in widgets (includingtext inputs,scrollables, and more!)
- Custom widget support (create your own!)
- Debug overlay with performance metrics
- First-class support for async actions (use futures!)
- Modular ecosystem split into reusable parts:
- Arenderer-agnostic native runtime enabling integration with existing systems
- Two built-in renderers leveraging
wgpu
andtiny-skia
iced_wgpu
supporting Vulkan, Metal and DX12iced_tiny_skia
offering a software alternative as a fallback
- Awindowing shell
Iced is currently experimental software.Take a look at the roadmap andcheck out the issues.
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:
- Take the result of ourview logic and layout its widgets.
- Process events from our system and producemessages for ourupdate logic.
- Draw the resulting user interface.
Read thebook, thedocumentation, and theexamples to learn more!
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.
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.
The development of Iced is sponsored by theCryptowatch team atKraken.com
About
A cross-platform GUI library for Rust, inspired by Elm
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.