Skip to main content

Hovered

Struct Hovered 

Source
pub struct Hovered(pub bool);
Expand description

A component that allows users to use regular Bevy change detection to determine when the pointer enters or leaves an entity. Users should insert this component on an entity to indicate interest in knowing about hover state changes.

The component’s boolean value will be true whenever the pointer is currently directly hovering over the entity, or any of the entity’s descendants (as defined by the ChildOf relationship). This is consistent with the behavior of the CSS :hover pseudo-class, which applies to the element and all of its descendants.

The contained boolean value is guaranteed to only be mutated when the pointer enters or leaves the entity, allowing Bevy change detection to be used efficiently. This is in contrast to the HoverMap resource, which is updated every frame.

Typically, a simple hoverable entity or widget will have this component added to it. More complex widgets can have this component added to each hoverable part.

The computational cost of keeping the Hovered components up to date is relatively cheap, and linear in the number of entities that have the Hovered component inserted.

Tuple Fields§

§0: bool

Implementations§

Source§

impl Hovered

Source

pub fn get(&self) -> bool

Get whether the entity is currently hovered.

Examples found in repository?
examples/ui/widgets/standard_widgets.rs (line 295)
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}
868
869fn menu_item(asset_server: &AssetServer) -> impl Bundle {
870    (
871        Node {
872            padding: UiRect::axes(px(8), px(2)),
873            justify_content: JustifyContent::Center,
874            align_items: AlignItems::Start,
875            ..default()
876        },
877        DemoMenuItem,
878        MenuItem,
879        Hovered::default(),
880        TabIndex(0),
881        BackgroundColor(NORMAL_BUTTON),
882        children![(
883            Text::new("Menu Item"),
884            TextFont {
885                font: asset_server.load("fonts/FiraSans-Bold.ttf").into(),
886                font_size: FontSize::Px(33.0),
887                ..default()
888            },
889            TextColor(Color::srgb(0.9, 0.9, 0.9)),
890            TextShadow::default(),
891        )],
892    )
893}
894
895fn update_menu_item_style(
896    mut buttons: Query<
897        (
898            Has<Pressed>,
899            &Hovered,
900            Has<InteractionDisabled>,
901            &mut BackgroundColor,
902        ),
903        (
904            Or<(
905                Changed<Pressed>,
906                Changed<Hovered>,
907                Added<InteractionDisabled>,
908            )>,
909            With<DemoMenuItem>,
910        ),
911    >,
912) {
913    for (pressed, hovered, disabled, mut color) in &mut buttons {
914        set_menu_item_style(disabled, hovered.get(), pressed, &mut color);
915    }
916}
917
918/// Supplementary system to detect removed marker components
919fn update_menu_item_style2(
920    mut buttons: Query<
921        (
922            Has<Pressed>,
923            &Hovered,
924            Has<InteractionDisabled>,
925            &mut BackgroundColor,
926        ),
927        With<DemoMenuItem>,
928    >,
929    mut removed_depressed: RemovedComponents<Pressed>,
930    mut removed_disabled: RemovedComponents<InteractionDisabled>,
931) {
932    removed_depressed
933        .read()
934        .chain(removed_disabled.read())
935        .for_each(|entity| {
936            if let Ok((pressed, hovered, disabled, mut color)) = buttons.get_mut(entity) {
937                set_menu_item_style(disabled, hovered.get(), pressed, &mut color);
938            }
939        });
940}
More examples
Hide additional examples
examples/ui/widgets/standard_widgets_observers.rs (line 177)
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}

Trait Implementations§

Source§

impl Clone for Hovered

Source§

fn clone(&self) -> Hovered

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Component for Hovered
where Hovered: Send + Sync + 'static,

Source§

const STORAGE_TYPE: StorageType = bevy_ecs::component::StorageType::Table

A constant indicating the storage type used for this component.
Source§

type Mutability = Immutable

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 more
Source§

fn register_required_components( _requiree: ComponentId, required_components: &mut RequiredComponentsRegistrator<'_, '_>, )

Registers required components. Read more
Source§

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<Hovered>>

Returns ComponentRelationshipAccessor required for working with relationships in dynamic contexts. Read more
Source§

fn on_add() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_add ComponentHook for this Component if one is defined.
Source§

fn on_insert() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_insert ComponentHook for this Component if one is defined.
Source§

fn on_discard() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_discard ComponentHook for this Component if one is defined.
Source§

fn on_remove() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_remove ComponentHook for this Component if one is defined.
Source§

fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_despawn ComponentHook for this Component if one is defined.
Source§

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 more
Source§

impl Copy for Hovered

Source§

impl Debug for Hovered

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for Hovered

Source§

fn default() -> Hovered

Returns the “default value” for a type. Read more
Source§

impl Eq for Hovered

Source§

impl FromArg for Hovered

Source§

type This<'from_arg> = Hovered

The type to convert into. Read more
Source§

fn from_arg(arg: Arg<'_>) -> Result<<Hovered as FromArg>::This<'_>, ArgError>

Creates an item from an argument. Read more
Source§

impl FromReflect for Hovered

Source§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<Hovered>

Constructs a concrete instance of Self from a reflected value.
Source§

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 more
Source§

impl GetOwnership for Hovered

Source§

fn ownership() -> Ownership

Returns the ownership of Self.
Source§

impl GetTypeRegistration for Hovered

Source§

fn get_type_registration() -> TypeRegistration

Returns the default TypeRegistration for this type.
Source§

fn register_type_dependencies(registry: &mut TypeRegistry)

Registers other types needed by this type. Read more
Source§

impl IntoReturn for Hovered

Source§

fn into_return<'into_return>(self) -> Return<'into_return>
where Hovered: 'into_return,

Converts Self into a Return value.
Source§

impl PartialEq for Hovered

Source§

fn eq(&self, other: &Hovered) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialReflect for Hovered

Source§

fn get_represented_type_info(&self) -> Option<&'static TypeInfo>

Returns the TypeInfo of the type represented by this value. Read more
Source§

fn try_apply( &mut self, value: &(dyn PartialReflect + 'static), ) -> Result<(), ApplyError>

Tries to apply a reflected value to this value. Read more
Source§

fn reflect_kind(&self) -> ReflectKind

Returns a zero-sized enumeration of “kinds” of type. Read more
Source§

fn reflect_ref(&self) -> ReflectRef<'_>

Returns an immutable enumeration of “kinds” of type. Read more
Source§

fn reflect_mut(&mut self) -> ReflectMut<'_>

Returns a mutable enumeration of “kinds” of type. Read more
Source§

fn reflect_owned(self: Box<Hovered>) -> ReflectOwned

Returns an owned enumeration of “kinds” of type. Read more
Source§

fn try_into_reflect( self: Box<Hovered>, ) -> 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)>

Attempts to cast this type to a fully-reflected value.
Source§

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<Hovered>) -> Box<dyn PartialReflect>

Casts this type to a boxed, reflected value. Read more
Source§

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)

Casts this type to a mutable, reflected value. Read more
Source§

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>

Returns a “partial comparison” result. Read more
Source§

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>

Attempts to clone Self using reflection. Read more
Source§

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>

Converts this reflected value into its dynamic representation based on its kind. Read more
Source§

fn reflect_clone_and_take<T>(&self) -> Result<T, ReflectCloneError>
where T: 'static, Self: Sized + TypePath,

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>

Returns a hash of the value (which includes the type). Read more
Source§

fn is_dynamic(&self) -> bool

Indicates whether or not this type is a dynamic type. Read more
Source§

impl Reflect for Hovered

Source§

fn into_any(self: Box<Hovered>) -> Box<dyn Any>

Returns the value as a Box<dyn Any>. Read more
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Returns the value as a &dyn Any. Read more
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Returns the value as a &mut dyn Any. Read more
Source§

fn into_reflect(self: Box<Hovered>) -> Box<dyn Reflect>

Casts this type to a boxed, fully-reflected value.
Source§

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)

Casts this type to a mutable, fully-reflected value.
Source§

fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>>

Performs a type-checked assignment of a reflected value to this value. Read more
Source§

impl StructuralPartialEq for Hovered

Source§

impl TupleStruct for Hovered

Source§

fn field(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>

Returns a reference to the value of the field with index index as a &dyn Reflect.
Source§

fn field_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 Reflect.
Source§

fn field_len(&self) -> usize

Returns the number of fields in the tuple struct.
Source§

fn iter_fields(&self) -> TupleStructFieldIter<'_>

Returns an iterator over the values of the tuple struct’s fields.
Source§

fn to_dynamic_tuple_struct(&self) -> DynamicTupleStruct

Creates a new DynamicTupleStruct from this tuple struct.
Source§

fn get_represented_tuple_struct_info(&self) -> Option<&'static TupleStructInfo>

Will return None if TypeInfo is not available.
Source§

impl TypePath for Hovered

Source§

fn type_path() -> &'static str

Returns the fully qualified path of the underlying type. Read more
Source§

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>

Returns the name of the type, or None if it is anonymous. Read more
Source§

fn crate_name() -> Option<&'static str>

Returns the name of the crate the type is in, or None if it is anonymous. Read more
Source§

fn module_path() -> Option<&'static str>

Returns the path to the module the type is in, or None if it is anonymous. Read more
Source§

impl Typed for Hovered

Source§

fn type_info() -> &'static TypeInfo

Returns the compile-time info for the underlying type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T, U> AsBindGroupShaderType<U> for T
where U: ShaderType, &'a T: for<'a> Into<U>,

Source§

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> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Brush for T
where T: Clone + PartialEq + Default + Debug,

Source§

impl<C> Bundle for C
where C: Component,

Source§

fn component_ids( components: &mut ComponentsRegistrator<'_>, ) -> impl Iterator<Item = ComponentId> + use<C>

Source§

fn get_component_ids( components: &Components, ) -> impl Iterator<Item = Option<ComponentId>>

Return a iterator over this Bundle’s component ids. This will be None if the component has not been registered.
Source§

impl<C> BundleFromComponents for C
where C: Component,

Source§

unsafe fn from_components<T, F>(ctx: &mut T, func: &mut F) -> C
where F: for<'a> FnMut(&'a mut T) -> OwningPtr<'a>, C: Sized,

Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ConditionalSend for T
where T: Send,

Source§

impl<T> Conv for T

Source§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

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>

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)

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)

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 T
where T: Any,

Source§

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>

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)

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)

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
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> DynEq for T
where T: Any + Eq,

Source§

fn dyn_eq(&self, other: &(dyn DynEq + 'static)) -> bool

This method tests for self and other values to be equal. Read more
Source§

impl<C> DynamicBundle for C
where C: Component,

Source§

type Effect = ()

An operation on the entity that happens after inserting this bundle.
Source§

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<'_>, )

Applies the after-effects of spawning this bundle. Read more
Source§

impl<T> DynamicTypePath for T
where T: TypePath,

Source§

impl<T> DynamicTyped for T
where T: Typed,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> ErasedBundleTemplate for T
where T: Template + Send + Sync + 'static, <T as Template>::Output: Bundle,

Source§

unsafe fn apply( &self, context: &mut TemplateContext<'_, '_>, ) -> Result<(), BevyError>

Applies this template to the given entity. Read more
Source§

fn clone_template(&self) -> Box<dyn ErasedBundleTemplate>

Clones this template. See Clone.
Source§

impl<T> ErasedComponentTemplate for T
where T: Template + Send + Sync + 'static, <T as Template>::Output: Component,

Source§

unsafe fn apply( &self, context: &mut TemplateContext<'_, '_>, bundle_writer: &mut BundleWriter<'_>, ) -> Result<(), BevyError>

Applies this template to the given entity. Read more
Source§

fn clone_template(&self) -> Box<dyn ErasedComponentTemplate>

Clones this template. See Clone.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> FmtForward for T

Source§

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,

Causes self to use its Display implementation when Debug-formatted.
Source§

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,

Causes self to use its LowerHex implementation when Debug-formatted.
Source§

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,

Causes self to use its Pointer implementation when Debug-formatted.
Source§

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,

Causes self to use its UpperHex implementation when Debug-formatted.
Source§

fn fmt_list(self) -> FmtList<Self>
where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> FromTemplate for T
where T: Clone + Default + Unpin,

Source§

type Template = T

The Template for this type.
Source§

impl<T> FromWorld for T
where T: Default,

Source§

fn from_world(_world: &mut World) -> T

Creates Self using default().

Source§

impl<T> GetPath for T
where T: Reflect + ?Sized,

Source§

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 more
Source§

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 more
Source§

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 more
Source§

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 more
Source§

impl<S> GetTupleStructField for S
where S: TupleStruct,

Source§

fn get_field<T>(&self, index: usize) -> Option<&T>
where T: Reflect,

Returns a reference to the value of the field with index index, downcast to T.
Source§

fn get_field_mut<T>(&mut self, index: usize) -> Option<&mut T>
where T: Reflect,

Returns a mutable reference to the value of the field with index index, downcast to T.
Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

impl<T> HitDataExtra for T
where T: Send + Sync + Debug + Any + 'static,

Source§

impl<T> Identity for T
where T: ?Sized,

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
Source§

impl<T> InitializeFromFunction<T> for T

Source§

fn initialize_from_function(f: fn() -> T) -> T

Create an instance of this type from an initialization function
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
Source§

impl<T> IntoResult<T> for T

Source§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<A> Is for A
where A: Any,

Source§

fn is<T>() -> bool
where T: Any,

Checks if the current type “is” another type, using a TypeId equality comparison. This is most useful in the context of generic logic. Read more
Source§

impl<T> NoneValue for T
where T: Default,

Source§

type NoneType = T

Source§

fn null_value() -> T

The none-equivalent value.
Source§

impl<G> PatchFromTemplate for G
where G: FromTemplate,

Source§

type Template = <G as FromTemplate>::Template

The Template that will be patched.
Source§

fn patch<F>(func: F) -> TemplatePatch<F, <G as PatchFromTemplate>::Template>
where F: FnOnce(&mut <G as PatchFromTemplate>::Template, &mut ResolveContext<'_>),

Takes a “patch function” func, and turns it into a TemplatePatch.
Source§

impl<T> PatchTemplate for T
where T: Template,

Source§

fn patch_template<F>(func: F) -> TemplatePatch<F, T>
where F: FnOnce(&mut T, &mut ResolveContext<'_>),

Takes a “patch function” func that patches this Template, and turns it into a TemplatePatch.
Source§

impl<T> Pipe for T
where T: ?Sized,

Source§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where 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) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
Source§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Source§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

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
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

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
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
Source§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

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§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Reflectable for T

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Settings for T
where T: 'static + Send + Sync,

Source§

impl<Ret> SpawnIfAsync<(), Ret> for Ret

Source§

fn spawn(self) -> Ret

Spawn the value into the dioxus runtime if it is an async block
Source§

impl<T, O> SuperFrom<T> for O
where O: From<T>,

Source§

fn super_from(input: T) -> O

Convert from a type to another type.
Source§

impl<T, O, M> SuperInto<O, M> for T
where O: SuperFrom<T, M>,

Source§

fn super_into(self) -> O

Convert from a type to another type.
Source§

impl<T> Tap for T

Source§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
Source§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
Source§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
Source§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
Source§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
Source§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
Source§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
Source§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
Source§

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

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
where Self: Borrow<B>, B: ?Sized,

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
where Self: BorrowMut<B>, B: ?Sized,

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
where Self: AsRef<R>, R: ?Sized,

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
where Self: AsMut<R>, R: ?Sized,

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
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
Source§

impl<T> Template for T
where T: Clone + Default + Unpin,

Source§

type Output = T

The type of value produced by this Template.
Source§

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

Clones this template. See Clone.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T> TryConv for T

Source§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> TypeData for T
where T: 'static + Send + Sync + Clone,

Source§

fn clone_type_data(&self) -> Box<dyn TypeData>

Creates a type-erased clone of this value.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more