pub struct BorderColor {
pub top: Color,
pub right: Color,
pub bottom: Color,
pub left: Color,
}Expand description
The border color of the UI node.
Fields§
§top: Color§right: Color§bottom: Color§left: ColorImplementations§
Source§impl BorderColor
impl BorderColor
Sourcepub const DEFAULT: BorderColor
pub const DEFAULT: BorderColor
Border color is transparent by default.
Sourcepub fn all(color: impl Into<Color>) -> BorderColor
pub fn all(color: impl Into<Color>) -> BorderColor
Helper to create a BorderColor struct with all borders set to the given color
Examples found in repository?
examples/ui/navigation/directional_navigation.rs (line 432)
425fn highlight_focused_element(
426 input_focus: Res<InputFocus>,
427 input_focus_visible: Res<InputFocusVisible>,
428 mut query: Query<(Entity, &mut BorderColor)>,
429) {
430 for (entity, mut border_color) in query.iter_mut() {
431 if input_focus.get() == Some(entity) && input_focus_visible.0 {
432 *border_color = BorderColor::all(FOCUSED_BORDER);
433 } else {
434 *border_color = BorderColor::DEFAULT;
435 }
436 }
437}More examples
examples/ui/navigation/directional_navigation_overrides.rs (line 825)
818fn highlight_focused_element(
819 input_focus: Res<InputFocus>,
820 input_focus_visible: Res<InputFocusVisible>,
821 mut query: Query<(Entity, &mut BorderColor, &Page)>,
822) {
823 for (entity, mut border_color, page) in query.iter_mut() {
824 if input_focus.get() == Some(entity) && input_focus_visible.0 {
825 *border_color = BorderColor::all(FOCUSED_BORDER_COLORS[page.0]);
826 } else {
827 *border_color = BorderColor::DEFAULT;
828 }
829 }
830}examples/ui/layout/ghost_nodes.rs (line 86)
72fn create_button() -> impl Bundle {
73 (
74 Button,
75 Node {
76 width: px(150),
77 height: px(65),
78 border: UiRect::all(px(5)),
79 // horizontally center child text
80 justify_content: JustifyContent::Center,
81 // vertically center child text
82 align_items: AlignItems::Center,
83 border_radius: BorderRadius::MAX,
84 ..default()
85 },
86 BorderColor::all(Color::BLACK),
87 BackgroundColor(Color::srgb(0.15, 0.15, 0.15)),
88 )
89}examples/3d/split_screen.rs (line 139)
127 fn rotate_button(caption: &str, direction: Direction) -> impl Bundle {
128 (
129 RotateCamera(direction),
130 Button,
131 Node {
132 width: px(40),
133 height: px(40),
134 border: UiRect::all(px(2)),
135 justify_content: JustifyContent::Center,
136 align_items: AlignItems::Center,
137 ..default()
138 },
139 BorderColor::all(Color::WHITE),
140 BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
141 children![Text::new(caption)],
142 )
143 }examples/ui/widgets/tab_navigation.rs (line 34)
24fn button_system(
25 mut interaction_query: Query<
26 (&Interaction, &mut BackgroundColor, &mut BorderColor),
27 (Changed<Interaction>, With<Button>),
28 >,
29) {
30 for (interaction, mut color, mut border_color) in &mut interaction_query {
31 match *interaction {
32 Interaction::Pressed => {
33 *color = PRESSED_BUTTON.into();
34 *border_color = BorderColor::all(RED);
35 }
36 Interaction::Hovered => {
37 *color = HOVERED_BUTTON.into();
38 *border_color = BorderColor::all(Color::WHITE);
39 }
40 Interaction::None => {
41 *color = NORMAL_BUTTON.into();
42 *border_color = BorderColor::all(Color::BLACK);
43 }
44 }
45 }
46}
47
48fn focus_system(
49 mut commands: Commands,
50 focus: Res<InputFocus>,
51 mut query: Query<Entity, With<Button>>,
52) {
53 if focus.is_changed() {
54 for button in query.iter_mut() {
55 if focus.get() == Some(button) {
56 commands.entity(button).insert(Outline {
57 color: Color::WHITE,
58 width: px(2),
59 offset: px(2),
60 });
61 } else {
62 commands.entity(button).remove::<Outline>();
63 }
64 }
65 }
66}
67
68fn setup(mut commands: Commands) {
69 // ui camera
70 commands.spawn(Camera2d);
71 commands
72 .spawn(Node {
73 width: percent(100),
74 height: percent(100),
75 display: Display::Flex,
76 flex_direction: FlexDirection::Column,
77 align_items: AlignItems::Center,
78 justify_content: JustifyContent::Center,
79 row_gap: px(6),
80 ..default()
81 })
82 .observe(
83 |mut event: On<Pointer<Click>>, mut focus: ResMut<InputFocus>| {
84 focus.clear();
85 event.propagate(false);
86 },
87 )
88 .with_children(|parent| {
89 for (label, tab_group, indices) in [
90 // In this group all the buttons have the same `TabIndex` so they will be visited according to their order as children.
91 ("TabGroup 0", TabGroup::new(0), [0, 0, 0, 0]),
92 // In this group the `TabIndex`s are reversed so the buttons will be visited in right-to-left order.
93 ("TabGroup 2", TabGroup::new(2), [3, 2, 1, 0]),
94 // In this group the orders of the indices and buttons match so the buttons will be visited in left-to-right order.
95 ("TabGroup 1", TabGroup::new(1), [0, 1, 2, 3]),
96 // Visit the modal group's buttons in an arbitrary order.
97 ("Modal TabGroup", TabGroup::modal(), [0, 3, 1, 2]),
98 ] {
99 parent.spawn(Text::new(label));
100 parent
101 .spawn((
102 Node {
103 display: Display::Flex,
104 flex_direction: FlexDirection::Row,
105 column_gap: px(6),
106 margin: UiRect {
107 bottom: px(10),
108 ..default()
109 },
110 ..default()
111 },
112 tab_group,
113 ))
114 .with_children(|parent| {
115 for i in indices {
116 parent
117 .spawn((
118 Button,
119 Node {
120 width: px(200),
121 height: px(65),
122 border: UiRect::all(px(5)),
123 justify_content: JustifyContent::Center,
124 align_items: AlignItems::Center,
125 ..default()
126 },
127 BorderColor::all(Color::BLACK),
128 BackgroundColor(NORMAL_BUTTON),
129 TabIndex(i),
130 children![(
131 Text::new(format!("TabIndex {i}")),
132 TextFont {
133 font_size: FontSize::Px(20.0),
134 ..default()
135 },
136 TextColor(Color::srgb(0.9, 0.9, 0.9)),
137 )],
138 ))
139 .observe(
140 |mut click: On<Pointer<Click>>,
141 mut focus: ResMut<InputFocus>| {
142 focus.set(click.entity, FocusCause::Pressed);
143 click.propagate(false);
144 },
145 );
146 }
147 });
148 }
149 });
150}examples/ui/widgets/standard_widgets.rs (line 207)
192fn button(asset_server: &AssetServer) -> impl Bundle {
193 (
194 Node {
195 width: px(150),
196 height: px(65),
197 border: UiRect::all(px(5)),
198 border_radius: BorderRadius::MAX,
199 justify_content: JustifyContent::Center,
200 align_items: AlignItems::Center,
201 ..default()
202 },
203 DemoButton,
204 Button,
205 Hovered::default(),
206 TabIndex(0),
207 BorderColor::all(Color::BLACK),
208 BackgroundColor(NORMAL_BUTTON),
209 children![(
210 Text::new("Button"),
211 TextFont {
212 font: asset_server.load("fonts/FiraSans-Bold.ttf").into(),
213 font_size: FontSize::Px(33.0),
214 ..default()
215 },
216 TextColor(Color::srgb(0.9, 0.9, 0.9)),
217 TextShadow::default(),
218 )],
219 )
220}
221
222fn menu_button(asset_server: &AssetServer) -> impl Bundle {
223 (
224 Node { ..default() },
225 DemoMenuAnchor,
226 observe(on_menu_event),
227 children![(
228 Node {
229 width: px(200),
230 height: px(65),
231 border: UiRect::all(px(5)),
232 box_sizing: BoxSizing::BorderBox,
233 justify_content: JustifyContent::SpaceBetween,
234 align_items: AlignItems::Center,
235 padding: UiRect::axes(px(16), px(0)),
236 border_radius: BorderRadius::all(px(5)),
237 ..default()
238 },
239 DemoMenuButton,
240 Button,
241 MenuButton,
242 Hovered::default(),
243 TabIndex(0),
244 BorderColor::all(Color::BLACK),
245 BackgroundColor(NORMAL_BUTTON),
246 children![
247 (
248 Text::new("Menu"),
249 TextFont {
250 font: asset_server.load("fonts/FiraSans-Bold.ttf").into(),
251 font_size: FontSize::Px(33.0),
252 ..default()
253 },
254 TextColor(Color::srgb(0.9, 0.9, 0.9)),
255 TextShadow::default(),
256 ),
257 (
258 Node {
259 width: px(12),
260 height: px(12),
261 ..default()
262 },
263 BackgroundColor(GRAY.into()),
264 )
265 ],
266 )],
267 )
268}
269
270fn update_button_style(
271 mut buttons: Query<
272 (
273 Has<Pressed>,
274 &Hovered,
275 Has<InteractionDisabled>,
276 &mut BackgroundColor,
277 &mut BorderColor,
278 &Children,
279 ),
280 (
281 Or<(
282 Changed<Pressed>,
283 Changed<Hovered>,
284 Added<InteractionDisabled>,
285 )>,
286 With<DemoButton>,
287 ),
288 >,
289 mut text_query: Query<&mut Text>,
290) {
291 for (pressed, hovered, disabled, mut color, mut border_color, children) in &mut buttons {
292 let mut text = text_query.get_mut(children[0]).unwrap();
293 set_button_style(
294 disabled,
295 hovered.get(),
296 pressed,
297 &mut color,
298 &mut border_color,
299 &mut text,
300 );
301 }
302}
303
304/// Supplementary system to detect removed marker components
305fn update_button_style2(
306 mut buttons: Query<
307 (
308 Has<Pressed>,
309 &Hovered,
310 Has<InteractionDisabled>,
311 &mut BackgroundColor,
312 &mut BorderColor,
313 &Children,
314 ),
315 With<DemoButton>,
316 >,
317 mut removed_depressed: RemovedComponents<Pressed>,
318 mut removed_disabled: RemovedComponents<InteractionDisabled>,
319 mut text_query: Query<&mut Text>,
320) {
321 removed_depressed
322 .read()
323 .chain(removed_disabled.read())
324 .for_each(|entity| {
325 if let Ok((pressed, hovered, disabled, mut color, mut border_color, children)) =
326 buttons.get_mut(entity)
327 {
328 let mut text = text_query.get_mut(children[0]).unwrap();
329 set_button_style(
330 disabled,
331 hovered.get(),
332 pressed,
333 &mut color,
334 &mut border_color,
335 &mut text,
336 );
337 }
338 });
339}
340
341fn set_button_style(
342 disabled: bool,
343 hovered: bool,
344 pressed: bool,
345 color: &mut BackgroundColor,
346 border_color: &mut BorderColor,
347 text: &mut Text,
348) {
349 match (disabled, hovered, pressed) {
350 // Disabled button
351 (true, _, _) => {
352 **text = "Disabled".to_string();
353 *color = NORMAL_BUTTON.into();
354 border_color.set_all(GRAY);
355 }
356
357 // Pressed and hovered button
358 (false, true, true) => {
359 **text = "Press".to_string();
360 *color = PRESSED_BUTTON.into();
361 border_color.set_all(RED);
362 }
363
364 // Hovered, unpressed button
365 (false, true, false) => {
366 **text = "Hover".to_string();
367 *color = HOVERED_BUTTON.into();
368 border_color.set_all(WHITE);
369 }
370
371 // Unhovered button (either pressed or not).
372 (false, false, _) => {
373 **text = "Button".to_string();
374 *color = NORMAL_BUTTON.into();
375 border_color.set_all(BLACK);
376 }
377 }
378}
379
380/// Create a demo slider
381fn slider(min: f32, max: f32, value: f32) -> impl Bundle {
382 (
383 Node {
384 display: Display::Flex,
385 flex_direction: FlexDirection::Column,
386 justify_content: JustifyContent::Center,
387 align_items: AlignItems::Stretch,
388 justify_items: JustifyItems::Center,
389 column_gap: px(4),
390 height: px(12),
391 width: percent(30),
392 ..default()
393 },
394 Name::new("Slider"),
395 Hovered::default(),
396 DemoSlider,
397 Slider {
398 track_click: TrackClick::Snap,
399 ..Default::default()
400 },
401 SliderValue(value),
402 SliderRange::new(min, max),
403 TabIndex(0),
404 Children::spawn((
405 // Slider background rail
406 Spawn((
407 Node {
408 height: px(6),
409 border_radius: BorderRadius::all(px(3)),
410 ..default()
411 },
412 BackgroundColor(SLIDER_TRACK), // Border color for the slider
413 )),
414 // Invisible track to allow absolute placement of thumb entity. This is narrower than
415 // the actual slider, which allows us to position the thumb entity using simple
416 // percentages, without having to measure the actual width of the slider thumb.
417 Spawn((
418 Node {
419 display: Display::Flex,
420 position_type: PositionType::Absolute,
421 left: px(0),
422 // Track is short by 12px to accommodate the thumb.
423 right: px(12),
424 top: px(0),
425 bottom: px(0),
426 ..default()
427 },
428 children![(
429 // Thumb
430 DemoSliderThumb,
431 SliderThumb,
432 Node {
433 display: Display::Flex,
434 width: px(12),
435 height: px(12),
436 position_type: PositionType::Absolute,
437 left: percent(0), // This will be updated by the slider's value
438 border_radius: BorderRadius::MAX,
439 ..default()
440 },
441 BackgroundColor(SLIDER_THUMB),
442 )],
443 )),
444 )),
445 )
446}
447
448/// Update the visuals of the slider based on the slider state.
449fn update_slider_style(
450 sliders: Query<
451 (
452 Entity,
453 &SliderValue,
454 &SliderRange,
455 &Hovered,
456 &SliderDragState,
457 Has<InteractionDisabled>,
458 ),
459 (
460 Or<(
461 Changed<SliderValue>,
462 Changed<SliderRange>,
463 Changed<Hovered>,
464 Changed<SliderDragState>,
465 Added<InteractionDisabled>,
466 )>,
467 With<DemoSlider>,
468 ),
469 >,
470 children: Query<&Children>,
471 mut thumbs: Query<(&mut Node, &mut BackgroundColor, Has<DemoSliderThumb>), Without<DemoSlider>>,
472) {
473 for (slider_ent, value, range, hovered, drag_state, disabled) in sliders.iter() {
474 for child in children.iter_descendants(slider_ent) {
475 if let Ok((mut thumb_node, mut thumb_bg, is_thumb)) = thumbs.get_mut(child)
476 && is_thumb
477 {
478 thumb_node.left = percent(range.thumb_position(value.0) * 100.0);
479 thumb_bg.0 = thumb_color(disabled, hovered.0 | drag_state.dragging);
480 }
481 }
482 }
483}
484
485fn update_slider_style2(
486 sliders: Query<
487 (Entity, &Hovered, &SliderDragState, Has<InteractionDisabled>),
488 With<DemoSlider>,
489 >,
490 children: Query<&Children>,
491 mut thumbs: Query<(&mut BackgroundColor, Has<DemoSliderThumb>), Without<DemoSlider>>,
492 mut removed_disabled: RemovedComponents<InteractionDisabled>,
493) {
494 removed_disabled.read().for_each(|entity| {
495 if let Ok((slider_ent, hovered, drag_state, disabled)) = sliders.get(entity) {
496 for child in children.iter_descendants(slider_ent) {
497 if let Ok((mut thumb_bg, is_thumb)) = thumbs.get_mut(child)
498 && is_thumb
499 {
500 thumb_bg.0 = thumb_color(disabled, hovered.0 | drag_state.dragging);
501 }
502 }
503 }
504 });
505}
506
507fn thumb_color(disabled: bool, hovered: bool) -> Color {
508 match (disabled, hovered) {
509 (true, _) => ELEMENT_FILL_DISABLED,
510
511 (false, true) => SLIDER_THUMB.lighter(0.3),
512
513 _ => SLIDER_THUMB,
514 }
515}
516
517/// Create a demo checkbox
518fn checkbox(asset_server: &AssetServer, caption: &str) -> impl Bundle {
519 (
520 Node {
521 display: Display::Flex,
522 flex_direction: FlexDirection::Row,
523 justify_content: JustifyContent::FlexStart,
524 align_items: AlignItems::Center,
525 align_content: AlignContent::Center,
526 column_gap: px(4),
527 ..default()
528 },
529 Name::new("Checkbox"),
530 Hovered::default(),
531 DemoCheckbox,
532 Checkbox,
533 TabIndex(0),
534 Children::spawn((
535 Spawn((
536 // Checkbox outer
537 Node {
538 display: Display::Flex,
539 width: px(16),
540 height: px(16),
541 border: UiRect::all(px(2)),
542 border_radius: BorderRadius::all(px(3)),
543 ..default()
544 },
545 BorderColor::all(ELEMENT_OUTLINE), // Border color for the checkbox
546 children![
547 // Checkbox inner
548 (
549 Node {
550 display: Display::Flex,
551 width: px(8),
552 height: px(8),
553 position_type: PositionType::Absolute,
554 left: px(2),
555 top: px(2),
556 ..default()
557 },
558 BackgroundColor(ELEMENT_FILL),
559 ),
560 ],
561 )),
562 Spawn((
563 Text::new(caption),
564 TextFont {
565 font: asset_server.load("fonts/FiraSans-Bold.ttf").into(),
566 font_size: FontSize::Px(20.0),
567 ..default()
568 },
569 )),
570 )),
571 )
572}
573
574// Update the element's styles.
575fn update_checkbox_or_radio_style(
576 mut q_checkbox: Query<
577 (Has<Checked>, &Hovered, Has<InteractionDisabled>, &Children),
578 (
579 Or<(With<DemoCheckbox>, With<DemoRadio>)>,
580 Or<(
581 Added<DemoCheckbox>,
582 Changed<Hovered>,
583 Added<Checked>,
584 Added<InteractionDisabled>,
585 )>,
586 ),
587 >,
588 mut q_border_color: Query<
589 (&mut BorderColor, &mut Children),
590 (Without<DemoCheckbox>, Without<DemoRadio>),
591 >,
592 mut q_bg_color: Query<&mut BackgroundColor, (Without<DemoCheckbox>, Without<Children>)>,
593) {
594 for (checked, Hovered(is_hovering), is_disabled, children) in q_checkbox.iter_mut() {
595 let Some(border_id) = children.first() else {
596 continue;
597 };
598
599 let Ok((mut border_color, border_children)) = q_border_color.get_mut(*border_id) else {
600 continue;
601 };
602
603 let Some(mark_id) = border_children.first() else {
604 warn!("Checkbox does not have a mark entity.");
605 continue;
606 };
607
608 let Ok(mut mark_bg) = q_bg_color.get_mut(*mark_id) else {
609 warn!("Checkbox mark entity lacking a background color.");
610 continue;
611 };
612
613 set_checkbox_or_radio_style(
614 is_disabled,
615 *is_hovering,
616 checked,
617 &mut border_color,
618 &mut mark_bg,
619 );
620 }
621}
622
623fn update_checkbox_or_radio_style2(
624 mut q_checkbox: Query<
625 (Has<Checked>, &Hovered, Has<InteractionDisabled>, &Children),
626 Or<(With<DemoCheckbox>, With<DemoRadio>)>,
627 >,
628 mut q_border_color: Query<
629 (&mut BorderColor, &mut Children),
630 (Without<DemoCheckbox>, Without<DemoRadio>),
631 >,
632 mut q_bg_color: Query<
633 &mut BackgroundColor,
634 (Without<DemoCheckbox>, Without<DemoRadio>, Without<Children>),
635 >,
636 mut removed_checked: RemovedComponents<Checked>,
637 mut removed_disabled: RemovedComponents<InteractionDisabled>,
638) {
639 removed_checked
640 .read()
641 .chain(removed_disabled.read())
642 .for_each(|entity| {
643 if let Ok((checked, Hovered(is_hovering), is_disabled, children)) =
644 q_checkbox.get_mut(entity)
645 {
646 let Some(border_id) = children.first() else {
647 return;
648 };
649
650 let Ok((mut border_color, border_children)) = q_border_color.get_mut(*border_id)
651 else {
652 return;
653 };
654
655 let Some(mark_id) = border_children.first() else {
656 warn!("Checkbox does not have a mark entity.");
657 return;
658 };
659
660 let Ok(mut mark_bg) = q_bg_color.get_mut(*mark_id) else {
661 warn!("Checkbox mark entity lacking a background color.");
662 return;
663 };
664
665 set_checkbox_or_radio_style(
666 is_disabled,
667 *is_hovering,
668 checked,
669 &mut border_color,
670 &mut mark_bg,
671 );
672 }
673 });
674}
675
676fn set_checkbox_or_radio_style(
677 disabled: bool,
678 hovering: bool,
679 checked: bool,
680 border_color: &mut BorderColor,
681 mark_bg: &mut BackgroundColor,
682) {
683 let color: Color = if disabled {
684 // If the element is disabled, use a lighter color
685 ELEMENT_OUTLINE.with_alpha(0.2)
686 } else if hovering {
687 // If hovering, use a lighter color
688 ELEMENT_OUTLINE.lighter(0.2)
689 } else {
690 // Default color for the element
691 ELEMENT_OUTLINE
692 };
693
694 // Update the background color of the element
695 border_color.set_all(color);
696
697 let mark_color: Color = match (disabled, checked) {
698 (true, true) => ELEMENT_FILL_DISABLED,
699 (false, true) => ELEMENT_FILL,
700 (_, false) => Srgba::NONE.into(),
701 };
702
703 if mark_bg.0 != mark_color {
704 // Update the color of the element
705 mark_bg.0 = mark_color;
706 }
707}
708
709/// Create a demo radio group
710fn radio_group(asset_server: &AssetServer) -> impl Bundle {
711 (
712 Node {
713 display: Display::Flex,
714 flex_direction: FlexDirection::Column,
715 align_items: AlignItems::Start,
716 column_gap: px(4),
717 ..default()
718 },
719 Name::new("RadioGroup"),
720 RadioGroup,
721 TabIndex::default(),
722 children![
723 (radio(asset_server, TrackClick::Drag, "Slider Drag"),),
724 (radio(asset_server, TrackClick::Step, "Slider Step"),),
725 (radio(asset_server, TrackClick::Snap, "Slider Snap"),)
726 ],
727 )
728}
729
730/// Create a demo radio button
731fn radio(asset_server: &AssetServer, value: TrackClick, caption: &str) -> impl Bundle {
732 (
733 Node {
734 display: Display::Flex,
735 flex_direction: FlexDirection::Row,
736 justify_content: JustifyContent::FlexStart,
737 align_items: AlignItems::Center,
738 align_content: AlignContent::Center,
739 column_gap: px(4),
740 ..default()
741 },
742 Name::new("RadioButton"),
743 Hovered::default(),
744 DemoRadio(value),
745 RadioButton,
746 Children::spawn((
747 Spawn((
748 // Radio outer
749 Node {
750 display: Display::Flex,
751 width: px(16),
752 height: px(16),
753 border: UiRect::all(px(2)),
754 border_radius: BorderRadius::MAX,
755 ..default()
756 },
757 BorderColor::all(ELEMENT_OUTLINE), // Border color for the radio button
758 children![
759 // Radio inner
760 (
761 Node {
762 display: Display::Flex,
763 width: px(8),
764 height: px(8),
765 position_type: PositionType::Absolute,
766 left: px(2),
767 top: px(2),
768 border_radius: BorderRadius::MAX,
769 ..default()
770 },
771 BackgroundColor(ELEMENT_FILL),
772 ),
773 ],
774 )),
775 Spawn((
776 Text::new(caption),
777 TextFont {
778 font: asset_server.load("fonts/FiraSans-Bold.ttf").into(),
779 font_size: FontSize::Px(20.0),
780 ..default()
781 },
782 )),
783 )),
784 )
785}
786
787fn on_menu_event(
788 menu_event: On<MenuEvent>,
789 q_anchor: Single<(Entity, &Children), With<DemoMenuAnchor>>,
790 q_popup: Query<Entity, With<MenuPopup>>,
791 assets: Res<AssetServer>,
792 mut focus: ResMut<InputFocus>,
793 mut commands: Commands,
794) {
795 let (anchor, children) = q_anchor.into_inner();
796 let popup = children.iter().find_map(|c| q_popup.get(c).ok());
797 info!("Menu action: {:?}", menu_event.action);
798 match menu_event.action {
799 MenuAction::Open(_) => {
800 if popup.is_none() {
801 spawn_menu(anchor, assets, commands);
802 }
803 }
804 MenuAction::Toggle => match popup {
805 Some(popup) => commands.entity(popup).despawn(),
806 None => spawn_menu(anchor, assets, commands),
807 },
808 MenuAction::CloseAll => {
809 if let Some(popup) = popup {
810 commands.entity(popup).despawn();
811 }
812 }
813 MenuAction::FocusRoot => {
814 focus.set(anchor, FocusCause::Navigated);
815 }
816 }
817}
818
819fn spawn_menu(anchor: Entity, assets: Res<AssetServer>, mut commands: Commands) {
820 let menu = commands
821 .spawn((
822 Node {
823 display: Display::Flex,
824 flex_direction: FlexDirection::Column,
825 min_height: px(10.),
826 min_width: percent(100),
827 border: UiRect::all(px(1)),
828 position_type: PositionType::Absolute,
829 ..default()
830 },
831 MenuPopup::default(),
832 BorderColor::all(GREEN),
833 BackgroundColor(GRAY.into()),
834 BoxShadow::new(
835 Srgba::BLACK.with_alpha(0.9).into(),
836 px(0),
837 px(0),
838 px(1),
839 px(4),
840 ),
841 GlobalZIndex(100),
842 Popover {
843 positions: vec![
844 PopoverPlacement {
845 side: PopoverSide::Bottom,
846 align: PopoverAlign::Start,
847 gap: 2.0,
848 },
849 PopoverPlacement {
850 side: PopoverSide::Top,
851 align: PopoverAlign::Start,
852 gap: 2.0,
853 },
854 ],
855 window_margin: 10.0,
856 },
857 OverrideClip,
858 children![
859 menu_item(&assets),
860 menu_item(&assets),
861 menu_item(&assets),
862 menu_item(&assets)
863 ],
864 ))
865 .id();
866 commands.entity(anchor).add_child(menu);
867}Additional examples can be found in:
- examples/ui/widgets/standard_widgets_observers.rs
- examples/ui/text/editable_text_filter.rs
- examples/ui/images/image_node.rs
- examples/usage/context_menu.rs
- examples/ui/widgets/button.rs
- examples/ui/layout/size_constraints.rs
- examples/remote/app_under_test.rs
- examples/3d/color_grading.rs
- examples/ui/widgets/viewport_node.rs
- examples/camera/2d_on_ui.rs
- examples/animation/animation_graph.rs
- examples/ui/text/text_background_colors.rs
- examples/testbed/ui.rs
- examples/asset/asset_saving.rs
- examples/ui/ui_target_camera.rs
- examples/ui/scroll_and_overflow/overflow.rs
- examples/ui/scroll_and_overflow/overflow_clip_margin.rs
- examples/animation/animation_masks.rs
- examples/ui/scroll_and_overflow/scrollbars.rs
- examples/ui/text/multiple_text_inputs.rs
- examples/ui/ui_drag_and_drop.rs
- examples/ui/styling/box_shadow.rs
- examples/ui/text/multiline_text_input.rs
- examples/ui/styling/gradients.rs
- examples/testbed/full_ui.rs
Sourcepub fn set_all(&mut self, color: impl Into<Color>) -> &mut BorderColor
pub fn set_all(&mut self, color: impl Into<Color>) -> &mut BorderColor
Helper to set all border colors to a given color.
Examples found in repository?
examples/ui/text/multiple_text_inputs.rs (line 256)
233fn update_row_border_colors(
234 input_focus: Res<InputFocus>,
235 input_rows: Query<&TextInputRow, With<EditableText>>,
236 mut row_borders: Query<(&TextInputRow, &mut BorderColor, Has<EditableText>)>,
237) {
238 if !input_focus.is_changed() {
239 return;
240 }
241
242 let focused_row = input_focus
243 .get()
244 .and_then(|focused_entity| input_rows.get(focused_entity).ok())
245 .map(|row| row.0);
246
247 for (row, mut border_color, is_input) in &mut row_borders {
248 let mut color = if is_input {
249 SLATE_300.into()
250 } else {
251 Color::WHITE
252 };
253 if Some(row.0) != focused_row {
254 color = color.darker(0.75);
255 }
256 border_color.set_all(color);
257 }
258}More examples
examples/ui/widgets/standard_widgets.rs (line 354)
341fn set_button_style(
342 disabled: bool,
343 hovered: bool,
344 pressed: bool,
345 color: &mut BackgroundColor,
346 border_color: &mut BorderColor,
347 text: &mut Text,
348) {
349 match (disabled, hovered, pressed) {
350 // Disabled button
351 (true, _, _) => {
352 **text = "Disabled".to_string();
353 *color = NORMAL_BUTTON.into();
354 border_color.set_all(GRAY);
355 }
356
357 // Pressed and hovered button
358 (false, true, true) => {
359 **text = "Press".to_string();
360 *color = PRESSED_BUTTON.into();
361 border_color.set_all(RED);
362 }
363
364 // Hovered, unpressed button
365 (false, true, false) => {
366 **text = "Hover".to_string();
367 *color = HOVERED_BUTTON.into();
368 border_color.set_all(WHITE);
369 }
370
371 // Unhovered button (either pressed or not).
372 (false, false, _) => {
373 **text = "Button".to_string();
374 *color = NORMAL_BUTTON.into();
375 border_color.set_all(BLACK);
376 }
377 }
378}
379
380/// Create a demo slider
381fn slider(min: f32, max: f32, value: f32) -> impl Bundle {
382 (
383 Node {
384 display: Display::Flex,
385 flex_direction: FlexDirection::Column,
386 justify_content: JustifyContent::Center,
387 align_items: AlignItems::Stretch,
388 justify_items: JustifyItems::Center,
389 column_gap: px(4),
390 height: px(12),
391 width: percent(30),
392 ..default()
393 },
394 Name::new("Slider"),
395 Hovered::default(),
396 DemoSlider,
397 Slider {
398 track_click: TrackClick::Snap,
399 ..Default::default()
400 },
401 SliderValue(value),
402 SliderRange::new(min, max),
403 TabIndex(0),
404 Children::spawn((
405 // Slider background rail
406 Spawn((
407 Node {
408 height: px(6),
409 border_radius: BorderRadius::all(px(3)),
410 ..default()
411 },
412 BackgroundColor(SLIDER_TRACK), // Border color for the slider
413 )),
414 // Invisible track to allow absolute placement of thumb entity. This is narrower than
415 // the actual slider, which allows us to position the thumb entity using simple
416 // percentages, without having to measure the actual width of the slider thumb.
417 Spawn((
418 Node {
419 display: Display::Flex,
420 position_type: PositionType::Absolute,
421 left: px(0),
422 // Track is short by 12px to accommodate the thumb.
423 right: px(12),
424 top: px(0),
425 bottom: px(0),
426 ..default()
427 },
428 children![(
429 // Thumb
430 DemoSliderThumb,
431 SliderThumb,
432 Node {
433 display: Display::Flex,
434 width: px(12),
435 height: px(12),
436 position_type: PositionType::Absolute,
437 left: percent(0), // This will be updated by the slider's value
438 border_radius: BorderRadius::MAX,
439 ..default()
440 },
441 BackgroundColor(SLIDER_THUMB),
442 )],
443 )),
444 )),
445 )
446}
447
448/// Update the visuals of the slider based on the slider state.
449fn update_slider_style(
450 sliders: Query<
451 (
452 Entity,
453 &SliderValue,
454 &SliderRange,
455 &Hovered,
456 &SliderDragState,
457 Has<InteractionDisabled>,
458 ),
459 (
460 Or<(
461 Changed<SliderValue>,
462 Changed<SliderRange>,
463 Changed<Hovered>,
464 Changed<SliderDragState>,
465 Added<InteractionDisabled>,
466 )>,
467 With<DemoSlider>,
468 ),
469 >,
470 children: Query<&Children>,
471 mut thumbs: Query<(&mut Node, &mut BackgroundColor, Has<DemoSliderThumb>), Without<DemoSlider>>,
472) {
473 for (slider_ent, value, range, hovered, drag_state, disabled) in sliders.iter() {
474 for child in children.iter_descendants(slider_ent) {
475 if let Ok((mut thumb_node, mut thumb_bg, is_thumb)) = thumbs.get_mut(child)
476 && is_thumb
477 {
478 thumb_node.left = percent(range.thumb_position(value.0) * 100.0);
479 thumb_bg.0 = thumb_color(disabled, hovered.0 | drag_state.dragging);
480 }
481 }
482 }
483}
484
485fn update_slider_style2(
486 sliders: Query<
487 (Entity, &Hovered, &SliderDragState, Has<InteractionDisabled>),
488 With<DemoSlider>,
489 >,
490 children: Query<&Children>,
491 mut thumbs: Query<(&mut BackgroundColor, Has<DemoSliderThumb>), Without<DemoSlider>>,
492 mut removed_disabled: RemovedComponents<InteractionDisabled>,
493) {
494 removed_disabled.read().for_each(|entity| {
495 if let Ok((slider_ent, hovered, drag_state, disabled)) = sliders.get(entity) {
496 for child in children.iter_descendants(slider_ent) {
497 if let Ok((mut thumb_bg, is_thumb)) = thumbs.get_mut(child)
498 && is_thumb
499 {
500 thumb_bg.0 = thumb_color(disabled, hovered.0 | drag_state.dragging);
501 }
502 }
503 }
504 });
505}
506
507fn thumb_color(disabled: bool, hovered: bool) -> Color {
508 match (disabled, hovered) {
509 (true, _) => ELEMENT_FILL_DISABLED,
510
511 (false, true) => SLIDER_THUMB.lighter(0.3),
512
513 _ => SLIDER_THUMB,
514 }
515}
516
517/// Create a demo checkbox
518fn checkbox(asset_server: &AssetServer, caption: &str) -> impl Bundle {
519 (
520 Node {
521 display: Display::Flex,
522 flex_direction: FlexDirection::Row,
523 justify_content: JustifyContent::FlexStart,
524 align_items: AlignItems::Center,
525 align_content: AlignContent::Center,
526 column_gap: px(4),
527 ..default()
528 },
529 Name::new("Checkbox"),
530 Hovered::default(),
531 DemoCheckbox,
532 Checkbox,
533 TabIndex(0),
534 Children::spawn((
535 Spawn((
536 // Checkbox outer
537 Node {
538 display: Display::Flex,
539 width: px(16),
540 height: px(16),
541 border: UiRect::all(px(2)),
542 border_radius: BorderRadius::all(px(3)),
543 ..default()
544 },
545 BorderColor::all(ELEMENT_OUTLINE), // Border color for the checkbox
546 children![
547 // Checkbox inner
548 (
549 Node {
550 display: Display::Flex,
551 width: px(8),
552 height: px(8),
553 position_type: PositionType::Absolute,
554 left: px(2),
555 top: px(2),
556 ..default()
557 },
558 BackgroundColor(ELEMENT_FILL),
559 ),
560 ],
561 )),
562 Spawn((
563 Text::new(caption),
564 TextFont {
565 font: asset_server.load("fonts/FiraSans-Bold.ttf").into(),
566 font_size: FontSize::Px(20.0),
567 ..default()
568 },
569 )),
570 )),
571 )
572}
573
574// Update the element's styles.
575fn update_checkbox_or_radio_style(
576 mut q_checkbox: Query<
577 (Has<Checked>, &Hovered, Has<InteractionDisabled>, &Children),
578 (
579 Or<(With<DemoCheckbox>, With<DemoRadio>)>,
580 Or<(
581 Added<DemoCheckbox>,
582 Changed<Hovered>,
583 Added<Checked>,
584 Added<InteractionDisabled>,
585 )>,
586 ),
587 >,
588 mut q_border_color: Query<
589 (&mut BorderColor, &mut Children),
590 (Without<DemoCheckbox>, Without<DemoRadio>),
591 >,
592 mut q_bg_color: Query<&mut BackgroundColor, (Without<DemoCheckbox>, Without<Children>)>,
593) {
594 for (checked, Hovered(is_hovering), is_disabled, children) in q_checkbox.iter_mut() {
595 let Some(border_id) = children.first() else {
596 continue;
597 };
598
599 let Ok((mut border_color, border_children)) = q_border_color.get_mut(*border_id) else {
600 continue;
601 };
602
603 let Some(mark_id) = border_children.first() else {
604 warn!("Checkbox does not have a mark entity.");
605 continue;
606 };
607
608 let Ok(mut mark_bg) = q_bg_color.get_mut(*mark_id) else {
609 warn!("Checkbox mark entity lacking a background color.");
610 continue;
611 };
612
613 set_checkbox_or_radio_style(
614 is_disabled,
615 *is_hovering,
616 checked,
617 &mut border_color,
618 &mut mark_bg,
619 );
620 }
621}
622
623fn update_checkbox_or_radio_style2(
624 mut q_checkbox: Query<
625 (Has<Checked>, &Hovered, Has<InteractionDisabled>, &Children),
626 Or<(With<DemoCheckbox>, With<DemoRadio>)>,
627 >,
628 mut q_border_color: Query<
629 (&mut BorderColor, &mut Children),
630 (Without<DemoCheckbox>, Without<DemoRadio>),
631 >,
632 mut q_bg_color: Query<
633 &mut BackgroundColor,
634 (Without<DemoCheckbox>, Without<DemoRadio>, Without<Children>),
635 >,
636 mut removed_checked: RemovedComponents<Checked>,
637 mut removed_disabled: RemovedComponents<InteractionDisabled>,
638) {
639 removed_checked
640 .read()
641 .chain(removed_disabled.read())
642 .for_each(|entity| {
643 if let Ok((checked, Hovered(is_hovering), is_disabled, children)) =
644 q_checkbox.get_mut(entity)
645 {
646 let Some(border_id) = children.first() else {
647 return;
648 };
649
650 let Ok((mut border_color, border_children)) = q_border_color.get_mut(*border_id)
651 else {
652 return;
653 };
654
655 let Some(mark_id) = border_children.first() else {
656 warn!("Checkbox does not have a mark entity.");
657 return;
658 };
659
660 let Ok(mut mark_bg) = q_bg_color.get_mut(*mark_id) else {
661 warn!("Checkbox mark entity lacking a background color.");
662 return;
663 };
664
665 set_checkbox_or_radio_style(
666 is_disabled,
667 *is_hovering,
668 checked,
669 &mut border_color,
670 &mut mark_bg,
671 );
672 }
673 });
674}
675
676fn set_checkbox_or_radio_style(
677 disabled: bool,
678 hovering: bool,
679 checked: bool,
680 border_color: &mut BorderColor,
681 mark_bg: &mut BackgroundColor,
682) {
683 let color: Color = if disabled {
684 // If the element is disabled, use a lighter color
685 ELEMENT_OUTLINE.with_alpha(0.2)
686 } else if hovering {
687 // If hovering, use a lighter color
688 ELEMENT_OUTLINE.lighter(0.2)
689 } else {
690 // Default color for the element
691 ELEMENT_OUTLINE
692 };
693
694 // Update the background color of the element
695 border_color.set_all(color);
696
697 let mark_color: Color = match (disabled, checked) {
698 (true, true) => ELEMENT_FILL_DISABLED,
699 (false, true) => ELEMENT_FILL,
700 (_, false) => Srgba::NONE.into(),
701 };
702
703 if mark_bg.0 != mark_color {
704 // Update the color of the element
705 mark_bg.0 = mark_color;
706 }
707}examples/ui/widgets/standard_widgets_observers.rs (line 187)
153fn button_on_interaction<E: EntityEvent, C: Component>(
154 event: On<E, C>,
155 mut buttons: Query<
156 (
157 &Hovered,
158 Has<InteractionDisabled>,
159 Has<Pressed>,
160 &mut BackgroundColor,
161 &mut BorderColor,
162 &Children,
163 ),
164 With<DemoButton>,
165 >,
166 mut text_query: Query<&mut Text>,
167) {
168 if let Ok((hovered, disabled, pressed, mut color, mut border_color, children)) =
169 buttons.get_mut(event.event_target())
170 {
171 if children.is_empty() {
172 return;
173 }
174 let Ok(mut text) = text_query.get_mut(children[0]) else {
175 return;
176 };
177 let hovered = hovered.get();
178 // These "removal event checks" exist because the `Remove` event is triggered _before_ the component is actually
179 // removed, meaning it still shows up in the query. We're investigating the best way to improve this scenario.
180 let pressed = pressed && !(E::is::<Remove>() && C::is::<Pressed>());
181 let disabled = disabled && !(E::is::<Remove>() && C::is::<InteractionDisabled>());
182 match (disabled, hovered, pressed) {
183 // Disabled button
184 (true, _, _) => {
185 **text = "Disabled".to_string();
186 *color = NORMAL_BUTTON.into();
187 border_color.set_all(GRAY);
188 }
189
190 // Pressed and hovered button
191 (false, true, true) => {
192 **text = "Press".to_string();
193 *color = PRESSED_BUTTON.into();
194 border_color.set_all(RED);
195 }
196
197 // Hovered, unpressed button
198 (false, true, false) => {
199 **text = "Hover".to_string();
200 *color = HOVERED_BUTTON.into();
201 border_color.set_all(WHITE);
202 }
203
204 // Unhovered button (either pressed or not).
205 (false, false, _) => {
206 **text = "Button".to_string();
207 *color = NORMAL_BUTTON.into();
208 border_color.set_all(BLACK);
209 }
210 }
211 }
212}
213
214/// Create a demo slider
215fn slider(min: f32, max: f32, value: f32) -> impl Bundle {
216 (
217 Node {
218 display: Display::Flex,
219 flex_direction: FlexDirection::Column,
220 justify_content: JustifyContent::Center,
221 align_items: AlignItems::Stretch,
222 justify_items: JustifyItems::Center,
223 column_gap: px(4),
224 height: px(12),
225 width: percent(30),
226 ..default()
227 },
228 Name::new("Slider"),
229 Hovered::default(),
230 DemoSlider,
231 Slider::default(),
232 SliderValue(value),
233 SliderRange::new(min, max),
234 TabIndex(0),
235 Children::spawn((
236 // Slider background rail
237 Spawn((
238 Node {
239 height: px(6),
240 border_radius: BorderRadius::all(px(3)),
241 ..default()
242 },
243 BackgroundColor(SLIDER_TRACK), // Border color for the checkbox
244 )),
245 // Invisible track to allow absolute placement of thumb entity. This is narrower than
246 // the actual slider, which allows us to position the thumb entity using simple
247 // percentages, without having to measure the actual width of the slider thumb.
248 Spawn((
249 Node {
250 display: Display::Flex,
251 position_type: PositionType::Absolute,
252 left: px(0),
253 // Track is short by 12px to accommodate the thumb.
254 right: px(12),
255 top: px(0),
256 bottom: px(0),
257 ..default()
258 },
259 children![(
260 // Thumb
261 DemoSliderThumb,
262 SliderThumb,
263 Node {
264 display: Display::Flex,
265 width: px(12),
266 height: px(12),
267 position_type: PositionType::Absolute,
268 left: percent(0), // This will be updated by the slider's value
269 border_radius: BorderRadius::MAX,
270 ..default()
271 },
272 BackgroundColor(SLIDER_THUMB),
273 )],
274 )),
275 )),
276 )
277}
278
279fn slider_on_interaction<E: EntityEvent, C: Component>(
280 event: On<E, C>,
281 sliders: Query<(Entity, &Hovered, Has<InteractionDisabled>), With<DemoSlider>>,
282 children: Query<&Children>,
283 mut thumbs: Query<(&mut BackgroundColor, Has<DemoSliderThumb>), Without<DemoSlider>>,
284) {
285 if let Ok((slider_ent, hovered, disabled)) = sliders.get(event.event_target()) {
286 // These "removal event checks" exist because the `Remove` event is triggered _before_ the component is actually
287 // removed, meaning it still shows up in the query. We're investigating the best way to improve this scenario.
288 let disabled = disabled && !(E::is::<Remove>() && C::is::<InteractionDisabled>());
289 for child in children.iter_descendants(slider_ent) {
290 if let Ok((mut thumb_bg, is_thumb)) = thumbs.get_mut(child)
291 && is_thumb
292 {
293 thumb_bg.0 = thumb_color(disabled, hovered.0);
294 }
295 }
296 }
297}
298
299fn slider_on_change_value<C: Component>(
300 insert: On<Insert, C>,
301 sliders: Query<(Entity, &SliderValue, &SliderRange), With<DemoSlider>>,
302 children: Query<&Children>,
303 mut thumbs: Query<(&mut Node, Has<DemoSliderThumb>), Without<DemoSlider>>,
304) {
305 if let Ok((slider_ent, value, range)) = sliders.get(insert.entity) {
306 for child in children.iter_descendants(slider_ent) {
307 if let Ok((mut thumb_node, is_thumb)) = thumbs.get_mut(child)
308 && is_thumb
309 {
310 thumb_node.left = percent(range.thumb_position(value.0) * 100.0);
311 }
312 }
313 }
314}
315
316fn thumb_color(disabled: bool, hovered: bool) -> Color {
317 match (disabled, hovered) {
318 (true, _) => GRAY.into(),
319
320 (false, true) => SLIDER_THUMB.lighter(0.3),
321
322 _ => SLIDER_THUMB,
323 }
324}
325
326/// Create a demo checkbox
327fn checkbox(asset_server: &AssetServer, caption: &str) -> impl Bundle {
328 (
329 Node {
330 display: Display::Flex,
331 flex_direction: FlexDirection::Row,
332 justify_content: JustifyContent::FlexStart,
333 align_items: AlignItems::Center,
334 align_content: AlignContent::Center,
335 column_gap: px(4),
336 ..default()
337 },
338 Name::new("Checkbox"),
339 Hovered::default(),
340 DemoCheckbox,
341 Checkbox,
342 TabIndex(0),
343 Children::spawn((
344 Spawn((
345 // Checkbox outer
346 Node {
347 display: Display::Flex,
348 width: px(16),
349 height: px(16),
350 border: UiRect::all(px(2)),
351 border_radius: BorderRadius::all(px(3)),
352 ..default()
353 },
354 BorderColor::all(CHECKBOX_OUTLINE), // Border color for the checkbox
355 children![
356 // Checkbox inner
357 (
358 Node {
359 display: Display::Flex,
360 width: px(8),
361 height: px(8),
362 position_type: PositionType::Absolute,
363 left: px(2),
364 top: px(2),
365 ..default()
366 },
367 BackgroundColor(Srgba::NONE.into()),
368 ),
369 ],
370 )),
371 Spawn((
372 Text::new(caption),
373 TextFont {
374 font: asset_server.load("fonts/FiraSans-Bold.ttf").into(),
375 font_size: FontSize::Px(20.0),
376 ..default()
377 },
378 )),
379 )),
380 )
381}
382
383fn checkbox_on_interaction<E: EntityEvent, C: Component>(
384 event: On<E, C>,
385 checkboxes: Query<
386 (&Hovered, Has<InteractionDisabled>, Has<Checked>, &Children),
387 With<DemoCheckbox>,
388 >,
389 mut borders: Query<(&mut BorderColor, &mut Children), Without<DemoCheckbox>>,
390 mut marks: Query<&mut BackgroundColor, (Without<DemoCheckbox>, Without<Children>)>,
391) {
392 if let Ok((hovered, disabled, checked, children)) = checkboxes.get(event.event_target()) {
393 let hovered = hovered.get();
394 // These "removal event checks" exist because the `Remove` event is triggered _before_ the component is actually
395 // removed, meaning it still shows up in the query. We're investigating the best way to improve this scenario.
396 let checked = checked && !(E::is::<Remove>() && C::is::<Checked>());
397 let disabled = disabled && !(E::is::<Remove>() && C::is::<InteractionDisabled>());
398
399 let Some(border_id) = children.first() else {
400 return;
401 };
402
403 let Ok((mut border_color, border_children)) = borders.get_mut(*border_id) else {
404 return;
405 };
406
407 let Some(mark_id) = border_children.first() else {
408 warn!("Checkbox does not have a mark entity.");
409 return;
410 };
411
412 let Ok(mut mark_bg) = marks.get_mut(*mark_id) else {
413 warn!("Checkbox mark entity lacking a background color.");
414 return;
415 };
416
417 let color: Color = if disabled {
418 // If the checkbox is disabled, use a lighter color
419 CHECKBOX_OUTLINE.with_alpha(0.2)
420 } else if hovered {
421 // If hovering, use a lighter color
422 CHECKBOX_OUTLINE.lighter(0.2)
423 } else {
424 // Default color for the checkbox
425 CHECKBOX_OUTLINE
426 };
427
428 // Update the background color of the check mark
429 border_color.set_all(color);
430
431 let mark_color: Color = match (disabled, checked) {
432 (true, true) => CHECKBOX_CHECK.with_alpha(0.5),
433 (false, true) => CHECKBOX_CHECK,
434 (_, false) => Srgba::NONE.into(),
435 };
436
437 if mark_bg.0 != mark_color {
438 // Update the color of the check mark
439 mark_bg.0 = mark_color;
440 }
441 }
442}examples/ui/ui_drag_and_drop.rs (line 63)
16fn setup(mut commands: Commands) {
17 commands.spawn(Camera2d);
18 commands
19 .spawn((Node {
20 display: Display::Grid,
21 align_self: AlignSelf::Center,
22 justify_self: JustifySelf::Center,
23 ..Default::default()
24 }, Pickable::IGNORE, BackgroundColor(Color::srgb(0.4, 0.4, 0.4))))
25 .with_children(|parent| {
26 let tile_colors = [
27 Color::srgb(0.2, 0.2, 0.8),
28 Color::srgb(0.8, 0.2, 0.2)
29 ];
30 for column in 0..COLUMNS {
31 for row in 0..ROWS {
32 let i = column + row * COLUMNS;
33 let tile_color = tile_colors[((row % 2) + column) as usize % tile_colors.len()];
34 let tile_border_color = tile_color.darker(0.025);
35 parent
36 .spawn((
37 Node {
38 width: px(TILE_SIZE),
39 height: px(TILE_SIZE),
40 border: px(4.).all(),
41 grid_row: GridPlacement::start(row + 1),
42 grid_column: GridPlacement::start(column + 1),
43 align_items: AlignItems::Center,
44 justify_content: JustifyContent::Center,
45 ..Default::default()
46 },
47 BorderColor::all(tile_border_color),
48 BackgroundColor(tile_color),
49 Outline {
50 width: px(2.),
51 offset: Val::ZERO,
52 color: Color::NONE,
53 },
54 Pickable {
55 should_block_lower: false,
56 is_hoverable: true,
57 },
58 GlobalZIndex::default()
59 ))
60 .observe(move |on_over: On<Pointer<Over>>, mut query: Query<(&mut BackgroundColor, &mut BorderColor)>| {
61 if let Ok((mut background_color, mut border_color)) = query.get_mut(on_over.event_target()) {
62 background_color.0 = tile_color.lighter(0.1);
63 border_color.set_all(tile_border_color.lighter(0.1));
64 }
65 })
66 .observe(move |on_out: On<Pointer<Out>>, mut query: Query<(&mut BackgroundColor, &mut BorderColor)>| {
67 if let Ok((mut background_color, mut border_color)) = query.get_mut(on_out.event_target()) {
68 background_color.0 = tile_color;
69 border_color.set_all(tile_border_color);
70 }
71 })
72 .observe(|on_drag_start: On<Pointer<DragStart>>, mut query: Query<(&mut Outline, &mut GlobalZIndex)>| {
73 if let Ok((mut outline, mut global_zindex, )) = query.get_mut(on_drag_start.event_target()) {
74 outline.color = Color::WHITE;
75 global_zindex.0 = 1;
76 }
77 })
78 .observe(|on_drag: On<Pointer<Drag>>, mut query: Query<&mut UiTransform>| {
79 if let Ok(mut transform) = query.get_mut(on_drag.event_target()) {
80 transform.translation = Val2::px(on_drag.distance.x, on_drag.distance.y);
81 }
82 })
83 .observe(move |on_drag_end: On<Pointer<DragEnd>>, mut query: Query<(&mut UiTransform, &mut Outline, &mut GlobalZIndex)>| {
84 if let Ok((mut transform, mut outline, mut global_zindex)) = query.get_mut(on_drag_end.event_target()) {
85 transform.translation = Val2::ZERO;
86 outline.color = Color::NONE;
87 global_zindex.0 = 0;
88 }
89 })
90 .observe(|on_drag_drop: On<Pointer<DragDrop>>, mut query: Query<&mut Node>| {
91 if let Ok([mut a, mut b]) = query.get_many_mut([on_drag_drop.event_target(), on_drag_drop.dropped]) {
92 core::mem::swap(&mut a.grid_row, &mut b.grid_row);
93 core::mem::swap(&mut a.grid_column, &mut b.grid_column);
94 }
95 })
96 .with_child((Text::new(format!("{i}")), Pickable::IGNORE));
97 }
98 }
99 });
100}Sourcepub fn is_fully_transparent(&self) -> bool
pub fn is_fully_transparent(&self) -> bool
Check if all contained border colors are transparent
Trait Implementations§
Source§impl Clone for BorderColor
impl Clone for BorderColor
Source§fn clone(&self) -> BorderColor
fn clone(&self) -> BorderColor
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Component for BorderColor
impl Component for BorderColor
Source§const STORAGE_TYPE: StorageType = bevy_ecs::component::StorageType::Table
const STORAGE_TYPE: StorageType = bevy_ecs::component::StorageType::Table
A constant indicating the storage type used for this component.
Source§type Mutability = Mutable
type Mutability = Mutable
A marker type to assist Bevy with determining if this component is
mutable, or immutable. Mutable components will have
Component<Mutability = Mutable>,
while immutable components will instead have Component<Mutability = Immutable>. Read moreSource§fn register_required_components(
_requiree: ComponentId,
required_components: &mut RequiredComponentsRegistrator<'_, '_>,
)
fn register_required_components( _requiree: ComponentId, required_components: &mut RequiredComponentsRegistrator<'_, '_>, )
Registers required components. Read more
Source§fn clone_behavior() -> ComponentCloneBehavior
fn clone_behavior() -> ComponentCloneBehavior
Called when registering this component, allowing to override clone function (or disable cloning altogether) for this component. Read more
Source§fn relationship_accessor() -> Option<ComponentRelationshipAccessor<BorderColor>>
fn relationship_accessor() -> Option<ComponentRelationshipAccessor<BorderColor>>
Returns
ComponentRelationshipAccessor required for working with relationships in dynamic contexts. Read moreSource§fn on_add() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_add() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_insert() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_insert() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_discard() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_discard() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_remove() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_remove() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn map_entities<E>(_this: &mut Self, _mapper: &mut E)where
E: EntityMapper,
fn map_entities<E>(_this: &mut Self, _mapper: &mut E)where
E: EntityMapper,
Maps the entities on this component using the given
EntityMapper. This is used to remap entities in contexts like scenes and entity cloning.
When deriving Component, this is populated by annotating fields containing entities with #[entities] Read moreimpl Copy for BorderColor
Source§impl Debug for BorderColor
impl Debug for BorderColor
Source§impl Default for BorderColor
impl Default for BorderColor
Source§fn default() -> BorderColor
fn default() -> BorderColor
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for BorderColor
impl<'de> Deserialize<'de> for BorderColor
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<BorderColor, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<BorderColor, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<T> From<T> for BorderColor
impl<T> From<T> for BorderColor
Source§fn from(color: T) -> BorderColor
fn from(color: T) -> BorderColor
Converts to this type from the input type.
Source§impl FromArg for BorderColor
impl FromArg for BorderColor
Source§impl FromReflect for BorderColor
impl FromReflect for BorderColor
Source§fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<BorderColor>
fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<BorderColor>
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 BorderColor
impl GetOwnership for BorderColor
Source§impl GetTypeRegistration for BorderColor
impl GetTypeRegistration for BorderColor
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 BorderColor
impl IntoReturn for BorderColor
Source§fn into_return<'into_return>(self) -> Return<'into_return>where
BorderColor: 'into_return,
fn into_return<'into_return>(self) -> Return<'into_return>where
BorderColor: 'into_return,
Source§impl PartialEq for BorderColor
impl PartialEq for BorderColor
Source§fn eq(&self, other: &BorderColor) -> bool
fn eq(&self, other: &BorderColor) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl PartialReflect for BorderColor
impl PartialReflect for BorderColor
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<BorderColor>) -> ReflectOwned
fn reflect_owned(self: Box<BorderColor>) -> ReflectOwned
Returns an owned enumeration of “kinds” of type. Read more
Source§fn try_into_reflect(
self: Box<BorderColor>,
) -> Result<Box<dyn Reflect>, Box<dyn PartialReflect>>
fn try_into_reflect( self: Box<BorderColor>, ) -> 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<BorderColor>) -> Box<dyn PartialReflect>
fn into_partial_reflect(self: Box<BorderColor>) -> 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 reflect_partial_cmp(
&self,
value: &(dyn PartialReflect + 'static),
) -> Option<Ordering>
fn reflect_partial_cmp( &self, value: &(dyn PartialReflect + 'static), ) -> Option<Ordering>
Returns a “partial 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.Source§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 BorderColor
impl Reflect for BorderColor
Source§fn into_any(self: Box<BorderColor>) -> Box<dyn Any>
fn into_any(self: Box<BorderColor>) -> 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<BorderColor>) -> Box<dyn Reflect>
fn into_reflect(self: Box<BorderColor>) -> 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 BorderColor
impl Serialize for BorderColor
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 BorderColor
impl Struct for BorderColor
Source§fn field(&self, name: &str) -> Option<&(dyn PartialReflect + 'static)>
fn field(&self, name: &str) -> Option<&(dyn PartialReflect + 'static)>
Gets 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)>
Gets 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)>
Gets 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)>
Gets a mutable reference to the value of the field with index
index
as a &mut dyn PartialReflect.Source§fn index_of_name(&self, name: &str) -> Option<usize>
fn index_of_name(&self, name: &str) -> Option<usize>
Gets the index of the field with the given name.
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.impl StructuralPartialEq for BorderColor
Source§impl TypePath for BorderColor
impl TypePath for BorderColor
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>
Auto Trait Implementations§
impl Freeze for BorderColor
impl RefUnwindSafe for BorderColor
impl Send for BorderColor
impl Sync for BorderColor
impl Unpin for BorderColor
impl UnsafeUnpin for BorderColor
impl UnwindSafe for BorderColor
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
impl<T> Brush for T
Source§impl<C> Bundle for Cwhere
C: Component,
impl<C> Bundle for Cwhere
C: Component,
fn component_ids( components: &mut ComponentsRegistrator<'_>, ) -> impl Iterator<Item = ComponentId> + use<C>
Source§fn get_component_ids(
components: &Components,
) -> impl Iterator<Item = Option<ComponentId>>
fn get_component_ids( components: &Components, ) -> impl Iterator<Item = Option<ComponentId>>
Source§impl<C> BundleFromComponents for Cwhere
C: Component,
impl<C> BundleFromComponents for Cwhere
C: Component,
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ConditionalSend for Twhere
T: Send,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<C> DynamicBundle for Cwhere
C: Component,
impl<C> DynamicBundle for Cwhere
C: Component,
Source§unsafe fn get_components(
ptr: MovingPtr<'_, C>,
func: &mut impl FnMut(StorageType, OwningPtr<'_>),
) -> <C as DynamicBundle>::Effect
unsafe fn get_components( ptr: MovingPtr<'_, C>, func: &mut impl FnMut(StorageType, OwningPtr<'_>), ) -> <C as DynamicBundle>::Effect
Moves the components out of the bundle. Read more
Source§unsafe fn apply_effect(
_ptr: MovingPtr<'_, MaybeUninit<C>>,
_entity: &mut EntityWorldMut<'_>,
)
unsafe fn apply_effect( _ptr: MovingPtr<'_, MaybeUninit<C>>, _entity: &mut EntityWorldMut<'_>, )
Applies the after-effects of spawning this bundle. Read more
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> ErasedBundleTemplate for T
impl<T> ErasedBundleTemplate for T
Source§unsafe fn apply(
&self,
context: &mut TemplateContext<'_, '_>,
) -> Result<(), BevyError>
unsafe fn apply( &self, context: &mut TemplateContext<'_, '_>, ) -> Result<(), BevyError>
Applies this template to the given
entity. Read moreSource§fn clone_template(&self) -> Box<dyn ErasedBundleTemplate>
fn clone_template(&self) -> Box<dyn ErasedBundleTemplate>
Clones this template. See
Clone.Source§impl<T> ErasedComponentTemplate for T
impl<T> ErasedComponentTemplate for T
Source§unsafe fn apply(
&self,
context: &mut TemplateContext<'_, '_>,
bundle_writer: &mut BundleWriter<'_>,
) -> Result<(), BevyError>
unsafe fn apply( &self, context: &mut TemplateContext<'_, '_>, bundle_writer: &mut BundleWriter<'_>, ) -> Result<(), BevyError>
Applies this template to the given
entity. Read moreSource§fn clone_template(&self) -> Box<dyn ErasedComponentTemplate>
fn clone_template(&self) -> Box<dyn ErasedComponentTemplate>
Clones this template. See
Clone.impl<T> ErasedDestructor for Twhere
T: 'static,
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> FromTemplate for T
impl<T> FromTemplate for T
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,
impl<T> HitDataExtra for T
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<G> PatchFromTemplate for Gwhere
G: FromTemplate,
impl<G> PatchFromTemplate for Gwhere
G: FromTemplate,
Source§fn patch<F>(func: F) -> TemplatePatch<F, <G as PatchFromTemplate>::Template>
fn patch<F>(func: F) -> TemplatePatch<F, <G as PatchFromTemplate>::Template>
Takes a “patch function”
func, and turns it into a TemplatePatch.Source§impl<T> PatchTemplate for Twhere
T: Template,
impl<T> PatchTemplate for Twhere
T: Template,
Source§fn patch_template<F>(func: F) -> TemplatePatch<F, T>
fn patch_template<F>(func: F) -> TemplatePatch<F, 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.impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
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().impl<T> Reflectable for T
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>
impl<T> Settings for T
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> Template for T
impl<T> Template for T
Source§fn build_template(
&self,
_context: &mut TemplateContext<'_, '_>,
) -> Result<<T as Template>::Output, BevyError>
fn build_template( &self, _context: &mut TemplateContext<'_, '_>, ) -> Result<<T as Template>::Output, BevyError>
Uses this template and the given
entity context to produce a Template::Output.Source§fn clone_template(&self) -> T
fn clone_template(&self) -> T
Clones this template. See
Clone.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.