Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/bevy_feathers/src/controls/color_slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,15 @@ impl FeathersColorSlider {
Node {
flex_grow: 1.0,
}
BackgroundGradient({vec![Gradient::Linear(LinearGradient {
BackgroundGradient(vec![Gradient::Linear(LinearGradient {
angle: PI * 0.5,
stops: vec![
ColorStop::new(Color::NONE, percent(0)),
ColorStop::new(Color::NONE, percent(50)),
ColorStop::new(Color::NONE, percent(100)),
],
color_space: InterpolationColorSpace::Srgba,
})]})
})])
ZIndex(1)
Children [(
Node {
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_feathers/src/controls/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ impl FeathersMenuPopup {
)
GlobalZIndex(100)
Popover {
positions: {vec![
positions: vec![
PopoverPlacement {
side: PopoverSide::Bottom,
align: PopoverAlign::Start,
Expand All @@ -234,7 +234,7 @@ impl FeathersMenuPopup {
align: PopoverAlign::Start,
gap: 2.0,
},
]},
],
window_margin: 10.0,
}
OverrideClip
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_feathers/src/controls/slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl FeathersSlider {
TabIndex(0)
FocusIndicator
// Use a gradient to draw the moving bar
BackgroundGradient({vec![Gradient::Linear(LinearGradient {
BackgroundGradient(vec![Gradient::Linear(LinearGradient {
angle: PI * 0.5,
stops: vec![
ColorStop::new(Color::NONE, percent(0)),
Expand All @@ -105,7 +105,7 @@ impl FeathersSlider {
ColorStop::new(Color::NONE, percent(100)),
],
color_space: InterpolationColorSpace::Srgba,
})]})
})])
Children [(
// Text container
Node {
Expand Down
22 changes: 20 additions & 2 deletions crates/bevy_scene/macros/src/bsn/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,13 @@ fn parenthesized_tokens(input: &ParseBuffer) -> Result<TokenStream> {
content.parse::<TokenStream>()
}

// Used to parse bracketed tokens "loosely" without caring about the content in `[...]`. This ensures autocomplete works.
fn bracketed_tokens(input: &ParseBuffer) -> Result<TokenStream> {
let content;
bracketed!(content in input);
content.parse::<TokenStream>()
}

fn tokens_between(begin: Cursor, end: Cursor) -> TokenStream {
assert!(begin <= end);
let mut cursor = begin;
Expand Down Expand Up @@ -487,8 +494,19 @@ impl Parse for BsnValue {
match PathType::new(&path) {
PathType::TypeFunction | PathType::Function => {
input.parse::<Path>()?;
let token_stream = parenthesized_tokens(input)?;
BsnValue::Expr(quote! { #path(#token_stream) })
let maybe_macro = input.parse::<Token![!]>().ok();
if input.peek(Paren) {
let token_stream = parenthesized_tokens(input)?;
BsnValue::Expr(quote! { #path #maybe_macro (#token_stream) })
} else if input.peek(Bracket) {
let token_stream = bracketed_tokens(input)?;
BsnValue::Expr(quote! { #path #maybe_macro [#token_stream] })
} else if input.peek(Brace) {
let token_stream = braced_tokens(input)?;
BsnValue::Expr(quote! { #path #maybe_macro { #token_stream } })
} else {
return Err(input.error("Unexpected input after function name"));
}
}
PathType::Const | PathType::TypeConst => {
input.parse::<Path>()?;
Expand Down
19 changes: 19 additions & 0 deletions crates/bevy_scene/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2183,4 +2183,23 @@ mod tests {
let indirect_ent = world.spawn_scene(indirect).unwrap();
assert!(indirect_ent.get::<Callback>().unwrap().callback == id2);
}

#[test]
fn direct_macro_values_in_bsn() {
let mut app = test_app();
let world = app.world_mut();

#[derive(Component, Default, Clone)]
struct Foo {
value: Vec<usize>,
}
let entity = world
.spawn_scene(bsn! {
Foo {
value: vec! [ 10usize ],
}
})
.unwrap();
assert_eq!(entity.get::<Foo>().unwrap().value, vec![10usize]);
}
}
12 changes: 6 additions & 6 deletions examples/large_scenes/bevy_city/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn settings_ui() -> impl Scene {
Text("Settings"),
(
@FeathersCheckbox {
@caption: {bsn! { Text("Simulate Cars") ThemedText }}
@caption: bsn! { Text("Simulate Cars") ThemedText }
}
Checked
on(checkbox_self_update)
Expand All @@ -74,7 +74,7 @@ pub fn settings_ui() -> impl Scene {
),
(
@FeathersCheckbox {
@caption: {bsn! { Text("Shadow maps enabled") ThemedText }}
@caption: bsn! { Text("Shadow maps enabled") ThemedText }
}
Checked
on(checkbox_self_update)
Expand All @@ -92,7 +92,7 @@ pub fn settings_ui() -> impl Scene {
),
(
@FeathersCheckbox {
@caption: {bsn! { Text("Contact shadows enabled") ThemedText }}
@caption: bsn! { Text("Contact shadows enabled") ThemedText }
}
Checked
on(checkbox_self_update)
Expand All @@ -110,7 +110,7 @@ pub fn settings_ui() -> impl Scene {
),
(
@FeathersCheckbox {
@caption: {bsn! { Text("Wireframe Enabled") ThemedText }}
@caption: bsn! { Text("Wireframe Enabled") ThemedText }
}
on(checkbox_self_update)
on(
Expand All @@ -124,7 +124,7 @@ pub fn settings_ui() -> impl Scene {
),
(
@FeathersCheckbox {
@caption: {bsn! { Text("CPU culling") ThemedText }}
@caption: bsn! { Text("CPU culling") ThemedText }
}
Checked
on(checkbox_self_update)
Expand All @@ -147,7 +147,7 @@ pub fn settings_ui() -> impl Scene {
),
(
@FeathersButton {
@caption: {bsn! { Text("Regenerate City") ThemedText }}
@caption: bsn! { Text("Regenerate City") ThemedText }
}
on(
|_activate: On<Activate>,
Expand Down
36 changes: 18 additions & 18 deletions examples/ui/widgets/feathers_gallery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ fn demo_column_1() -> impl Scene {
Children [
(
@FeathersButton {
@caption: {bsn! { Text("Normal") ThemedText }}
@caption: bsn! { Text("Normal") ThemedText }
}
Node {
flex_grow: 1.0,
Expand All @@ -136,7 +136,7 @@ fn demo_column_1() -> impl Scene {
),
(
@FeathersButton {
@caption: {bsn! { Text("Disabled") ThemedText }},
@caption: bsn! { Text("Disabled") ThemedText },
}
Node {
flex_grow: 1.0,
Expand All @@ -150,7 +150,7 @@ fn demo_column_1() -> impl Scene {
),
(
@FeathersButton {
@caption: {bsn! { Text("Primary") ThemedText }},
@caption: bsn! { Text("Primary") ThemedText },
@variant: ButtonVariant::Primary,
}
AccessibleLabel("Primary")
Expand All @@ -166,7 +166,7 @@ fn demo_column_1() -> impl Scene {
Children [
(
@FeathersMenuButton {
@caption: {bsn! { Text("Menu") ThemedText }}
@caption: bsn! { Text("Menu") ThemedText }
}
AccessibleLabel("Menu Example")
Node {
Expand All @@ -178,15 +178,15 @@ fn demo_column_1() -> impl Scene {
Children [
(
@FeathersMenuItem {
@caption: {bsn! { Text("MenuItem 1") ThemedText }}
@caption: bsn! { Text("MenuItem 1") ThemedText }
}
on(|_: On<Activate>| {
info!("Menu item 1 clicked!");
})
),
(
@FeathersMenuItem {
@caption: {bsn! { Text("MenuItem 2") ThemedText }}
@caption: bsn! { Text("MenuItem 2") ThemedText }
}
on(|_: On<Activate>| {
info!("Menu item 2 clicked!");
Expand All @@ -195,7 +195,7 @@ fn demo_column_1() -> impl Scene {
@FeathersMenuDivider,
(
@FeathersMenuItem {
@caption: {bsn! { Text("MenuItem 3") ThemedText }}
@caption: bsn! { Text("MenuItem 3") ThemedText }
}
on(|_: On<Activate>| {
info!("Menu item 3 clicked!");
Expand All @@ -218,7 +218,7 @@ fn demo_column_1() -> impl Scene {
Children [
(
@FeathersButton {
@caption: {bsn! { Text("Left") ThemedText }},
@caption: bsn! { Text("Left") ThemedText },
@corners: RoundedCorners::Left,
}
Node {
Expand All @@ -231,7 +231,7 @@ fn demo_column_1() -> impl Scene {
),
(
@FeathersButton {
@caption: {bsn! { Text("Center") ThemedText }},
@caption: bsn! { Text("Center") ThemedText },
@corners: RoundedCorners::None,
}
Node {
Expand All @@ -244,7 +244,7 @@ fn demo_column_1() -> impl Scene {
),
(
@FeathersButton {
@caption: {bsn! { Text("Right") ThemedText }},
@caption: bsn! { Text("Right") ThemedText },
@variant: ButtonVariant::Primary,
@corners: RoundedCorners::Right,
}
Expand Down Expand Up @@ -272,7 +272,7 @@ fn demo_column_1() -> impl Scene {
),
(
@FeathersCheckbox {
@caption: {bsn! { Text("Checkbox") ThemedText }}
@caption: bsn! { Text("Checkbox") ThemedText }
}
Checked
AccessibleLabel("Checkbox Example")
Expand All @@ -298,7 +298,7 @@ fn demo_column_1() -> impl Scene {
),
(
@FeathersCheckbox {
@caption: {bsn! { Text("Fast Click Checkbox") ThemedText }}
@caption: bsn! { Text("Fast Click Checkbox") ThemedText }
}
ActivateOnPress
AccessibleLabel("Fast Click Checkbox Example")
Expand All @@ -317,7 +317,7 @@ fn demo_column_1() -> impl Scene {
),
(
@FeathersCheckbox {
@caption: {bsn! { Text("Disabled") ThemedText }},
@caption: bsn! { Text("Disabled") ThemedText },
}
InteractionDisabled
AccessibleLabel("Disabled Checkbox Example")
Expand All @@ -327,7 +327,7 @@ fn demo_column_1() -> impl Scene {
),
(
@FeathersCheckbox {
@caption: {bsn! { Text("Checked+Disabled") ThemedText }}
@caption: bsn! { Text("Checked+Disabled") ThemedText }
}
InteractionDisabled
Checked
Expand Down Expand Up @@ -356,22 +356,22 @@ fn demo_column_1() -> impl Scene {
Children [
(
@FeathersRadio {
@caption: {bsn! { Text("One") ThemedText }}
@caption: bsn! { Text("One") ThemedText }
}
Checked
),
@FeathersRadio {
@caption: {bsn! { Text("Two") ThemedText }}
@caption: bsn! { Text("Two") ThemedText }
},
(
@FeathersRadio {
@caption: {bsn! { Text("Fast Click") ThemedText }}
@caption: bsn! { Text("Fast Click") ThemedText }
}
ActivateOnPress
),
(
@FeathersRadio {
@caption: {bsn! { Text("Disabled") ThemedText }}
@caption: bsn! { Text("Disabled") ThemedText }
}
InteractionDisabled
),
Expand Down
Loading