|
| 1 | +use eframe::{egui, NativeOptions}; |
| 2 | +use efx::efx; |
| 3 | + |
| 4 | +fn main() -> eframe::Result<()> { |
| 5 | + let native = NativeOptions::default(); |
| 6 | + eframe::run_native( |
| 7 | + "EFx Sandbox", |
| 8 | + native, |
| 9 | + Box::new(|_cc| Ok(Box::new(App::default()))), |
| 10 | + ) |
| 11 | +} |
| 12 | + |
| 13 | +#[derive(Default)] |
| 14 | +struct App { |
| 15 | + counter: i32, |
| 16 | + input: String, |
| 17 | +} |
| 18 | + |
| 19 | +impl eframe::App for App { |
| 20 | + fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { |
| 21 | + egui::CentralPanel::default().show(ctx, |ui| { |
| 22 | + // Header |
| 23 | + let _ = efx!(ui, r#" |
| 24 | + <Column gap="8"> |
| 25 | + <Label size="20" bold="true">EFx sandbox</Label> |
| 26 | + <Separator/> |
| 27 | + </Column> |
| 28 | + "#); |
| 29 | + |
| 30 | + // Increment/decrement buttons - catch Response |
| 31 | + ui.horizontal(|ui| { |
| 32 | + let inc = efx!(ui, r#"<Button tooltip="Increment">+1</Button>"#); |
| 33 | + if inc.clicked() { self.counter += 1; } |
| 34 | + |
| 35 | + let dec = efx!(ui, r#"<Button tooltip="Decrement">-1</Button>"#); |
| 36 | + if dec.clicked() { self.counter -= 1; } |
| 37 | + }); |
| 38 | + |
| 39 | + // Dynamic text via {expr} |
| 40 | + let _ = efx!(ui, r#"<Label>Counter: {self.counter}</Label>"#); |
| 41 | + |
| 42 | + // Input field (binding directly to the state field) |
| 43 | + let _ = efx!(ui, r#"<TextField value="self.input" hint="type here…"/>"#); |
| 44 | + |
| 45 | + // Scrolling + different tags |
| 46 | + let _ = efx!(ui, r##" |
| 47 | + <ScrollArea axis="vertical" max-height="160" always-show="true" id="demo-log"> |
| 48 | + <Column gap="6"> |
| 49 | + <Label monospace="true">You typed: {self.input.clone()}</Label> |
| 50 | + <Row gap="8"> |
| 51 | + <Hyperlink url="https://efxui.com" tooltip="Project site"/> |
| 52 | + <Hyperlink url="help:about" open_external="false">About</Hyperlink> |
| 53 | + </Row> |
| 54 | + <Separator/> |
| 55 | + <Row gap="10" wrap="true"> |
| 56 | + <Button fill="#333333" rounding="8">A</Button> |
| 57 | + <Button frame="false">B</Button> |
| 58 | + <Button min_width="100" tooltip="Wide">Wide</Button> |
| 59 | + </Row> |
| 60 | + </Column> |
| 61 | + </ScrollArea> |
| 62 | + "##); |
| 63 | + }); |
| 64 | + } |
| 65 | +} |
0 commit comments