No description
Find a file
Héctor Ramón Jiménez d11ac25868 Write README
2019-07-27 23:49:19 +02:00
examples/ggez Add TODO to mouse input conversion in ggez example 2019-07-23 12:24:24 +02:00
resources Implement button::Renderer in ggez example 2019-07-22 20:14:23 +02:00
src Wire mouse_motion_event to Runtime 2019-07-23 11:02:53 +02:00
.gitignore Initial commit 2019-05-29 03:17:48 +02:00
.travis.yml Install dev libs in CI 2019-07-21 12:43:28 +02:00
Cargo.toml Write README 2019-07-27 23:49:19 +02:00
README.md Write README 2019-07-27 23:49:19 +02:00
rustfmt.toml Decouple iced from coffee 2019-07-20 19:12:31 +02:00

Iced

Build Status Documentation Crates.io License

An opinionated GUI runtime for Rust, heavily inspired by Elm.

Features

  • Simple, easy to use API
  • Responsive, flexbox-based layouting
  • Type-safe, reactive programming model without weak references
  • Built-in widgets
  • Custom widget support
  • Renderer-agnostic runtime

Usage

Add iced as a dependency in your Cargo.toml:

iced = "0.1"

Iced moves fast and the master branch can contain breaking changes! If you want to learn about a specific release, check out the release list.

Overview

Here is an example showcasing an interactive counter that can be incremented and decremented using two different buttons:

use iced::{button, Button, Column, Text};
use crate::MyRenderer;

struct Counter {
    // The counter value
    value: i32,

    // Local state of the two counter buttons
    // This is internal widget state that may change outside our update
    // logic
    increment_button: button::State,
    decrement_button: button::State,
}

// The user interactions we are interested on
#[derive(Debug, Clone, Copy)]
pub enum Message {
    IncrementPressed,
    DecrementPressed,
}

impl Counter {
    // The update logic, called when a message is produced
    fn react(&mut self, message: Message) {
        // We update the counter value after an interaction here
        match message {
            Message::IncrementPressed => {
                self.value += 1;
            }
            Message::DecrementPressed => {
                self.value -= 1;
            }
        }
    }

    // The layout logic, describing the different components of the counter
    fn layout(&mut self, window: &Window) -> Element<Message, MyRenderer> {
        // We use a column so the elements inside are laid out vertically
        Column::new()
            .push(
                // The increment button. We tell it to produce an
                // `IncrementPressed` message when pressed
                Button::new(&mut self.increment_button, "+")
                    .on_press(Message::IncrementPressed),
            )
            .push(
                // We show the value of the counter here
                Text::new(&self.value.to_string()).size(50),
            )
            .push(
                // The decrement button. We tell it to produce a
                // `DecrementPressed` message when pressed
                Button::new(&mut self.decrement_button, "-")
                    .on_press(Message::DecrementPressed),
            )
            .into() // We can return a generic `Element` and avoid breaking
                    // changes if we redesign the counter in the future.
    }
}