add top-level selection

This commit is contained in:
Skyler Lehmkuhl
2026-03-01 10:22:46 -05:00
parent 78577babb1
commit 13840ee45f
9 changed files with 509 additions and 33 deletions
@@ -1,14 +1,19 @@
/// Info Panel pane - displays and edits properties of selected objects
///
/// Shows context-sensitive property editors based on current selection:
/// Shows context-sensitive property editors based on current focus:
/// - Tool options (when a tool is active)
/// - Transform properties (when shapes are selected)
/// - Shape properties (fill/stroke for selected shapes)
/// - Document settings (when nothing is selected)
/// - Layer properties (when layers are focused)
/// - Clip instance properties (when clip instances are focused)
/// - Shape properties (fill/stroke for selected geometry)
/// - Note info (when piano roll notes are focused)
/// - Node info (when node graph nodes are focused)
/// - Asset info (when asset library items are focused)
/// - Document settings (when nothing is focused)
use eframe::egui::{self, DragValue, Ui};
use lightningbeam_core::actions::{SetDocumentPropertiesAction, SetShapePropertiesAction};
use lightningbeam_core::layer::AnyLayer;
use lightningbeam_core::layer::{AnyLayer, LayerTrait};
use lightningbeam_core::selection::FocusSelection;
use lightningbeam_core::shape::ShapeColor;
use lightningbeam_core::tool::{SimplifyMode, Tool};
use super::{NodePath, PaneRenderer, SharedPaneState};
@@ -31,7 +36,7 @@ impl InfopanelPane {
}
}
/// Aggregated info about the current selection
/// Aggregated info about the current DCEL selection
struct SelectionInfo {
/// True if nothing is selected
is_empty: bool,
@@ -60,7 +65,7 @@ impl Default for SelectionInfo {
}
impl InfopanelPane {
/// Gather info about the current selection
/// Gather info about the current DCEL selection
fn gather_selection_info(&self, shared: &SharedPaneState) -> SelectionInfo {
let mut info = SelectionInfo::default();
@@ -406,7 +411,7 @@ impl InfopanelPane {
});
}
/// Render document settings section (shown when nothing is selected)
/// Render document settings section (shown when nothing is focused)
fn render_document_section(&self, ui: &mut Ui, path: &NodePath, shared: &mut SharedPaneState) {
egui::CollapsingHeader::new("Document")
.id_salt(("document", path))
@@ -503,6 +508,328 @@ impl InfopanelPane {
ui.add_space(4.0);
});
}
/// Render layer info section
fn render_layer_section(&self, ui: &mut Ui, path: &NodePath, shared: &SharedPaneState, layer_ids: &[Uuid]) {
let document = shared.action_executor.document();
egui::CollapsingHeader::new("Layer")
.id_salt(("layer_info", path))
.default_open(true)
.show(ui, |ui| {
ui.add_space(4.0);
if layer_ids.len() == 1 {
if let Some(layer) = document.get_layer(&layer_ids[0]) {
ui.horizontal(|ui| {
ui.label("Name:");
ui.label(layer.name());
});
let type_name = match layer {
AnyLayer::Vector(_) => "Vector",
AnyLayer::Audio(a) => match a.audio_layer_type {
lightningbeam_core::layer::AudioLayerType::Midi => "MIDI",
lightningbeam_core::layer::AudioLayerType::Sampled => "Audio",
},
AnyLayer::Video(_) => "Video",
AnyLayer::Effect(_) => "Effect",
AnyLayer::Group(_) => "Group",
};
ui.horizontal(|ui| {
ui.label("Type:");
ui.label(type_name);
});
ui.horizontal(|ui| {
ui.label("Opacity:");
ui.label(format!("{:.0}%", layer.opacity() * 100.0));
});
if matches!(layer, AnyLayer::Audio(_)) {
ui.horizontal(|ui| {
ui.label("Volume:");
ui.label(format!("{:.0}%", layer.volume() * 100.0));
});
}
if layer.muted() {
ui.label("Muted");
}
if layer.locked() {
ui.label("Locked");
}
}
} else {
ui.label(format!("{} layers selected", layer_ids.len()));
}
ui.add_space(4.0);
});
}
/// Render clip instance info section
fn render_clip_instance_section(&self, ui: &mut Ui, path: &NodePath, shared: &SharedPaneState, clip_ids: &[Uuid]) {
let document = shared.action_executor.document();
egui::CollapsingHeader::new("Clip Instance")
.id_salt(("clip_instance_info", path))
.default_open(true)
.show(ui, |ui| {
ui.add_space(4.0);
if clip_ids.len() == 1 {
// Find the clip instance across all layers
let ci_id = clip_ids[0];
let mut found = false;
for layer in document.all_layers() {
let instances: &[lightningbeam_core::clip::ClipInstance] = match layer {
AnyLayer::Vector(l) => &l.clip_instances,
AnyLayer::Audio(l) => &l.clip_instances,
AnyLayer::Video(l) => &l.clip_instances,
AnyLayer::Effect(l) => &l.clip_instances,
AnyLayer::Group(_) => &[],
};
if let Some(ci) = instances.iter().find(|c| c.id == ci_id) {
found = true;
if let Some(name) = &ci.name {
ui.horizontal(|ui| {
ui.label("Name:");
ui.label(name.as_str());
});
}
// Show clip name based on type
let clip_name = document.get_vector_clip(&ci.clip_id).map(|c| c.name.as_str())
.or_else(|| document.get_video_clip(&ci.clip_id).map(|c| c.name.as_str()))
.or_else(|| document.get_audio_clip(&ci.clip_id).map(|c| c.name.as_str()));
if let Some(name) = clip_name {
ui.horizontal(|ui| {
ui.label("Clip:");
ui.label(name);
});
}
ui.horizontal(|ui| {
ui.label("Start:");
ui.label(format!("{:.2}s", ci.effective_start()));
});
let clip_dur = document.get_clip_duration(&ci.clip_id)
.unwrap_or_else(|| ci.trim_end.unwrap_or(1.0) - ci.trim_start);
let total_dur = ci.total_duration(clip_dur);
ui.horizontal(|ui| {
ui.label("Duration:");
ui.label(format!("{:.2}s", total_dur));
});
if ci.trim_start > 0.0 {
ui.horizontal(|ui| {
ui.label("Trim Start:");
ui.label(format!("{:.2}s", ci.trim_start));
});
}
if ci.playback_speed != 1.0 {
ui.horizontal(|ui| {
ui.label("Speed:");
ui.label(format!("{:.2}x", ci.playback_speed));
});
}
break;
}
}
if !found {
ui.label("Clip instance not found");
}
} else {
ui.label(format!("{} clip instances selected", clip_ids.len()));
}
ui.add_space(4.0);
});
}
/// Render MIDI note info section
fn render_notes_section(
&self,
ui: &mut Ui,
path: &NodePath,
shared: &SharedPaneState,
layer_id: Uuid,
midi_clip_id: u32,
indices: &[usize],
) {
egui::CollapsingHeader::new("Notes")
.id_salt(("notes_info", path))
.default_open(true)
.show(ui, |ui| {
ui.add_space(4.0);
// Show layer name
let document = shared.action_executor.document();
if let Some(layer) = document.get_layer(&layer_id) {
ui.horizontal(|ui| {
ui.label("Layer:");
ui.label(layer.name());
});
}
if indices.len() == 1 {
// Single note — show details if we can resolve from the event cache
if let Some(events) = shared.midi_event_cache.get(&midi_clip_id) {
// Events are (time, note, velocity, is_on) — resolve to notes
let mut notes: Vec<(f64, u8, u8, f64)> = Vec::new(); // (time, note, vel, dur)
let mut pending: std::collections::HashMap<u8, (f64, u8)> = std::collections::HashMap::new();
for &(time, note, vel, is_on) in events {
if is_on {
pending.insert(note, (time, vel));
} else if let Some((start, v)) = pending.remove(&note) {
notes.push((start, note, v, time - start));
}
}
notes.sort_by(|a, b| a.0.partial_cmp(&b.0).unwrap_or(std::cmp::Ordering::Equal));
let idx = indices[0];
if idx < notes.len() {
let (time, note, vel, dur) = notes[idx];
let note_name = midi_note_name(note);
ui.horizontal(|ui| {
ui.label("Note:");
ui.label(format!("{} ({})", note_name, note));
});
ui.horizontal(|ui| {
ui.label("Time:");
ui.label(format!("{:.3}s", time));
});
ui.horizontal(|ui| {
ui.label("Duration:");
ui.label(format!("{:.3}s", dur));
});
ui.horizontal(|ui| {
ui.label("Velocity:");
ui.label(format!("{}", vel));
});
}
}
} else {
ui.label(format!("{} notes selected", indices.len()));
}
ui.add_space(4.0);
});
}
/// Render node graph info section
fn render_nodes_section(&self, ui: &mut Ui, path: &NodePath, node_indices: &[u32]) {
egui::CollapsingHeader::new("Nodes")
.id_salt(("nodes_info", path))
.default_open(true)
.show(ui, |ui| {
ui.add_space(4.0);
ui.label(format!(
"{} node{} selected",
node_indices.len(),
if node_indices.len() == 1 { "" } else { "s" }
));
ui.add_space(4.0);
});
}
/// Render asset info section
fn render_asset_section(&self, ui: &mut Ui, path: &NodePath, shared: &SharedPaneState, asset_ids: &[Uuid]) {
let document = shared.action_executor.document();
egui::CollapsingHeader::new("Asset")
.id_salt(("asset_info", path))
.default_open(true)
.show(ui, |ui| {
ui.add_space(4.0);
if asset_ids.len() == 1 {
let id = asset_ids[0];
if let Some(clip) = document.get_vector_clip(&id) {
ui.horizontal(|ui| {
ui.label("Name:");
ui.label(&clip.name);
});
ui.horizontal(|ui| {
ui.label("Type:");
ui.label("Vector");
});
ui.horizontal(|ui| {
ui.label("Size:");
ui.label(format!("{:.0} x {:.0}", clip.width, clip.height));
});
ui.horizontal(|ui| {
ui.label("Duration:");
ui.label(format!("{:.2}s", clip.duration));
});
} else if let Some(clip) = document.get_video_clip(&id) {
ui.horizontal(|ui| {
ui.label("Name:");
ui.label(&clip.name);
});
ui.horizontal(|ui| {
ui.label("Type:");
ui.label("Video");
});
ui.horizontal(|ui| {
ui.label("Size:");
ui.label(format!("{:.0} x {:.0}", clip.width, clip.height));
});
ui.horizontal(|ui| {
ui.label("Duration:");
ui.label(format!("{:.2}s", clip.duration));
});
ui.horizontal(|ui| {
ui.label("Frame Rate:");
ui.label(format!("{:.1} fps", clip.frame_rate));
});
} else if let Some(clip) = document.get_audio_clip(&id) {
ui.horizontal(|ui| {
ui.label("Name:");
ui.label(&clip.name);
});
let type_name = match &clip.clip_type {
lightningbeam_core::clip::AudioClipType::Sampled { .. } => "Audio (Sampled)",
lightningbeam_core::clip::AudioClipType::Midi { .. } => "Audio (MIDI)",
lightningbeam_core::clip::AudioClipType::Recording => "Audio (Recording)",
};
ui.horizontal(|ui| {
ui.label("Type:");
ui.label(type_name);
});
ui.horizontal(|ui| {
ui.label("Duration:");
ui.label(format!("{:.2}s", clip.duration));
});
} else {
// Could be an image asset or effect — show ID
ui.label(format!("Asset {}", id));
}
} else {
ui.label(format!("{} assets selected", asset_ids.len()));
}
ui.add_space(4.0);
});
}
}
/// Convert MIDI note number to note name (e.g. 60 -> "C4")
fn midi_note_name(note: u8) -> String {
const NAMES: [&str; 12] = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"];
let octave = (note as i32 / 12) - 1;
let name = NAMES[note as usize % 12];
format!("{}{}", name, octave)
}
impl PaneRenderer for InfopanelPane {
@@ -536,29 +863,59 @@ impl PaneRenderer for InfopanelPane {
// 1. Tool options section (always shown if tool has options)
self.render_tool_section(ui, path, shared);
// 2. Gather selection info
let info = self.gather_selection_info(shared);
// 3. Shape properties section (if DCEL elements selected)
if info.dcel_count > 0 {
self.render_shape_section(ui, path, shared, &info);
}
// 5. Document settings (if nothing selected)
if info.is_empty {
self.render_document_section(ui, path, shared);
}
// Show selection count at bottom
if info.dcel_count > 0 {
ui.add_space(8.0);
ui.separator();
ui.add_space(4.0);
ui.label(format!(
"{} object{} selected",
info.dcel_count,
if info.dcel_count == 1 { "" } else { "s" }
));
// 2. Focus-driven content
// Clone focus to avoid borrow issues with shared
let focus = shared.focus.clone();
match &focus {
FocusSelection::Layers(ids) => {
self.render_layer_section(ui, path, shared, ids);
}
FocusSelection::ClipInstances(ids) => {
self.render_clip_instance_section(ui, path, shared, ids);
}
FocusSelection::Geometry { .. } => {
let info = self.gather_selection_info(shared);
if info.dcel_count > 0 {
self.render_shape_section(ui, path, shared, &info);
}
// Selection count
if info.dcel_count > 0 {
ui.add_space(8.0);
ui.separator();
ui.add_space(4.0);
ui.label(format!(
"{} object{} selected",
info.dcel_count,
if info.dcel_count == 1 { "" } else { "s" }
));
}
}
FocusSelection::Notes { layer_id, midi_clip_id, indices } => {
self.render_notes_section(ui, path, shared, *layer_id, *midi_clip_id, indices);
}
FocusSelection::Nodes(indices) => {
self.render_nodes_section(ui, path, indices);
}
FocusSelection::Assets(ids) => {
self.render_asset_section(ui, path, shared, ids);
}
FocusSelection::None => {
// Fallback: check if there's a DCEL selection even without focus
let info = self.gather_selection_info(shared);
if info.dcel_count > 0 {
self.render_shape_section(ui, path, shared, &info);
ui.add_space(8.0);
ui.separator();
ui.add_space(4.0);
ui.label(format!(
"{} object{} selected",
info.dcel_count,
if info.dcel_count == 1 { "" } else { "s" }
));
} else {
self.render_document_section(ui, path, shared);
}
}
}
});
}