Skip to main content

WidgetQuery

Trait WidgetQuery 

Source
pub trait WidgetQuery<'w, 's> {
    type WidgetView<'a>
       where Self: 'a;

    // Required methods
    fn find_by_id<'a>(
        &'a mut self,
        target_id: &str,
    ) -> Option<Self::WidgetView<'a>>;
    fn find_by_entity<'a>(
        &'a mut self,
        entity: Entity,
    ) -> Option<Self::WidgetView<'a>>;
    fn find_by_class(&self, target_class: &str) -> Vec<Entity>;
    fn get_components<'a>(
        &'a mut self,
        entity: Entity,
    ) -> Option<Self::WidgetView<'a>>;
}
Expand description

Trait used for widgets system param.

When using widget queries in event handlers that may navigate, use the navigate! macro to automatically exit the function after navigation:

fn on_button_click(
    _click: On<Clicked>,
    mut text_q: TextQuery,
    mut router: ResMut<Router>
) {
    if let Some(mut text) = text_q.find_by_id("status") {
        text.set_text("Navigating...");
    }

    navigate!(router, "next-page", ()); // Function exits here automatically
    // This code will never execute
}

This prevents common issues where loops or code continue executing after navigation:

fn mark_items_complete(
    _click: On<Clicked>,
    mut btn_q: ButtonQuery,
    mut router: ResMut<Router>
) {
    for entity in btn_q.find_by_class("item-btn") {
        if let Some(mut btn) = btn_q.find_by_entity(entity) {
            if btn.text.value.0 == "target_item" {
                btn.class.add_class("completed");
                navigate!(router, "home", ()); // Exits function and loop
            }
        }
    }
}

Required Associated Types§

Source

type WidgetView<'a> where Self: 'a

The specific view struct this query returns (Ex, ButtonWidget, TextWidget).

Required Methods§

Source

fn find_by_id<'a>(&'a mut self, target_id: &str) -> Option<Self::WidgetView<'a>>

Method to find widget by ID.

Source

fn find_by_entity<'a>( &'a mut self, entity: Entity, ) -> Option<Self::WidgetView<'a>>

Method to find widget by Entity.

Source

fn find_by_class(&self, target_class: &str) -> Vec<Entity>

Method to find entities that match with provided classes.

Source

fn get_components<'a>( &'a mut self, entity: Entity, ) -> Option<Self::WidgetView<'a>>

Get related components of an entity.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<'w, 's> WidgetQuery<'w, 's> for ButtonQuery<'w, 's>

Source§

type WidgetView<'a> = ButtonWidget<'a> where Self: 'a

Source§

impl<'w, 's> WidgetQuery<'w, 's> for CheckboxQuery<'w, 's>

Source§

type WidgetView<'a> = CheckboxWidget<'a, 'w, 's> where Self: 'a

Source§

impl<'w, 's> WidgetQuery<'w, 's> for CircularQuery<'w, 's>

Source§

type WidgetView<'a> = CircularWidget<'a, 'w, 's> where Self: 'a

Source§

impl<'w, 's> WidgetQuery<'w, 's> for ColumnQuery<'w, 's>

Source§

type WidgetView<'a> = ColumnWidget<'a, 'w, 's> where Self: 'a

Source§

impl<'w, 's> WidgetQuery<'w, 's> for DropdownQuery<'w, 's>

Source§

type WidgetView<'a> = DropdownWidget<'a> where Self: 'a

Source§

impl<'w, 's> WidgetQuery<'w, 's> for ImageQuery<'w, 's>

Source§

type WidgetView<'a> = ImageWidget<'a, 'w, 's> where Self: 'a

Source§

impl<'w, 's> WidgetQuery<'w, 's> for LinkQuery<'w, 's>

Source§

type WidgetView<'a> = LinkWidget<'a> where Self: 'a

Source§

impl<'w, 's> WidgetQuery<'w, 's> for ModalQuery<'w, 's>

Source§

type WidgetView<'a> = ModalWidget<'a> where Self: 'a

Source§

impl<'w, 's> WidgetQuery<'w, 's> for ProgressBarQuery<'w, 's>

Source§

type WidgetView<'a> = ProgressBarWidget<'a, 'w, 's> where Self: 'a

Source§

impl<'w, 's> WidgetQuery<'w, 's> for RadioGroupQuery<'w, 's>

Source§

type WidgetView<'a> = RadioGroupWidget<'a, 'w, 's> where Self: 'a

Source§

impl<'w, 's> WidgetQuery<'w, 's> for RadioQuery<'w, 's>

Source§

type WidgetView<'a> = RadioWidget<'a, 'w, 's> where Self: 'a

Source§

impl<'w, 's> WidgetQuery<'w, 's> for RootQuery<'w, 's>

Source§

type WidgetView<'a> = RootWidget<'a, 'w, 's> where Self: 'a

Source§

impl<'w, 's> WidgetQuery<'w, 's> for RowQuery<'w, 's>

Source§

type WidgetView<'a> = RowWidget<'a, 'w, 's> where Self: 'a

Source§

impl<'w, 's> WidgetQuery<'w, 's> for ScrollQuery<'w, 's>

Source§

type WidgetView<'a> = ScrollWidget<'a, 'w, 's> where Self: 'a

Source§

impl<'w, 's> WidgetQuery<'w, 's> for SelectQuery<'w, 's>

Source§

type WidgetView<'a> = SelectWidget<'a, 'w, 's> where Self: 'a

Source§

impl<'w, 's> WidgetQuery<'w, 's> for SliderQuery<'w, 's>

Source§

type WidgetView<'a> = SliderWidget<'a, 'w, 's> where Self: 'a

Source§

impl<'w, 's> WidgetQuery<'w, 's> for TextInputQuery<'w, 's>

Source§

type WidgetView<'a> = TextInputWidget<'a, 'w, 's> where Self: 'a

Source§

impl<'w, 's> WidgetQuery<'w, 's> for TextQuery<'w, 's>

Source§

type WidgetView<'a> = TextWidget<'a> where Self: 'a