-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
eframe: add a simplified native-only API for simple native apps
- Loading branch information
Showing
7 changed files
with
122 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "hello_world_simple" | ||
version = "0.1.0" | ||
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"] | ||
license = "MIT OR Apache-2.0" | ||
edition = "2021" | ||
rust-version = "1.65" | ||
publish = false | ||
|
||
|
||
[dependencies] | ||
eframe = { path = "../../crates/eframe", features = [ | ||
"__screenshot", # __screenshot is so we can dump a ascreenshot using EFRAME_SCREENSHOT_TO | ||
] } | ||
tracing-subscriber = "0.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Example showing some UI controls like `Label`, `TextEdit`, `Slider`, `Button`. | ||
|
||
```sh | ||
cargo run -p hello_world | ||
``` | ||
|
||
![](screenshot.png) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release | ||
|
||
use eframe::egui; | ||
|
||
fn main() -> Result<(), eframe::Error> { | ||
// Log to stdout (if you run with `RUST_LOG=debug`). | ||
tracing_subscriber::fmt::init(); | ||
|
||
let options = eframe::NativeOptions { | ||
initial_window_size: Some(egui::vec2(320.0, 240.0)), | ||
..Default::default() | ||
}; | ||
|
||
// Our application state: | ||
let mut name = "Arthur".to_owned(); | ||
let mut age = 42; | ||
|
||
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)); | ||
}); | ||
}) | ||
} |