- Notifications
You must be signed in to change notification settings - Fork1
A cross-platform GUI library for Rust, inspired by Elm
License
payload/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, andthe 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
- Twobuilt-in renderers leveraging
wgpu
andtiny-skia
iced_wgpu
supporting Vulkan, Metal and DX12iced_tiny_skia
offering a software alternative as a fallback
- Awindowing shell
- Aweb runtime leveraging the DOM
Iced is currently experimental software.Take a look at the roadmap,check out the issues, andfeel free to contribute!
Addiced
as a dependency in yourCargo.toml
:
iced ="0.10"
If your project is using a Rust edition older than 2021, then you will need tosetresolver = "2"
in the[package]
section as well.
Iced moves fast and themaster
branch can contain breaking changes! Ifyou want to learn about a specific release, check outthe release list.
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:
structCounter{// The counter valuevalue: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{IncrementPressed,DecrementPressed,}
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// `IncrementPressed` message when pressed button("+").on_press(Message::IncrementPressed),// We show the value of the counter here text(self.value).size(50),// The decrement button. We tell it to produce a// `DecrementPressed` message when pressed button("-").on_press(Message::DecrementPressed),]}}
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::IncrementPressed =>{self.value +=1;}Message::DecrementPressed =>{self.value -=1;}}}}
And that's everything! We just wrote a whole user interface. Iced is now ableto:
- 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.
Browse 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 engine 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 keepingthe ecosystem modular:
Contributions are greatly appreciated! If you want to contribute, pleaseread ourcontributing guidelines for more details.
Feedback is also welcome! You can open a discussion or come chat to ourDiscord server.
The development of Iced is sponsored by theCryptowatch team atKraken.com