Upgrade to Bevy 0.19 and harden editor workflows
CI / Format, lint, test, build (push) Has been cancelled
CI / Format, lint, test, build (push) Has been cancelled
This commit is contained in:
1 parent
3f85d25cc7
commit
b5e561904c
204 files changed
+6972
-29907
No files matched your search
@@ -897,6 +897,10 @@ fn visible_assets(
|
||||
rows
|
||||
}
|
||||
|
||||
#[expect(
|
||||
clippy::too_many_arguments,
|
||||
reason = "asset grid rendering keeps immediate-mode UI inputs explicit"
|
||||
)]
|
||||
fn asset_grid(
|
||||
world: &mut World,
|
||||
ui: &mut egui::Ui,
|
||||
@@ -1169,6 +1173,10 @@ fn prefetch_embedded_thumbnails(
|
||||
});
|
||||
}
|
||||
|
||||
#[expect(
|
||||
clippy::too_many_arguments,
|
||||
reason = "embedded asset rendering keeps immediate-mode UI inputs explicit"
|
||||
)]
|
||||
fn draw_embedded_asset_cell(
|
||||
world: &mut World,
|
||||
ui: &mut egui::Ui,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Dock tab open/focus helpers and default panel node placement.
|
||||
|
||||
use egui_dock::{DockState, Node, NodeIndex, SurfaceIndex, TabIndex, Tree};
|
||||
use egui_dock::{DockState, Node, NodeIndex, NodePath, SurfaceIndex, TabIndex, TabPath, Tree};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::EditorTab;
|
||||
@@ -43,15 +43,15 @@ impl PanelNodes {
|
||||
/// Scan the main surface for open tabs and refresh node indices (handles user drag/split).
|
||||
pub fn discover(dock: &DockState<EditorTab>, fallback: Self) -> Self {
|
||||
let mut nodes = fallback;
|
||||
for ((surface, node_idx), tab) in dock.iter_all_tabs() {
|
||||
if surface != SurfaceIndex::main() {
|
||||
for (path, tab) in dock.iter_all_tabs() {
|
||||
if path.surface != SurfaceIndex::main() {
|
||||
continue;
|
||||
}
|
||||
match tab {
|
||||
EditorTab::Viewport | EditorTab::GameView => nodes.main_view = node_idx.0,
|
||||
EditorTab::Hierarchy => nodes.hierarchy = node_idx.0,
|
||||
EditorTab::Inspector => nodes.inspector = node_idx.0,
|
||||
EditorTab::AssetBrowser | EditorTab::Toolbar => nodes.bottom = node_idx.0,
|
||||
EditorTab::Viewport | EditorTab::GameView => nodes.main_view = path.node.0,
|
||||
EditorTab::Hierarchy => nodes.hierarchy = path.node.0,
|
||||
EditorTab::Inspector => nodes.inspector = path.node.0,
|
||||
EditorTab::AssetBrowser | EditorTab::Toolbar => nodes.bottom = path.node.0,
|
||||
}
|
||||
}
|
||||
nodes
|
||||
@@ -93,8 +93,9 @@ pub fn open_and_focus_tab(
|
||||
let tab_idx = push_tab_to_node(tree, node, tab);
|
||||
(node, tab_idx)
|
||||
};
|
||||
dock.set_active_tab((SurfaceIndex::main(), node, tab_idx));
|
||||
dock.set_focused_node_and_surface((SurfaceIndex::main(), node));
|
||||
let node_path = NodePath::new(SurfaceIndex::main(), node);
|
||||
let _ = dock.set_active_tab(TabPath::new(SurfaceIndex::main(), node, tab_idx));
|
||||
dock.set_focused_node_and_surface(node_path);
|
||||
(node, tab_idx)
|
||||
}
|
||||
|
||||
|
||||
@@ -17,5 +17,26 @@ fn configure_editor_fonts(mut contexts: Query<&mut EguiContext, Added<PrimaryEgu
|
||||
};
|
||||
let mut fonts = bevy_egui::egui::FontDefinitions::default();
|
||||
egui_phosphor_icons::add_fonts(&mut fonts);
|
||||
|
||||
// Phosphor families contain icon glyphs only. Text fallbacks give egui a
|
||||
// replacement glyph for malformed/missing icons without changing icon lookup.
|
||||
let text_fallbacks = fonts
|
||||
.families
|
||||
.get(&bevy_egui::egui::FontFamily::Proportional)
|
||||
.cloned()
|
||||
.unwrap_or_default();
|
||||
for (family, font_names) in &mut fonts.families {
|
||||
let bevy_egui::egui::FontFamily::Name(name) = family else {
|
||||
continue;
|
||||
};
|
||||
if !name.starts_with("phosphor-") {
|
||||
continue;
|
||||
}
|
||||
for fallback in &text_fallbacks {
|
||||
if !font_names.contains(fallback) {
|
||||
font_names.push(fallback.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
ctx.get_mut().set_fonts(fonts);
|
||||
}
|
||||
@@ -20,10 +20,10 @@ use crate::ui::helpers::{
|
||||
use crate::ui::hierarchy_ops::{
|
||||
authored_children, editor_visibility, entity_hierarchy_path, entity_matches_filter,
|
||||
hierarchy_label_for_entity, is_entity_locked, level_object_roots, sort_siblings,
|
||||
would_create_cycle,
|
||||
would_create_cycle, HierarchyLabel,
|
||||
};
|
||||
use crate::ui::hierarchy_state::{HierarchyPanelState, HierarchySort};
|
||||
use crate::ui::theme::panel_heading;
|
||||
use crate::ui::theme::{panel_heading, TEXT, TEXT_DIM, TEXT_SELECTED};
|
||||
|
||||
#[derive(Clone)]
|
||||
struct HierarchyDragPayload {
|
||||
@@ -138,6 +138,7 @@ pub fn hierarchy_panel_ui(
|
||||
.is_some();
|
||||
|
||||
egui::ScrollArea::vertical()
|
||||
.id_salt("hierarchy_tree")
|
||||
.scroll_source(ScrollSource {
|
||||
scroll_bar: true,
|
||||
drag: !dragging,
|
||||
@@ -230,6 +231,10 @@ fn draw_root_drop_zone(ui: &mut egui::Ui, drop_target: &mut Option<DropTarget>)
|
||||
}
|
||||
}
|
||||
|
||||
#[expect(
|
||||
clippy::too_many_arguments,
|
||||
reason = "recursive hierarchy rendering threads interaction state explicitly"
|
||||
)]
|
||||
fn draw_authored_node(
|
||||
world: &mut World,
|
||||
ui: &mut egui::Ui,
|
||||
@@ -278,7 +283,7 @@ fn draw_authored_node(
|
||||
} else {
|
||||
icons::CARET_RIGHT
|
||||
};
|
||||
if ui.small_button(twistie.as_str()).clicked() {
|
||||
if ui.small_button(twistie.regular()).clicked() {
|
||||
let path = path.clone();
|
||||
let expanding = !world
|
||||
.resource::<HierarchyPanelState>()
|
||||
@@ -353,7 +358,8 @@ fn draw_authored_node(
|
||||
} else {
|
||||
let selected = selected_entities.contains(entity);
|
||||
let label = hierarchy_label_for_entity(world, entity, HierarchyNodeKind::Authored);
|
||||
let response = ui.selectable_label(selected, label);
|
||||
let color = if selected { TEXT_SELECTED } else { TEXT };
|
||||
let response = ui.selectable_label(selected, hierarchy_label_text(label, color));
|
||||
if response.clicked() && !is_locked {
|
||||
let additive = ui.input(|input| {
|
||||
input.modifiers.shift || input.modifiers.command || input.modifiers.ctrl
|
||||
@@ -512,7 +518,7 @@ fn draw_generated_node(
|
||||
} else {
|
||||
icons::CARET_RIGHT
|
||||
};
|
||||
if ui.small_button(twistie.as_str()).clicked() {
|
||||
if ui.small_button(twistie.regular()).clicked() {
|
||||
is_expanded = !is_expanded;
|
||||
}
|
||||
} else {
|
||||
@@ -520,14 +526,10 @@ fn draw_generated_node(
|
||||
}
|
||||
ui.add_enabled(
|
||||
false,
|
||||
egui::Label::new(
|
||||
egui::RichText::new(hierarchy_label_for_entity(
|
||||
world,
|
||||
entity,
|
||||
HierarchyNodeKind::Generated,
|
||||
))
|
||||
.weak(),
|
||||
),
|
||||
egui::Label::new(hierarchy_label_text(
|
||||
hierarchy_label_for_entity(world, entity, HierarchyNodeKind::Generated),
|
||||
TEXT_DIM,
|
||||
)),
|
||||
);
|
||||
});
|
||||
if !is_expanded {
|
||||
@@ -555,7 +557,9 @@ fn draw_runtime_node(
|
||||
ui.add_space(depth as f32 * 14.0);
|
||||
ui.add_space(18.0);
|
||||
let label = hierarchy_label_for_entity(world, entity, HierarchyNodeKind::Runtime);
|
||||
let response = ui.selectable_label(selected_entities.contains(entity), label);
|
||||
let selected = selected_entities.contains(entity);
|
||||
let color = if selected { TEXT_SELECTED } else { TEXT_DIM };
|
||||
let response = ui.selectable_label(selected, hierarchy_label_text(label, color));
|
||||
if response.clicked() {
|
||||
selected_entities.select_replace(entity);
|
||||
}
|
||||
@@ -575,6 +579,29 @@ fn draw_runtime_node(
|
||||
}
|
||||
}
|
||||
|
||||
fn hierarchy_label_text(label: HierarchyLabel, color: egui::Color32) -> egui::WidgetText {
|
||||
let mut job = egui::text::LayoutJob::default();
|
||||
job.append(
|
||||
label.icon,
|
||||
0.0,
|
||||
egui::TextFormat {
|
||||
font_id: egui::FontId::new(13.0, egui::FontFamily::Name("phosphor-regular".into())),
|
||||
color,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
job.append(
|
||||
&format!(" {}", label.text),
|
||||
0.0,
|
||||
egui::TextFormat {
|
||||
font_id: egui::FontId::new(13.0, egui::FontFamily::Proportional),
|
||||
color,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
job.into()
|
||||
}
|
||||
|
||||
fn authored_context_menu(
|
||||
world: &mut World,
|
||||
ui: &mut egui::Ui,
|
||||
@@ -596,15 +623,16 @@ fn authored_context_menu(
|
||||
delete_entities_with_history(world, &[entity]);
|
||||
ui.close();
|
||||
}
|
||||
if selected_entities.len() >= 2 && selected_entities.contains(entity) {
|
||||
if ui.button("Group").clicked() {
|
||||
let entities: Vec<Entity> = selected_entities
|
||||
.iter()
|
||||
.filter(|e| is_level_object(world, *e))
|
||||
.collect();
|
||||
group_selection_with_history(world, &entities);
|
||||
ui.close();
|
||||
}
|
||||
if selected_entities.len() >= 2
|
||||
&& selected_entities.contains(entity)
|
||||
&& ui.button("Group").clicked()
|
||||
{
|
||||
let entities: Vec<Entity> = selected_entities
|
||||
.iter()
|
||||
.filter(|e| is_level_object(world, *e))
|
||||
.collect();
|
||||
group_selection_with_history(world, &entities);
|
||||
ui.close();
|
||||
}
|
||||
if ui.button("Unparent").clicked() {
|
||||
reparent_with_history(world, entity, None);
|
||||
@@ -701,7 +729,7 @@ pub(crate) fn is_hierarchy_generated_child(world: &World, entity: Entity) -> boo
|
||||
&& (entity_ref.contains::<Transform>() || entity_ref.contains::<GlobalTransform>())
|
||||
&& (entity_ref.contains::<Name>()
|
||||
|| entity_ref.contains::<Mesh3d>()
|
||||
|| entity_ref.contains::<SceneRoot>())
|
||||
|| entity_ref.contains::<WorldAssetRoot>())
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -350,11 +350,16 @@ pub fn actor_kind_icon(kind: ActorKind) -> &'static str {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct HierarchyLabel {
|
||||
pub icon: &'static str,
|
||||
pub text: String,
|
||||
}
|
||||
|
||||
pub fn hierarchy_label_for_entity(
|
||||
world: &World,
|
||||
entity: Entity,
|
||||
kind: HierarchyNodeKind,
|
||||
) -> String {
|
||||
) -> HierarchyLabel {
|
||||
use egui_phosphor_icons::icons;
|
||||
let icon = world
|
||||
.get::<ActorKind>(entity)
|
||||
@@ -365,18 +370,18 @@ pub fn hierarchy_label_for_entity(
|
||||
HierarchyNodeKind::Generated => icons::STACK.as_str(),
|
||||
HierarchyNodeKind::Runtime => icons::CPU.as_str(),
|
||||
});
|
||||
let mut label = format!("{} {}", icon, entity_name(world, entity));
|
||||
let mut text = entity_name(world, entity);
|
||||
if let Some(light) = world.get::<LightDesc>(entity) {
|
||||
if matches!(light.kind, AuthoringLightKind::Directional) {
|
||||
label.push_str(" ☀");
|
||||
text.push_str(" (sun)");
|
||||
}
|
||||
}
|
||||
match kind {
|
||||
HierarchyNodeKind::Authored => {}
|
||||
HierarchyNodeKind::Generated => label.push_str(" (generated)"),
|
||||
HierarchyNodeKind::Runtime => label.push_str(" (runtime)"),
|
||||
HierarchyNodeKind::Generated => text.push_str(" (generated)"),
|
||||
HierarchyNodeKind::Runtime => text.push_str(" (runtime)"),
|
||||
}
|
||||
label
|
||||
HierarchyLabel { icon, text }
|
||||
}
|
||||
|
||||
pub fn entity_matches_filter(world: &World, entity: Entity, filter_lower: &str) -> bool {
|
||||
|
||||
@@ -48,12 +48,13 @@ impl Default for HierarchyPanelState {
|
||||
|
||||
impl HierarchyPanelState {
|
||||
pub fn from_prefs(prefs: &UserPreferences) -> Self {
|
||||
let mut state = Self::default();
|
||||
state.filter = prefs.hierarchy_filter.clone();
|
||||
state.show_generated = prefs.hierarchy_show_generated;
|
||||
state.show_runtime = prefs.hierarchy_show_runtime;
|
||||
state.sort_mode = prefs.hierarchy_sort_mode;
|
||||
state
|
||||
Self {
|
||||
filter: prefs.hierarchy_filter.clone(),
|
||||
show_generated: prefs.hierarchy_show_generated,
|
||||
show_runtime: prefs.hierarchy_show_runtime,
|
||||
sort_mode: prefs.hierarchy_sort_mode,
|
||||
..Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mark_dirty(&mut self) {
|
||||
|
||||
@@ -764,7 +764,7 @@ fn add_component_picker_shelf(
|
||||
target: Entity,
|
||||
anchor: egui::Rect,
|
||||
) {
|
||||
if !world.get_entity(target).is_ok() {
|
||||
if world.get_entity(target).is_err() {
|
||||
if let Some(mut state) = world.get_resource_mut::<InspectorPanelState>() {
|
||||
state.add_component_open = false;
|
||||
state.add_component_target = None;
|
||||
@@ -777,7 +777,7 @@ fn add_component_picker_shelf(
|
||||
.descriptors
|
||||
.clone();
|
||||
|
||||
let visible = ui.clip_rect().intersect(ui.ctx().available_rect());
|
||||
let visible = ui.clip_rect().intersect(ui.ctx().content_rect());
|
||||
let space_above = (anchor.min.y - visible.top()).max(0.0);
|
||||
let space_below = (visible.bottom() - anchor.max.y).max(0.0);
|
||||
let direction = if space_below >= space_above {
|
||||
@@ -865,7 +865,7 @@ fn add_component_picker_shelf_contents(
|
||||
}
|
||||
|
||||
let search = search_input.to_lowercase();
|
||||
let filtered = filtered_component_descriptors(&descriptors, &search);
|
||||
let filtered = filtered_component_descriptors(descriptors, &search);
|
||||
{
|
||||
let mut state = world.resource_mut::<InspectorPanelState>();
|
||||
if !filtered.is_empty() {
|
||||
@@ -905,7 +905,7 @@ fn add_component_picker_shelf_contents(
|
||||
.resource::<InspectorPanelState>()
|
||||
.add_component_selected_index;
|
||||
if let Some(descriptor) = filtered.get(selected_index) {
|
||||
let add_state = component_add_state(world, target, descriptor, &descriptors);
|
||||
let add_state = component_add_state(world, target, descriptor, descriptors);
|
||||
if add_state.addable {
|
||||
insert_registered_component(world, target, descriptor.type_name);
|
||||
let mut state = world.resource_mut::<InspectorPanelState>();
|
||||
@@ -941,8 +941,7 @@ fn add_component_picker_shelf_contents(
|
||||
last_category = Some(descriptor.category);
|
||||
}
|
||||
|
||||
let add_state =
|
||||
component_add_state(world, target, descriptor, &descriptors);
|
||||
let add_state = component_add_state(world, target, descriptor, descriptors);
|
||||
let selected = index == selected_index;
|
||||
let row = ui
|
||||
.horizontal(|ui| {
|
||||
@@ -1893,8 +1892,10 @@ fn static_mesh_renderer_ui(world: &mut World, ui: &mut egui::Ui, entity: Entity)
|
||||
.clicked();
|
||||
if add_slot {
|
||||
let index = renderer.slots.len();
|
||||
let mut entry = StaticMeshRendererEntry::default();
|
||||
entry.id = ComponentInstanceId::new(format!("slot:{index}"));
|
||||
let entry = StaticMeshRendererEntry {
|
||||
id: ComponentInstanceId::new(format!("slot:{index}")),
|
||||
..Default::default()
|
||||
};
|
||||
renderer.slots.push(entry);
|
||||
changed = true;
|
||||
}
|
||||
@@ -2026,6 +2027,10 @@ fn thumbnail_for_mesh(
|
||||
.and_then(|candidate| candidate.texture_id)
|
||||
}
|
||||
|
||||
#[expect(
|
||||
clippy::too_many_arguments,
|
||||
reason = "asset selector rows keep immediate-mode UI inputs explicit"
|
||||
)]
|
||||
fn asset_selector_row(
|
||||
ui: &mut egui::Ui,
|
||||
label: &str,
|
||||
@@ -2075,6 +2080,10 @@ fn asset_selector_row(
|
||||
response
|
||||
}
|
||||
|
||||
#[expect(
|
||||
clippy::too_many_arguments,
|
||||
reason = "asset selector controls keep immediate-mode UI inputs explicit"
|
||||
)]
|
||||
fn asset_selector_control(
|
||||
ui: &mut egui::Ui,
|
||||
icon: Icon,
|
||||
|
||||
@@ -9,7 +9,6 @@ use crate::history::{apply_command_redo, apply_command_undo, EditorHistory};
|
||||
use crate::scene_io::{SceneIo, SceneIoRequest};
|
||||
use crate::settings_ui::{open_project_settings_panel, ProjectSettingsPanel};
|
||||
use crate::state::{EditorMode, PlayPaused};
|
||||
use crate::workspace::{request_new_project, request_open_project};
|
||||
|
||||
use super::diagnostics::{BrushDiagnosticsPanel, DiagnosticsPanel};
|
||||
use super::dock_tabs::{open_and_focus_tab, tab_is_open, tab_label, PanelNodes, PANEL_TABS};
|
||||
@@ -22,25 +21,14 @@ use super::EditorTab;
|
||||
|
||||
pub fn top_menu_bar(
|
||||
world: &mut World,
|
||||
ctx: &egui::Context,
|
||||
root_ui: &mut egui::Ui,
|
||||
selected: &SelectedEntities,
|
||||
dock_state: &mut DockState<EditorTab>,
|
||||
panel_nodes: &mut PanelNodes,
|
||||
) {
|
||||
egui::TopBottomPanel::top("editor_menu_bar").show(ctx, |ui| {
|
||||
egui::Panel::top("editor_menu_bar").show_inside(root_ui, |ui| {
|
||||
egui::MenuBar::new().ui(ui, |ui| {
|
||||
ui.menu_button("File", |ui| {
|
||||
ui.menu_button("Project", |ui| {
|
||||
if menu_item(ui, "New Project", None, true).clicked() {
|
||||
request_new_project(world);
|
||||
ui.close();
|
||||
}
|
||||
if menu_item(ui, "Open Project...", None, true).clicked() {
|
||||
request_open_project(world);
|
||||
ui.close();
|
||||
}
|
||||
});
|
||||
ui.separator();
|
||||
if menu_item(ui, "New Scene", None, true).clicked() {
|
||||
world.resource_mut::<SceneIo>().request = Some(SceneIoRequest::New);
|
||||
ui.close();
|
||||
|
||||
+32
-26
@@ -66,7 +66,7 @@ pub struct UiState {
|
||||
}
|
||||
|
||||
pub fn egui_captures_keyboard(ctx: &egui::Context) -> bool {
|
||||
ctx.wants_keyboard_input()
|
||||
ctx.egui_wants_keyboard_input()
|
||||
}
|
||||
|
||||
pub fn egui_captures_keyboard_from_world(world: &mut World) -> bool {
|
||||
@@ -118,6 +118,10 @@ impl UiState {
|
||||
}
|
||||
}
|
||||
|
||||
#[expect(
|
||||
deprecated,
|
||||
reason = "bevy_egui exposes a Context during EguiPrimaryContextPass, so one top-level panel must bridge to the new Ui-based panel API"
|
||||
)]
|
||||
fn ui(&mut self, world: &mut World, ctx: &mut egui::Context, dt: f32) {
|
||||
apply_editor_theme(ctx);
|
||||
|
||||
@@ -129,17 +133,6 @@ impl UiState {
|
||||
}
|
||||
}
|
||||
|
||||
top_menu_bar(
|
||||
world,
|
||||
ctx,
|
||||
&self.selected_entities,
|
||||
&mut self.dock_state,
|
||||
&mut self.panel_nodes,
|
||||
);
|
||||
|
||||
editor_toolbar_panel(world, ctx);
|
||||
status_bar_ui(world, ctx, &self.selected_entities, mode);
|
||||
|
||||
self.pointer_in_viewport = false;
|
||||
self.viewport_pointer_pos = None;
|
||||
|
||||
@@ -154,21 +147,34 @@ impl UiState {
|
||||
});
|
||||
}
|
||||
|
||||
let mut viewer = TabViewer {
|
||||
world,
|
||||
viewport_rect: &mut self.viewport_rect,
|
||||
pointer_in_viewport: &mut self.pointer_in_viewport,
|
||||
viewport_pointer_pos: &mut self.viewport_pointer_pos,
|
||||
playing,
|
||||
cursor_grabbed,
|
||||
selected_entities: &mut self.selected_entities,
|
||||
renaming_entity: &mut self.renaming_entity,
|
||||
rename_buffer: &mut self.rename_buffer,
|
||||
};
|
||||
egui::CentralPanel::no_frame().show(ctx, |root_ui| {
|
||||
top_menu_bar(
|
||||
world,
|
||||
root_ui,
|
||||
&self.selected_entities,
|
||||
&mut self.dock_state,
|
||||
&mut self.panel_nodes,
|
||||
);
|
||||
|
||||
DockArea::new(&mut self.dock_state)
|
||||
.style(editor_dock_style(ctx))
|
||||
.show(ctx, &mut viewer);
|
||||
editor_toolbar_panel(world, root_ui);
|
||||
status_bar_ui(world, root_ui, &self.selected_entities, mode);
|
||||
|
||||
let mut viewer = TabViewer {
|
||||
world,
|
||||
viewport_rect: &mut self.viewport_rect,
|
||||
pointer_in_viewport: &mut self.pointer_in_viewport,
|
||||
viewport_pointer_pos: &mut self.viewport_pointer_pos,
|
||||
playing,
|
||||
cursor_grabbed,
|
||||
selected_entities: &mut self.selected_entities,
|
||||
renaming_entity: &mut self.renaming_entity,
|
||||
rename_buffer: &mut self.rename_buffer,
|
||||
};
|
||||
|
||||
DockArea::new(&mut self.dock_state)
|
||||
.style(editor_dock_style(ctx))
|
||||
.show_inside(root_ui, &mut viewer);
|
||||
});
|
||||
|
||||
self.panel_nodes = PanelNodes::discover(&self.dock_state, self.panel_nodes);
|
||||
|
||||
|
||||
@@ -13,59 +13,87 @@ use super::theme::{status_bar_frame, TEXT};
|
||||
|
||||
pub fn status_bar_ui(
|
||||
world: &World,
|
||||
ctx: &egui::Context,
|
||||
root_ui: &mut egui::Ui,
|
||||
selected: &SelectedEntities,
|
||||
mode: EditorMode,
|
||||
) {
|
||||
egui::TopBottomPanel::bottom("editor_status_bar")
|
||||
.exact_height(24.0)
|
||||
egui::Panel::bottom("editor_status_bar")
|
||||
.exact_size(24.0)
|
||||
.frame(status_bar_frame())
|
||||
.show(ctx, |ui| {
|
||||
ui.horizontal_centered(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = 16.0;
|
||||
ui.label(egui::RichText::new(scene_line(world)).color(TEXT));
|
||||
.show_inside(root_ui, |ui| {
|
||||
ui.spacing_mut().item_spacing.x = 12.0;
|
||||
egui::containers::Sides::new()
|
||||
.shrink_left()
|
||||
.truncate()
|
||||
.show(
|
||||
ui,
|
||||
|ui| {
|
||||
let status = primary_status_line(world);
|
||||
ui.add(
|
||||
egui::Label::new(egui::RichText::new(&status).color(TEXT)).truncate(),
|
||||
)
|
||||
.on_hover_text(status);
|
||||
},
|
||||
|ui| {
|
||||
let mode_label = match mode {
|
||||
EditorMode::Editing => "Edit".to_string(),
|
||||
EditorMode::Playing => {
|
||||
if world.resource::<PlayPaused>().0 {
|
||||
"Play (paused)".to_string()
|
||||
} else {
|
||||
"Play".to_string()
|
||||
}
|
||||
}
|
||||
};
|
||||
ui.label(egui::RichText::new(mode_label).color(TEXT));
|
||||
|
||||
let mode_label = match mode {
|
||||
EditorMode::Editing => "Edit".to_string(),
|
||||
EditorMode::Playing => {
|
||||
if world.resource::<PlayPaused>().0 {
|
||||
"Play (paused)".to_string()
|
||||
} else {
|
||||
"Play".to_string()
|
||||
let count = selected.len();
|
||||
let selection = match count {
|
||||
0 => "None".to_string(),
|
||||
1 => "1 selected".to_string(),
|
||||
_ => format!("{count} selected"),
|
||||
};
|
||||
ui.label(egui::RichText::new(selection).color(TEXT));
|
||||
|
||||
ui.label(
|
||||
egui::RichText::new(world.resource::<EditorHistory>().status.clone())
|
||||
.color(TEXT),
|
||||
);
|
||||
|
||||
if let Some(operator_label) = world.resource::<ActiveOperator>().label() {
|
||||
ui.label(egui::RichText::new(operator_label).color(TEXT));
|
||||
}
|
||||
}
|
||||
};
|
||||
ui.label(egui::RichText::new(mode_label).color(TEXT));
|
||||
|
||||
let count = selected.len();
|
||||
let sel = if count == 0 {
|
||||
"None".to_string()
|
||||
} else if count == 1 {
|
||||
"1 selected".to_string()
|
||||
} else {
|
||||
format!("{count} selected")
|
||||
};
|
||||
ui.label(egui::RichText::new(sel).color(TEXT));
|
||||
|
||||
ui.label(
|
||||
egui::RichText::new(world.resource::<EditorHistory>().status.clone())
|
||||
.color(TEXT),
|
||||
#[cfg(feature = "hot-reload")]
|
||||
if let Some(hot) = world.get_resource::<crate::hot_reload::HotReloadState>()
|
||||
{
|
||||
ui.label(egui::RichText::new(hot.label.clone()).color(TEXT));
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
if let Some(operator_label) = world.resource::<ActiveOperator>().label() {
|
||||
ui.label(egui::RichText::new(operator_label).color(TEXT));
|
||||
}
|
||||
|
||||
#[cfg(feature = "hot-reload")]
|
||||
if let Some(hot) = world.get_resource::<crate::hot_reload::HotReloadState>() {
|
||||
ui.label(egui::RichText::new(hot.label.clone()).color(TEXT));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn scene_line(world: &World) -> String {
|
||||
let scene_io = world.resource::<SceneIo>();
|
||||
fn scene_line(scene_io: &SceneIo) -> String {
|
||||
let dirty = if scene_io.dirty { " *" } else { "" };
|
||||
format!("Scene: {}{dirty}", scene_io.active_path_label())
|
||||
}
|
||||
|
||||
fn primary_status_line(world: &World) -> String {
|
||||
let scene_io = world.resource::<SceneIo>();
|
||||
format!("{} | {}", scene_io.status, scene_line(scene_io))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn scene_line_marks_unsaved_changes() {
|
||||
let mut scene_io = SceneIo::default();
|
||||
assert!(!scene_line(&scene_io).ends_with('*'));
|
||||
|
||||
scene_io.mark_dirty();
|
||||
assert!(scene_line(&scene_io).ends_with('*'));
|
||||
}
|
||||
}
|
||||
@@ -52,7 +52,7 @@ pub fn apply_editor_theme(ctx: &egui::Context) {
|
||||
visuals.window_stroke = Stroke::new(1.0, BORDER);
|
||||
visuals.window_corner_radius = CornerRadius::same(4);
|
||||
|
||||
let mut style = (*ctx.style()).clone();
|
||||
let mut style = (*ctx.global_style()).clone();
|
||||
style.visuals = visuals;
|
||||
style.spacing.item_spacing = egui::vec2(8.0, 6.0);
|
||||
style.spacing.button_padding = egui::vec2(8.0, 4.0);
|
||||
@@ -69,11 +69,11 @@ pub fn apply_editor_theme(ctx: &egui::Context) {
|
||||
egui::TextStyle::Heading,
|
||||
FontId::new(15.0, egui::FontFamily::Proportional),
|
||||
);
|
||||
ctx.set_style(style);
|
||||
ctx.set_global_style(style);
|
||||
}
|
||||
|
||||
pub fn editor_dock_style(ctx: &egui::Context) -> DockStyle {
|
||||
let mut style = DockStyle::from_egui(ctx.style().as_ref());
|
||||
let mut style = DockStyle::from_egui(ctx.global_style().as_ref());
|
||||
style.dock_area_padding = Some(egui::Margin::same(2));
|
||||
style.main_surface_border_stroke = Stroke::new(1.0, BORDER);
|
||||
style.separator.width = 2.0;
|
||||
|
||||
@@ -19,11 +19,13 @@ use super::widgets::{icon_button, panel_toolbar_row, toolbar_separator, transpor
|
||||
|
||||
/// Toolbar strip height (menu bar is separate).
|
||||
const TOOLBAR_HEIGHT: f32 = 56.0;
|
||||
const TRANSPORT_WIDTH: f32 = 152.0;
|
||||
const TRANSPORT_SLOT_STEP: f32 = 54.0;
|
||||
|
||||
pub fn editor_toolbar_panel(world: &mut World, ctx: &egui::Context) {
|
||||
egui::TopBottomPanel::top("editor_toolbar")
|
||||
.exact_height(TOOLBAR_HEIGHT)
|
||||
.show(ctx, |ui| {
|
||||
pub fn editor_toolbar_panel(world: &mut World, root_ui: &mut egui::Ui) {
|
||||
egui::Panel::top("editor_toolbar")
|
||||
.exact_size(TOOLBAR_HEIGHT)
|
||||
.show_inside(root_ui, |ui| {
|
||||
toolbar_ui(world, ui);
|
||||
});
|
||||
}
|
||||
@@ -41,7 +43,7 @@ pub fn toolbar_ui(world: &mut World, ui: &mut egui::Ui) {
|
||||
);
|
||||
let transport_rect = egui::Rect::from_center_size(
|
||||
egui::pos2(toolbar_rect.center().x, center_y),
|
||||
egui::vec2(transport_width(world), 44.0),
|
||||
egui::vec2(TRANSPORT_WIDTH, 44.0),
|
||||
);
|
||||
|
||||
let mut left_ui = ui.new_child(
|
||||
@@ -63,16 +65,6 @@ pub fn toolbar_ui(world: &mut World, ui: &mut egui::Ui) {
|
||||
transport_controls(world, &mut transport_ui);
|
||||
}
|
||||
|
||||
fn transport_width(world: &World) -> f32 {
|
||||
let button_count = match *world.resource::<State<EditorMode>>().get() {
|
||||
EditorMode::Editing => 1.0,
|
||||
EditorMode::Playing => 3.0,
|
||||
};
|
||||
let gap_count = button_count - 1.0;
|
||||
|
||||
button_count * 44.0 + gap_count * 10.0
|
||||
}
|
||||
|
||||
fn left_toolbar(world: &mut World, ui: &mut egui::Ui) {
|
||||
panel_toolbar_row(ui, |ui| {
|
||||
if icon_button(ui, icons::CUBE, "Spawn cube").clicked() {
|
||||
@@ -113,7 +105,13 @@ fn transport_controls(world: &mut World, ui: &mut egui::Ui) {
|
||||
let mode = *world.resource::<State<EditorMode>>().get();
|
||||
match mode {
|
||||
EditorMode::Editing => {
|
||||
if transport_button_large(ui, icons::PLAY, "Play (F5)", true).clicked() {
|
||||
ui.add_space(TRANSPORT_SLOT_STEP);
|
||||
let play_clicked = ui
|
||||
.push_id("transport_center", |ui| {
|
||||
transport_button_large(ui, icons::PLAY, "Play (F5)", true).clicked()
|
||||
})
|
||||
.inner;
|
||||
if play_clicked {
|
||||
toggle_play_mode(world);
|
||||
}
|
||||
}
|
||||
@@ -125,12 +123,21 @@ fn transport_controls(world: &mut World, ui: &mut egui::Ui) {
|
||||
} else {
|
||||
"Pause simulation (F6)"
|
||||
};
|
||||
if transport_button_large(ui, pause_icon, pause_tip, false).clicked() {
|
||||
let pause_clicked = ui
|
||||
.push_id("transport_left", |ui| {
|
||||
transport_button_large(ui, pause_icon, pause_tip, false).clicked()
|
||||
})
|
||||
.inner;
|
||||
if pause_clicked {
|
||||
toggle_play_paused(world);
|
||||
}
|
||||
if transport_button_large(ui, icons::STOP, "Stop and return to Edit (F5)", false)
|
||||
.clicked()
|
||||
{
|
||||
let stop_clicked = ui
|
||||
.push_id("transport_center", |ui| {
|
||||
transport_button_large(ui, icons::STOP, "Stop and return to Edit (F5)", false)
|
||||
.clicked()
|
||||
})
|
||||
.inner;
|
||||
if stop_clicked {
|
||||
toggle_play_mode(world);
|
||||
}
|
||||
|
||||
@@ -139,7 +146,12 @@ fn transport_controls(world: &mut World, ui: &mut egui::Ui) {
|
||||
PlayPossession::Possessed => (icons::SIGN_OUT, "Eject from player (F8)"),
|
||||
PlayPossession::Ejected => (icons::USER, "Possess player (F8)"),
|
||||
};
|
||||
if transport_button_large(ui, eject_icon, eject_tip, false).clicked() {
|
||||
let possession_clicked = ui
|
||||
.push_id("transport_right", |ui| {
|
||||
transport_button_large(ui, eject_icon, eject_tip, false).clicked()
|
||||
})
|
||||
.inner;
|
||||
if possession_clicked {
|
||||
toggle_possession(world);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ use crate::render_target::ViewportRenderTarget;
|
||||
use crate::selection::ViewportClick;
|
||||
use crate::state::PlayPossession;
|
||||
use crate::viewport::actor_icons::ActorIconSettings;
|
||||
use crate::viewport::brush_edit::BrushEditMode;
|
||||
use crate::viewport::brush_edit::{BrushEditMode, BrushElementSelection};
|
||||
use crate::viewport::brush_tool::{BrushToolPhase, BrushToolState};
|
||||
use crate::viewport::{
|
||||
snap_translation, viewport_ground_position, EditorViewportMode, ViewportDisplayMode,
|
||||
@@ -36,6 +36,10 @@ pub struct ViewportUiState {
|
||||
|
||||
const VIEWPORT_TOOLTIP: &str = "RMB + WASD/QE: fly | MMB: pan | Scroll: dolly\nW/E/R: gizmo | X: world/local | F: focus | G: game view | Ctrl+G: grid\nTab: cycle overlapping picks | Play/Pause/Stop: main toolbar (F5 / F6)";
|
||||
|
||||
#[expect(
|
||||
clippy::too_many_arguments,
|
||||
reason = "viewport tab rendering keeps immediate-mode UI inputs explicit"
|
||||
)]
|
||||
pub fn viewport_tab_ui(
|
||||
world: &mut World,
|
||||
ui: &mut egui::Ui,
|
||||
@@ -161,20 +165,58 @@ fn scene_view_brush_mode_badge(world: &World, ctx: &egui::Context, scene_rect: e
|
||||
if !mode.is_element_mode() {
|
||||
return;
|
||||
}
|
||||
let selected_count = world
|
||||
.get_resource::<BrushElementSelection>()
|
||||
.map(|selection| selection.elements.len())
|
||||
.unwrap_or(0);
|
||||
egui::Area::new(egui::Id::new("scene_view_brush_mode_badge"))
|
||||
.fixed_pos(scene_rect.right_bottom() + egui::vec2(-150.0, -22.0))
|
||||
.fixed_pos(scene_rect.left_top() + egui::vec2(8.0, 52.0))
|
||||
.interactable(false)
|
||||
.show(ctx, |ui| {
|
||||
egui::Frame::new()
|
||||
.fill(egui::Color32::from_rgba_unmultiplied(35, 44, 50, 220))
|
||||
.corner_radius(egui::CornerRadius::same(3))
|
||||
.inner_margin(egui::Margin::symmetric(6, 2))
|
||||
.fill(egui::Color32::from_rgba_unmultiplied(20, 18, 28, 230))
|
||||
.stroke(egui::Stroke::new(
|
||||
1.0,
|
||||
egui::Color32::from_rgba_unmultiplied(210, 140, 255, 210),
|
||||
))
|
||||
.corner_radius(egui::CornerRadius::same(4))
|
||||
.inner_margin(egui::Margin::symmetric(8, 6))
|
||||
.show(ui, |ui| {
|
||||
ui.label(
|
||||
egui::RichText::new(format!("Brush: {}", mode.label()))
|
||||
.color(egui::Color32::from_rgb(170, 220, 255))
|
||||
.small(),
|
||||
);
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(
|
||||
egui::RichText::new(format!("Brush {}", mode.label()))
|
||||
.color(egui::Color32::from_rgb(230, 190, 255))
|
||||
.strong(),
|
||||
);
|
||||
ui.label(
|
||||
egui::RichText::new(format!("{selected_count} selected"))
|
||||
.color(egui::Color32::from_rgb(205, 200, 215))
|
||||
.small(),
|
||||
);
|
||||
ui.label(
|
||||
egui::RichText::new("Element gizmo")
|
||||
.color(egui::Color32::from_rgb(255, 190, 120))
|
||||
.small(),
|
||||
);
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
match mode {
|
||||
BrushEditMode::Vertex => key_hint(ui, "LMB", "Select vertex"),
|
||||
BrushEditMode::Edge => key_hint(ui, "LMB", "Select edge"),
|
||||
BrushEditMode::Face => key_hint(ui, "LMB", "Select face"),
|
||||
BrushEditMode::Clip => key_hint(ui, "LMB", "Select face"),
|
||||
BrushEditMode::Object => {}
|
||||
}
|
||||
if !matches!(mode, BrushEditMode::Clip) {
|
||||
key_hint(ui, "W/E/R", "Move/rotate/scale");
|
||||
}
|
||||
if matches!(mode, BrushEditMode::Clip) {
|
||||
key_hint(ui, "Enter", "Clip");
|
||||
}
|
||||
key_hint(ui, "Shift+LMB", "Multi");
|
||||
key_hint(ui, "Esc", "Object");
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user