ui testing
Some checks failed
Rust / build (push) Failing after 4s

This commit is contained in:
2026-03-16 20:31:40 -04:00
parent f9e96cc74b
commit fca907aee4
3 changed files with 65 additions and 23 deletions

View File

@@ -56,8 +56,6 @@ fn setup(mut commands: Commands)
))
.insert(Msaa::Off)
.insert(RenderLayers::default());
// *msaa = Msaa::Off;
}
fn orbit_camera_upate(

View File

@@ -1,5 +1,5 @@
use bevy::{
camera::{visibility::RenderLayers, CameraOutputMode, Viewport},
camera::{visibility::RenderLayers, CameraOutputMode},
prelude::*,
render::render_resource::BlendState,
};
@@ -7,6 +7,8 @@ use shared::states::AssetLoadState;
use crate::ui::states::BuildUIState;
pub struct BuildUIPlugin;
#[derive(Component)]
pub struct BuildUIItem;
impl Plugin for BuildUIPlugin
{
@@ -18,6 +20,7 @@ impl Plugin for BuildUIPlugin
Update,
spawn_ui.run_if(in_state(AssetLoadState::LoadComplete).and(in_state(BuildUIState::Init))),
);
app.add_systems(PostUpdate, cleanup_ui.run_if(in_state(BuildUIState::Cleanup)));
}
}
@@ -58,18 +61,59 @@ fn spawn_ui(mut commands: Commands, mut next_state: ResMut<NextState<BuildUIStat
..default()
},
RenderLayers::layer(1),
Name::new("Build UI Root"),
BuildUIItem,
))
// .insert(PickingBehavior::IGNORE)
.with_children(|parent| {
parent.spawn((
.with_children(|build_root| {
build_root
.spawn((
Name::new("Build UI"),
Node {
width: Val::Px(500.),
height: Val::Px(100.),
..Default::default()
justify_content: JustifyContent::Stretch,
..default()
},
BackgroundColor(LinearRgba::GREEN.into()),
))
.with_children(|build_ui| {
build_ui
.spawn((
Name::new("Toolbar"),
Node {
width: Val::Percent(100.),
height: Val::Px(80.),
padding: UiRect::horizontal(Val::Px(10.)),
justify_content: JustifyContent::Stretch,
..default()
},
BackgroundColor(LinearRgba::BLUE.into()),
))
.with_children(|toolbar| {
for i in 0..6
{
toolbar.spawn((
Name::new(format!("Button {}", i)),
Node {
height: Val::Percent(100.),
width: Val::Auto,
..default()
},
BackgroundColor(LinearRgba::WHITE.into()),
));
}
});
});
});
next_state.set(BuildUIState::Update);
}
fn cleanup_ui(mut commands: Commands, ui_items: Query<Entity, With<BuildUIItem>>)
{
for item in ui_items.iter()
{
commands.entity(item).despawn();
}
}

View File

@@ -1,6 +1,6 @@
use bevy::asset::RenderAssetUsages;
use bevy::prelude::*;
use bevy_inspector_egui::bevy_egui::EguiContexts;
use bevy_inspector_egui::bevy_egui::{EguiContexts, EguiTextureHandle};
use bevy_inspector_egui::egui::{self};
use image::{ImageBuffer, Rgba};
use world_generation::biome_asset::BiomeAsset;
@@ -18,10 +18,10 @@ impl Plugin for EditorPlugin
app.init_resource::<UIState>();
app.add_systems(PostUpdate, prepare_image.run_if(in_state(GeneratorState::SpawnMap)));
app.add_systems(
Update,
(render_map_ui, update_map_render, asset_reloaded).run_if(in_state(GeneratorState::Idle)),
);
// app.add_systems(
// Update,
// (render_map_ui, update_map_render, asset_reloaded).run_if(in_state(GeneratorState::Idle)),
// );
}
}
@@ -92,14 +92,14 @@ fn asset_reloaded(
}
fn render_map_ui(
// image: Res<MapImage>,
image: Res<MapImage>,
heightmap: Res<Map>,
biome_map: Res<BiomeMap>,
mut contexts: EguiContexts,
mut state: ResMut<UIState>,
)
{
// let id = contexts.add_image(image.0.);
let id = contexts.add_image(EguiTextureHandle::Strong(image.0.clone()));
let mut map_type = state.target_map_type;
let ctx = contexts.ctx_mut().expect("Failed to get egui context");
egui::Window::new("Map").open(&mut state.is_open).show(ctx, |ui| {
@@ -127,10 +127,10 @@ fn render_map_ui(
);
});
// ui.add(egui::widgets::Image::new(egui::load::SizedTexture::new(
// id,
// [512.0, 512.0],
// )));
ui.add(egui::widgets::Image::new(egui::load::SizedTexture::new(
id,
[512.0, 512.0],
)));
if ui.button("Save Image").clicked()
{