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

eframe: Add a simplified native-only API for simple native apps #2453

Merged
merged 4 commits into from
Mar 30, 2023

Conversation

emilk
Copy link
Owner

@emilk emilk commented Dec 14, 2022

This lets you use eframe right from your main, with much less noise. This could be very useful for small, simple apps.

Example usage:

use eframe::egui;

fn main() -> Result<(), eframe::EframeError> {
    // Our application state:
    let mut name = "Arthur".to_owned();
    let mut age = 42;

    let options = eframe::NativeOptions::default();
    eframe::run_simple_native("My egui App", options, move |ctx, _frame| {
        egui::CentralPanel::default().show(ctx, |ui| {
            ui.heading("My egui Application");
            ui.horizontal(|ui| {
                let name_label = ui.label("Your name: ");
                ui.text_edit_singleline(&mut name)
                    .labelled_by(name_label.id);
            });
            ui.add(egui::Slider::new(&mut age, 0..=120).text("age"));
            if ui.button("Click each year").clicked() {
                age += 1;
            }
            ui.label(format!("Hello '{}', age {}", name, age));
        });
    })
}

It does the same as https://github.com/emilk/egui/blob/master/examples/hello_world/src/main.rs, but with much less code

@emilk emilk marked this pull request as ready for review March 29, 2023 08:32
@emilk emilk merged commit 92c4e23 into master Mar 30, 2023
@emilk emilk deleted the emilk/simplified-usage branch March 30, 2023 08:00
@emilk emilk added feature New feature or request eframe Relates to epi and eframe labels Apr 18, 2023
@emilk emilk changed the title eframe: add a simplified native-only API for simple native apps eframe: Add a simplified native-only API for simple native apps Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
eframe Relates to epi and eframe feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant