pub fn build(mut self, mut res: UiButtonBuilderResources) -> Entity {
        // unwraps are safe because we create the entities inside
        let mut id = self.name.clone();
        let image_entity = res.entities.create();
        res.transform
            .insert(
                image_entity,
                UiTransform::new(
                    self.name,
                    self.anchor,
                    self.x,
                    self.y,
                    self.z,
                    self.width,
                    self.height,
                    self.tab_order,
                ).with_stretch(self.stretch),
            )
            .unwrap();
        let image_handle = self.image.unwrap_or_else(|| {
            res.loader
                .load_from_data(DEFAULT_BKGD_COLOR.into(), (), &res.texture_asset)
        });

        res.image
            .insert(
                image_entity,
                UiImage {
                    texture: image_handle.clone(),
                },
            )
            .unwrap();
        res.mouse_reactive
            .insert(image_entity, MouseReactive)
            .unwrap();
        if let Some(parent) = self.parent.take() {
            res.parent
                .insert(image_entity, Parent { entity: parent })
                .unwrap();
        }

        id.push_str("_btn_txt");
        let text_entity = res.entities.create();
        res.transform
            .insert(
                text_entity,
                UiTransform::new(id, Anchor::Middle, 0., 0., -0.01, 0., 0., 10)
                    .as_transparent()
                    .with_stretch(Stretch::XY {
                        x_margin: 0.,
                        y_margin: 0.,
                    }),
            )
            .unwrap();
        let font_handle = self.font.unwrap_or_else(|| {
            res.loader.load(
                DEFAULT_FONT_NAME,
                TtfFormat,
                Default::default(),
                (),
                &res.font_asset,
            )
        });
        res.text
            .insert(
                text_entity,
                UiText::new(font_handle, self.text, self.text_color, self.font_size),
            )
            .unwrap();
        res.parent
            .insert(
                text_entity,
                Parent {
                    entity: image_entity,
                },
            )
            .unwrap();

        res.button
            .insert(
                image_entity,
                UiButton {
                    normal_text_color: self.text_color,
                    hover_text_color: self.hover_text_color,
                    press_text_color: self.press_text_color,
                },
            )
            .unwrap();
        if self.hover_image.is_some() || self.press_image.is_some() {
            res.action_image
                .insert(
                    image_entity,
                    OnUiActionImage::new(Some(image_handle), self.hover_image, self.press_image),
                )
                .unwrap();
        }

        if self.hover_sound.is_some() || self.press_sound.is_some() || self.release_sound.is_some()
        {
            res.action_sound
                .insert(
                    image_entity,
                    OnUiActionSound::new(self.hover_sound, self.press_sound, self.release_sound),
                )
                .unwrap();
        }
        image_entity
    }
/// Build this with the `UiButtonBuilderResources`.    
Build this with the `UiButtonBuilderResources`.
Build this with the ` UiButtonBuilderResources ` .
pub fn build(mut self, mut res: UiButtonBuilderResources) -> Entity {
        // unwraps are safe because we create the entities inside
        let mut id = self.name.clone();
        let image_entity = res.entities.create();
        res.transform
            .insert(
                image_entity,
                UiTransform::new(
                    self.name,
                    self.anchor,
                    self.x,
                    self.y,
                    self.z,
                    self.width,
                    self.height,
                    self.tab_order,
                ).with_stretch(self.stretch),
            )
            .unwrap();
        let image_handle = self.image.unwrap_or_else(|| {
            res.loader
                .load_from_data(DEFAULT_BKGD_COLOR.into(), (), &res.texture_asset)
        });
        res.image
            .insert(
                image_entity,
                UiImage {
                    texture: image_handle.clone(),
                },
            )
            .unwrap();
        res.mouse_reactive
            .insert(image_entity, MouseReactive)
            .unwrap();
        if let Some(parent) = self.parent.take() {
            res.parent
                .insert(image_entity, Parent { entity: parent })
                .unwrap();
        }
        id.push_str("_btn_txt");
        let text_entity = res.entities.create();
        res.transform
            .insert(
                text_entity,
                UiTransform::new(id, Anchor::Middle, 0., 0., -0.01, 0., 0., 10)
                    .as_transparent()
                    .with_stretch(Stretch::XY {
                        x_margin: 0.,
                        y_margin: 0.,
                    }),
            )
            .unwrap();
        let font_handle = self.font.unwrap_or_else(|| {
            res.loader.load(
                DEFAULT_FONT_NAME,
                TtfFormat,
                Default::default(),
                (),
                &res.font_asset,
            )
        });
        res.text
            .insert(
                text_entity,
                UiText::new(font_handle, self.text, self.text_color, self.font_size),
            )
            .unwrap();
        res.parent
            .insert(
                text_entity,
                Parent {
                    entity: image_entity,
                },
            )
            .unwrap();
        res.button
            .insert(
                image_entity,
                UiButton {
                    normal_text_color: self.text_color,
                    hover_text_color: self.hover_text_color,
                    press_text_color: self.press_text_color,
                },
            )
            .unwrap();
        if self.hover_image.is_some() || self.press_image.is_some() {
            res.action_image
                .insert(
                    image_entity,
                    OnUiActionImage::new(Some(image_handle), self.hover_image, self.press_image),
                )
                .unwrap();
        }
        if self.hover_sound.is_some() || self.press_sound.is_some() || self.release_sound.is_some()
        {
            res.action_sound
                .insert(
                    image_entity,
                    OnUiActionSound::new(self.hover_sound, self.press_sound, self.release_sound),
                )
                .unwrap();
        }
        image_entity
    }
pub fn build ( mut self , mut res : UiButtonBuilderResources ) -> Entity { // unwraps are safe because we create the entities inside let mut id = self . name . clone ( ) ; let image_entity = res . entities . create ( ) ; res . transform . insert ( image_entity , UiTransform :: new ( self . name , self . anchor , self . x , self . y , self . z , self . width , self . height , self . tab_order , ) . with_stretch ( self . stretch ) , ) . unwrap ( ) ; let image_handle = self . image . unwrap_or_else ( | | { res . loader . load_from_data ( DEFAULT_BKGD_COLOR . into ( ) , ( ) , & res . texture_asset ) } ) ; res . image . insert ( image_entity , UiImage { texture : image_handle . clone ( ) , } , ) . unwrap ( ) ; res . mouse_reactive . insert ( image_entity , MouseReactive ) . unwrap ( ) ; if let Some ( parent ) = self . parent . take ( ) { res . parent . insert ( image_entity , Parent { entity : parent } ) . unwrap ( ) ; } id . push_str ( " " ) ; let text_entity = res . entities . create ( ) ; res . transform . insert ( text_entity , UiTransform :: new ( id , Anchor :: Middle , 0. , 0. , - 0.01 , 0. , 0. , 10 ) . as_transparent ( ) . with_stretch ( Stretch :: XY { x_margin : 0. , y_margin : 0. , } ) , ) . unwrap ( ) ; let font_handle = self . font . unwrap_or_else ( | | { res . loader . load ( DEFAULT_FONT_NAME , TtfFormat , Default :: default ( ) , ( ) , & res . font_asset , ) } ) ; res . text . insert ( text_entity , UiText :: new ( font_handle , self . text , self . text_color , self . font_size ) , ) . unwrap ( ) ; res . parent . insert ( text_entity , Parent { entity : image_entity , } , ) . unwrap ( ) ; res . button . insert ( image_entity , UiButton { normal_text_color : self . text_color , hover_text_color : self . hover_text_color , press_text_color : self . press_text_color , } , ) . unwrap ( ) ; if self . hover_image . is_some ( ) || self . press_image . is_some ( ) { res . action_image . insert ( image_entity , OnUiActionImage :: new ( Some ( image_handle ) , self . hover_image , self . press_image ) , ) . unwrap ( ) ; } if self . hover_sound . is_some ( ) || self . press_sound . is_some ( ) || self . release_sound . is_some ( ) { res . action_sound . insert ( image_entity , OnUiActionSound :: new ( self . hover_sound , self . press_sound , self . release_sound ) , ) . unwrap ( ) ; } image_entity }
Build this with the `UiButtonBuilderResources`.
Build this with the ` UiButtonBuilderResources ` .
mut self
res
UiButtonBuilderResources
mut self
res
UiButtonBuilderResources