Start M0 editor workflow polish
This commit is contained in:
1 parent
3e053a81ab
commit
19c4d017dc
8 files changed
+236
-40
No files matched your search
@@ -8,7 +8,7 @@ use crate::state::{EditorMode, PlayPossession};
|
||||
use crate::ui::helpers::{
|
||||
reset_scene_lighting_to_project_defaults, toggle_play_mode, toggle_play_paused,
|
||||
};
|
||||
use crate::ui::selection_ops::focus_editor_camera_on_selection;
|
||||
use crate::ui::selection_ops::{focus_editor_camera_on_selection, reset_selected_transforms};
|
||||
use crate::ui::theme::{apply_editor_theme, PANEL_BG, TEXT, TEXT_DIM};
|
||||
use crate::ui::UiState;
|
||||
|
||||
@@ -127,6 +127,8 @@ pub struct CommandPalette {
|
||||
pub open: bool,
|
||||
pub filter: String,
|
||||
pub pending_run: Option<String>,
|
||||
pub focus_filter: bool,
|
||||
pub selected_index: usize,
|
||||
}
|
||||
|
||||
pub struct ExtensibilityPlugin;
|
||||
@@ -160,6 +162,7 @@ fn register_builtin_commands(mut registry: ResMut<EditorCommandRegistry>) {
|
||||
registry.register(Box::new(ResetLightingCommand));
|
||||
registry.register(Box::new(GroupSelectionCommand));
|
||||
registry.register(Box::new(FocusSelectionCommand));
|
||||
registry.register(Box::new(ResetSelectionTransformCommand));
|
||||
registry.register(Box::new(CreatePostProcessVolumeCommand));
|
||||
registry.register(Box::new(FocusActiveVolumesCommand));
|
||||
registry.register(Box::new(SelectVolumesAtCameraCommand));
|
||||
@@ -272,6 +275,18 @@ impl EditorCommand for FocusSelectionCommand {
|
||||
}
|
||||
}
|
||||
|
||||
struct ResetSelectionTransformCommand;
|
||||
|
||||
impl EditorCommand for ResetSelectionTransformCommand {
|
||||
fn name(&self) -> &str {
|
||||
"selection.reset_transform"
|
||||
}
|
||||
|
||||
fn execute(&self, world: &mut World) {
|
||||
reset_selected_transforms(world);
|
||||
}
|
||||
}
|
||||
|
||||
struct CreatePostProcessVolumeCommand;
|
||||
|
||||
impl EditorCommand for CreatePostProcessVolumeCommand {
|
||||
@@ -322,6 +337,8 @@ fn command_palette_ui(
|
||||
|
||||
if ctx.input(|input| input.modifiers.command && input.key_pressed(egui::Key::P)) {
|
||||
palette.open = true;
|
||||
palette.focus_filter = true;
|
||||
palette.selected_index = 0;
|
||||
}
|
||||
|
||||
if !palette.open {
|
||||
@@ -339,25 +356,71 @@ fn command_palette_ui(
|
||||
.color(TEXT_DIM)
|
||||
.small(),
|
||||
);
|
||||
ui.add(
|
||||
let filter_response = ui.add(
|
||||
egui::TextEdit::singleline(&mut palette.filter)
|
||||
.hint_text("Type to filter...")
|
||||
.desired_width(f32::INFINITY),
|
||||
);
|
||||
if palette.focus_filter {
|
||||
filter_response.request_focus();
|
||||
palette.focus_filter = false;
|
||||
}
|
||||
if filter_response.changed() {
|
||||
palette.selected_index = 0;
|
||||
}
|
||||
|
||||
let filter = palette.filter.to_lowercase();
|
||||
let filtered_names: Vec<String> = registry
|
||||
.names()
|
||||
.into_iter()
|
||||
.filter(|name| filter.is_empty() || name.to_lowercase().contains(&filter))
|
||||
.collect();
|
||||
if !filtered_names.is_empty() {
|
||||
palette.selected_index = palette.selected_index.min(filtered_names.len() - 1);
|
||||
} else {
|
||||
palette.selected_index = 0;
|
||||
}
|
||||
|
||||
if ui.input_mut(|input| input.consume_key(egui::Modifiers::NONE, egui::Key::ArrowDown))
|
||||
&& !filtered_names.is_empty()
|
||||
{
|
||||
palette.selected_index = (palette.selected_index + 1) % filtered_names.len();
|
||||
}
|
||||
if ui.input_mut(|input| input.consume_key(egui::Modifiers::NONE, egui::Key::ArrowUp))
|
||||
&& !filtered_names.is_empty()
|
||||
{
|
||||
palette.selected_index = if palette.selected_index == 0 {
|
||||
filtered_names.len() - 1
|
||||
} else {
|
||||
palette.selected_index - 1
|
||||
};
|
||||
}
|
||||
if ui.input_mut(|input| input.consume_key(egui::Modifiers::NONE, egui::Key::Enter)) {
|
||||
if let Some(name) = filtered_names.get(palette.selected_index) {
|
||||
palette.pending_run = Some(name.clone());
|
||||
palette.open = false;
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
if ui.input_mut(|input| input.consume_key(egui::Modifiers::NONE, egui::Key::Escape)) {
|
||||
palette.open = false;
|
||||
ui.close();
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
egui::ScrollArea::vertical()
|
||||
.max_height(280.0)
|
||||
.show(ui, |ui| {
|
||||
for name in registry.names() {
|
||||
if !palette.filter.is_empty()
|
||||
&& !name.to_lowercase().contains(&palette.filter.to_lowercase())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
for (index, name) in filtered_names.iter().enumerate() {
|
||||
let selected = index == palette.selected_index;
|
||||
let response =
|
||||
ui.selectable_label(false, egui::RichText::new(&name).color(TEXT));
|
||||
ui.selectable_label(selected, egui::RichText::new(name).color(TEXT));
|
||||
if selected {
|
||||
response.scroll_to_me(Some(egui::Align::Center));
|
||||
}
|
||||
if response.clicked() {
|
||||
palette.pending_run = Some(name);
|
||||
palette.selected_index = index;
|
||||
palette.pending_run = Some(name.clone());
|
||||
palette.open = false;
|
||||
ui.close();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user