UI Screens for BevyEngine

version downloads

This is a little thing I put together for creating simple UI screens using the BevyEngine. The idea is to define the screens in a sort of poor-man's markup and this crate will then provide some functions to create the UI 'widgets'.

For example, the following in a file will create a screen looking like:

sample_picture

with the code: ```sh // startupsystem fn setup( mut commands: Commands, assetserver: Res, materials: ResMut> ) { commands.spawnbundle(OrthographicCameraBundle::new2d()); commands.spawn_bundle(UiCameraBundle::default());

let controls = gerg_ui::instantiate_controls_from_file("screen1.ui");
let _entities = gerg_ui::spawn_controls(&mut commands, asset_server, materials, controls, Vec2::new(1920.0, 1080.0), String::from("screen1.ui"));

}

// buttonclicksystem fn closebuttonclicksystem( mut commands: Commands, buttonclickedquery: Query<(Entity, &GergButton, &GergControl), With>, allcontrolsquery: Query<(Entity, &GergControl)> ) { for (entity, button, control) in buttonclickedquery.iter() { println!("Hey, a button was clicked! - {} - {}", button.name, control.groupname);

    commands.entity(entity).remove::<ButtonClicked>();

    if button.name == "close_button" {
        for (entity, control) in all_controls_query.iter() {
            if control.group_name == "screen1.ui" {
                commands.entity(entity).insert(DestroyControl);
            }
        }
    }
}

}

// textchangesystem fn changetextsystem( diagnostics: Res, mut query: Query<(&mut Text, &GergLabel), With> ) { for (mut text, label) in query.itermut() { if label.name == "label1" { let mut fps = 0.0; if let Some(fpsdiagnostic) = diagnostics.get(FrameTimeDiagnosticsPlugin::FPS) { if let Some(fpsavg) = fpsdiagnostic.average() { fps = fps_avg; } }

        text.sections[0].value = format!("FPS: {:.1}", fps);
    }
}

} ```

```sh --globalsettings-- fontname: CrimsonText-Regular.ttf // mandatory font_size: 30 // defaults to 20 if missing color: 255;255;255 // defaults to WHITE if missing --end--

--picturebox-- name: frame1 texturename: bigframe.png // mandatory size: 1200;782 // mandatory //centerposition: 0;0 // middle of screen is 0;0, defaults to 0;0 if missing, but dockwith will override draworder: 0 // optional, defaults to 0 if missing dockwith: screen.topleft<->this.top_left offset: 10;-80 --end--

--picturebox-- name: heading texturename: bigheading.png size: 1200;76 draworder: 0.1 dockwith: frame1.topmiddle<->this.bottom_middle offset: 0;-1 --end--

--button-- name: closebutton texturenamenormal: closebuttonn.png // mandatory texturenamehover: closebuttonh.png // optional, will use texturenamenormal if missing texturenameactive: closebuttona.png // optional, will use texturenamenormal if missing texturenamedisabled: closebuttonn.png // optional, will use texturenamenormal if missing onclicksound: audio/mouseclick1.mp3 // optional, will play no sound on click if missing size: 43;44 // mandatory boundingbox: 0;0;43;44 // optional, will use size of texture if missing boundingcircle: 0;0;20 // optional, will use boundingbox if missing draworder: 0.2 // defaults to 0 if missing dockwith: heading.topright<->this.topright offset: -7;-7 --end--

--picturebox-- name: panelinner texturename: innerframe.png size: 556;740 draworder: 0.3 dockwith: frame1.centerleft<->this.centerleft offset: 20;0 color: BLUE --end--

--label-- name: label1 size: 200;50 // mandatory textstring: FPS: // mandatory fontname: CrimsonText-Regular.ttf // optional, will use globalsettings if missing fontsize: 50 // optional, will use globalsettings if missing color: CYAN // optional, will use globalsettings if missing statictext: false // optional, defaults to false if missing dockwith: panelinner.topleft<->this.top_left offset: 15;-15 --end-- ```