Add asset pane
This commit is contained in:
@@ -0,0 +1,814 @@
|
||||
//! Asset Library pane - browse and manage project assets
|
||||
//!
|
||||
//! Displays all clips in the document organized by category:
|
||||
//! - Vector Clips (animations)
|
||||
//! - Video Clips (imported video files)
|
||||
//! - Audio Clips (sampled audio and MIDI)
|
||||
|
||||
use eframe::egui;
|
||||
use lightningbeam_core::clip::AudioClipType;
|
||||
use lightningbeam_core::document::Document;
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::{DragClipType, DraggingAsset, NodePath, PaneRenderer, SharedPaneState};
|
||||
use crate::widgets::ImeTextField;
|
||||
|
||||
// Layout constants
|
||||
const SEARCH_BAR_HEIGHT: f32 = 30.0;
|
||||
const CATEGORY_TAB_HEIGHT: f32 = 28.0;
|
||||
const ITEM_HEIGHT: f32 = 40.0;
|
||||
const ITEM_PADDING: f32 = 4.0;
|
||||
|
||||
/// Asset category for filtering
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum AssetCategory {
|
||||
All,
|
||||
Vector,
|
||||
Video,
|
||||
Audio,
|
||||
Images,
|
||||
}
|
||||
|
||||
impl AssetCategory {
|
||||
pub fn display_name(&self) -> &'static str {
|
||||
match self {
|
||||
AssetCategory::All => "All",
|
||||
AssetCategory::Vector => "Vector",
|
||||
AssetCategory::Video => "Video",
|
||||
AssetCategory::Audio => "Audio",
|
||||
AssetCategory::Images => "Images",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn all() -> &'static [AssetCategory] {
|
||||
&[
|
||||
AssetCategory::All,
|
||||
AssetCategory::Vector,
|
||||
AssetCategory::Video,
|
||||
AssetCategory::Audio,
|
||||
AssetCategory::Images,
|
||||
]
|
||||
}
|
||||
|
||||
/// Get the color associated with this category
|
||||
pub fn color(&self) -> egui::Color32 {
|
||||
match self {
|
||||
AssetCategory::All => egui::Color32::from_gray(150),
|
||||
AssetCategory::Vector => egui::Color32::from_rgb(100, 150, 255), // Blue
|
||||
AssetCategory::Video => egui::Color32::from_rgb(255, 150, 100), // Orange
|
||||
AssetCategory::Audio => egui::Color32::from_rgb(100, 255, 150), // Green
|
||||
AssetCategory::Images => egui::Color32::from_rgb(255, 200, 100), // Yellow/Gold
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Unified asset entry for display
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AssetEntry {
|
||||
pub id: Uuid,
|
||||
pub name: String,
|
||||
pub category: AssetCategory,
|
||||
/// More specific clip type for drag-and-drop compatibility
|
||||
pub drag_clip_type: DragClipType,
|
||||
pub duration: f64,
|
||||
pub dimensions: Option<(f64, f64)>,
|
||||
pub extra_info: String,
|
||||
}
|
||||
|
||||
/// Pending delete confirmation state
|
||||
#[derive(Debug, Clone)]
|
||||
struct PendingDelete {
|
||||
asset_id: Uuid,
|
||||
asset_name: String,
|
||||
category: AssetCategory,
|
||||
in_use: bool,
|
||||
}
|
||||
|
||||
/// Inline rename editing state
|
||||
#[derive(Debug, Clone)]
|
||||
struct RenameState {
|
||||
asset_id: Uuid,
|
||||
category: AssetCategory,
|
||||
edit_text: String,
|
||||
}
|
||||
|
||||
/// Context menu state with position
|
||||
#[derive(Debug, Clone)]
|
||||
struct ContextMenuState {
|
||||
asset_id: Uuid,
|
||||
position: egui::Pos2,
|
||||
}
|
||||
|
||||
pub struct AssetLibraryPane {
|
||||
/// Current search filter text
|
||||
search_filter: String,
|
||||
|
||||
/// Currently selected category tab
|
||||
selected_category: AssetCategory,
|
||||
|
||||
/// Currently selected asset ID (for future drag-to-timeline)
|
||||
selected_asset: Option<Uuid>,
|
||||
|
||||
/// Context menu state with position
|
||||
context_menu: Option<ContextMenuState>,
|
||||
|
||||
/// Pending delete confirmation
|
||||
pending_delete: Option<PendingDelete>,
|
||||
|
||||
/// Active rename state
|
||||
rename_state: Option<RenameState>,
|
||||
}
|
||||
|
||||
impl AssetLibraryPane {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
search_filter: String::new(),
|
||||
selected_category: AssetCategory::All,
|
||||
selected_asset: None,
|
||||
context_menu: None,
|
||||
pending_delete: None,
|
||||
rename_state: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Collect all assets from the document into a unified list
|
||||
fn collect_assets(&self, document: &Document) -> Vec<AssetEntry> {
|
||||
let mut assets = Vec::new();
|
||||
|
||||
// Collect vector clips
|
||||
for (id, clip) in &document.vector_clips {
|
||||
assets.push(AssetEntry {
|
||||
id: *id,
|
||||
name: clip.name.clone(),
|
||||
category: AssetCategory::Vector,
|
||||
drag_clip_type: DragClipType::Vector,
|
||||
duration: clip.duration,
|
||||
dimensions: Some((clip.width, clip.height)),
|
||||
extra_info: format!("{}x{}", clip.width as u32, clip.height as u32),
|
||||
});
|
||||
}
|
||||
|
||||
// Collect video clips
|
||||
for (id, clip) in &document.video_clips {
|
||||
assets.push(AssetEntry {
|
||||
id: *id,
|
||||
name: clip.name.clone(),
|
||||
category: AssetCategory::Video,
|
||||
drag_clip_type: DragClipType::Video,
|
||||
duration: clip.duration,
|
||||
dimensions: Some((clip.width, clip.height)),
|
||||
extra_info: format!("{:.0}fps", clip.frame_rate),
|
||||
});
|
||||
}
|
||||
|
||||
// Collect audio clips
|
||||
for (id, clip) in &document.audio_clips {
|
||||
let (extra_info, drag_clip_type) = match &clip.clip_type {
|
||||
AudioClipType::Sampled { .. } => ("Sampled".to_string(), DragClipType::AudioSampled),
|
||||
AudioClipType::Midi { .. } => ("MIDI".to_string(), DragClipType::AudioMidi),
|
||||
};
|
||||
|
||||
assets.push(AssetEntry {
|
||||
id: *id,
|
||||
name: clip.name.clone(),
|
||||
category: AssetCategory::Audio,
|
||||
drag_clip_type,
|
||||
duration: clip.duration,
|
||||
dimensions: None,
|
||||
extra_info,
|
||||
});
|
||||
}
|
||||
|
||||
// Collect image assets
|
||||
for (id, asset) in &document.image_assets {
|
||||
assets.push(AssetEntry {
|
||||
id: *id,
|
||||
name: asset.name.clone(),
|
||||
category: AssetCategory::Images,
|
||||
drag_clip_type: DragClipType::Image,
|
||||
duration: 0.0, // Images don't have duration
|
||||
dimensions: Some((asset.width as f64, asset.height as f64)),
|
||||
extra_info: format!("{}x{}", asset.width, asset.height),
|
||||
});
|
||||
}
|
||||
|
||||
// Sort alphabetically by name
|
||||
assets.sort_by(|a, b| a.name.to_lowercase().cmp(&b.name.to_lowercase()));
|
||||
|
||||
assets
|
||||
}
|
||||
|
||||
/// Filter assets based on current category and search text
|
||||
fn filter_assets<'a>(&self, assets: &'a [AssetEntry]) -> Vec<&'a AssetEntry> {
|
||||
let search_lower = self.search_filter.to_lowercase();
|
||||
|
||||
assets
|
||||
.iter()
|
||||
.filter(|asset| {
|
||||
// Category filter
|
||||
let category_matches = self.selected_category == AssetCategory::All
|
||||
|| asset.category == self.selected_category;
|
||||
|
||||
// Search filter
|
||||
let search_matches =
|
||||
search_lower.is_empty() || asset.name.to_lowercase().contains(&search_lower);
|
||||
|
||||
category_matches && search_matches
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Check if an asset is currently in use (has clip instances on layers)
|
||||
fn is_asset_in_use(document: &Document, asset_id: Uuid, category: AssetCategory) -> bool {
|
||||
// Check all layers for clip instances referencing this asset
|
||||
for layer in &document.root.children {
|
||||
match layer {
|
||||
lightningbeam_core::layer::AnyLayer::Vector(vl) => {
|
||||
if category == AssetCategory::Vector {
|
||||
for instance in &vl.clip_instances {
|
||||
if instance.clip_id == asset_id {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
lightningbeam_core::layer::AnyLayer::Video(vl) => {
|
||||
if category == AssetCategory::Video {
|
||||
for instance in &vl.clip_instances {
|
||||
if instance.clip_id == asset_id {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
lightningbeam_core::layer::AnyLayer::Audio(al) => {
|
||||
if category == AssetCategory::Audio {
|
||||
for instance in &al.clip_instances {
|
||||
if instance.clip_id == asset_id {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
/// Delete an asset from the document
|
||||
fn delete_asset(document: &mut Document, asset_id: Uuid, category: AssetCategory) {
|
||||
match category {
|
||||
AssetCategory::Vector => {
|
||||
document.remove_vector_clip(&asset_id);
|
||||
}
|
||||
AssetCategory::Video => {
|
||||
document.remove_video_clip(&asset_id);
|
||||
}
|
||||
AssetCategory::Audio => {
|
||||
document.remove_audio_clip(&asset_id);
|
||||
}
|
||||
AssetCategory::Images => {
|
||||
document.remove_image_asset(&asset_id);
|
||||
}
|
||||
AssetCategory::All => {} // Not a real category for deletion
|
||||
}
|
||||
}
|
||||
|
||||
/// Rename an asset in the document
|
||||
fn rename_asset(document: &mut Document, asset_id: Uuid, category: AssetCategory, new_name: &str) {
|
||||
match category {
|
||||
AssetCategory::Vector => {
|
||||
if let Some(clip) = document.get_vector_clip_mut(&asset_id) {
|
||||
clip.name = new_name.to_string();
|
||||
}
|
||||
}
|
||||
AssetCategory::Video => {
|
||||
if let Some(clip) = document.get_video_clip_mut(&asset_id) {
|
||||
clip.name = new_name.to_string();
|
||||
}
|
||||
}
|
||||
AssetCategory::Audio => {
|
||||
if let Some(clip) = document.get_audio_clip_mut(&asset_id) {
|
||||
clip.name = new_name.to_string();
|
||||
}
|
||||
}
|
||||
AssetCategory::Images => {
|
||||
if let Some(asset) = document.get_image_asset_mut(&asset_id) {
|
||||
asset.name = new_name.to_string();
|
||||
}
|
||||
}
|
||||
AssetCategory::All => {} // Not a real category for renaming
|
||||
}
|
||||
}
|
||||
|
||||
/// Render the search bar at the top
|
||||
fn render_search_bar(&mut self, ui: &mut egui::Ui, rect: egui::Rect, shared: &SharedPaneState) {
|
||||
let search_rect =
|
||||
egui::Rect::from_min_size(rect.min, egui::vec2(rect.width(), SEARCH_BAR_HEIGHT));
|
||||
|
||||
// Background
|
||||
let bg_style = shared.theme.style(".panel-header", ui.ctx());
|
||||
let bg_color = bg_style
|
||||
.background_color
|
||||
.unwrap_or(egui::Color32::from_rgb(30, 30, 30));
|
||||
ui.painter().rect_filled(search_rect, 0.0, bg_color);
|
||||
|
||||
// Label position
|
||||
let label_pos = search_rect.min + egui::vec2(8.0, (SEARCH_BAR_HEIGHT - 14.0) / 2.0);
|
||||
ui.painter().text(
|
||||
label_pos,
|
||||
egui::Align2::LEFT_TOP,
|
||||
"Search:",
|
||||
egui::FontId::proportional(14.0),
|
||||
egui::Color32::from_gray(180),
|
||||
);
|
||||
|
||||
// Text field using IME-safe widget
|
||||
let text_edit_rect = egui::Rect::from_min_size(
|
||||
search_rect.min + egui::vec2(65.0, 4.0),
|
||||
egui::vec2(search_rect.width() - 75.0, SEARCH_BAR_HEIGHT - 8.0),
|
||||
);
|
||||
|
||||
let mut child_ui = ui.new_child(egui::UiBuilder::new().max_rect(text_edit_rect));
|
||||
ImeTextField::new(&mut self.search_filter)
|
||||
.placeholder("Filter assets...")
|
||||
.desired_width(text_edit_rect.width())
|
||||
.show(&mut child_ui);
|
||||
}
|
||||
|
||||
/// Render category tabs
|
||||
fn render_category_tabs(
|
||||
&mut self,
|
||||
ui: &mut egui::Ui,
|
||||
rect: egui::Rect,
|
||||
shared: &SharedPaneState,
|
||||
) {
|
||||
let tabs_rect =
|
||||
egui::Rect::from_min_size(rect.min, egui::vec2(rect.width(), CATEGORY_TAB_HEIGHT));
|
||||
|
||||
// Background
|
||||
let bg_style = shared.theme.style(".panel-content", ui.ctx());
|
||||
let bg_color = bg_style
|
||||
.background_color
|
||||
.unwrap_or(egui::Color32::from_rgb(40, 40, 40));
|
||||
ui.painter().rect_filled(tabs_rect, 0.0, bg_color);
|
||||
|
||||
// Tab buttons
|
||||
let tab_width = tabs_rect.width() / AssetCategory::all().len() as f32;
|
||||
|
||||
for (i, category) in AssetCategory::all().iter().enumerate() {
|
||||
let tab_rect = egui::Rect::from_min_size(
|
||||
tabs_rect.min + egui::vec2(i as f32 * tab_width, 0.0),
|
||||
egui::vec2(tab_width, CATEGORY_TAB_HEIGHT),
|
||||
);
|
||||
|
||||
let is_selected = self.selected_category == *category;
|
||||
|
||||
// Tab background
|
||||
let tab_bg = if is_selected {
|
||||
egui::Color32::from_rgb(60, 60, 60)
|
||||
} else {
|
||||
egui::Color32::TRANSPARENT
|
||||
};
|
||||
ui.painter().rect_filled(tab_rect, 0.0, tab_bg);
|
||||
|
||||
// Handle click
|
||||
let response = ui.allocate_rect(tab_rect, egui::Sense::click());
|
||||
if response.clicked() {
|
||||
self.selected_category = *category;
|
||||
}
|
||||
|
||||
// Category color indicator
|
||||
let indicator_color = category.color();
|
||||
|
||||
let text_color = if is_selected {
|
||||
indicator_color
|
||||
} else {
|
||||
egui::Color32::from_gray(150)
|
||||
};
|
||||
|
||||
ui.painter().text(
|
||||
tab_rect.center(),
|
||||
egui::Align2::CENTER_CENTER,
|
||||
category.display_name(),
|
||||
egui::FontId::proportional(12.0),
|
||||
text_color,
|
||||
);
|
||||
|
||||
// Underline for selected tab
|
||||
if is_selected {
|
||||
ui.painter().line_segment(
|
||||
[
|
||||
egui::pos2(tab_rect.min.x + 4.0, tab_rect.max.y - 2.0),
|
||||
egui::pos2(tab_rect.max.x - 4.0, tab_rect.max.y - 2.0),
|
||||
],
|
||||
egui::Stroke::new(2.0, indicator_color),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Render the asset list
|
||||
fn render_asset_list(
|
||||
&mut self,
|
||||
ui: &mut egui::Ui,
|
||||
rect: egui::Rect,
|
||||
shared: &mut SharedPaneState,
|
||||
assets: &[&AssetEntry],
|
||||
) {
|
||||
// Background
|
||||
let bg_style = shared.theme.style(".panel-content", ui.ctx());
|
||||
let bg_color = bg_style
|
||||
.background_color
|
||||
.unwrap_or(egui::Color32::from_rgb(25, 25, 25));
|
||||
ui.painter().rect_filled(rect, 0.0, bg_color);
|
||||
|
||||
// Text colors
|
||||
let text_style = shared.theme.style(".text-primary", ui.ctx());
|
||||
let text_color = text_style
|
||||
.text_color
|
||||
.unwrap_or(egui::Color32::from_gray(200));
|
||||
let secondary_text_color = egui::Color32::from_gray(120);
|
||||
|
||||
// Show empty state message if no assets
|
||||
if assets.is_empty() {
|
||||
let message = if !self.search_filter.is_empty() {
|
||||
"No assets match your search"
|
||||
} else {
|
||||
"No assets in this category"
|
||||
};
|
||||
|
||||
ui.painter().text(
|
||||
rect.center(),
|
||||
egui::Align2::CENTER_CENTER,
|
||||
message,
|
||||
egui::FontId::proportional(14.0),
|
||||
secondary_text_color,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Use egui's built-in ScrollArea for scrolling
|
||||
let scroll_area_rect = rect;
|
||||
ui.allocate_ui_at_rect(scroll_area_rect, |ui| {
|
||||
egui::ScrollArea::vertical()
|
||||
.auto_shrink([false, false])
|
||||
.show(ui, |ui| {
|
||||
ui.set_min_width(scroll_area_rect.width() - 16.0); // Account for scrollbar
|
||||
|
||||
for asset in assets {
|
||||
let (item_rect, response) = ui.allocate_exact_size(
|
||||
egui::vec2(ui.available_width(), ITEM_HEIGHT),
|
||||
egui::Sense::click_and_drag(),
|
||||
);
|
||||
|
||||
let is_selected = self.selected_asset == Some(asset.id);
|
||||
let is_being_dragged = shared
|
||||
.dragging_asset
|
||||
.as_ref()
|
||||
.map(|d| d.clip_id == asset.id)
|
||||
.unwrap_or(false);
|
||||
|
||||
// Item background
|
||||
let item_bg = if is_being_dragged {
|
||||
egui::Color32::from_rgb(80, 100, 120) // Highlight when dragging
|
||||
} else if is_selected {
|
||||
egui::Color32::from_rgb(60, 80, 100)
|
||||
} else if response.hovered() {
|
||||
egui::Color32::from_rgb(45, 45, 45)
|
||||
} else {
|
||||
egui::Color32::from_rgb(35, 35, 35)
|
||||
};
|
||||
ui.painter().rect_filled(item_rect, 3.0, item_bg);
|
||||
|
||||
// Category color indicator bar
|
||||
let indicator_color = asset.category.color();
|
||||
let indicator_rect = egui::Rect::from_min_size(
|
||||
item_rect.min,
|
||||
egui::vec2(4.0, ITEM_HEIGHT),
|
||||
);
|
||||
ui.painter().rect_filled(indicator_rect, 0.0, indicator_color);
|
||||
|
||||
// Asset name (or inline edit field)
|
||||
let is_renaming = self.rename_state.as_ref().map(|s| s.asset_id == asset.id).unwrap_or(false);
|
||||
|
||||
if is_renaming {
|
||||
// Inline rename text field using IME-safe widget
|
||||
let name_rect = egui::Rect::from_min_size(
|
||||
item_rect.min + egui::vec2(10.0, 4.0),
|
||||
egui::vec2(item_rect.width() - 20.0, 18.0),
|
||||
);
|
||||
|
||||
if let Some(ref mut state) = self.rename_state {
|
||||
let mut child_ui = ui.new_child(egui::UiBuilder::new().max_rect(name_rect));
|
||||
ImeTextField::new(&mut state.edit_text)
|
||||
.font_size(13.0)
|
||||
.desired_width(name_rect.width())
|
||||
.request_focus()
|
||||
.show(&mut child_ui);
|
||||
}
|
||||
} else {
|
||||
// Normal asset name display
|
||||
ui.painter().text(
|
||||
item_rect.min + egui::vec2(12.0, 8.0),
|
||||
egui::Align2::LEFT_TOP,
|
||||
&asset.name,
|
||||
egui::FontId::proportional(13.0),
|
||||
text_color,
|
||||
);
|
||||
}
|
||||
|
||||
// Metadata line (images don't have duration)
|
||||
let metadata = if asset.category == AssetCategory::Images {
|
||||
// For images, just show dimensions
|
||||
asset.extra_info.clone()
|
||||
} else if let Some((w, h)) = asset.dimensions {
|
||||
format!(
|
||||
"{:.1}s | {}x{} | {}",
|
||||
asset.duration, w as u32, h as u32, asset.extra_info
|
||||
)
|
||||
} else {
|
||||
format!("{:.1}s | {}", asset.duration, asset.extra_info)
|
||||
};
|
||||
|
||||
ui.painter().text(
|
||||
item_rect.min + egui::vec2(12.0, 24.0),
|
||||
egui::Align2::LEFT_TOP,
|
||||
&metadata,
|
||||
egui::FontId::proportional(10.0),
|
||||
secondary_text_color,
|
||||
);
|
||||
|
||||
// Handle click (selection)
|
||||
if response.clicked() {
|
||||
self.selected_asset = Some(asset.id);
|
||||
}
|
||||
|
||||
// Handle right-click (context menu)
|
||||
if response.secondary_clicked() {
|
||||
if let Some(pos) = ui.ctx().pointer_interact_pos() {
|
||||
self.context_menu = Some(ContextMenuState {
|
||||
asset_id: asset.id,
|
||||
position: pos,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Handle double-click (start rename)
|
||||
if response.double_clicked() {
|
||||
self.rename_state = Some(RenameState {
|
||||
asset_id: asset.id,
|
||||
category: asset.category,
|
||||
edit_text: asset.name.clone(),
|
||||
});
|
||||
}
|
||||
|
||||
// Handle drag start
|
||||
if response.drag_started() {
|
||||
*shared.dragging_asset = Some(DraggingAsset {
|
||||
clip_id: asset.id,
|
||||
clip_type: asset.drag_clip_type,
|
||||
name: asset.name.clone(),
|
||||
duration: asset.duration,
|
||||
dimensions: asset.dimensions,
|
||||
});
|
||||
}
|
||||
|
||||
// Add small spacing between items
|
||||
ui.add_space(ITEM_PADDING);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Draw drag preview at cursor when dragging
|
||||
if let Some(dragging) = shared.dragging_asset.as_ref() {
|
||||
if let Some(pos) = ui.ctx().pointer_interact_pos() {
|
||||
// Draw a semi-transparent preview
|
||||
let preview_rect = egui::Rect::from_min_size(
|
||||
pos + egui::vec2(10.0, 10.0), // Offset from cursor
|
||||
egui::vec2(150.0, 30.0),
|
||||
);
|
||||
|
||||
// Use top layer for drag preview
|
||||
let painter = ui.ctx().layer_painter(egui::LayerId::new(
|
||||
egui::Order::Tooltip,
|
||||
egui::Id::new("drag_preview"),
|
||||
));
|
||||
|
||||
painter.rect_filled(
|
||||
preview_rect,
|
||||
4.0,
|
||||
egui::Color32::from_rgba_unmultiplied(60, 60, 60, 220),
|
||||
);
|
||||
|
||||
painter.text(
|
||||
preview_rect.center(),
|
||||
egui::Align2::CENTER_CENTER,
|
||||
&dragging.name,
|
||||
egui::FontId::proportional(12.0),
|
||||
egui::Color32::WHITE,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Clear drag state when mouse is released (if not dropped on valid target)
|
||||
// Note: Valid drop targets (Timeline, Stage) will clear this themselves
|
||||
if ui.input(|i| i.pointer.any_released()) {
|
||||
// Only clear if we're still within this pane (dropped back on library)
|
||||
if let Some(pos) = ui.ctx().pointer_interact_pos() {
|
||||
if rect.contains(pos) {
|
||||
*shared.dragging_asset = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PaneRenderer for AssetLibraryPane {
|
||||
fn render_content(
|
||||
&mut self,
|
||||
ui: &mut egui::Ui,
|
||||
rect: egui::Rect,
|
||||
_path: &NodePath,
|
||||
shared: &mut SharedPaneState,
|
||||
) {
|
||||
let document = shared.action_executor.document();
|
||||
|
||||
// Collect and filter assets
|
||||
let all_assets = self.collect_assets(document);
|
||||
let filtered_assets = self.filter_assets(&all_assets);
|
||||
|
||||
// Layout: Search bar -> Category tabs -> Asset list
|
||||
let search_rect =
|
||||
egui::Rect::from_min_size(rect.min, egui::vec2(rect.width(), SEARCH_BAR_HEIGHT));
|
||||
|
||||
let tabs_rect = egui::Rect::from_min_size(
|
||||
rect.min + egui::vec2(0.0, SEARCH_BAR_HEIGHT),
|
||||
egui::vec2(rect.width(), CATEGORY_TAB_HEIGHT),
|
||||
);
|
||||
|
||||
let list_rect = egui::Rect::from_min_max(
|
||||
rect.min + egui::vec2(0.0, SEARCH_BAR_HEIGHT + CATEGORY_TAB_HEIGHT),
|
||||
rect.max,
|
||||
);
|
||||
|
||||
// Render components
|
||||
self.render_search_bar(ui, search_rect, shared);
|
||||
self.render_category_tabs(ui, tabs_rect, shared);
|
||||
self.render_asset_list(ui, list_rect, shared, &filtered_assets);
|
||||
|
||||
// Context menu handling
|
||||
if let Some(ref context_state) = self.context_menu.clone() {
|
||||
let context_asset_id = context_state.asset_id;
|
||||
let menu_pos = context_state.position;
|
||||
|
||||
// Find the asset info
|
||||
if let Some(asset) = all_assets.iter().find(|a| a.id == context_asset_id) {
|
||||
let asset_name = asset.name.clone();
|
||||
let asset_category = asset.category;
|
||||
let in_use = Self::is_asset_in_use(
|
||||
shared.action_executor.document(),
|
||||
context_asset_id,
|
||||
asset_category,
|
||||
);
|
||||
|
||||
// Show context menu popup at the stored position
|
||||
let menu_id = egui::Id::new("asset_context_menu");
|
||||
let menu_response = egui::Area::new(menu_id)
|
||||
.order(egui::Order::Foreground)
|
||||
.fixed_pos(menu_pos)
|
||||
.show(ui.ctx(), |ui| {
|
||||
egui::Frame::popup(ui.style()).show(ui, |ui| {
|
||||
ui.set_min_width(120.0);
|
||||
|
||||
if ui.button("Rename").clicked() {
|
||||
// Start inline rename
|
||||
self.rename_state = Some(RenameState {
|
||||
asset_id: context_asset_id,
|
||||
category: asset_category,
|
||||
edit_text: asset_name.clone(),
|
||||
});
|
||||
self.context_menu = None;
|
||||
}
|
||||
|
||||
if ui.button("Delete").clicked() {
|
||||
// Set up pending delete confirmation
|
||||
self.pending_delete = Some(PendingDelete {
|
||||
asset_id: context_asset_id,
|
||||
asset_name: asset_name.clone(),
|
||||
category: asset_category,
|
||||
in_use,
|
||||
});
|
||||
self.context_menu = None;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Close menu on click outside (using primary button release)
|
||||
let menu_rect = menu_response.response.rect;
|
||||
if ui.input(|i| i.pointer.primary_released()) {
|
||||
if let Some(pos) = ui.ctx().pointer_interact_pos() {
|
||||
if !menu_rect.contains(pos) {
|
||||
self.context_menu = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Also close on Escape
|
||||
if ui.input(|i| i.key_pressed(egui::Key::Escape)) {
|
||||
self.context_menu = None;
|
||||
}
|
||||
} else {
|
||||
self.context_menu = None;
|
||||
}
|
||||
}
|
||||
|
||||
// Delete confirmation dialog
|
||||
if let Some(ref pending) = self.pending_delete.clone() {
|
||||
let window_id = egui::Id::new("delete_confirm_dialog");
|
||||
let mut should_close = false;
|
||||
let mut should_delete = false;
|
||||
|
||||
egui::Window::new("Confirm Delete")
|
||||
.id(window_id)
|
||||
.collapsible(false)
|
||||
.resizable(false)
|
||||
.anchor(egui::Align2::CENTER_CENTER, egui::vec2(0.0, 0.0))
|
||||
.show(ui.ctx(), |ui| {
|
||||
ui.set_min_width(300.0);
|
||||
|
||||
if pending.in_use {
|
||||
ui.label(egui::RichText::new("Warning: This asset is currently in use!")
|
||||
.color(egui::Color32::from_rgb(255, 180, 100)));
|
||||
ui.add_space(4.0);
|
||||
ui.label("Deleting it will remove all clip instances that reference it.");
|
||||
ui.add_space(8.0);
|
||||
}
|
||||
|
||||
ui.label(format!("Are you sure you want to delete \"{}\"?", pending.asset_name));
|
||||
ui.add_space(12.0);
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
if ui.button("Cancel").clicked() {
|
||||
should_close = true;
|
||||
}
|
||||
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
let delete_text = if pending.in_use { "Delete Anyway" } else { "Delete" };
|
||||
if ui.button(delete_text).clicked() {
|
||||
should_delete = true;
|
||||
should_close = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
if should_delete {
|
||||
// Perform the delete
|
||||
Self::delete_asset(
|
||||
shared.action_executor.document_mut(),
|
||||
pending.asset_id,
|
||||
pending.category,
|
||||
);
|
||||
}
|
||||
|
||||
if should_close {
|
||||
self.pending_delete = None;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle rename state (Enter to confirm, Escape to cancel, click outside to confirm)
|
||||
if let Some(ref state) = self.rename_state.clone() {
|
||||
let mut should_confirm = false;
|
||||
let mut should_cancel = false;
|
||||
|
||||
// Check for Enter or Escape
|
||||
ui.input(|i| {
|
||||
if i.key_pressed(egui::Key::Enter) {
|
||||
should_confirm = true;
|
||||
} else if i.key_pressed(egui::Key::Escape) {
|
||||
should_cancel = true;
|
||||
}
|
||||
});
|
||||
|
||||
if should_confirm {
|
||||
let new_name = state.edit_text.trim();
|
||||
if !new_name.is_empty() {
|
||||
Self::rename_asset(
|
||||
shared.action_executor.document_mut(),
|
||||
state.asset_id,
|
||||
state.category,
|
||||
new_name,
|
||||
);
|
||||
}
|
||||
self.rename_state = None;
|
||||
} else if should_cancel {
|
||||
self.rename_state = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn name(&self) -> &str {
|
||||
"Asset Library"
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
use eframe::egui;
|
||||
use lightningbeam_core::{pane::PaneType, tool::Tool};
|
||||
use uuid::Uuid;
|
||||
|
||||
// Type alias for node paths (matches main.rs)
|
||||
pub type NodePath = Vec<usize>;
|
||||
@@ -18,6 +19,37 @@ pub struct ViewActionHandler {
|
||||
pub zoom_center: egui::Vec2,
|
||||
}
|
||||
|
||||
/// Clip type for drag-and-drop operations
|
||||
/// Distinguishes between different clip/layer type combinations
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum DragClipType {
|
||||
/// Vector animation clip
|
||||
Vector,
|
||||
/// Video clip
|
||||
Video,
|
||||
/// Sampled audio clip (WAV, MP3, etc.)
|
||||
AudioSampled,
|
||||
/// MIDI clip
|
||||
AudioMidi,
|
||||
/// Static image asset
|
||||
Image,
|
||||
}
|
||||
|
||||
/// Information about an asset being dragged from the Asset Library
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DraggingAsset {
|
||||
/// The clip ID being dragged
|
||||
pub clip_id: Uuid,
|
||||
/// Type of clip (determines compatible layer types)
|
||||
pub clip_type: DragClipType,
|
||||
/// Display name
|
||||
pub name: String,
|
||||
/// Duration in seconds
|
||||
pub duration: f64,
|
||||
/// Dimensions (width, height) for vector/video clips, None for audio
|
||||
pub dimensions: Option<(f64, f64)>,
|
||||
}
|
||||
|
||||
pub mod toolbar;
|
||||
pub mod stage;
|
||||
pub mod timeline;
|
||||
@@ -26,6 +58,7 @@ pub mod outliner;
|
||||
pub mod piano_roll;
|
||||
pub mod node_editor;
|
||||
pub mod preset_browser;
|
||||
pub mod asset_library;
|
||||
|
||||
/// Which color mode is active for the eyedropper tool
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
@@ -78,6 +111,8 @@ pub struct SharedPaneState<'a> {
|
||||
/// Global playback state
|
||||
pub playback_time: &'a mut f64, // Current playback position in seconds
|
||||
pub is_playing: &'a mut bool, // Whether playback is currently active
|
||||
/// Asset being dragged from Asset Library (for cross-pane drag-and-drop)
|
||||
pub dragging_asset: &'a mut Option<DraggingAsset>,
|
||||
}
|
||||
|
||||
/// Trait for pane rendering
|
||||
@@ -116,6 +151,7 @@ pub enum PaneInstance {
|
||||
PianoRoll(piano_roll::PianoRollPane),
|
||||
NodeEditor(node_editor::NodeEditorPane),
|
||||
PresetBrowser(preset_browser::PresetBrowserPane),
|
||||
AssetLibrary(asset_library::AssetLibraryPane),
|
||||
}
|
||||
|
||||
impl PaneInstance {
|
||||
@@ -132,6 +168,9 @@ impl PaneInstance {
|
||||
PaneType::PresetBrowser => {
|
||||
PaneInstance::PresetBrowser(preset_browser::PresetBrowserPane::new())
|
||||
}
|
||||
PaneType::AssetLibrary => {
|
||||
PaneInstance::AssetLibrary(asset_library::AssetLibraryPane::new())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,6 +185,7 @@ impl PaneInstance {
|
||||
PaneInstance::PianoRoll(_) => PaneType::PianoRoll,
|
||||
PaneInstance::NodeEditor(_) => PaneType::NodeEditor,
|
||||
PaneInstance::PresetBrowser(_) => PaneType::PresetBrowser,
|
||||
PaneInstance::AssetLibrary(_) => PaneType::AssetLibrary,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -161,6 +201,7 @@ impl PaneRenderer for PaneInstance {
|
||||
PaneInstance::PianoRoll(p) => p.render_header(ui, shared),
|
||||
PaneInstance::NodeEditor(p) => p.render_header(ui, shared),
|
||||
PaneInstance::PresetBrowser(p) => p.render_header(ui, shared),
|
||||
PaneInstance::AssetLibrary(p) => p.render_header(ui, shared),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,6 +221,7 @@ impl PaneRenderer for PaneInstance {
|
||||
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),
|
||||
PaneInstance::AssetLibrary(p) => p.render_content(ui, rect, path, shared),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,6 +235,7 @@ impl PaneRenderer for PaneInstance {
|
||||
PaneInstance::PianoRoll(p) => p.name(),
|
||||
PaneInstance::NodeEditor(p) => p.name(),
|
||||
PaneInstance::PresetBrowser(p) => p.name(),
|
||||
PaneInstance::AssetLibrary(p) => p.name(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,16 +3,49 @@
|
||||
/// Renders composited layers using Vello GPU renderer via egui callbacks.
|
||||
|
||||
use eframe::egui;
|
||||
use super::{NodePath, PaneRenderer, SharedPaneState};
|
||||
use lightningbeam_core::action::Action;
|
||||
use lightningbeam_core::clip::ClipInstance;
|
||||
use lightningbeam_core::layer::{AnyLayer, AudioLayer, AudioLayerType, VideoLayer, VectorLayer};
|
||||
use super::{DragClipType, NodePath, PaneRenderer, SharedPaneState};
|
||||
use std::sync::{Arc, Mutex, OnceLock};
|
||||
use vello::kurbo::Shape;
|
||||
|
||||
/// Check if a clip type matches a layer type
|
||||
fn layer_matches_clip_type(layer: &AnyLayer, clip_type: DragClipType) -> bool {
|
||||
match (layer, clip_type) {
|
||||
(AnyLayer::Vector(_), DragClipType::Vector) => true,
|
||||
(AnyLayer::Vector(_), DragClipType::Image) => true, // Images go on vector layers as shapes
|
||||
(AnyLayer::Video(_), DragClipType::Video) => true,
|
||||
(AnyLayer::Audio(audio), DragClipType::AudioSampled) => {
|
||||
audio.audio_layer_type == AudioLayerType::Sampled
|
||||
}
|
||||
(AnyLayer::Audio(audio), DragClipType::AudioMidi) => {
|
||||
audio.audio_layer_type == AudioLayerType::Midi
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new layer of the appropriate type for a clip
|
||||
fn create_layer_for_clip_type(clip_type: DragClipType, name: &str) -> AnyLayer {
|
||||
match clip_type {
|
||||
DragClipType::Vector => AnyLayer::Vector(VectorLayer::new(name)),
|
||||
DragClipType::Video => AnyLayer::Video(VideoLayer::new(name)),
|
||||
DragClipType::AudioSampled => AnyLayer::Audio(AudioLayer::new_sampled(name)),
|
||||
DragClipType::AudioMidi => AnyLayer::Audio(AudioLayer::new_midi(name)),
|
||||
// Images are placed as shapes on vector layers, not their own layer type
|
||||
DragClipType::Image => AnyLayer::Vector(VectorLayer::new(name)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Shared Vello resources (created once, reused by all Stage panes)
|
||||
struct SharedVelloResources {
|
||||
renderer: Arc<Mutex<vello::Renderer>>,
|
||||
blit_pipeline: wgpu::RenderPipeline,
|
||||
blit_bind_group_layout: wgpu::BindGroupLayout,
|
||||
sampler: wgpu::Sampler,
|
||||
/// Shared image cache for avoiding re-decoding images every frame
|
||||
image_cache: Mutex<lightningbeam_core::renderer::ImageCache>,
|
||||
}
|
||||
|
||||
/// Per-instance Vello resources (created for each Stage pane)
|
||||
@@ -33,10 +66,10 @@ impl SharedVelloResources {
|
||||
let renderer = vello::Renderer::new(
|
||||
device,
|
||||
vello::RendererOptions {
|
||||
surface_format: None,
|
||||
use_cpu: false,
|
||||
antialiasing_support: vello::AaSupport::all(),
|
||||
num_init_threads: std::num::NonZeroUsize::new(1),
|
||||
pipeline_cache: None,
|
||||
},
|
||||
).map_err(|e| format!("Failed to create Vello renderer: {}", e))?;
|
||||
|
||||
@@ -82,13 +115,13 @@ impl SharedVelloResources {
|
||||
layout: Some(&pipeline_layout),
|
||||
vertex: wgpu::VertexState {
|
||||
module: &shader,
|
||||
entry_point: "vs_main",
|
||||
entry_point: Some("vs_main"),
|
||||
buffers: &[],
|
||||
compilation_options: Default::default(),
|
||||
},
|
||||
fragment: Some(wgpu::FragmentState {
|
||||
module: &shader,
|
||||
entry_point: "fs_main",
|
||||
entry_point: Some("fs_main"),
|
||||
targets: &[Some(wgpu::ColorTargetState {
|
||||
format: wgpu::TextureFormat::Rgba8Unorm, // egui's target format
|
||||
blend: Some(wgpu::BlendState::ALPHA_BLENDING),
|
||||
@@ -130,6 +163,7 @@ impl SharedVelloResources {
|
||||
blit_pipeline,
|
||||
blit_bind_group_layout,
|
||||
sampler,
|
||||
image_cache: Mutex::new(lightningbeam_core::renderer::ImageCache::new()),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -283,7 +317,9 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
* Affine::scale(self.zoom as f64);
|
||||
|
||||
// Render the document to the scene with camera transform
|
||||
lightningbeam_core::renderer::render_document_with_transform(&self.document, &mut scene, camera_transform);
|
||||
let mut image_cache = shared.image_cache.lock().unwrap();
|
||||
lightningbeam_core::renderer::render_document_with_transform(&self.document, &mut scene, camera_transform, &mut image_cache);
|
||||
drop(image_cache); // Explicitly release lock before other operations
|
||||
|
||||
// Render drag preview objects with transparency
|
||||
if let (Some(delta), Some(active_layer_id)) = (self.drag_delta, self.active_layer_id) {
|
||||
@@ -306,7 +342,7 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
let combined_transform = camera_transform * object_transform;
|
||||
|
||||
// Render shape with semi-transparent fill (light blue, 40% opacity)
|
||||
let alpha_color = Color::rgba8(100, 150, 255, 100);
|
||||
let alpha_color = Color::from_rgba8(100, 150, 255, 100);
|
||||
scene.fill(
|
||||
Fill::NonZero,
|
||||
combined_transform,
|
||||
@@ -339,7 +375,7 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
};
|
||||
|
||||
// Draw preview outline
|
||||
let alpha_color = Color::rgba8(255, 150, 100, 150); // Orange, semi-transparent
|
||||
let alpha_color = Color::from_rgba8(255, 150, 100, 150); // Orange, semi-transparent
|
||||
let stroke_width = 2.0 / self.zoom.max(0.5) as f64;
|
||||
scene.stroke(
|
||||
&Stroke::new(stroke_width),
|
||||
@@ -362,7 +398,7 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
use vello::peniko::{Color, Fill};
|
||||
use vello::kurbo::{Circle, Rect as KurboRect, Shape as KurboShape, Stroke};
|
||||
|
||||
let selection_color = Color::rgb8(0, 120, 255); // Blue
|
||||
let selection_color = Color::from_rgb8(0, 120, 255); // Blue
|
||||
let stroke_width = 2.0 / self.zoom.max(0.5) as f64;
|
||||
|
||||
// 1. Draw selection outlines around selected objects
|
||||
@@ -413,7 +449,7 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
scene.stroke(
|
||||
&Stroke::new(1.0),
|
||||
combined_transform,
|
||||
Color::rgb8(255, 255, 255),
|
||||
Color::from_rgb8(255, 255, 255),
|
||||
None,
|
||||
&corner_circle,
|
||||
);
|
||||
@@ -444,7 +480,7 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
let combined_transform = camera_transform * clip_transform;
|
||||
|
||||
// Draw selection outline with different color for clip instances
|
||||
let clip_selection_color = Color::rgb8(255, 120, 0); // Orange
|
||||
let clip_selection_color = Color::from_rgb8(255, 120, 0); // Orange
|
||||
scene.stroke(
|
||||
&Stroke::new(stroke_width),
|
||||
combined_transform,
|
||||
@@ -476,7 +512,7 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
scene.stroke(
|
||||
&Stroke::new(1.0),
|
||||
combined_transform,
|
||||
Color::rgb8(255, 255, 255),
|
||||
Color::from_rgb8(255, 255, 255),
|
||||
None,
|
||||
&corner_circle,
|
||||
);
|
||||
@@ -495,7 +531,7 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
);
|
||||
|
||||
// Semi-transparent fill
|
||||
let marquee_fill = Color::rgba8(0, 120, 255, 100);
|
||||
let marquee_fill = Color::from_rgba8(0, 120, 255, 100);
|
||||
scene.fill(
|
||||
Fill::NonZero,
|
||||
camera_transform,
|
||||
@@ -564,7 +600,7 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
let preview_transform = camera_transform * Affine::translate((position.x, position.y));
|
||||
|
||||
// Use actual fill color (same as final shape)
|
||||
let fill_color = Color::rgba8(
|
||||
let fill_color = Color::from_rgba8(
|
||||
self.fill_color.r(),
|
||||
self.fill_color.g(),
|
||||
self.fill_color.b(),
|
||||
@@ -622,7 +658,7 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
let preview_transform = camera_transform * Affine::translate((position.x, position.y));
|
||||
|
||||
// Use actual fill color (same as final shape)
|
||||
let fill_color = Color::rgba8(
|
||||
let fill_color = Color::from_rgba8(
|
||||
self.fill_color.r(),
|
||||
self.fill_color.g(),
|
||||
self.fill_color.b(),
|
||||
@@ -665,7 +701,7 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
|
||||
if length > 0.0 {
|
||||
// Use actual stroke color for line preview
|
||||
let stroke_color = Color::rgba8(
|
||||
let stroke_color = Color::from_rgba8(
|
||||
self.stroke_color.r(),
|
||||
self.stroke_color.g(),
|
||||
self.stroke_color.b(),
|
||||
@@ -698,7 +734,7 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
let preview_transform = camera_transform * Affine::translate((center.x, center.y));
|
||||
|
||||
// Use actual fill color (same as final shape)
|
||||
let fill_color = Color::rgba8(
|
||||
let fill_color = Color::from_rgba8(
|
||||
self.fill_color.r(),
|
||||
self.fill_color.g(),
|
||||
self.fill_color.b(),
|
||||
@@ -749,7 +785,7 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
|
||||
// Draw the preview path with stroke
|
||||
let stroke_width = (2.0 / self.zoom.max(0.5) as f64).max(1.0);
|
||||
let stroke_color = Color::rgb8(
|
||||
let stroke_color = Color::from_rgb8(
|
||||
self.stroke_color.r(),
|
||||
self.stroke_color.g(),
|
||||
self.stroke_color.b(),
|
||||
@@ -783,7 +819,7 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
if let Some(object) = vector_layer.get_object(&object_id) {
|
||||
if let Some(shape) = vector_layer.get_shape(&object.shape_id) {
|
||||
let handle_size = (8.0 / self.zoom.max(0.5) as f64).max(6.0);
|
||||
let handle_color = Color::rgb8(0, 120, 255); // Blue
|
||||
let handle_color = Color::from_rgb8(0, 120, 255); // Blue
|
||||
let rotation_handle_offset = 20.0 / self.zoom.max(0.5) as f64;
|
||||
|
||||
// Get shape's local bounding box
|
||||
@@ -876,7 +912,7 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
scene.stroke(
|
||||
&Stroke::new(1.0),
|
||||
camera_transform,
|
||||
Color::rgb8(255, 255, 255),
|
||||
Color::from_rgb8(255, 255, 255),
|
||||
None,
|
||||
&handle_rect,
|
||||
);
|
||||
@@ -906,7 +942,7 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
scene.stroke(
|
||||
&Stroke::new(1.0),
|
||||
camera_transform,
|
||||
Color::rgb8(255, 255, 255),
|
||||
Color::from_rgb8(255, 255, 255),
|
||||
None,
|
||||
&edge_circle,
|
||||
);
|
||||
@@ -931,7 +967,7 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
scene.fill(
|
||||
Fill::NonZero,
|
||||
camera_transform,
|
||||
Color::rgb8(50, 200, 50),
|
||||
Color::from_rgb8(50, 200, 50),
|
||||
None,
|
||||
&rotation_circle,
|
||||
);
|
||||
@@ -940,7 +976,7 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
scene.stroke(
|
||||
&Stroke::new(1.0),
|
||||
camera_transform,
|
||||
Color::rgb8(255, 255, 255),
|
||||
Color::from_rgb8(255, 255, 255),
|
||||
None,
|
||||
&rotation_circle,
|
||||
);
|
||||
@@ -956,7 +992,7 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
scene.stroke(
|
||||
&Stroke::new(1.0),
|
||||
camera_transform,
|
||||
Color::rgb8(50, 200, 50),
|
||||
Color::from_rgb8(50, 200, 50),
|
||||
None,
|
||||
&line_path,
|
||||
);
|
||||
@@ -985,7 +1021,7 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
|
||||
if let Some(bbox) = combined_bbox {
|
||||
let handle_size = (8.0 / self.zoom.max(0.5) as f64).max(6.0);
|
||||
let handle_color = Color::rgb8(0, 120, 255);
|
||||
let handle_color = Color::from_rgb8(0, 120, 255);
|
||||
let rotation_handle_offset = 20.0 / self.zoom.max(0.5) as f64;
|
||||
|
||||
scene.stroke(&Stroke::new(stroke_width), camera_transform, handle_color, None, &bbox);
|
||||
@@ -1003,7 +1039,7 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
corner.x + handle_size / 2.0, corner.y + handle_size / 2.0,
|
||||
);
|
||||
scene.fill(Fill::NonZero, camera_transform, handle_color, None, &handle_rect);
|
||||
scene.stroke(&Stroke::new(1.0), camera_transform, Color::rgb8(255, 255, 255), None, &handle_rect);
|
||||
scene.stroke(&Stroke::new(1.0), camera_transform, Color::from_rgb8(255, 255, 255), None, &handle_rect);
|
||||
}
|
||||
|
||||
let edges = [
|
||||
@@ -1016,13 +1052,13 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
for edge in &edges {
|
||||
let edge_circle = Circle::new(*edge, handle_size / 2.0);
|
||||
scene.fill(Fill::NonZero, camera_transform, handle_color, None, &edge_circle);
|
||||
scene.stroke(&Stroke::new(1.0), camera_transform, Color::rgb8(255, 255, 255), None, &edge_circle);
|
||||
scene.stroke(&Stroke::new(1.0), camera_transform, Color::from_rgb8(255, 255, 255), None, &edge_circle);
|
||||
}
|
||||
|
||||
let rotation_handle_pos = vello::kurbo::Point::new(bbox.center().x, bbox.y0 - rotation_handle_offset);
|
||||
let rotation_circle = Circle::new(rotation_handle_pos, handle_size / 2.0);
|
||||
scene.fill(Fill::NonZero, camera_transform, Color::rgb8(50, 200, 50), None, &rotation_circle);
|
||||
scene.stroke(&Stroke::new(1.0), camera_transform, Color::rgb8(255, 255, 255), None, &rotation_circle);
|
||||
scene.fill(Fill::NonZero, camera_transform, Color::from_rgb8(50, 200, 50), None, &rotation_circle);
|
||||
scene.stroke(&Stroke::new(1.0), camera_transform, Color::from_rgb8(255, 255, 255), None, &rotation_circle);
|
||||
|
||||
let line_path = {
|
||||
let mut path = vello::kurbo::BezPath::new();
|
||||
@@ -1030,7 +1066,7 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
path.line_to(vello::kurbo::Point::new(bbox.center().x, bbox.y0));
|
||||
path
|
||||
};
|
||||
scene.stroke(&Stroke::new(1.0), camera_transform, Color::rgb8(50, 200, 50), None, &line_path);
|
||||
scene.stroke(&Stroke::new(1.0), camera_transform, Color::from_rgb8(50, 200, 50), None, &line_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1041,7 +1077,7 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
// Render scene to texture using shared renderer
|
||||
if let Some(texture_view) = &instance_resources.texture_view {
|
||||
let render_params = vello::RenderParams {
|
||||
base_color: vello::peniko::Color::rgb8(45, 45, 48), // Dark background
|
||||
base_color: vello::peniko::Color::from_rgb8(45, 45, 48), // Dark background
|
||||
width,
|
||||
height,
|
||||
antialiasing_method: vello::AaConfig::Msaa16,
|
||||
@@ -4020,6 +4056,134 @@ impl PaneRenderer for StagePane {
|
||||
// Handle input for pan/zoom and tool controls
|
||||
self.handle_input(ui, rect, shared);
|
||||
|
||||
// Handle asset drag-and-drop from Asset Library
|
||||
if let Some(dragging) = shared.dragging_asset.clone() {
|
||||
if let Some(pointer_pos) = ui.ctx().pointer_interact_pos() {
|
||||
// Check if pointer is over the stage
|
||||
if rect.contains(pointer_pos) {
|
||||
// Visual feedback: draw ghost preview at cursor
|
||||
let preview_size = egui::vec2(60.0, 40.0);
|
||||
let preview_rect = egui::Rect::from_center_size(pointer_pos, preview_size);
|
||||
ui.painter().rect_filled(
|
||||
preview_rect,
|
||||
4.0,
|
||||
egui::Color32::from_rgba_unmultiplied(100, 150, 255, 100),
|
||||
);
|
||||
ui.painter().rect_stroke(
|
||||
preview_rect,
|
||||
4.0,
|
||||
egui::Stroke::new(2.0, egui::Color32::WHITE),
|
||||
egui::StrokeKind::Middle,
|
||||
);
|
||||
ui.painter().text(
|
||||
preview_rect.center(),
|
||||
egui::Align2::CENTER_CENTER,
|
||||
&dragging.name,
|
||||
egui::FontId::proportional(10.0),
|
||||
egui::Color32::WHITE,
|
||||
);
|
||||
|
||||
// Handle drop on mouse release
|
||||
if ui.input(|i| i.pointer.any_released()) {
|
||||
// Convert screen position to world coordinates
|
||||
let canvas_pos = pointer_pos - rect.min;
|
||||
let world_pos = (canvas_pos - self.pan_offset) / self.zoom;
|
||||
|
||||
// Use playhead time
|
||||
let drop_time = *shared.playback_time;
|
||||
|
||||
// Find or create a compatible layer
|
||||
let document = shared.action_executor.document();
|
||||
let mut target_layer_id = None;
|
||||
|
||||
// Check if active layer is compatible
|
||||
if let Some(active_id) = shared.active_layer_id {
|
||||
if let Some(layer) = document.get_layer(active_id) {
|
||||
if layer_matches_clip_type(layer, dragging.clip_type) {
|
||||
target_layer_id = Some(*active_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If no compatible active layer, we need to create a new layer
|
||||
if target_layer_id.is_none() {
|
||||
// Create new layer
|
||||
let layer_name = format!("{} Layer", match dragging.clip_type {
|
||||
DragClipType::Vector => "Vector",
|
||||
DragClipType::Video => "Video",
|
||||
DragClipType::AudioSampled => "Audio",
|
||||
DragClipType::AudioMidi => "MIDI",
|
||||
DragClipType::Image => "Image",
|
||||
});
|
||||
let new_layer = create_layer_for_clip_type(dragging.clip_type, &layer_name);
|
||||
|
||||
// Create add layer action
|
||||
let mut add_layer_action = lightningbeam_core::actions::AddLayerAction::new(new_layer);
|
||||
|
||||
// Execute immediately to get the layer ID
|
||||
add_layer_action.execute(shared.action_executor.document_mut());
|
||||
target_layer_id = add_layer_action.created_layer_id();
|
||||
|
||||
// Update active layer to the new layer
|
||||
if let Some(layer_id) = target_layer_id {
|
||||
*shared.active_layer_id = Some(layer_id);
|
||||
}
|
||||
}
|
||||
|
||||
// Add clip instance or shape to the target layer
|
||||
if let Some(layer_id) = target_layer_id {
|
||||
// For images, create a shape with image fill instead of a clip instance
|
||||
if dragging.clip_type == DragClipType::Image {
|
||||
// Get image dimensions (from the dragging info)
|
||||
let (width, height) = dragging.dimensions.unwrap_or((100.0, 100.0));
|
||||
|
||||
// Create a rectangle path at the origin (position handled by transform)
|
||||
use kurbo::BezPath;
|
||||
let mut path = BezPath::new();
|
||||
path.move_to((0.0, 0.0));
|
||||
path.line_to((width, 0.0));
|
||||
path.line_to((width, height));
|
||||
path.line_to((0.0, height));
|
||||
path.close_path();
|
||||
|
||||
// Create shape with image fill (references the ImageAsset)
|
||||
use lightningbeam_core::shape::Shape;
|
||||
let shape = Shape::new(path).with_image_fill(dragging.clip_id);
|
||||
|
||||
// Create shape instance at drop position
|
||||
use lightningbeam_core::object::ShapeInstance;
|
||||
let shape_instance = ShapeInstance::new(shape.id)
|
||||
.with_position(world_pos.x as f64, world_pos.y as f64);
|
||||
|
||||
// Create and queue action
|
||||
let action = lightningbeam_core::actions::AddShapeAction::new(
|
||||
layer_id,
|
||||
shape,
|
||||
shape_instance,
|
||||
);
|
||||
shared.pending_actions.push(Box::new(action));
|
||||
} else {
|
||||
// For clips, create a clip instance
|
||||
let clip_instance = ClipInstance::new(dragging.clip_id)
|
||||
.with_timeline_start(drop_time)
|
||||
.with_position(world_pos.x as f64, world_pos.y as f64);
|
||||
|
||||
// Create and queue action
|
||||
let action = lightningbeam_core::actions::AddClipInstanceAction::new(
|
||||
layer_id,
|
||||
clip_instance,
|
||||
);
|
||||
shared.pending_actions.push(Box::new(action));
|
||||
}
|
||||
}
|
||||
|
||||
// Clear drag state
|
||||
*shared.dragging_asset = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Register handler for pending view actions (two-phase dispatch)
|
||||
// Priority: Mouse-over (0-99) > Fallback Stage(1000) > Fallback Timeline(1001) etc.
|
||||
const STAGE_MOUSE_OVER_PRIORITY: u32 = 0;
|
||||
|
||||
@@ -7,8 +7,9 @@
|
||||
/// - Basic layer visualization
|
||||
|
||||
use eframe::egui;
|
||||
use lightningbeam_core::layer::LayerTrait;
|
||||
use super::{NodePath, PaneRenderer, SharedPaneState};
|
||||
use lightningbeam_core::clip::ClipInstance;
|
||||
use lightningbeam_core::layer::{AnyLayer, AudioLayerType, LayerTrait};
|
||||
use super::{DragClipType, NodePath, PaneRenderer, SharedPaneState};
|
||||
|
||||
const RULER_HEIGHT: f32 = 30.0;
|
||||
const LAYER_HEIGHT: f32 = 60.0;
|
||||
@@ -56,6 +57,21 @@ pub struct TimelinePane {
|
||||
layer_control_clicked: bool,
|
||||
}
|
||||
|
||||
/// Check if a clip type can be dropped on a layer type
|
||||
fn can_drop_on_layer(layer: &AnyLayer, clip_type: DragClipType) -> bool {
|
||||
match (layer, clip_type) {
|
||||
(AnyLayer::Vector(_), DragClipType::Vector) => true,
|
||||
(AnyLayer::Video(_), DragClipType::Video) => true,
|
||||
(AnyLayer::Audio(audio), DragClipType::AudioSampled) => {
|
||||
audio.audio_layer_type == AudioLayerType::Sampled
|
||||
}
|
||||
(AnyLayer::Audio(audio), DragClipType::AudioMidi) => {
|
||||
audio.audio_layer_type == AudioLayerType::Midi
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
impl TimelinePane {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
@@ -780,6 +796,7 @@ impl TimelinePane {
|
||||
clip_rect,
|
||||
3.0,
|
||||
egui::Stroke::new(3.0, bright_color),
|
||||
egui::StrokeKind::Middle,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1543,6 +1560,79 @@ impl PaneRenderer for TimelinePane {
|
||||
shared.audio_controller.as_mut().map(|c| &mut **c),
|
||||
);
|
||||
|
||||
// Handle asset drag-and-drop from Asset Library
|
||||
if let Some(dragging) = shared.dragging_asset.as_ref() {
|
||||
if let Some(pointer_pos) = ui.ctx().pointer_interact_pos() {
|
||||
// Check if pointer is in content area (not ruler or header column)
|
||||
if content_rect.contains(pointer_pos) {
|
||||
// Calculate which layer the pointer is over
|
||||
let relative_y = pointer_pos.y - content_rect.min.y + self.viewport_scroll_y;
|
||||
let hovered_layer_index = (relative_y / LAYER_HEIGHT) as usize;
|
||||
|
||||
// Get the layer at this index (accounting for reversed display order)
|
||||
let layers: Vec<_> = document.root.children.iter().rev().collect();
|
||||
|
||||
if let Some(layer) = layers.get(hovered_layer_index) {
|
||||
let is_compatible = can_drop_on_layer(layer, dragging.clip_type);
|
||||
|
||||
// Visual feedback: highlight compatible tracks
|
||||
let layer_y = content_rect.min.y + hovered_layer_index as f32 * LAYER_HEIGHT - self.viewport_scroll_y;
|
||||
let highlight_rect = egui::Rect::from_min_size(
|
||||
egui::pos2(content_rect.min.x, layer_y),
|
||||
egui::vec2(content_rect.width(), LAYER_HEIGHT),
|
||||
);
|
||||
|
||||
let highlight_color = if is_compatible {
|
||||
egui::Color32::from_rgba_unmultiplied(100, 255, 100, 40) // Green
|
||||
} else {
|
||||
egui::Color32::from_rgba_unmultiplied(255, 100, 100, 40) // Red
|
||||
};
|
||||
|
||||
ui.painter().rect_filled(highlight_rect, 0.0, highlight_color);
|
||||
|
||||
// Show drop time indicator
|
||||
let drop_time = self.x_to_time(pointer_pos.x - content_rect.min.x);
|
||||
let drop_x = self.time_to_x(drop_time);
|
||||
if drop_x >= 0.0 && drop_x <= content_rect.width() {
|
||||
ui.painter().line_segment(
|
||||
[
|
||||
egui::pos2(content_rect.min.x + drop_x, layer_y),
|
||||
egui::pos2(content_rect.min.x + drop_x, layer_y + LAYER_HEIGHT),
|
||||
],
|
||||
egui::Stroke::new(2.0, egui::Color32::WHITE),
|
||||
);
|
||||
}
|
||||
|
||||
// Handle drop on mouse release
|
||||
if ui.input(|i| i.pointer.any_released()) && is_compatible {
|
||||
let layer_id = layer.id();
|
||||
let drop_time = self.x_to_time(pointer_pos.x - content_rect.min.x).max(0.0);
|
||||
|
||||
// Get document dimensions for centering
|
||||
let doc = shared.action_executor.document();
|
||||
let center_x = doc.width / 2.0;
|
||||
let center_y = doc.height / 2.0;
|
||||
|
||||
// Create clip instance centered on stage, at drop time
|
||||
let clip_instance = ClipInstance::new(dragging.clip_id)
|
||||
.with_timeline_start(drop_time)
|
||||
.with_position(center_x, center_y);
|
||||
|
||||
// Create and queue action
|
||||
let action = lightningbeam_core::actions::AddClipInstanceAction::new(
|
||||
layer_id,
|
||||
clip_instance,
|
||||
);
|
||||
shared.pending_actions.push(Box::new(action));
|
||||
|
||||
// Clear drag state
|
||||
*shared.dragging_asset = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Register handler for pending view actions (two-phase dispatch)
|
||||
// Priority: Mouse-over (0-99) > Fallback Timeline(1001)
|
||||
const TIMELINE_MOUSE_OVER_PRIORITY: u32 = 0;
|
||||
|
||||
@@ -97,6 +97,7 @@ impl PaneRenderer for ToolbarPane {
|
||||
button_rect,
|
||||
4.0,
|
||||
egui::Stroke::new(2.0, egui::Color32::from_gray(180)),
|
||||
egui::StrokeKind::Middle,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -109,6 +110,7 @@ impl PaneRenderer for ToolbarPane {
|
||||
button_rect,
|
||||
4.0,
|
||||
egui::Stroke::new(2.0, egui::Color32::from_rgb(100, 150, 255)),
|
||||
egui::StrokeKind::Middle,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -239,5 +241,6 @@ fn draw_color_button(ui: &mut egui::Ui, rect: egui::Rect, color: egui::Color32)
|
||||
rect,
|
||||
2.0,
|
||||
egui::Stroke::new(1.0, egui::Color32::from_gray(80)),
|
||||
egui::StrokeKind::Middle,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user