This commit is contained in:
Skyler Lehmkuhl
2025-11-13 18:12:21 -05:00
parent bf007e774e
commit 48da21e062
25 changed files with 6812 additions and 137 deletions
@@ -0,0 +1,45 @@
/// Info Panel pane - displays properties of selected objects
///
/// This will eventually show editable properties.
/// For now, it's a placeholder.
use eframe::egui;
use super::{NodePath, PaneRenderer, SharedPaneState};
pub struct InfopanelPane {}
impl InfopanelPane {
pub fn new() -> Self {
Self {}
}
}
impl PaneRenderer for InfopanelPane {
fn render_content(
&mut self,
ui: &mut egui::Ui,
rect: egui::Rect,
_path: &NodePath,
_shared: &mut SharedPaneState,
) {
// Placeholder rendering
ui.painter().rect_filled(
rect,
0.0,
egui::Color32::from_rgb(30, 50, 40),
);
let text = "Info Panel\n(TODO: Implement property editor)";
ui.painter().text(
rect.center(),
egui::Align2::CENTER_CENTER,
text,
egui::FontId::proportional(16.0),
egui::Color32::from_gray(150),
);
}
fn name(&self) -> &str {
"Info Panel"
}
}
@@ -0,0 +1,145 @@
/// Pane implementations for the editor
///
/// Each pane type has its own module with implementation details.
/// Panes can hold local state and access shared state through SharedPaneState.
use eframe::egui;
use lightningbeam_core::{pane::PaneType, tool::Tool};
// Type alias for node paths (matches main.rs)
pub type NodePath = Vec<usize>;
pub mod toolbar;
pub mod stage;
pub mod timeline;
pub mod infopanel;
pub mod outliner;
pub mod piano_roll;
pub mod node_editor;
pub mod preset_browser;
/// Shared state that all panes can access
pub struct SharedPaneState<'a> {
pub tool_icon_cache: &'a mut crate::ToolIconCache,
pub icon_cache: &'a mut crate::IconCache,
pub selected_tool: &'a mut Tool,
pub fill_color: &'a mut egui::Color32,
pub stroke_color: &'a mut egui::Color32,
}
/// Trait for pane rendering
///
/// Panes implement this trait to provide custom rendering logic.
/// The header is optional and typically used for controls (e.g., Timeline playback).
/// The content area is the main body of the pane.
pub trait PaneRenderer {
/// Render the optional header section with controls
///
/// Returns true if a header was rendered, false if no header
fn render_header(&mut self, ui: &mut egui::Ui, shared: &mut SharedPaneState) -> bool {
false // Default: no header
}
/// Render the main content area
fn render_content(
&mut self,
ui: &mut egui::Ui,
rect: egui::Rect,
path: &NodePath,
shared: &mut SharedPaneState,
);
/// Get the display name of this pane
fn name(&self) -> &str;
}
/// Enum wrapper for all pane implementations (enum dispatch pattern)
pub enum PaneInstance {
Stage(stage::StagePane),
Timeline(timeline::TimelinePane),
Toolbar(toolbar::ToolbarPane),
Infopanel(infopanel::InfopanelPane),
Outliner(outliner::OutlinerPane),
PianoRoll(piano_roll::PianoRollPane),
NodeEditor(node_editor::NodeEditorPane),
PresetBrowser(preset_browser::PresetBrowserPane),
}
impl PaneInstance {
/// Create a new pane instance for the given type
pub fn new(pane_type: PaneType) -> Self {
match pane_type {
PaneType::Stage => PaneInstance::Stage(stage::StagePane::new()),
PaneType::Timeline => PaneInstance::Timeline(timeline::TimelinePane::new()),
PaneType::Toolbar => PaneInstance::Toolbar(toolbar::ToolbarPane::new()),
PaneType::Infopanel => PaneInstance::Infopanel(infopanel::InfopanelPane::new()),
PaneType::Outliner => PaneInstance::Outliner(outliner::OutlinerPane::new()),
PaneType::PianoRoll => PaneInstance::PianoRoll(piano_roll::PianoRollPane::new()),
PaneType::NodeEditor => PaneInstance::NodeEditor(node_editor::NodeEditorPane::new()),
PaneType::PresetBrowser => {
PaneInstance::PresetBrowser(preset_browser::PresetBrowserPane::new())
}
}
}
/// Get the pane type of this instance
pub fn pane_type(&self) -> PaneType {
match self {
PaneInstance::Stage(_) => PaneType::Stage,
PaneInstance::Timeline(_) => PaneType::Timeline,
PaneInstance::Toolbar(_) => PaneType::Toolbar,
PaneInstance::Infopanel(_) => PaneType::Infopanel,
PaneInstance::Outliner(_) => PaneType::Outliner,
PaneInstance::PianoRoll(_) => PaneType::PianoRoll,
PaneInstance::NodeEditor(_) => PaneType::NodeEditor,
PaneInstance::PresetBrowser(_) => PaneType::PresetBrowser,
}
}
}
impl PaneRenderer for PaneInstance {
fn render_header(&mut self, ui: &mut egui::Ui, shared: &mut SharedPaneState) -> bool {
match self {
PaneInstance::Stage(p) => p.render_header(ui, shared),
PaneInstance::Timeline(p) => p.render_header(ui, shared),
PaneInstance::Toolbar(p) => p.render_header(ui, shared),
PaneInstance::Infopanel(p) => p.render_header(ui, shared),
PaneInstance::Outliner(p) => p.render_header(ui, shared),
PaneInstance::PianoRoll(p) => p.render_header(ui, shared),
PaneInstance::NodeEditor(p) => p.render_header(ui, shared),
PaneInstance::PresetBrowser(p) => p.render_header(ui, shared),
}
}
fn render_content(
&mut self,
ui: &mut egui::Ui,
rect: egui::Rect,
path: &NodePath,
shared: &mut SharedPaneState,
) {
match self {
PaneInstance::Stage(p) => p.render_content(ui, rect, path, shared),
PaneInstance::Timeline(p) => p.render_content(ui, rect, path, shared),
PaneInstance::Toolbar(p) => p.render_content(ui, rect, path, shared),
PaneInstance::Infopanel(p) => p.render_content(ui, rect, path, shared),
PaneInstance::Outliner(p) => p.render_content(ui, rect, path, shared),
PaneInstance::PianoRoll(p) => p.render_content(ui, rect, path, shared),
PaneInstance::NodeEditor(p) => p.render_content(ui, rect, path, shared),
PaneInstance::PresetBrowser(p) => p.render_content(ui, rect, path, shared),
}
}
fn name(&self) -> &str {
match self {
PaneInstance::Stage(p) => p.name(),
PaneInstance::Timeline(p) => p.name(),
PaneInstance::Toolbar(p) => p.name(),
PaneInstance::Infopanel(p) => p.name(),
PaneInstance::Outliner(p) => p.name(),
PaneInstance::PianoRoll(p) => p.name(),
PaneInstance::NodeEditor(p) => p.name(),
PaneInstance::PresetBrowser(p) => p.name(),
}
}
}
@@ -0,0 +1,45 @@
/// Node Editor pane - node-based visual programming
///
/// This will eventually render a node graph with Vello.
/// For now, it's a placeholder.
use eframe::egui;
use super::{NodePath, PaneRenderer, SharedPaneState};
pub struct NodeEditorPane {}
impl NodeEditorPane {
pub fn new() -> Self {
Self {}
}
}
impl PaneRenderer for NodeEditorPane {
fn render_content(
&mut self,
ui: &mut egui::Ui,
rect: egui::Rect,
_path: &NodePath,
_shared: &mut SharedPaneState,
) {
// Placeholder rendering
ui.painter().rect_filled(
rect,
0.0,
egui::Color32::from_rgb(30, 45, 50),
);
let text = "Node Editor\n(TODO: Implement node graph)";
ui.painter().text(
rect.center(),
egui::Align2::CENTER_CENTER,
text,
egui::FontId::proportional(16.0),
egui::Color32::from_gray(150),
);
}
fn name(&self) -> &str {
"Node Editor"
}
}
@@ -0,0 +1,47 @@
/// Outliner pane - layer hierarchy view
///
/// This will eventually show a tree view of layers.
/// For now, it's a placeholder.
use eframe::egui;
use super::{NodePath, PaneRenderer, SharedPaneState};
pub struct OutlinerPane {
// TODO: Add tree expansion state
}
impl OutlinerPane {
pub fn new() -> Self {
Self {}
}
}
impl PaneRenderer for OutlinerPane {
fn render_content(
&mut self,
ui: &mut egui::Ui,
rect: egui::Rect,
_path: &NodePath,
_shared: &mut SharedPaneState,
) {
// Placeholder rendering
ui.painter().rect_filled(
rect,
0.0,
egui::Color32::from_rgb(40, 50, 30),
);
let text = "Outliner\n(TODO: Implement layer tree)";
ui.painter().text(
rect.center(),
egui::Align2::CENTER_CENTER,
text,
egui::FontId::proportional(16.0),
egui::Color32::from_gray(150),
);
}
fn name(&self) -> &str {
"Outliner"
}
}
@@ -0,0 +1,45 @@
/// Piano Roll pane - MIDI editor
///
/// This will eventually render a piano roll with Vello.
/// For now, it's a placeholder.
use eframe::egui;
use super::{NodePath, PaneRenderer, SharedPaneState};
pub struct PianoRollPane {}
impl PianoRollPane {
pub fn new() -> Self {
Self {}
}
}
impl PaneRenderer for PianoRollPane {
fn render_content(
&mut self,
ui: &mut egui::Ui,
rect: egui::Rect,
_path: &NodePath,
_shared: &mut SharedPaneState,
) {
// Placeholder rendering
ui.painter().rect_filled(
rect,
0.0,
egui::Color32::from_rgb(55, 35, 45),
);
let text = "Piano Roll\n(TODO: Implement MIDI editor)";
ui.painter().text(
rect.center(),
egui::Align2::CENTER_CENTER,
text,
egui::FontId::proportional(16.0),
egui::Color32::from_gray(150),
);
}
fn name(&self) -> &str {
"Piano Roll"
}
}
@@ -0,0 +1,45 @@
/// Preset Browser pane - asset and preset library
///
/// This will eventually show a file browser for presets.
/// For now, it's a placeholder.
use eframe::egui;
use super::{NodePath, PaneRenderer, SharedPaneState};
pub struct PresetBrowserPane {}
impl PresetBrowserPane {
pub fn new() -> Self {
Self {}
}
}
impl PaneRenderer for PresetBrowserPane {
fn render_content(
&mut self,
ui: &mut egui::Ui,
rect: egui::Rect,
_path: &NodePath,
_shared: &mut SharedPaneState,
) {
// Placeholder rendering
ui.painter().rect_filled(
rect,
0.0,
egui::Color32::from_rgb(50, 45, 30),
);
let text = "Preset Browser\n(TODO: Implement file browser)";
ui.painter().text(
rect.center(),
egui::Align2::CENTER_CENTER,
text,
egui::FontId::proportional(16.0),
egui::Color32::from_gray(150),
);
}
fn name(&self) -> &str {
"Preset Browser"
}
}
@@ -0,0 +1,47 @@
/// Stage pane - main animation canvas
///
/// This will eventually render the composited layers using Vello.
/// For now, it's a placeholder.
use eframe::egui;
use super::{NodePath, PaneRenderer, SharedPaneState};
pub struct StagePane {
// TODO: Add state for camera, selection, etc.
}
impl StagePane {
pub fn new() -> Self {
Self {}
}
}
impl PaneRenderer for StagePane {
fn render_content(
&mut self,
ui: &mut egui::Ui,
rect: egui::Rect,
_path: &NodePath,
_shared: &mut SharedPaneState,
) {
// Placeholder rendering
ui.painter().rect_filled(
rect,
0.0,
egui::Color32::from_rgb(30, 40, 50),
);
let text = "Stage Pane\n(TODO: Implement Vello rendering)";
ui.painter().text(
rect.center(),
egui::Align2::CENTER_CENTER,
text,
egui::FontId::proportional(16.0),
egui::Color32::from_gray(150),
);
}
fn name(&self) -> &str {
"Stage"
}
}
@@ -0,0 +1,57 @@
/// Timeline pane - frame-based animation timeline
///
/// This will eventually render keyframes, layers, and playback controls.
/// For now, it's a placeholder.
use eframe::egui;
use super::{NodePath, PaneRenderer, SharedPaneState};
pub struct TimelinePane {
// TODO: Add state for zoom, scroll, playback, etc.
}
impl TimelinePane {
pub fn new() -> Self {
Self {}
}
}
impl PaneRenderer for TimelinePane {
fn render_header(&mut self, ui: &mut egui::Ui, _shared: &mut SharedPaneState) -> bool {
// TODO: Add playback controls (play/pause, frame counter, zoom)
ui.horizontal(|ui| {
ui.label("⏯");
ui.label("Frame: 0");
ui.label("FPS: 24");
});
true // Header was rendered
}
fn render_content(
&mut self,
ui: &mut egui::Ui,
rect: egui::Rect,
_path: &NodePath,
_shared: &mut SharedPaneState,
) {
// Placeholder rendering
ui.painter().rect_filled(
rect,
0.0,
egui::Color32::from_rgb(40, 30, 50),
);
let text = "Timeline Pane\n(TODO: Implement frame scrubbing)";
ui.painter().text(
rect.center(),
egui::Align2::CENTER_CENTER,
text,
egui::FontId::proportional(16.0),
egui::Color32::from_gray(150),
);
}
fn name(&self) -> &str {
"Timeline"
}
}
@@ -0,0 +1,235 @@
/// Toolbar pane - displays drawing tool buttons
///
/// The toolbar shows all available drawing tools in a responsive grid layout.
/// Users can click to select tools, which updates the global selected_tool state.
use eframe::egui;
use lightningbeam_core::tool::Tool;
use super::{NodePath, PaneRenderer, SharedPaneState};
/// Toolbar pane state
pub struct ToolbarPane {
// No local state needed for toolbar
}
impl ToolbarPane {
pub fn new() -> Self {
Self {}
}
}
impl PaneRenderer for ToolbarPane {
fn render_content(
&mut self,
ui: &mut egui::Ui,
rect: egui::Rect,
path: &NodePath,
shared: &mut SharedPaneState,
) {
let button_size = 60.0;
let button_padding = 8.0;
let button_spacing = 4.0;
// Calculate how many columns we can fit
let available_width = rect.width() - (button_padding * 2.0);
let columns =
((available_width + button_spacing) / (button_size + button_spacing)).floor() as usize;
let columns = columns.max(1); // At least 1 column
// Calculate total number of tools and rows
let tools = Tool::all();
let total_tools = tools.len();
let total_rows = (total_tools + columns - 1) / columns;
let mut y = rect.top() + button_padding;
// Process tools row by row for centered layout
for row in 0..total_rows {
let start_idx = row * columns;
let end_idx = (start_idx + columns).min(total_tools);
let buttons_in_row = end_idx - start_idx;
// Calculate the total width of buttons in this row
let row_width = (buttons_in_row as f32 * button_size)
+ ((buttons_in_row.saturating_sub(1)) as f32 * button_spacing);
// Center the row
let mut x = rect.left() + (rect.width() - row_width) / 2.0;
for tool_idx in start_idx..end_idx {
let tool = &tools[tool_idx];
let button_rect =
egui::Rect::from_min_size(egui::pos2(x, y), egui::vec2(button_size, button_size));
// Check if this is the selected tool
let is_selected = *shared.selected_tool == *tool;
// Button background
let bg_color = if is_selected {
egui::Color32::from_rgb(70, 100, 150) // Highlighted blue
} else {
egui::Color32::from_rgb(50, 50, 50)
};
ui.painter().rect_filled(button_rect, 4.0, bg_color);
// Load and render tool icon
if let Some(icon) = shared.tool_icon_cache.get_or_load(*tool, ui.ctx()) {
let icon_rect = button_rect.shrink(8.0); // Padding inside button
ui.painter().image(
icon.id(),
icon_rect,
egui::Rect::from_min_max(egui::pos2(0.0, 0.0), egui::pos2(1.0, 1.0)),
egui::Color32::WHITE,
);
}
// Make button interactive (include path to ensure unique IDs across panes)
let button_id = ui.id().with(("tool_button", path, *tool as usize));
let response = ui.interact(button_rect, button_id, egui::Sense::click());
// Check for click first
if response.clicked() {
*shared.selected_tool = *tool;
}
if response.hovered() {
ui.painter().rect_stroke(
button_rect,
4.0,
egui::Stroke::new(2.0, egui::Color32::from_gray(180)),
);
}
// Show tooltip with tool name and shortcut (consumes response)
response.on_hover_text(format!("{} ({})", tool.display_name(), tool.shortcut_hint()));
// Draw selection border
if is_selected {
ui.painter().rect_stroke(
button_rect,
4.0,
egui::Stroke::new(2.0, egui::Color32::from_rgb(100, 150, 255)),
);
}
// Move to next column in this row
x += button_size + button_spacing;
}
// Move to next row
y += button_size + button_spacing;
}
// Add color pickers below the tool buttons
y += button_spacing * 2.0; // Extra spacing
// Fill Color
let fill_label_width = 40.0;
let color_button_size = 50.0;
let color_row_width = fill_label_width + color_button_size + button_spacing;
let color_x = rect.left() + (rect.width() - color_row_width) / 2.0;
// Fill color label
ui.painter().text(
egui::pos2(color_x + fill_label_width / 2.0, y + color_button_size / 2.0),
egui::Align2::CENTER_CENTER,
"Fill",
egui::FontId::proportional(14.0),
egui::Color32::from_gray(200),
);
// Fill color button
let fill_button_rect = egui::Rect::from_min_size(
egui::pos2(color_x + fill_label_width + button_spacing, y),
egui::vec2(color_button_size, color_button_size),
);
let fill_button_id = ui.id().with(("fill_color_button", path));
let fill_response = ui.interact(fill_button_rect, fill_button_id, egui::Sense::click());
// Draw fill color button with checkerboard for alpha
draw_color_button(ui, fill_button_rect, *shared.fill_color);
if fill_response.clicked() {
// Open color picker popup
ui.memory_mut(|mem| mem.toggle_popup(fill_button_id));
}
// Show fill color picker popup
egui::popup::popup_below_widget(ui, fill_button_id, &fill_response, egui::popup::PopupCloseBehavior::CloseOnClickOutside, |ui: &mut egui::Ui| {
egui::color_picker::color_picker_color32(ui, shared.fill_color, egui::color_picker::Alpha::OnlyBlend);
});
y += color_button_size + button_spacing;
// Stroke color label
ui.painter().text(
egui::pos2(color_x + fill_label_width / 2.0, y + color_button_size / 2.0),
egui::Align2::CENTER_CENTER,
"Stroke",
egui::FontId::proportional(14.0),
egui::Color32::from_gray(200),
);
// Stroke color button
let stroke_button_rect = egui::Rect::from_min_size(
egui::pos2(color_x + fill_label_width + button_spacing, y),
egui::vec2(color_button_size, color_button_size),
);
let stroke_button_id = ui.id().with(("stroke_color_button", path));
let stroke_response = ui.interact(stroke_button_rect, stroke_button_id, egui::Sense::click());
// Draw stroke color button with checkerboard for alpha
draw_color_button(ui, stroke_button_rect, *shared.stroke_color);
if stroke_response.clicked() {
// Open color picker popup
ui.memory_mut(|mem| mem.toggle_popup(stroke_button_id));
}
// Show stroke color picker popup
egui::popup::popup_below_widget(ui, stroke_button_id, &stroke_response, egui::popup::PopupCloseBehavior::CloseOnClickOutside, |ui: &mut egui::Ui| {
egui::color_picker::color_picker_color32(ui, shared.stroke_color, egui::color_picker::Alpha::OnlyBlend);
});
}
fn name(&self) -> &str {
"Toolbar"
}
}
/// Draw a color button with checkerboard background for alpha channel
fn draw_color_button(ui: &mut egui::Ui, rect: egui::Rect, color: egui::Color32) {
// Draw checkerboard background
let checker_size = 5.0;
let cols = (rect.width() / checker_size).ceil() as usize;
let rows = (rect.height() / checker_size).ceil() as usize;
for row in 0..rows {
for col in 0..cols {
let is_light = (row + col) % 2 == 0;
let checker_color = if is_light {
egui::Color32::from_gray(180)
} else {
egui::Color32::from_gray(120)
};
let checker_rect = egui::Rect::from_min_size(
egui::pos2(
rect.min.x + col as f32 * checker_size,
rect.min.y + row as f32 * checker_size,
),
egui::vec2(checker_size, checker_size),
).intersect(rect);
ui.painter().rect_filled(checker_rect, 0.0, checker_color);
}
}
// Draw color on top
ui.painter().rect_filled(rect, 2.0, color);
// Draw border
ui.painter().rect_stroke(
rect,
2.0,
egui::Stroke::new(1.0, egui::Color32::from_gray(80)),
);
}