-
Notifications
You must be signed in to change notification settings - Fork 1
/
superellipse_transparency.rs
101 lines (91 loc) · 3.06 KB
/
superellipse_transparency.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//! This example demonstrates spawning a superellipse material node.
use bevy::{color::palettes::css, prelude::*};
use bevy_round_ui::prelude::*;
fn main() {
App::new()
.add_plugins((DefaultPlugins, BevyRoundUiDefaultPlugins))
.add_systems(Startup, setup)
.run();
}
const PANEL_WIDTH: f32 = 400.0;
const PANEL_HEIGHT: f32 = 200.0;
const BORDER_THICKNESS: f32 = 10.;
#[derive(Component)]
pub enum PanelSize {
Short,
Square,
Long,
}
fn setup(mut commands: Commands, mut materials: ResMut<Assets<SuperellipseUiMaterial>>) {
// Camera so we can see UI
commands.spawn(Camera2dBundle::default());
let border_radius: Vec4 = RoundUiBorder::all(PANEL_WIDTH / 4.).into();
let background_color: LinearRgba = Color::srgba(0.36078432, 0.7019608, 0.6862745, 0.5).into();
let border_color: LinearRgba = Color::srgba(1., 1., 1., 0.25).into();
// Add the material
let panel_material_superellipse = materials.add(SuperellipseUiMaterial {
background_color,
border_color,
border_radius,
border_thickness: BORDER_THICKNESS,
});
// Spawn 2 colored columns so we can see the transparency of the material
commands
.spawn(NodeBundle {
style: Style {
flex_direction: FlexDirection::Row,
width: Val::Percent(100.0),
height: Val::Percent(100.0),
..default()
},
..default()
})
.with_children(|p| {
p.spawn(NodeBundle {
style: Style {
flex_direction: FlexDirection::Column,
width: Val::Percent(50.0),
height: Val::Percent(100.0),
..default()
},
background_color: css::DARK_GRAY.into(),
..default()
});
p.spawn(NodeBundle {
style: Style {
flex_direction: FlexDirection::Column,
width: Val::Percent(50.0),
height: Val::Percent(100.0),
..default()
},
background_color: css::ORANGE_RED.into(),
..default()
});
});
// Spawn the material in the middle of the screen
commands
.spawn(NodeBundle {
style: Style {
width: Val::Percent(100.0),
height: Val::Percent(100.0),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
..default()
},
..default()
})
.with_children(|p| {
p.spawn((
PanelSize::Short,
MaterialNodeBundle {
material: panel_material_superellipse,
style: Style {
width: Val::Px(PANEL_WIDTH),
height: Val::Px(PANEL_HEIGHT),
..default()
},
..default()
},
));
});
}