StarArawn / kayak_ui

Other
471 stars 50 forks source link

Can't render multiple images in Kayak App #192

Closed ThousandthStar closed 1 year ago

ThousandthStar commented 1 year ago

When using this rsx! UI, the second image doesn't render (I tried two nine-patches as well):


<KayakAppBundle>

                    <NinePatchBundle
                        nine_patch = {NinePatch{
                            handle: ui_bg_image.clone(),
                            ..Default::default()
                        }}
                        styles = {KStyle{
                            width: StyleProp::Value(Units::Pixels(tile_size.0 * 5.0)),
                            height: StyleProp::Value(Units::Pixels(tile_size.0 * 9.0)),
                            ..KStyle::default()
                        }}
                    >
                        <TextWidgetBundle
                            text={TextProps {
                                content: "8bit Duels".into(),
                                size: 20.0,
                                user_styles: KStyle{
                                    color: StyleProp::Value(Color::hex("a05e5e").unwrap_or(Color::BLACK)),
                                    offset: StyleProp::Value(Edge::axis(Units::Pixels(tile_size.0 * 1.35), Units::Pixels(tile_size.0))),
                                    ..KStyle::default()
                                },
                                ..Default::default()
                            }}
                        />
                    </NinePatchBundle>
                    <KImageBundle
                        image = {KImage(ui_bg_image)}
                        styles = {KStyle{
                            offset: StyleProp::Value(Edge::new(
                                Units::Auto,
                                Units::Pixels(tile_size.0 * 10.0),
                                Units::Auto,
                                Units::Auto
                            )),
                            ..KStyle::default()
                        }}
                    />
        </KayakAppBundle>

I really have no idea what is going on here. Any help is appreciated. The full code is here https://github.com/ThousandthStar/8bit-duels

StarArawn commented 1 year ago

I wasn't able to reproduce this in the main menu example here: https://github.com/StarArawn/kayak_ui/blob/main/examples/main_menu.rs This uses multiple images. I'll try to pull your repo and give it a go when I get a chance.

ThousandthStar commented 1 year ago

Looking at that example, the problem may be that I am not giving the KImageBundle styles a width and height property.

ThousandthStar commented 1 year ago

I also tried using two nine patches inside a larger nine patch but that still didn't work.

StarArawn commented 1 year ago

I also tried using two nine patches inside a larger nine patch but that still didn't work.

Thanks I'll take a look shortly.

ThousandthStar commented 1 year ago

@StarArawn got it to work after all! The problem was that I had an image that was the height of the screen, so my other image was rendered below the screen. The simple solution was to add an offset value to the KStyle of my nine patch, with the top value being negative. It works now, wasn't a bug.