Skip to content

Commit 7782102

Browse files
committed
Added Sandbox, fixed ScrollArea tag
1 parent 89532a0 commit 7782102

4 files changed

Lines changed: 95 additions & 7 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[workspace]
2-
members = ["efx", "efx-core", "efx-attrnames"]
2+
members = ["efx", "efx-core", "efx-attrnames", "efx-sandbox"]
33
resolver = "2"
44
rust-version = "1.85"

efx-sandbox/Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "efx-sandbox"
3+
version = "0.1.0"
4+
edition = "2024"
5+
rust-version = "1.85"
6+
publish = false
7+
8+
[dependencies]
9+
eframe = "0.32"
10+
efx = { path = "../efx" }
11+
efx-core = { path = "../efx-core" }

efx-sandbox/src/main.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
}

efx/src/tags/scroll_area.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,34 @@ impl Tag for ScrollArea {
2828
let mut build = quote!( let mut __efx_sa = #axis; );
2929

3030
if let Some(b) = self.attributes.always_show {
31-
build.extend(quote!( __efx_sa = __efx_sa.always_show_scroll(#b); ));
31+
if b {
32+
build.extend(quote!(
33+
__efx_sa = __efx_sa.scroll_bar_visibility(
34+
egui::containers::scroll_area::ScrollBarVisibility::AlwaysVisible
35+
);
36+
));
37+
} else {
38+
build.extend(quote!(
39+
__efx_sa = __efx_sa.scroll_bar_visibility(
40+
egui::containers::scroll_area::ScrollBarVisibility::VisibleWhenNeeded
41+
);
42+
));
43+
}
3244
}
3345
if let Some(b) = self.attributes.bottom {
34-
build.extend(quote!( __efx_sa = __efx_sa.stick_to_bottom(#b); ));
46+
build.extend(quote!( __efx_sa = __efx_sa.stick_to_bottom(#b); ));
3547
}
3648
if let Some(b) = self.attributes.right {
37-
build.extend(quote!( __efx_sa = __efx_sa.stick_to_right(#b); ));
49+
build.extend(quote!( __efx_sa = __efx_sa.stick_to_right(#b); ));
3850
}
3951
if let Some(h) = self.attributes.max_height {
40-
build.extend(quote!( __efx_sa = __efx_sa.max_height(#h as _); ));
52+
build.extend(quote!( __efx_sa = __efx_sa.max_height(#h as _); ));
4153
}
4254
if let Some(w) = self.attributes.max_width {
43-
build.extend(quote!( __efx_sa = __efx_sa.max_width(#w as _); ));
55+
build.extend(quote!( __efx_sa = __efx_sa.max_width(#w as _); ));
4456
}
4557
if let Some(id) = self.attributes.id.clone() {
46-
build.extend(quote!( __efx_sa = __efx_sa.id_source(#id); ));
58+
build.extend(quote!( __efx_sa = __efx_sa.id_salt(#id); ));
4759
}
4860

4961
build

0 commit comments

Comments
 (0)