mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 05:10:03 -04:00
hierarchy & example
This commit is contained in:
19
examples/styling_engine/Cargo.toml
Normal file
19
examples/styling_engine/Cargo.toml
Normal file
@@ -0,0 +1,19 @@
|
||||
[package]
|
||||
name = "styling_engine"
|
||||
version = "0.1.0"
|
||||
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
edition = "2024"
|
||||
rust-version = "1.92"
|
||||
publish = false
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
|
||||
[dependencies]
|
||||
eframe = { workspace = true, features = [
|
||||
"default",
|
||||
"__screenshot", # __screenshot is so we can dump a screenshot using EFRAME_SCREENSHOT_TO
|
||||
] }
|
||||
env_logger = { workspace = true, features = ["auto-color", "humantime"] }
|
||||
7
examples/styling_engine/README.md
Normal file
7
examples/styling_engine/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
Example showing how the style engine work.
|
||||
|
||||
```sh
|
||||
cargo run -p styling_engine
|
||||
```
|
||||
|
||||

|
||||
3
examples/styling_engine/screenshot.png
Normal file
3
examples/styling_engine/screenshot.png
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:7cde6a351fbcf5a5d3b5474353c627a9c93801563880b7ff41dfa025da3c6d37
|
||||
size 8587
|
||||
44
examples/styling_engine/src/main.rs
Normal file
44
examples/styling_engine/src/main.rs
Normal file
@@ -0,0 +1,44 @@
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
||||
#![expect(rustdoc::missing_crate_level_docs)] // it's an example
|
||||
|
||||
use eframe::egui::{self, Button, Frame, Grid, Margin, Panel, widget_style::HasModifiers as _};
|
||||
|
||||
fn main() -> eframe::Result {
|
||||
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
|
||||
|
||||
let options = eframe::NativeOptions {
|
||||
viewport: egui::ViewportBuilder::default().with_inner_size([600.0, 400.0]),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let mut style_code = "// future style code live editor".to_owned();
|
||||
|
||||
eframe::run_ui_native("My egui App", options, move |ui, _frame| {
|
||||
// Add a modifier to this ui
|
||||
ui.add_modifier("body");
|
||||
ui.label("body");
|
||||
egui::CentralPanel::default().show_inside(ui, |ui| {
|
||||
// Add a modifier to this ui
|
||||
ui.add_modifier("central panel");
|
||||
ui.label("central panel");
|
||||
|
||||
Panel::left("style_code").show_inside(ui, |ui| {
|
||||
ui.add_modifier("style code editor");
|
||||
ui.label("style code editor");
|
||||
|
||||
ui.text_edit_multiline(&mut style_code);
|
||||
});
|
||||
|
||||
Grid::new("grid").show(ui, |ui| {
|
||||
ui.add_modifier("grid");
|
||||
|
||||
Frame::new().inner_margin(Margin::same(10)).show(ui, |ui| {
|
||||
ui.add_modifier("frame1");
|
||||
|
||||
ui.add(Button::new("button1").with_modifier("button1"));
|
||||
ui.add(Button::new("button2").with_modifier("button2"));
|
||||
})
|
||||
});
|
||||
});
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user