Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Program API #2331

Merged
merged 8 commits into from
Mar 16, 2024
Merged

Program API #2331

merged 8 commits into from
Mar 16, 2024

Conversation

hecrj
Copy link
Member

@hecrj hecrj commented Mar 16, 2024

This PR introduces a new Program API as a more convenient—although less powerful—alternative to the Sandbox and Application traits.

The main motivation is lowering the learning curve and entry barrier of the library. Specifically, Application has a lot of moving parts (e.g. Flags, Executor, Theme, subscription, etc.)

The run Function

There is a new run function in the root module that can be used to easily run basic applications, like the classic counter:

use iced::widget::{button, column, text, Column};

pub fn main() -> iced::Result {
    iced::run("A counter", update, view)
}

#[derive(Debug, Clone)]
enum Message {
    Increment,
}

fn update(value: &mut u64, message: Message) {
    match message {
        Message::Increment => *value += 1,
    }
}

fn view(value: &u64) -> Column<Message> {
    column![
        text(value),
        button("+").on_press(Message::Increment),
    ]
}

The Program API

The Program API can be used to create and run iced applications step by step—without coupling your logic to a trait or a specific type.

For instance, here is the new main function of the clock example:

pub fn main() -> iced::Result {
    iced::sandbox("Clock - Iced", Clock::update, Clock::view)
        .subscription(Clock::subscription)
        .theme(Clock::theme)
        .antialiased()
        .run()
}

@hecrj hecrj added this to the 0.13 milestone Mar 16, 2024
@hecrj hecrj enabled auto-merge March 16, 2024 15:56
@hecrj hecrj disabled auto-merge March 16, 2024 15:57
@hecrj hecrj enabled auto-merge March 16, 2024 15:59
@hecrj hecrj merged commit 503a48e into master Mar 16, 2024
24 checks passed
@hecrj hecrj deleted the program-api branch March 16, 2024 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant