pub struct ColorStop {
pub color: Color,
pub point: Val,
pub hint: f32,
}Expand description
A color stop for a gradient
Fields§
§color: ColorColor
point: ValLogical position along the gradient line. Stop positions are relative to the start of the gradient and not other stops.
hint: f32Normalized position between this and the following stop of the interpolation midpoint.
Implementations§
Source§impl ColorStop
impl ColorStop
Sourcepub fn new(color: impl Into<Color>, point: Val) -> ColorStop
pub fn new(color: impl Into<Color>, point: Val) -> ColorStop
Create a new color stop
Examples found in repository?
examples/stress_tests/many_gradients.rs (line 105)
83fn setup(mut commands: Commands, args: Res<Args>) {
84 commands.spawn(Camera2d);
85
86 let rows_to_spawn = args.gradient_count.div_ceil(COLS);
87
88 // Create a grid of gradients
89 commands
90 .spawn(Node {
91 width: percent(100),
92 height: percent(100),
93 display: Display::Grid,
94 grid_template_columns: RepeatedGridTrack::flex(COLS as u16, 1.0),
95 grid_template_rows: RepeatedGridTrack::flex(rows_to_spawn as u16, 1.0),
96 ..default()
97 })
98 .with_children(|parent| {
99 for i in 0..args.gradient_count {
100 let angle = (i as f32 * 10.0) % 360.0;
101
102 let mut gradient = LinearGradient::new(
103 angle,
104 vec![
105 ColorStop::new(RED, percent(0)),
106 ColorStop::new(BLUE, percent(100)),
107 ColorStop::new(GREEN, percent(20)),
108 ColorStop::new(YELLOW, percent(40)),
109 ColorStop::new(ORANGE, percent(60)),
110 ColorStop::new(LIME, percent(80)),
111 ColorStop::new(DARK_CYAN, percent(90)),
112 ],
113 );
114
115 gradient.color_space = if args.srgb {
116 InterpolationColorSpace::Srgba
117 } else if args.hsl {
118 InterpolationColorSpace::Hsla
119 } else {
120 InterpolationColorSpace::Oklaba
121 };
122
123 parent.spawn((
124 Node {
125 width: percent(100),
126 height: percent(100),
127 ..default()
128 },
129 BackgroundGradient(vec![Gradient::Linear(gradient)]),
130 GradientNode { index: i },
131 ));
132 }
133 });
134}
135
136#[derive(Component)]
137struct GradientNode {
138 index: usize,
139}
140
141fn animate_gradients(
142 mut gradients: Query<(&mut BackgroundGradient, &GradientNode)>,
143 args: Res<Args>,
144 time: Res<Time>,
145) {
146 if !args.animate {
147 return;
148 }
149
150 let t = time.elapsed_secs();
151
152 for (mut bg_gradient, node) in &mut gradients {
153 let offset = node.index as f32 * 0.01;
154 let hue_shift = sin(t + offset) * 0.5 + 0.5;
155
156 if let Some(Gradient::Linear(gradient)) = bg_gradient.0.get_mut(0) {
157 let color1 = Color::hsl(hue_shift * 360.0, 1.0, 0.5);
158 let color2 = Color::hsl((hue_shift + 0.3) * 360.0 % 360.0, 1.0, 0.5);
159
160 gradient.stops = vec![
161 ColorStop::new(color1, percent(0)),
162 ColorStop::new(color2, percent(100)),
163 ColorStop::new(
164 Color::hsl((hue_shift + 0.1) * 360.0 % 360.0, 1.0, 0.5),
165 percent(20),
166 ),
167 ColorStop::new(
168 Color::hsl((hue_shift + 0.15) * 360.0 % 360.0, 1.0, 0.5),
169 percent(40),
170 ),
171 ColorStop::new(
172 Color::hsl((hue_shift + 0.2) * 360.0 % 360.0, 1.0, 0.5),
173 percent(60),
174 ),
175 ColorStop::new(
176 Color::hsl((hue_shift + 0.25) * 360.0 % 360.0, 1.0, 0.5),
177 percent(80),
178 ),
179 ColorStop::new(
180 Color::hsl((hue_shift + 0.28) * 360.0 % 360.0, 1.0, 0.5),
181 percent(90),
182 ),
183 ];
184 }
185 }
186}More examples
examples/testbed/ui.rs (line 802)
800 pub fn setup(mut commands: Commands) {
801 let color_stops = vec![
802 ColorStop::new(Color::BLACK, px(5)),
803 ColorStop::new(Color::WHITE, px(5)),
804 ColorStop::new(Color::WHITE, percent(100)),
805 ColorStop::auto(RED),
806 ];
807
808 commands.spawn((Camera2d, DespawnOnExit(super::Scene::RadialGradient)));
809 commands
810 .spawn((
811 Node {
812 width: percent(100),
813 height: percent(100),
814 display: Display::Grid,
815 align_items: AlignItems::Start,
816 grid_template_columns: vec![RepeatedGridTrack::px(
817 GridTrackRepetition::AutoFill,
818 CELL_SIZE,
819 )],
820 grid_auto_flow: GridAutoFlow::Row,
821 row_gap: px(GAP),
822 column_gap: px(GAP),
823 padding: UiRect::all(px(GAP)),
824 ..default()
825 },
826 DespawnOnExit(super::Scene::RadialGradient),
827 ))
828 .with_children(|commands| {
829 for (shape, shape_label) in [
830 (RadialGradientShape::ClosestSide, "ClosestSide"),
831 (RadialGradientShape::FarthestSide, "FarthestSide"),
832 (RadialGradientShape::Circle(percent(55)), "Circle(55%)"),
833 (RadialGradientShape::FarthestCorner, "FarthestCorner"),
834 ] {
835 for (position, position_label) in [
836 (UiPosition::TOP_LEFT, "TOP_LEFT"),
837 (UiPosition::LEFT, "LEFT"),
838 (UiPosition::BOTTOM_LEFT, "BOTTOM_LEFT"),
839 (UiPosition::TOP, "TOP"),
840 (UiPosition::CENTER, "CENTER"),
841 (UiPosition::BOTTOM, "BOTTOM"),
842 (UiPosition::TOP_RIGHT, "TOP_RIGHT"),
843 (UiPosition::RIGHT, "RIGHT"),
844 (UiPosition::BOTTOM_RIGHT, "BOTTOM_RIGHT"),
845 ] {
846 for (w, h) in [(CELL_SIZE, CELL_SIZE), (CELL_SIZE, CELL_SIZE / 2.)] {
847 commands
848 .spawn((
849 BackgroundColor(GRAY_700.into()),
850 Node {
851 display: Display::Grid,
852 width: px(CELL_SIZE),
853 ..Default::default()
854 },
855 ))
856 .with_children(|commands| {
857 commands.spawn((
858 Node {
859 margin: UiRect::all(px(2)),
860 ..default()
861 },
862 Text(format!("{shape_label}\n{position_label}")),
863 TextFont::from_font_size(9.),
864 ));
865 commands.spawn((
866 Node {
867 width: px(w),
868 height: px(h),
869 ..default()
870 },
871 BackgroundGradient::from(RadialGradient {
872 stops: color_stops.clone(),
873 position,
874 shape,
875 ..default()
876 }),
877 ));
878 });
879 }
880 }
881 }
882 });
883 }examples/ui/gradients.rs (line 41)
26fn setup(mut commands: Commands) {
27 commands.spawn(Camera2d);
28
29 commands
30 .spawn(Node {
31 flex_direction: FlexDirection::Column,
32 row_gap: px(20),
33 margin: UiRect::all(px(20)),
34 ..Default::default()
35 })
36 .with_children(|commands| {
37 for (b, stops) in [
38 (
39 4.,
40 vec![
41 ColorStop::new(Color::WHITE, percent(15)),
42 ColorStop::new(Color::BLACK, percent(85)),
43 ],
44 ),
45 (4., vec![RED.into(), BLUE.into(), LIME.into()]),
46 (
47 0.,
48 vec![
49 RED.into(),
50 ColorStop::new(RED, percent(100. / 7.)),
51 ColorStop::new(ORANGE, percent(100. / 7.)),
52 ColorStop::new(ORANGE, percent(200. / 7.)),
53 ColorStop::new(YELLOW, percent(200. / 7.)),
54 ColorStop::new(YELLOW, percent(300. / 7.)),
55 ColorStop::new(GREEN, percent(300. / 7.)),
56 ColorStop::new(GREEN, percent(400. / 7.)),
57 ColorStop::new(BLUE, percent(400. / 7.)),
58 ColorStop::new(BLUE, percent(500. / 7.)),
59 ColorStop::new(INDIGO, percent(500. / 7.)),
60 ColorStop::new(INDIGO, percent(600. / 7.)),
61 ColorStop::new(VIOLET, percent(600. / 7.)),
62 VIOLET.into(),
63 ],
64 ),
65 ] {
66 commands.spawn(Node::default()).with_children(|commands| {
67 commands
68 .spawn(Node {
69 flex_direction: FlexDirection::Column,
70 row_gap: px(5),
71 ..Default::default()
72 })
73 .with_children(|commands| {
74 for (w, h) in [(70., 70.), (35., 70.), (70., 35.)] {
75 commands
76 .spawn(Node {
77 column_gap: px(10),
78 ..Default::default()
79 })
80 .with_children(|commands| {
81 for angle in (0..8).map(|i| i as f32 * TAU / 8.) {
82 commands.spawn((
83 Node {
84 width: px(w),
85 height: px(h),
86 border: UiRect::all(px(b)),
87 ..default()
88 },
89 BorderRadius::all(px(20)),
90 BackgroundGradient::from(LinearGradient {
91 angle,
92 stops: stops.clone(),
93 ..default()
94 }),
95 BorderGradient::from(LinearGradient {
96 angle: 3. * TAU / 8.,
97 stops: vec![
98 YELLOW.into(),
99 Color::WHITE.into(),
100 ORANGE.into(),
101 ],
102 ..default()
103 }),
104 ));
105 }
106 });
107 }
108 });
109
110 commands.spawn(Node::default()).with_children(|commands| {
111 commands.spawn((
112 Node {
113 aspect_ratio: Some(1.),
114 height: percent(100),
115 border: UiRect::all(px(b)),
116 margin: UiRect::left(px(20)),
117 ..default()
118 },
119 BorderRadius::all(px(20)),
120 BackgroundGradient::from(LinearGradient {
121 angle: 0.,
122 stops: stops.clone(),
123 ..default()
124 }),
125 BorderGradient::from(LinearGradient {
126 angle: 3. * TAU / 8.,
127 stops: vec![YELLOW.into(), Color::WHITE.into(), ORANGE.into()],
128 ..default()
129 }),
130 AnimateMarker,
131 ));
132
133 commands.spawn((
134 Node {
135 aspect_ratio: Some(1.),
136 height: percent(100),
137 border: UiRect::all(px(b)),
138 margin: UiRect::left(px(20)),
139 ..default()
140 },
141 BorderRadius::all(px(20)),
142 BackgroundGradient::from(RadialGradient {
143 stops: stops.clone(),
144 shape: RadialGradientShape::ClosestSide,
145 position: UiPosition::CENTER,
146 ..default()
147 }),
148 BorderGradient::from(LinearGradient {
149 angle: 3. * TAU / 8.,
150 stops: vec![YELLOW.into(), Color::WHITE.into(), ORANGE.into()],
151 ..default()
152 }),
153 AnimateMarker,
154 ));
155 commands.spawn((
156 Node {
157 aspect_ratio: Some(1.),
158 height: percent(100),
159 border: UiRect::all(px(b)),
160 margin: UiRect::left(px(20)),
161 ..default()
162 },
163 BorderRadius::all(px(20)),
164 BackgroundGradient::from(ConicGradient {
165 start: 0.,
166 stops: stops
167 .iter()
168 .map(|stop| AngularColorStop::auto(stop.color))
169 .collect(),
170 position: UiPosition::CENTER,
171 ..default()
172 }),
173 BorderGradient::from(LinearGradient {
174 angle: 3. * TAU / 8.,
175 stops: vec![YELLOW.into(), Color::WHITE.into(), ORANGE.into()],
176 ..default()
177 }),
178 AnimateMarker,
179 ));
180 });
181 });
182 }
183
184 let button = commands.spawn((
185 Button,
186 Node {
187 border: UiRect::all(px(2)),
188 padding: UiRect::axes(px(8), px(4)),
189 // horizontally center child text
190 justify_content: JustifyContent::Center,
191 // vertically center child text
192 align_items: AlignItems::Center,
193 ..default()
194 },
195 BorderColor::all(Color::WHITE),
196 BorderRadius::MAX,
197 BackgroundColor(Color::BLACK),
198 children![(
199 Text::new("next color space"),
200 TextColor(Color::srgb(0.9, 0.9, 0.9)),
201 TextShadow::default(),
202 )]
203 )).observe(
204 |_event: On<Pointer<Over>>, mut border_query: Query<&mut BorderColor, With<Button>>| {
205 *border_query.single_mut().unwrap() = BorderColor::all(RED);
206
207
208 })
209 .observe(
210 |_event: On<Pointer<Out>>, mut border_query: Query<&mut BorderColor, With<Button>>| {
211 *border_query.single_mut().unwrap() = BorderColor::all(Color::WHITE);
212 })
213 .observe(
214 |_event: On<Pointer<Click>>,
215 mut gradients_query: Query<&mut BackgroundGradient>,
216 mut label_query: Query<
217 &mut Text,
218 With<CurrentColorSpaceLabel>,
219 >| {
220 let mut current_space = InterpolationColorSpace::default();
221 for mut gradients in gradients_query.iter_mut() {
222 for gradient in gradients.0.iter_mut() {
223 let space = match gradient {
224 Gradient::Linear(linear_gradient) => {
225 &mut linear_gradient.color_space
226 }
227 Gradient::Radial(radial_gradient) => {
228 &mut radial_gradient.color_space
229 }
230 Gradient::Conic(conic_gradient) => {
231 &mut conic_gradient.color_space
232 }
233 };
234 *space = match *space {
235 InterpolationColorSpace::Oklaba => {
236 InterpolationColorSpace::Oklcha
237 }
238 InterpolationColorSpace::Oklcha => {
239 InterpolationColorSpace::OklchaLong
240 }
241 InterpolationColorSpace::OklchaLong => {
242 InterpolationColorSpace::Srgba
243 }
244 InterpolationColorSpace::Srgba => {
245 InterpolationColorSpace::LinearRgba
246 }
247 InterpolationColorSpace::LinearRgba => {
248 InterpolationColorSpace::Hsla
249 }
250 InterpolationColorSpace::Hsla => {
251 InterpolationColorSpace::HslaLong
252 }
253 InterpolationColorSpace::HslaLong => {
254 InterpolationColorSpace::Hsva
255 }
256 InterpolationColorSpace::Hsva => {
257 InterpolationColorSpace::HsvaLong
258 }
259 InterpolationColorSpace::HsvaLong => {
260 InterpolationColorSpace::Oklaba
261 }
262 };
263 current_space = *space;
264 }
265 }
266 for mut label in label_query.iter_mut() {
267 label.0 = format!("{current_space:?}");
268 }
269 }
270 ).id();
271
272 commands.spawn(
273 Node {
274 flex_direction: FlexDirection::Column,
275 row_gap: px(10),
276 align_items: AlignItems::Center,
277 ..Default::default()
278 }
279 ).with_children(|commands| {
280 commands.spawn((Text::new(format!("{:?}", InterpolationColorSpace::default())), TextFont { font_size: 25., ..default() }, CurrentColorSpaceLabel));
281
282 })
283 .add_child(button);
284 });
285}Sourcepub fn auto(color: impl Into<Color>) -> ColorStop
pub fn auto(color: impl Into<Color>) -> ColorStop
An automatic color stop. The positions of automatic stops are interpolated evenly between explicit stops.
Examples found in repository?
examples/ui/stacked_gradients.rs (line 36)
16fn setup(mut commands: Commands) {
17 commands.spawn(Camera2d);
18 commands
19 .spawn(Node {
20 display: Display::Grid,
21 width: percent(100),
22 height: percent(100),
23
24 ..Default::default()
25 })
26 .with_children(|commands| {
27 commands.spawn((
28 Node {
29 width: percent(100),
30 height: percent(100),
31 ..Default::default()
32 },
33 BackgroundColor(Color::BLACK),
34 BackgroundGradient(vec![
35 LinearGradient::to_top_right(vec![
36 ColorStop::auto(RED),
37 ColorStop::auto(RED.with_alpha(0.)),
38 ])
39 .into(),
40 LinearGradient::to_top_left(vec![
41 ColorStop::auto(BLUE),
42 ColorStop::auto(BLUE.with_alpha(0.)),
43 ])
44 .into(),
45 ConicGradient {
46 start: 0.,
47 position: UiPosition::CENTER,
48 stops: vec![
49 AngularColorStop::auto(YELLOW.with_alpha(0.)),
50 AngularColorStop::auto(YELLOW.with_alpha(0.)),
51 AngularColorStop::auto(YELLOW),
52 AngularColorStop::auto(YELLOW.with_alpha(0.)),
53 AngularColorStop::auto(YELLOW.with_alpha(0.)),
54 ],
55 ..Default::default()
56 }
57 .into(),
58 RadialGradient {
59 position: UiPosition::TOP.at_x(percent(5)),
60 shape: RadialGradientShape::Circle(vh(30)),
61 stops: vec![
62 ColorStop::auto(Color::WHITE),
63 ColorStop::auto(YELLOW),
64 ColorStop::auto(YELLOW.with_alpha(0.1)),
65 ColorStop::auto(YELLOW.with_alpha(0.)),
66 ],
67 ..Default::default()
68 }
69 .into(),
70 LinearGradient {
71 angle: TAU / 16.,
72 stops: vec![
73 ColorStop::auto(Color::BLACK),
74 ColorStop::auto(Color::BLACK.with_alpha(0.)),
75 ],
76 ..Default::default()
77 }
78 .into(),
79 LinearGradient {
80 angle: 15. * TAU / 16.,
81 stops: vec![
82 ColorStop::auto(Color::BLACK),
83 ColorStop::auto(Color::BLACK.with_alpha(0.)),
84 ],
85 ..Default::default()
86 }
87 .into(),
88 ]),
89 ));
90 });
91}More examples
examples/testbed/ui.rs (line 711)
685 pub fn setup(mut commands: Commands) {
686 commands.spawn((Camera2d, DespawnOnExit(super::Scene::LinearGradient)));
687 commands
688 .spawn((
689 Node {
690 flex_direction: bevy::ui::FlexDirection::Column,
691 width: bevy::ui::percent(100),
692 height: bevy::ui::percent(100),
693 justify_content: JustifyContent::Center,
694 align_items: AlignItems::Center,
695 row_gap: bevy::ui::px(5),
696 ..default()
697 },
698 DespawnOnExit(super::Scene::LinearGradient),
699 ))
700 .with_children(|commands| {
701 let mut i = 0;
702 commands
703 .spawn(Node {
704 display: bevy::ui::Display::Grid,
705 row_gap: bevy::ui::px(4),
706 column_gap: bevy::ui::px(4),
707 ..Default::default()
708 })
709 .with_children(|commands| {
710 for stops in [
711 vec![ColorStop::auto(RED), ColorStop::auto(YELLOW)],
712 vec![
713 ColorStop::auto(Color::BLACK),
714 ColorStop::auto(RED),
715 ColorStop::auto(Color::WHITE),
716 ],
717 vec![
718 Color::hsl(180.71191, 0.0, 0.3137255).into(),
719 Color::hsl(180.71191, 0.5, 0.3137255).into(),
720 Color::hsl(180.71191, 1.0, 0.3137255).into(),
721 ],
722 vec![
723 Color::hsl(180.71191, 0.825, 0.0).into(),
724 Color::hsl(180.71191, 0.825, 0.5).into(),
725 Color::hsl(180.71191, 0.825, 1.0).into(),
726 ],
727 vec![
728 Color::hsl(0.0 + 0.0001, 1.0, 0.5).into(),
729 Color::hsl(180.0, 1.0, 0.5).into(),
730 Color::hsl(360.0 - 0.0001, 1.0, 0.5).into(),
731 ],
732 vec![
733 Color::WHITE.into(),
734 RED.into(),
735 LIME.into(),
736 BLUE.into(),
737 Color::BLACK.into(),
738 ],
739 ] {
740 for color_space in [
741 InterpolationColorSpace::LinearRgba,
742 InterpolationColorSpace::Srgba,
743 InterpolationColorSpace::Oklaba,
744 InterpolationColorSpace::Oklcha,
745 InterpolationColorSpace::OklchaLong,
746 InterpolationColorSpace::Hsla,
747 InterpolationColorSpace::HslaLong,
748 InterpolationColorSpace::Hsva,
749 InterpolationColorSpace::HsvaLong,
750 ] {
751 let row = i % 18 + 1;
752 let column = i / 18 + 1;
753 i += 1;
754
755 commands.spawn((
756 Node {
757 grid_row: GridPlacement::start(row as i16 + 1),
758 grid_column: GridPlacement::start(column as i16 + 1),
759 justify_content: JustifyContent::SpaceEvenly,
760 ..Default::default()
761 },
762 children![(
763 Node {
764 height: bevy::ui::px(30),
765 width: bevy::ui::px(300),
766 justify_content: JustifyContent::Center,
767 ..Default::default()
768 },
769 BackgroundGradient::from(LinearGradient {
770 color_space,
771 angle: LinearGradient::TO_RIGHT,
772 stops: stops.clone(),
773 }),
774 children![
775 Node {
776 position_type: PositionType::Absolute,
777 ..default()
778 },
779 TextFont::from_font_size(10.),
780 bevy::ui::widget::Text(format!("{color_space:?}")),
781 ]
782 )],
783 ));
784 }
785 }
786 });
787 });
788 }
789}
790
791mod radial_gradient {
792 use bevy::color::palettes::css::RED;
793 use bevy::color::palettes::tailwind::GRAY_700;
794 use bevy::prelude::*;
795 use bevy::ui::ColorStop;
796
797 const CELL_SIZE: f32 = 80.;
798 const GAP: f32 = 10.;
799
800 pub fn setup(mut commands: Commands) {
801 let color_stops = vec![
802 ColorStop::new(Color::BLACK, px(5)),
803 ColorStop::new(Color::WHITE, px(5)),
804 ColorStop::new(Color::WHITE, percent(100)),
805 ColorStop::auto(RED),
806 ];
807
808 commands.spawn((Camera2d, DespawnOnExit(super::Scene::RadialGradient)));
809 commands
810 .spawn((
811 Node {
812 width: percent(100),
813 height: percent(100),
814 display: Display::Grid,
815 align_items: AlignItems::Start,
816 grid_template_columns: vec![RepeatedGridTrack::px(
817 GridTrackRepetition::AutoFill,
818 CELL_SIZE,
819 )],
820 grid_auto_flow: GridAutoFlow::Row,
821 row_gap: px(GAP),
822 column_gap: px(GAP),
823 padding: UiRect::all(px(GAP)),
824 ..default()
825 },
826 DespawnOnExit(super::Scene::RadialGradient),
827 ))
828 .with_children(|commands| {
829 for (shape, shape_label) in [
830 (RadialGradientShape::ClosestSide, "ClosestSide"),
831 (RadialGradientShape::FarthestSide, "FarthestSide"),
832 (RadialGradientShape::Circle(percent(55)), "Circle(55%)"),
833 (RadialGradientShape::FarthestCorner, "FarthestCorner"),
834 ] {
835 for (position, position_label) in [
836 (UiPosition::TOP_LEFT, "TOP_LEFT"),
837 (UiPosition::LEFT, "LEFT"),
838 (UiPosition::BOTTOM_LEFT, "BOTTOM_LEFT"),
839 (UiPosition::TOP, "TOP"),
840 (UiPosition::CENTER, "CENTER"),
841 (UiPosition::BOTTOM, "BOTTOM"),
842 (UiPosition::TOP_RIGHT, "TOP_RIGHT"),
843 (UiPosition::RIGHT, "RIGHT"),
844 (UiPosition::BOTTOM_RIGHT, "BOTTOM_RIGHT"),
845 ] {
846 for (w, h) in [(CELL_SIZE, CELL_SIZE), (CELL_SIZE, CELL_SIZE / 2.)] {
847 commands
848 .spawn((
849 BackgroundColor(GRAY_700.into()),
850 Node {
851 display: Display::Grid,
852 width: px(CELL_SIZE),
853 ..Default::default()
854 },
855 ))
856 .with_children(|commands| {
857 commands.spawn((
858 Node {
859 margin: UiRect::all(px(2)),
860 ..default()
861 },
862 Text(format!("{shape_label}\n{position_label}")),
863 TextFont::from_font_size(9.),
864 ));
865 commands.spawn((
866 Node {
867 width: px(w),
868 height: px(h),
869 ..default()
870 },
871 BackgroundGradient::from(RadialGradient {
872 stops: color_stops.clone(),
873 position,
874 shape,
875 ..default()
876 }),
877 ));
878 });
879 }
880 }
881 }
882 });
883 }examples/testbed/full_ui.rs (line 176)
31fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
32 // Camera
33 commands.spawn((Camera2d, IsDefaultUiCamera, BoxShadowSamples(6)));
34
35 // root node
36 commands
37 .spawn(Node {
38 width: percent(100),
39 height: percent(100),
40 justify_content: JustifyContent::SpaceBetween,
41 ..default()
42 })
43 .insert(Pickable::IGNORE)
44 .with_children(|parent| {
45 // left vertical fill (border)
46 parent
47 .spawn((
48 Node {
49 width: px(200),
50 border: UiRect::all(px(2)),
51 ..default()
52 },
53 BackgroundColor(Color::srgb(0.65, 0.65, 0.65)),
54 ))
55 .with_children(|parent| {
56 // left vertical fill (content)
57 parent
58 .spawn((
59 Node {
60 width: percent(100),
61 flex_direction: FlexDirection::Column,
62 padding: UiRect::all(px(5)),
63 row_gap: px(5),
64 ..default()
65 },
66 BackgroundColor(Color::srgb(0.15, 0.15, 0.15)),
67 Visibility::Visible,
68 ))
69 .with_children(|parent| {
70 // text
71 parent.spawn((
72 Text::new("Text Example"),
73 TextFont {
74 font: asset_server.load("fonts/FiraSans-Bold.ttf"),
75 font_size: 25.0,
76 ..default()
77 },
78 // Because this is a distinct label widget and
79 // not button/list item text, this is necessary
80 // for accessibility to treat the text accordingly.
81 Label,
82 ));
83
84 #[cfg(feature = "bevy_ui_debug")]
85 {
86 // Debug overlay text
87 parent.spawn((
88 Text::new("Press Space to toggle debug outlines."),
89 TextFont {
90 font: asset_server.load("fonts/FiraSans-Bold.ttf"),
91 ..default()
92 },
93 Label,
94 ));
95
96 parent.spawn((
97 Text::new("V: toggle UI root's visibility"),
98 TextFont {
99 font: asset_server.load("fonts/FiraSans-Bold.ttf"),
100 font_size: 12.,
101 ..default()
102 },
103 Label,
104 ));
105
106 parent.spawn((
107 Text::new("S: toggle outlines for hidden nodes"),
108 TextFont {
109 font: asset_server.load("fonts/FiraSans-Bold.ttf"),
110 font_size: 12.,
111 ..default()
112 },
113 Label,
114 ));
115 parent.spawn((
116 Text::new("C: toggle outlines for clipped nodes"),
117 TextFont {
118 font: asset_server.load("fonts/FiraSans-Bold.ttf"),
119 font_size: 12.,
120 ..default()
121 },
122 Label,
123 ));
124 }
125 #[cfg(not(feature = "bevy_ui_debug"))]
126 parent.spawn((
127 Text::new("Try enabling feature \"bevy_ui_debug\"."),
128 TextFont {
129 font: asset_server.load("fonts/FiraSans-Bold.ttf"),
130 ..default()
131 },
132 Label,
133 ));
134 });
135 });
136 // right vertical fill
137 parent
138 .spawn(Node {
139 flex_direction: FlexDirection::Column,
140 justify_content: JustifyContent::Center,
141 align_items: AlignItems::Center,
142 width: px(200),
143 ..default()
144 })
145 .with_children(|parent| {
146 // Title
147 parent.spawn((
148 Text::new("Scrolling list"),
149 TextFont {
150 font: asset_server.load("fonts/FiraSans-Bold.ttf"),
151 font_size: 21.,
152 ..default()
153 },
154 Label,
155 ));
156 // Scrolling list
157 parent
158 .spawn((
159 Node {
160 flex_direction: FlexDirection::Column,
161 align_self: AlignSelf::Stretch,
162 height: percent(50),
163 overflow: Overflow::scroll_y(),
164 ..default()
165 },
166 BackgroundColor(Color::srgb(0.10, 0.10, 0.10)),
167 ))
168 .with_children(|parent| {
169 parent
170 .spawn((
171 Node {
172 flex_direction: FlexDirection::Column,
173 ..Default::default()
174 },
175 BackgroundGradient::from(LinearGradient::to_bottom(vec![
176 ColorStop::auto(NAVY),
177 ColorStop::auto(Color::BLACK),
178 ])),
179 Pickable {
180 should_block_lower: false,
181 ..Default::default()
182 },
183 ))
184 .with_children(|parent| {
185 // List items
186 for i in 0..25 {
187 parent
188 .spawn((
189 Text(format!("Item {i}")),
190 TextFont {
191 font: asset_server
192 .load("fonts/FiraSans-Bold.ttf"),
193 ..default()
194 },
195 Label,
196 AccessibilityNode(Accessible::new(Role::ListItem)),
197 ))
198 .insert(Pickable {
199 should_block_lower: false,
200 ..default()
201 });
202 }
203 });
204 });
205 });
206
207 parent
208 .spawn(Node {
209 left: px(210),
210 bottom: px(10),
211 position_type: PositionType::Absolute,
212 ..default()
213 })
214 .with_children(|parent| {
215 parent
216 .spawn((
217 Node {
218 width: px(200),
219 height: px(200),
220 border: UiRect::all(px(20)),
221 flex_direction: FlexDirection::Column,
222 justify_content: JustifyContent::Center,
223 ..default()
224 },
225 BorderColor::all(LIME),
226 BackgroundColor(Color::srgb(0.8, 0.8, 1.)),
227 ))
228 .with_children(|parent| {
229 parent.spawn((
230 ImageNode::new(asset_server.load("branding/bevy_logo_light.png")),
231 // Uses the transform to rotate the logo image by 45 degrees
232 Node {
233 ..Default::default()
234 },
235 UiTransform {
236 rotation: Rot2::radians(0.25 * PI),
237 ..Default::default()
238 },
239 BorderRadius::all(px(10)),
240 Outline {
241 width: px(2),
242 offset: px(4),
243 color: DARK_GRAY.into(),
244 },
245 ));
246 });
247 });
248
249 let shadow_style = ShadowStyle {
250 color: Color::BLACK.with_alpha(0.5),
251 blur_radius: px(2),
252 x_offset: px(10),
253 y_offset: px(10),
254 ..default()
255 };
256
257 // render order test: reddest in the back, whitest in the front (flex center)
258 parent
259 .spawn(Node {
260 width: percent(100),
261 height: percent(100),
262 position_type: PositionType::Absolute,
263 align_items: AlignItems::Center,
264 justify_content: JustifyContent::Center,
265 ..default()
266 })
267 .insert(Pickable::IGNORE)
268 .with_children(|parent| {
269 parent
270 .spawn((
271 Node {
272 width: px(100),
273 height: px(100),
274 ..default()
275 },
276 BackgroundColor(Color::srgb(1.0, 0.0, 0.)),
277 BoxShadow::from(shadow_style),
278 ))
279 .with_children(|parent| {
280 parent.spawn((
281 Node {
282 // Take the size of the parent node.
283 width: percent(100),
284 height: percent(100),
285 position_type: PositionType::Absolute,
286 left: px(20),
287 bottom: px(20),
288 ..default()
289 },
290 BackgroundColor(Color::srgb(1.0, 0.3, 0.3)),
291 BoxShadow::from(shadow_style),
292 ));
293 parent.spawn((
294 Node {
295 width: percent(100),
296 height: percent(100),
297 position_type: PositionType::Absolute,
298 left: px(40),
299 bottom: px(40),
300 ..default()
301 },
302 BackgroundColor(Color::srgb(1.0, 0.5, 0.5)),
303 BoxShadow::from(shadow_style),
304 ));
305 parent.spawn((
306 Node {
307 width: percent(100),
308 height: percent(100),
309 position_type: PositionType::Absolute,
310 left: px(60),
311 bottom: px(60),
312 ..default()
313 },
314 BackgroundColor(Color::srgb(0.0, 0.7, 0.7)),
315 BoxShadow::from(shadow_style),
316 ));
317 // alpha test
318 parent.spawn((
319 Node {
320 width: percent(100),
321 height: percent(100),
322 position_type: PositionType::Absolute,
323 left: px(80),
324 bottom: px(80),
325 ..default()
326 },
327 BackgroundColor(Color::srgba(1.0, 0.9, 0.9, 0.4)),
328 BoxShadow::from(ShadowStyle {
329 color: Color::BLACK.with_alpha(0.3),
330 ..shadow_style
331 }),
332 ));
333 });
334 });
335 // bevy logo (flex center)
336 parent
337 .spawn(Node {
338 width: percent(100),
339 position_type: PositionType::Absolute,
340 justify_content: JustifyContent::Center,
341 align_items: AlignItems::FlexStart,
342 ..default()
343 })
344 .with_children(|parent| {
345 // bevy logo (image)
346 parent
347 .spawn((
348 ImageNode::new(asset_server.load("branding/bevy_logo_dark_big.png"))
349 .with_mode(NodeImageMode::Stretch),
350 Node {
351 width: px(500),
352 height: px(125),
353 margin: UiRect::top(vmin(5)),
354 ..default()
355 },
356 ))
357 .with_children(|parent| {
358 // alt text
359 // This UI node takes up no space in the layout and the `Text` component is used by the accessibility module
360 // and is not rendered.
361 parent.spawn((
362 Node {
363 display: Display::None,
364 ..default()
365 },
366 Text::new("Bevy logo"),
367 ));
368 });
369 });
370
371 // four bevy icons demonstrating image flipping
372 parent
373 .spawn(Node {
374 width: percent(100),
375 height: percent(100),
376 position_type: PositionType::Absolute,
377 justify_content: JustifyContent::Center,
378 align_items: AlignItems::FlexEnd,
379 column_gap: px(10),
380 padding: UiRect::all(px(10)),
381 ..default()
382 })
383 .insert(Pickable::IGNORE)
384 .with_children(|parent| {
385 for (flip_x, flip_y) in
386 [(false, false), (false, true), (true, true), (true, false)]
387 {
388 parent.spawn((
389 ImageNode {
390 image: asset_server.load("branding/icon.png"),
391 flip_x,
392 flip_y,
393 ..default()
394 },
395 Node {
396 // The height will be chosen automatically to preserve the image's aspect ratio
397 width: px(75),
398 ..default()
399 },
400 ));
401 }
402 });
403 });
404}Sourcepub fn px(color: impl Into<Color>, px: f32) -> ColorStop
pub fn px(color: impl Into<Color>, px: f32) -> ColorStop
A color stop with its position in logical pixels.
Sourcepub fn percent(color: impl Into<Color>, percent: f32) -> ColorStop
pub fn percent(color: impl Into<Color>, percent: f32) -> ColorStop
A color stop with a percentage position.
pub const fn with_hint(self, hint: f32) -> ColorStop
Trait Implementations§
Source§impl<'de> Deserialize<'de> for ColorStop
impl<'de> Deserialize<'de> for ColorStop
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<ColorStop, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<ColorStop, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl FromReflect for ColorStop
impl FromReflect for ColorStop
Source§fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<ColorStop>
fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<ColorStop>
Constructs a concrete instance of
Self from a reflected value.Source§fn take_from_reflect(
reflect: Box<dyn PartialReflect>,
) -> Result<Self, Box<dyn PartialReflect>>
fn take_from_reflect( reflect: Box<dyn PartialReflect>, ) -> Result<Self, Box<dyn PartialReflect>>
Attempts to downcast the given value to
Self using,
constructing the value using from_reflect if that fails. Read moreSource§impl GetOwnership for ColorStop
impl GetOwnership for ColorStop
Source§impl GetTypeRegistration for ColorStop
impl GetTypeRegistration for ColorStop
Source§fn get_type_registration() -> TypeRegistration
fn get_type_registration() -> TypeRegistration
Returns the default
TypeRegistration for this type.Source§fn register_type_dependencies(registry: &mut TypeRegistry)
fn register_type_dependencies(registry: &mut TypeRegistry)
Registers other types needed by this type. Read more
Source§impl IntoReturn for ColorStop
impl IntoReturn for ColorStop
Source§impl PartialReflect for ColorStop
impl PartialReflect for ColorStop
Source§fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
Source§fn try_apply(
&mut self,
value: &(dyn PartialReflect + 'static),
) -> Result<(), ApplyError>
fn try_apply( &mut self, value: &(dyn PartialReflect + 'static), ) -> Result<(), ApplyError>
Source§fn reflect_kind(&self) -> ReflectKind
fn reflect_kind(&self) -> ReflectKind
Returns a zero-sized enumeration of “kinds” of type. Read more
Source§fn reflect_ref(&self) -> ReflectRef<'_>
fn reflect_ref(&self) -> ReflectRef<'_>
Returns an immutable enumeration of “kinds” of type. Read more
Source§fn reflect_mut(&mut self) -> ReflectMut<'_>
fn reflect_mut(&mut self) -> ReflectMut<'_>
Returns a mutable enumeration of “kinds” of type. Read more
Source§fn reflect_owned(self: Box<ColorStop>) -> ReflectOwned
fn reflect_owned(self: Box<ColorStop>) -> ReflectOwned
Returns an owned enumeration of “kinds” of type. Read more
Source§fn try_into_reflect(
self: Box<ColorStop>,
) -> Result<Box<dyn Reflect>, Box<dyn PartialReflect>>
fn try_into_reflect( self: Box<ColorStop>, ) -> Result<Box<dyn Reflect>, Box<dyn PartialReflect>>
Attempts to cast this type to a boxed, fully-reflected value.
Source§fn try_as_reflect(&self) -> Option<&(dyn Reflect + 'static)>
fn try_as_reflect(&self) -> Option<&(dyn Reflect + 'static)>
Attempts to cast this type to a fully-reflected value.
Source§fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + 'static)>
fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + 'static)>
Attempts to cast this type to a mutable, fully-reflected value.
Source§fn into_partial_reflect(self: Box<ColorStop>) -> Box<dyn PartialReflect>
fn into_partial_reflect(self: Box<ColorStop>) -> Box<dyn PartialReflect>
Casts this type to a boxed, reflected value. Read more
Source§fn as_partial_reflect(&self) -> &(dyn PartialReflect + 'static)
fn as_partial_reflect(&self) -> &(dyn PartialReflect + 'static)
Casts this type to a reflected value. Read more
Source§fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + 'static)
fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + 'static)
Casts this type to a mutable, reflected value. Read more
Source§fn reflect_partial_eq(
&self,
value: &(dyn PartialReflect + 'static),
) -> Option<bool>
fn reflect_partial_eq( &self, value: &(dyn PartialReflect + 'static), ) -> Option<bool>
Returns a “partial equality” comparison result. Read more
Source§fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
Debug formatter for the value. Read more
Source§fn reflect_clone(&self) -> Result<Box<dyn Reflect>, ReflectCloneError>
fn reflect_clone(&self) -> Result<Box<dyn Reflect>, ReflectCloneError>
Attempts to clone
Self using reflection. Read moreSource§fn apply(&mut self, value: &(dyn PartialReflect + 'static))
fn apply(&mut self, value: &(dyn PartialReflect + 'static))
Applies a reflected value to this value. Read more
Source§fn to_dynamic(&self) -> Box<dyn PartialReflect>
fn to_dynamic(&self) -> Box<dyn PartialReflect>
Source§fn reflect_clone_and_take<T>(&self) -> Result<T, ReflectCloneError>
fn reflect_clone_and_take<T>(&self) -> Result<T, ReflectCloneError>
For a type implementing
PartialReflect, combines reflect_clone and
take in a useful fashion, automatically constructing an appropriate
ReflectCloneError if the downcast fails. Read moreSource§fn reflect_hash(&self) -> Option<u64>
fn reflect_hash(&self) -> Option<u64>
Returns a hash of the value (which includes the type). Read more
Source§fn is_dynamic(&self) -> bool
fn is_dynamic(&self) -> bool
Indicates whether or not this type is a dynamic type. Read more
Source§impl Reflect for ColorStop
impl Reflect for ColorStop
Source§fn into_any(self: Box<ColorStop>) -> Box<dyn Any>
fn into_any(self: Box<ColorStop>) -> Box<dyn Any>
Returns the value as a
Box<dyn Any>. Read moreSource§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Returns the value as a
&mut dyn Any. Read moreSource§fn into_reflect(self: Box<ColorStop>) -> Box<dyn Reflect>
fn into_reflect(self: Box<ColorStop>) -> Box<dyn Reflect>
Casts this type to a boxed, fully-reflected value.
Source§fn as_reflect(&self) -> &(dyn Reflect + 'static)
fn as_reflect(&self) -> &(dyn Reflect + 'static)
Casts this type to a fully-reflected value.
Source§fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)
fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)
Casts this type to a mutable, fully-reflected value.
Source§impl Serialize for ColorStop
impl Serialize for ColorStop
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
Source§impl Struct for ColorStop
impl Struct for ColorStop
Source§fn field(&self, name: &str) -> Option<&(dyn PartialReflect + 'static)>
fn field(&self, name: &str) -> Option<&(dyn PartialReflect + 'static)>
Returns a reference to the value of the field named
name as a &dyn PartialReflect.Source§fn field_mut(
&mut self,
name: &str,
) -> Option<&mut (dyn PartialReflect + 'static)>
fn field_mut( &mut self, name: &str, ) -> Option<&mut (dyn PartialReflect + 'static)>
Returns a mutable reference to the value of the field named
name as a
&mut dyn PartialReflect.Source§fn field_at(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>
fn field_at(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>
Returns a reference to the value of the field with index
index as a
&dyn PartialReflect.Source§fn field_at_mut(
&mut self,
index: usize,
) -> Option<&mut (dyn PartialReflect + 'static)>
fn field_at_mut( &mut self, index: usize, ) -> Option<&mut (dyn PartialReflect + 'static)>
Returns a mutable reference to the value of the field with index
index
as a &mut dyn PartialReflect.Source§fn name_at(&self, index: usize) -> Option<&str>
fn name_at(&self, index: usize) -> Option<&str>
Returns the name of the field with index
index.Source§fn iter_fields(&self) -> FieldIter<'_> ⓘ
fn iter_fields(&self) -> FieldIter<'_> ⓘ
Returns an iterator over the values of the reflectable fields for this struct.
Source§fn to_dynamic_struct(&self) -> DynamicStruct
fn to_dynamic_struct(&self) -> DynamicStruct
Creates a new
DynamicStruct from this struct.Source§fn get_represented_struct_info(&self) -> Option<&'static StructInfo>
fn get_represented_struct_info(&self) -> Option<&'static StructInfo>
Will return
None if TypeInfo is not available.Source§impl TypePath for ColorStop
impl TypePath for ColorStop
Source§fn type_path() -> &'static str
fn type_path() -> &'static str
Returns the fully qualified path of the underlying type. Read more
Source§fn short_type_path() -> &'static str
fn short_type_path() -> &'static str
Returns a short, pretty-print enabled path to the type. Read more
Source§fn type_ident() -> Option<&'static str>
fn type_ident() -> Option<&'static str>
Source§fn crate_name() -> Option<&'static str>
fn crate_name() -> Option<&'static str>
impl Copy for ColorStop
impl StructuralPartialEq for ColorStop
Auto Trait Implementations§
impl Freeze for ColorStop
impl RefUnwindSafe for ColorStop
impl Send for ColorStop
impl Sync for ColorStop
impl Unpin for ColorStop
impl UnwindSafe for ColorStop
Blanket Implementations§
Source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
Source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
Return the
T ShaderType for self. When used in AsBindGroup
derives, it is safe to assume that all images in self exist.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Converts
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Converts
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Converts
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Converts
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> DynamicTypePath for Twhere
T: TypePath,
impl<T> DynamicTypePath for Twhere
T: TypePath,
Source§fn reflect_type_path(&self) -> &str
fn reflect_type_path(&self) -> &str
See
TypePath::type_path.Source§fn reflect_short_type_path(&self) -> &str
fn reflect_short_type_path(&self) -> &str
Source§fn reflect_type_ident(&self) -> Option<&str>
fn reflect_type_ident(&self) -> Option<&str>
See
TypePath::type_ident.Source§fn reflect_crate_name(&self) -> Option<&str>
fn reflect_crate_name(&self) -> Option<&str>
See
TypePath::crate_name.Source§fn reflect_module_path(&self) -> Option<&str>
fn reflect_module_path(&self) -> Option<&str>
Source§impl<T> DynamicTyped for Twhere
T: Typed,
impl<T> DynamicTyped for Twhere
T: Typed,
Source§fn reflect_type_info(&self) -> &'static TypeInfo
fn reflect_type_info(&self) -> &'static TypeInfo
See
Typed::type_info.Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
Causes
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
Causes
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
Causes
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
Causes
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
Causes
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
Causes
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
Causes
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
Causes
self to use its UpperHex implementation when
Debug-formatted.Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
Source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self using default().
Source§impl<S> GetField for Swhere
S: Struct,
impl<S> GetField for Swhere
S: Struct,
Source§impl<T> GetPath for T
impl<T> GetPath for T
Source§fn reflect_path<'p>(
&self,
path: impl ReflectPath<'p>,
) -> Result<&(dyn PartialReflect + 'static), ReflectPathError<'p>>
fn reflect_path<'p>( &self, path: impl ReflectPath<'p>, ) -> Result<&(dyn PartialReflect + 'static), ReflectPathError<'p>>
Returns a reference to the value specified by
path. Read moreSource§fn reflect_path_mut<'p>(
&mut self,
path: impl ReflectPath<'p>,
) -> Result<&mut (dyn PartialReflect + 'static), ReflectPathError<'p>>
fn reflect_path_mut<'p>( &mut self, path: impl ReflectPath<'p>, ) -> Result<&mut (dyn PartialReflect + 'static), ReflectPathError<'p>>
Returns a mutable reference to the value specified by
path. Read moreSource§fn path<'p, T>(
&self,
path: impl ReflectPath<'p>,
) -> Result<&T, ReflectPathError<'p>>where
T: Reflect,
fn path<'p, T>(
&self,
path: impl ReflectPath<'p>,
) -> Result<&T, ReflectPathError<'p>>where
T: Reflect,
Returns a statically typed reference to the value specified by
path. Read moreSource§fn path_mut<'p, T>(
&mut self,
path: impl ReflectPath<'p>,
) -> Result<&mut T, ReflectPathError<'p>>where
T: Reflect,
fn path_mut<'p, T>(
&mut self,
path: impl ReflectPath<'p>,
) -> Result<&mut T, ReflectPathError<'p>>where
T: Reflect,
Returns a statically typed mutable reference to the value specified by
path. Read moreSource§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> InitializeFromFunction<T> for T
impl<T> InitializeFromFunction<T> for T
Source§fn initialize_from_function(f: fn() -> T) -> T
fn initialize_from_function(f: fn() -> T) -> T
Create an instance of this type from an initialization function
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
Source§fn into_result(self) -> Result<T, RunSystemError>
fn into_result(self) -> Result<T, RunSystemError>
Converts this type into the system output type.
Source§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Pipes by value. This is generally the method you want to use. Read more
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
Borrows
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
Mutably borrows
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
Borrows
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
Mutably borrows
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
Borrows
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian().Source§impl<T> Serialize for T
impl<T> Serialize for T
fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>
fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>
Source§impl<Ret> SpawnIfAsync<(), Ret> for Ret
impl<Ret> SpawnIfAsync<(), Ret> for Ret
Source§impl<T, O> SuperFrom<T> for Owhere
O: From<T>,
impl<T, O> SuperFrom<T> for Owhere
O: From<T>,
Source§fn super_from(input: T) -> O
fn super_from(input: T) -> O
Convert from a type to another type.
Source§impl<T, O, M> SuperInto<O, M> for Twhere
O: SuperFrom<T, M>,
impl<T, O, M> SuperInto<O, M> for Twhere
O: SuperFrom<T, M>,
Source§fn super_into(self) -> O
fn super_into(self) -> O
Convert from a type to another type.
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Immutable access to the
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
Mutable access to the
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
Immutable access to the
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
Mutable access to the
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Immutable access to the
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Mutable access to the
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
Calls
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
Calls
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
Calls
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
Calls
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
Calls
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
Calls
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
Calls
.tap_deref() only in debug builds, and is erased in release
builds.Source§impl<T, U> ToSample<U> for Twhere
U: FromSample<T>,
impl<T, U> ToSample<U> for Twhere
U: FromSample<T>,
fn to_sample_(self) -> U
Source§impl<T> TypeData for T
impl<T> TypeData for T
Source§fn clone_type_data(&self) -> Box<dyn TypeData>
fn clone_type_data(&self) -> Box<dyn TypeData>
Creates a type-erased clone of this value.