Can't set button color

206 Views Asked by At

Based on this UI example I've add a custom button at the end of on_start method. But when I run the game the button body is invisible, only its text is shown ("1234567").

The code I added to the example:

// ...

use amethyst::assets::AssetStorage;
use amethyst::assets::Handle;
use amethyst::assets::Loader;
use amethyst::renderer::loaders::load_from_srgba;
use amethyst::renderer::palette::Srgba;
use amethyst::renderer::Texture;
use amethyst::renderer::types::TextureData;
use amethyst::ui::Anchor;
use amethyst::ui::UiButtonBuilder;
use amethyst::ui::UiImage;

// ...

impl SimpleState for Example {
    fn on_start(&mut self, data: StateData<'_, GameData<'_, '_>>) {
        // ...

        let texture_handle: Handle<Texture> = {
            let loader = world.read_resource::<Loader>();
            let texture_assets = world.read_resource::<AssetStorage<Texture>>();
            let texture_builder = load_from_srgba(Srgba::new(0.8, 0.6, 0.3, 1.0));
            loader.load_from_data(TextureData::from(texture_builder), (), &texture_assets)
        };

        let button = UiButtonBuilder::<(), u32>::new("1234567".to_string())
            .with_id(666)
            .with_font_size(12.0)
            .with_position(64.0, -64.0)
            .with_size(64.0 * 3.0, 64.0)
            .with_anchor(Anchor::TopMiddle)
            // HAS NO EFFECT
            .with_image(texture_handle)
            // HAS NO EFFECT
            .with_hover_image(UiImage::SolidColor([0.1, 0.1, 0.1, 0.5]))
            .with_layer(12.0)
            .build_from_world(&world);

        world.insert(button);
    }
}

// ...

What is the proper way to create a button on the fly with custom color?

I'm using amethyst v0.15.

enter image description here

1

There are 1 best solutions below

0
On BEST ANSWER

There is a bug with the UiButtonBuilder. I just created this issue: https://github.com/amethyst/amethyst/issues/2298