Add info panel

This commit is contained in:
Skyler Lehmkuhl
2025-11-30 10:01:10 -05:00
parent 4d1e052ee7
commit c943f7bfe6
15 changed files with 2876 additions and 119 deletions
File diff suppressed because it is too large Load Diff
@@ -1,16 +1,752 @@
/// Info Panel pane - displays properties of selected objects
/// Info Panel pane - displays and edits properties of selected objects
///
/// This will eventually show editable properties.
/// For now, it's a placeholder.
/// Shows context-sensitive property editors based on current selection:
/// - 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)
use eframe::egui;
use eframe::egui::{self, DragValue, Sense, Ui};
use lightningbeam_core::actions::{
InstancePropertyChange, SetDocumentPropertiesAction, SetInstancePropertiesAction,
SetShapePropertiesAction,
};
use lightningbeam_core::layer::AnyLayer;
use lightningbeam_core::shape::ShapeColor;
use lightningbeam_core::tool::{SimplifyMode, Tool};
use super::{NodePath, PaneRenderer, SharedPaneState};
use uuid::Uuid;
pub struct InfopanelPane {}
/// Info panel pane state
pub struct InfopanelPane {
/// Whether the tool options section is expanded
tool_section_open: bool,
/// Whether the transform section is expanded
transform_section_open: bool,
/// Whether the shape properties section is expanded
shape_section_open: bool,
}
impl InfopanelPane {
pub fn new() -> Self {
Self {}
Self {
tool_section_open: true,
transform_section_open: true,
shape_section_open: true,
}
}
}
/// Aggregated info about the current selection
struct SelectionInfo {
/// True if nothing is selected
is_empty: bool,
/// Number of selected shape instances
shape_count: usize,
/// Layer ID of selected shapes (assumes single layer selection for now)
layer_id: Option<Uuid>,
/// Selected shape instance IDs
instance_ids: Vec<Uuid>,
/// Shape IDs referenced by selected instances
shape_ids: Vec<Uuid>,
// Transform values (None = mixed values across selection)
x: Option<f64>,
y: Option<f64>,
rotation: Option<f64>,
scale_x: Option<f64>,
scale_y: Option<f64>,
skew_x: Option<f64>,
skew_y: Option<f64>,
opacity: Option<f64>,
// Shape property values (None = mixed)
fill_color: Option<Option<ShapeColor>>,
stroke_color: Option<Option<ShapeColor>>,
stroke_width: Option<f64>,
}
impl Default for SelectionInfo {
fn default() -> Self {
Self {
is_empty: true,
shape_count: 0,
layer_id: None,
instance_ids: Vec::new(),
shape_ids: Vec::new(),
x: None,
y: None,
rotation: None,
scale_x: None,
scale_y: None,
skew_x: None,
skew_y: None,
opacity: None,
fill_color: None,
stroke_color: None,
stroke_width: None,
}
}
}
impl InfopanelPane {
/// Gather info about the current selection
fn gather_selection_info(&self, shared: &SharedPaneState) -> SelectionInfo {
let mut info = SelectionInfo::default();
let selected_instances = shared.selection.shape_instances();
info.shape_count = selected_instances.len();
info.is_empty = info.shape_count == 0;
if info.is_empty {
return info;
}
info.instance_ids = selected_instances.to_vec();
// Find the layer containing the selected instances
let document = shared.action_executor.document();
let active_layer_id = *shared.active_layer_id;
if let Some(layer_id) = active_layer_id {
info.layer_id = Some(layer_id);
if let Some(layer) = document.get_layer(&layer_id) {
if let AnyLayer::Vector(vector_layer) = layer {
// Gather values from all selected instances
let mut first = true;
for instance_id in &info.instance_ids {
if let Some(instance) = vector_layer.get_object(instance_id) {
info.shape_ids.push(instance.shape_id);
if first {
// First instance - set initial values
info.x = Some(instance.transform.x);
info.y = Some(instance.transform.y);
info.rotation = Some(instance.transform.rotation);
info.scale_x = Some(instance.transform.scale_x);
info.scale_y = Some(instance.transform.scale_y);
info.skew_x = Some(instance.transform.skew_x);
info.skew_y = Some(instance.transform.skew_y);
info.opacity = Some(instance.opacity);
// Get shape properties
if let Some(shape) = vector_layer.shapes.get(&instance.shape_id) {
info.fill_color = Some(shape.fill_color);
info.stroke_color = Some(shape.stroke_color);
info.stroke_width = shape
.stroke_style
.as_ref()
.map(|s| Some(s.width))
.unwrap_or(Some(1.0));
}
first = false;
} else {
// Check if values differ (set to None if mixed)
if info.x != Some(instance.transform.x) {
info.x = None;
}
if info.y != Some(instance.transform.y) {
info.y = None;
}
if info.rotation != Some(instance.transform.rotation) {
info.rotation = None;
}
if info.scale_x != Some(instance.transform.scale_x) {
info.scale_x = None;
}
if info.scale_y != Some(instance.transform.scale_y) {
info.scale_y = None;
}
if info.skew_x != Some(instance.transform.skew_x) {
info.skew_x = None;
}
if info.skew_y != Some(instance.transform.skew_y) {
info.skew_y = None;
}
if info.opacity != Some(instance.opacity) {
info.opacity = None;
}
// Check shape properties
if let Some(shape) = vector_layer.shapes.get(&instance.shape_id) {
// Compare fill colors - set to None if mixed
if let Some(current_fill) = &info.fill_color {
if *current_fill != shape.fill_color {
info.fill_color = None;
}
}
// Compare stroke colors - set to None if mixed
if let Some(current_stroke) = &info.stroke_color {
if *current_stroke != shape.stroke_color {
info.stroke_color = None;
}
}
let stroke_w = shape
.stroke_style
.as_ref()
.map(|s| s.width)
.unwrap_or(1.0);
if info.stroke_width != Some(stroke_w) {
info.stroke_width = None;
}
}
}
}
}
}
}
}
info
}
/// Render tool-specific options section
fn render_tool_section(&mut self, ui: &mut Ui, shared: &mut SharedPaneState) {
let tool = *shared.selected_tool;
// Only show tool options for tools that have options
let has_options = matches!(
tool,
Tool::Draw | Tool::Rectangle | Tool::Ellipse | Tool::PaintBucket | Tool::Polygon | Tool::Line
);
if !has_options {
return;
}
egui::CollapsingHeader::new("Tool Options")
.default_open(self.tool_section_open)
.show(ui, |ui| {
self.tool_section_open = true;
ui.add_space(4.0);
match tool {
Tool::Draw => {
// Stroke width
ui.horizontal(|ui| {
ui.label("Stroke Width:");
ui.add(DragValue::new(shared.stroke_width).speed(0.1).range(0.1..=100.0));
});
// Simplify mode
ui.horizontal(|ui| {
ui.label("Simplify:");
egui::ComboBox::from_id_salt("draw_simplify")
.selected_text(match shared.draw_simplify_mode {
SimplifyMode::Corners => "Corners",
SimplifyMode::Smooth => "Smooth",
SimplifyMode::Verbatim => "Verbatim",
})
.show_ui(ui, |ui| {
ui.selectable_value(
shared.draw_simplify_mode,
SimplifyMode::Corners,
"Corners",
);
ui.selectable_value(
shared.draw_simplify_mode,
SimplifyMode::Smooth,
"Smooth",
);
ui.selectable_value(
shared.draw_simplify_mode,
SimplifyMode::Verbatim,
"Verbatim",
);
});
});
// Fill shape toggle
ui.checkbox(shared.fill_enabled, "Fill Shape");
}
Tool::Rectangle | Tool::Ellipse => {
// Stroke width
ui.horizontal(|ui| {
ui.label("Stroke Width:");
ui.add(DragValue::new(shared.stroke_width).speed(0.1).range(0.1..=100.0));
});
// Fill shape toggle
ui.checkbox(shared.fill_enabled, "Fill Shape");
}
Tool::PaintBucket => {
// Gap tolerance
ui.horizontal(|ui| {
ui.label("Gap Tolerance:");
ui.add(
DragValue::new(shared.paint_bucket_gap_tolerance)
.speed(0.1)
.range(0.0..=50.0),
);
});
}
Tool::Polygon => {
// Number of sides
ui.horizontal(|ui| {
ui.label("Sides:");
let mut sides = *shared.polygon_sides as i32;
if ui.add(DragValue::new(&mut sides).range(3..=20)).changed() {
*shared.polygon_sides = sides.max(3) as u32;
}
});
// Stroke width
ui.horizontal(|ui| {
ui.label("Stroke Width:");
ui.add(DragValue::new(shared.stroke_width).speed(0.1).range(0.1..=100.0));
});
// Fill shape toggle
ui.checkbox(shared.fill_enabled, "Fill Shape");
}
Tool::Line => {
// Stroke width
ui.horizontal(|ui| {
ui.label("Stroke Width:");
ui.add(DragValue::new(shared.stroke_width).speed(0.1).range(0.1..=100.0));
});
}
_ => {}
}
ui.add_space(4.0);
});
}
/// Render transform properties section
fn render_transform_section(
&mut self,
ui: &mut Ui,
shared: &mut SharedPaneState,
info: &SelectionInfo,
) {
egui::CollapsingHeader::new("Transform")
.default_open(self.transform_section_open)
.show(ui, |ui| {
self.transform_section_open = true;
ui.add_space(4.0);
let layer_id = match info.layer_id {
Some(id) => id,
None => return,
};
// Position X
self.render_transform_field(
ui,
"X:",
info.x,
1.0,
f64::NEG_INFINITY..=f64::INFINITY,
|value| InstancePropertyChange::X(value),
layer_id,
&info.instance_ids,
shared,
);
// Position Y
self.render_transform_field(
ui,
"Y:",
info.y,
1.0,
f64::NEG_INFINITY..=f64::INFINITY,
|value| InstancePropertyChange::Y(value),
layer_id,
&info.instance_ids,
shared,
);
ui.add_space(4.0);
// Rotation
self.render_transform_field(
ui,
"Rotation:",
info.rotation,
1.0,
-360.0..=360.0,
|value| InstancePropertyChange::Rotation(value),
layer_id,
&info.instance_ids,
shared,
);
ui.add_space(4.0);
// Scale X
self.render_transform_field(
ui,
"Scale X:",
info.scale_x,
0.01,
0.01..=100.0,
|value| InstancePropertyChange::ScaleX(value),
layer_id,
&info.instance_ids,
shared,
);
// Scale Y
self.render_transform_field(
ui,
"Scale Y:",
info.scale_y,
0.01,
0.01..=100.0,
|value| InstancePropertyChange::ScaleY(value),
layer_id,
&info.instance_ids,
shared,
);
ui.add_space(4.0);
// Skew X
self.render_transform_field(
ui,
"Skew X:",
info.skew_x,
1.0,
-89.0..=89.0,
|value| InstancePropertyChange::SkewX(value),
layer_id,
&info.instance_ids,
shared,
);
// Skew Y
self.render_transform_field(
ui,
"Skew Y:",
info.skew_y,
1.0,
-89.0..=89.0,
|value| InstancePropertyChange::SkewY(value),
layer_id,
&info.instance_ids,
shared,
);
ui.add_space(4.0);
// Opacity
self.render_transform_field(
ui,
"Opacity:",
info.opacity,
0.01,
0.0..=1.0,
|value| InstancePropertyChange::Opacity(value),
layer_id,
&info.instance_ids,
shared,
);
ui.add_space(4.0);
});
}
/// Render a single transform property field with drag-to-adjust
fn render_transform_field<F>(
&self,
ui: &mut Ui,
label: &str,
value: Option<f64>,
speed: f64,
range: std::ops::RangeInclusive<f64>,
make_change: F,
layer_id: Uuid,
instance_ids: &[Uuid],
shared: &mut SharedPaneState,
) where
F: Fn(f64) -> InstancePropertyChange,
{
ui.horizontal(|ui| {
// Label with drag sense for drag-to-adjust
let label_response = ui.add(egui::Label::new(label).sense(Sense::drag()));
match value {
Some(mut v) => {
// Handle drag on label
if label_response.dragged() {
let delta = label_response.drag_delta().x as f64 * speed;
v = (v + delta).clamp(*range.start(), *range.end());
// Create action for each selected instance
for instance_id in instance_ids {
let action = SetInstancePropertiesAction::new(
layer_id,
*instance_id,
make_change(v),
);
shared.pending_actions.push(Box::new(action));
}
}
// DragValue widget
let response = ui.add(
DragValue::new(&mut v)
.speed(speed)
.range(range.clone()),
);
if response.changed() {
// Create action for each selected instance
for instance_id in instance_ids {
let action = SetInstancePropertiesAction::new(
layer_id,
*instance_id,
make_change(v),
);
shared.pending_actions.push(Box::new(action));
}
}
}
None => {
// Mixed values - show placeholder
ui.label("--");
}
}
});
}
/// Render shape properties section (fill/stroke)
fn render_shape_section(
&mut self,
ui: &mut Ui,
shared: &mut SharedPaneState,
info: &SelectionInfo,
) {
egui::CollapsingHeader::new("Shape")
.default_open(self.shape_section_open)
.show(ui, |ui| {
self.shape_section_open = true;
ui.add_space(4.0);
let layer_id = match info.layer_id {
Some(id) => id,
None => return,
};
// Fill color
ui.horizontal(|ui| {
ui.label("Fill:");
match info.fill_color {
Some(Some(color)) => {
let mut egui_color = egui::Color32::from_rgba_unmultiplied(
color.r, color.g, color.b, color.a,
);
if ui.color_edit_button_srgba(&mut egui_color).changed() {
let new_color = Some(ShapeColor::new(
egui_color.r(),
egui_color.g(),
egui_color.b(),
egui_color.a(),
));
// Create action for each selected shape
for shape_id in &info.shape_ids {
let action = SetShapePropertiesAction::set_fill_color(
layer_id,
*shape_id,
new_color,
);
shared.pending_actions.push(Box::new(action));
}
}
}
Some(None) => {
if ui.button("Add Fill").clicked() {
// Add default black fill
let default_fill = Some(ShapeColor::rgb(0, 0, 0));
for shape_id in &info.shape_ids {
let action = SetShapePropertiesAction::set_fill_color(
layer_id,
*shape_id,
default_fill,
);
shared.pending_actions.push(Box::new(action));
}
}
}
None => {
ui.label("--");
}
}
});
// Stroke color
ui.horizontal(|ui| {
ui.label("Stroke:");
match info.stroke_color {
Some(Some(color)) => {
let mut egui_color = egui::Color32::from_rgba_unmultiplied(
color.r, color.g, color.b, color.a,
);
if ui.color_edit_button_srgba(&mut egui_color).changed() {
let new_color = Some(ShapeColor::new(
egui_color.r(),
egui_color.g(),
egui_color.b(),
egui_color.a(),
));
// Create action for each selected shape
for shape_id in &info.shape_ids {
let action = SetShapePropertiesAction::set_stroke_color(
layer_id,
*shape_id,
new_color,
);
shared.pending_actions.push(Box::new(action));
}
}
}
Some(None) => {
if ui.button("Add Stroke").clicked() {
// Add default black stroke
let default_stroke = Some(ShapeColor::rgb(0, 0, 0));
for shape_id in &info.shape_ids {
let action = SetShapePropertiesAction::set_stroke_color(
layer_id,
*shape_id,
default_stroke,
);
shared.pending_actions.push(Box::new(action));
}
}
}
None => {
ui.label("--");
}
}
});
// Stroke width
ui.horizontal(|ui| {
ui.label("Stroke Width:");
match info.stroke_width {
Some(mut width) => {
let response = ui.add(
DragValue::new(&mut width)
.speed(0.1)
.range(0.1..=100.0),
);
if response.changed() {
for shape_id in &info.shape_ids {
let action = SetShapePropertiesAction::set_stroke_width(
layer_id,
*shape_id,
width,
);
shared.pending_actions.push(Box::new(action));
}
}
}
None => {
ui.label("--");
}
}
});
ui.add_space(4.0);
});
}
/// Render document settings section (shown when nothing is selected)
fn render_document_section(&self, ui: &mut Ui, shared: &mut SharedPaneState) {
egui::CollapsingHeader::new("Document")
.default_open(true)
.show(ui, |ui| {
ui.add_space(4.0);
let document = shared.action_executor.document();
// Get current values for editing
let mut width = document.width;
let mut height = document.height;
let mut duration = document.duration;
let mut framerate = document.framerate;
let layer_count = document.root.children.len();
// Canvas width
ui.horizontal(|ui| {
ui.label("Width:");
if ui
.add(DragValue::new(&mut width).speed(1.0).range(1.0..=10000.0))
.changed()
{
let action = SetDocumentPropertiesAction::set_width(width);
shared.pending_actions.push(Box::new(action));
}
});
// Canvas height
ui.horizontal(|ui| {
ui.label("Height:");
if ui
.add(DragValue::new(&mut height).speed(1.0).range(1.0..=10000.0))
.changed()
{
let action = SetDocumentPropertiesAction::set_height(height);
shared.pending_actions.push(Box::new(action));
}
});
// Duration
ui.horizontal(|ui| {
ui.label("Duration:");
if ui
.add(
DragValue::new(&mut duration)
.speed(0.1)
.range(0.1..=3600.0)
.suffix("s"),
)
.changed()
{
let action = SetDocumentPropertiesAction::set_duration(duration);
shared.pending_actions.push(Box::new(action));
}
});
// Framerate
ui.horizontal(|ui| {
ui.label("Framerate:");
if ui
.add(
DragValue::new(&mut framerate)
.speed(1.0)
.range(1.0..=120.0)
.suffix(" fps"),
)
.changed()
{
let action = SetDocumentPropertiesAction::set_framerate(framerate);
shared.pending_actions.push(Box::new(action));
}
});
// Layer count (read-only)
ui.horizontal(|ui| {
ui.label("Layers:");
ui.label(format!("{}", layer_count));
});
ui.add_space(4.0);
});
}
}
@@ -20,23 +756,61 @@ impl PaneRenderer for InfopanelPane {
ui: &mut egui::Ui,
rect: egui::Rect,
_path: &NodePath,
_shared: &mut SharedPaneState,
shared: &mut SharedPaneState,
) {
// Placeholder rendering
// Background
ui.painter().rect_filled(
rect,
0.0,
egui::Color32::from_rgb(30, 50, 40),
egui::Color32::from_rgb(30, 35, 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),
// Create scrollable area for content
let content_rect = rect.shrink(8.0);
let mut content_ui = ui.new_child(
egui::UiBuilder::new()
.max_rect(content_rect)
.layout(egui::Layout::top_down(egui::Align::LEFT)),
);
egui::ScrollArea::vertical()
.id_salt("infopanel_scroll")
.show(&mut content_ui, |ui| {
ui.set_min_width(content_rect.width() - 16.0);
// 1. Tool options section (always shown if tool has options)
self.render_tool_section(ui, shared);
// 2. Gather selection info
let info = self.gather_selection_info(shared);
// 3. Transform section (if shapes selected)
if info.shape_count > 0 {
self.render_transform_section(ui, shared, &info);
}
// 4. Shape properties section (if shapes selected)
if info.shape_count > 0 {
self.render_shape_section(ui, shared, &info);
}
// 5. Document settings (if nothing selected)
if info.is_empty {
self.render_document_section(ui, shared);
}
// Show selection count at bottom
if info.shape_count > 0 {
ui.add_space(8.0);
ui.separator();
ui.add_space(4.0);
ui.label(format!(
"{} object{} selected",
info.shape_count,
if info.shape_count == 1 { "" } else { "s" }
));
}
});
}
fn name(&self) -> &str {
@@ -113,6 +113,15 @@ pub struct SharedPaneState<'a> {
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>,
// Tool-specific options for infopanel
/// Stroke width for drawing tools (Draw, Rectangle, Ellipse, Line, Polygon)
pub stroke_width: &'a mut f64,
/// Whether to fill shapes when drawing (Rectangle, Ellipse, Polygon)
pub fill_enabled: &'a mut bool,
/// Fill gap tolerance for paint bucket tool
pub paint_bucket_gap_tolerance: &'a mut f64,
/// Number of sides for polygon tool
pub polygon_sides: &'a mut u32,
}
/// Trait for pane rendering
@@ -231,13 +231,14 @@ struct VelloCallback {
pan_offset: egui::Vec2,
zoom: f32,
instance_id: u64,
document: lightningbeam_core::document::Document,
document: std::sync::Arc<lightningbeam_core::document::Document>,
tool_state: lightningbeam_core::tool::ToolState,
active_layer_id: Option<uuid::Uuid>,
drag_delta: Option<vello::kurbo::Vec2>, // Delta for drag preview (world space)
selection: lightningbeam_core::selection::Selection,
fill_color: egui::Color32, // Current fill color for previews
stroke_color: egui::Color32, // Current stroke color for previews
stroke_width: f64, // Current stroke width for previews
selected_tool: lightningbeam_core::tool::Tool, // Current tool for rendering mode-specific UI
eyedropper_request: Option<(egui::Pos2, super::ColorMode)>, // Pending eyedropper sample
playback_time: f64, // Current playback time for animation evaluation
@@ -249,18 +250,19 @@ impl VelloCallback {
pan_offset: egui::Vec2,
zoom: f32,
instance_id: u64,
document: lightningbeam_core::document::Document,
document: std::sync::Arc<lightningbeam_core::document::Document>,
tool_state: lightningbeam_core::tool::ToolState,
active_layer_id: Option<uuid::Uuid>,
drag_delta: Option<vello::kurbo::Vec2>,
selection: lightningbeam_core::selection::Selection,
fill_color: egui::Color32,
stroke_color: egui::Color32,
stroke_width: f64,
selected_tool: lightningbeam_core::tool::Tool,
eyedropper_request: Option<(egui::Pos2, super::ColorMode)>,
playback_time: f64,
) -> Self {
Self { rect, pan_offset, zoom, instance_id, document, tool_state, active_layer_id, drag_delta, selection, fill_color, stroke_color, selected_tool, eyedropper_request, playback_time }
Self { rect, pan_offset, zoom, instance_id, document, tool_state, active_layer_id, drag_delta, selection, fill_color, stroke_color, stroke_width, selected_tool, eyedropper_request, playback_time }
}
}
@@ -331,14 +333,44 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
// Render each object at its preview position (original + delta)
for (object_id, original_pos) in original_positions {
// Try shape instance first
if let Some(_object) = vector_layer.get_object(object_id) {
if let Some(shape) = vector_layer.get_shape(&_object.shape_id) {
if let Some(object) = vector_layer.get_object(object_id) {
if let Some(shape) = vector_layer.get_shape(&object.shape_id) {
// New position = original + delta
let new_x = original_pos.x + delta.x;
let new_y = original_pos.y + delta.y;
// Build transform for preview position
let object_transform = Affine::translate((new_x, new_y));
// Build skew transform around shape center (matching renderer.rs)
let path = shape.path();
let skew_transform = if object.transform.skew_x != 0.0 || object.transform.skew_y != 0.0 {
let bbox = path.bounding_box();
let center_x = (bbox.x0 + bbox.x1) / 2.0;
let center_y = (bbox.y0 + bbox.y1) / 2.0;
let skew_x_affine = if object.transform.skew_x != 0.0 {
Affine::skew(object.transform.skew_x.to_radians().tan(), 0.0)
} else {
Affine::IDENTITY
};
let skew_y_affine = if object.transform.skew_y != 0.0 {
Affine::skew(0.0, object.transform.skew_y.to_radians().tan())
} else {
Affine::IDENTITY
};
Affine::translate((center_x, center_y))
* skew_x_affine
* skew_y_affine
* Affine::translate((-center_x, -center_y))
} else {
Affine::IDENTITY
};
// Build full transform: translate * rotate * scale * skew
let object_transform = Affine::translate((new_x, new_y))
* Affine::rotate(object.transform.rotation.to_radians())
* Affine::scale_non_uniform(object.transform.scale_x, object.transform.scale_y)
* skew_transform;
let combined_transform = camera_transform * object_transform;
// Render shape with semi-transparent fill (light blue, 40% opacity)
@@ -348,7 +380,7 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
combined_transform,
&Brush::Solid(alpha_color),
None,
shape.path(),
path,
);
}
}
@@ -783,8 +815,7 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
preview_path.line_to(*point);
}
// Draw the preview path with stroke
let stroke_width = (2.0 / self.zoom.max(0.5) as f64).max(1.0);
// Draw the preview path with stroke using configured stroke width
let stroke_color = Color::from_rgb8(
self.stroke_color.r(),
self.stroke_color.g(),
@@ -792,7 +823,7 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
);
scene.stroke(
&Stroke::new(stroke_width),
&Stroke::new(self.stroke_width),
camera_transform,
stroke_color,
None,
@@ -1636,8 +1667,8 @@ impl StagePane {
// Mouse up: create the rectangle shape
if response.drag_stopped() || (ui.input(|i| i.pointer.any_released()) && matches!(shared.tool_state, ToolState::CreatingRectangle { .. })) {
if let ToolState::CreatingRectangle { start_point, current_point, centered, constrain_square } = shared.tool_state.clone() {
// Calculate rectangle bounds based on mode
let (width, height, position) = if centered {
// Calculate rectangle bounds and center position based on mode
let (width, height, center) = if centered {
// Centered mode: start_point is center
let dx = current_point.x - start_point.x;
let dy = current_point.y - start_point.y;
@@ -1649,8 +1680,8 @@ impl StagePane {
(dx.abs() * 2.0, dy.abs() * 2.0)
};
let pos = Point::new(start_point.x - w / 2.0, start_point.y - h / 2.0);
(w, h, pos)
// start_point is already the center
(w, h, start_point)
} else {
// Corner mode: start_point is corner
let mut min_x = start_point.x.min(current_point.x);
@@ -1676,21 +1707,35 @@ impl StagePane {
}
}
(max_x - min_x, max_y - min_y, Point::new(min_x, min_y))
// Return width, height, and center position
let center_x = (min_x + max_x) / 2.0;
let center_y = (min_y + max_y) / 2.0;
(max_x - min_x, max_y - min_y, Point::new(center_x, center_y))
};
// Only create shape if rectangle has non-zero size
if width > 1.0 && height > 1.0 {
use lightningbeam_core::shape::{Shape, ShapeColor};
use lightningbeam_core::shape::{Shape, ShapeColor, StrokeStyle};
use lightningbeam_core::object::ShapeInstance;
use lightningbeam_core::actions::AddShapeAction;
// Create shape with rectangle path (built from lines)
// Create shape with rectangle path centered at origin
let path = Self::create_rectangle_path(width, height);
let shape = Shape::new(path).with_fill(ShapeColor::from_egui(*shared.fill_color));
let mut shape = Shape::new(path);
// Create object at the calculated position
let object = ShapeInstance::new(shape.id).with_position(position.x, position.y);
// Apply fill if enabled
if *shared.fill_enabled {
shape = shape.with_fill(ShapeColor::from_egui(*shared.fill_color));
}
// Apply stroke with configured width
shape = shape.with_stroke(
ShapeColor::from_egui(*shared.stroke_color),
StrokeStyle { width: *shared.stroke_width, ..Default::default() }
);
// Create object at the center position
let object = ShapeInstance::new(shape.id).with_position(center.x, center.y);
// Create and execute action immediately
let action = AddShapeAction::new(active_layer_id, shape, object);
@@ -1798,13 +1843,24 @@ impl StagePane {
// Only create shape if ellipse has non-zero size
if rx > 1.0 && ry > 1.0 {
use lightningbeam_core::shape::{Shape, ShapeColor};
use lightningbeam_core::shape::{Shape, ShapeColor, StrokeStyle};
use lightningbeam_core::object::ShapeInstance;
use lightningbeam_core::actions::AddShapeAction;
// Create shape with ellipse path (built from bezier curves)
let path = Self::create_ellipse_path(rx, ry);
let shape = Shape::new(path).with_fill(ShapeColor::from_egui(*shared.fill_color));
let mut shape = Shape::new(path);
// Apply fill if enabled
if *shared.fill_enabled {
shape = shape.with_fill(ShapeColor::from_egui(*shared.fill_color));
}
// Apply stroke with configured width
shape = shape.with_stroke(
ShapeColor::from_egui(*shared.stroke_color),
StrokeStyle { width: *shared.stroke_width, ..Default::default() }
);
// Create object at the calculated position
let object = ShapeInstance::new(shape.id).with_position(position.x, position.y);
@@ -1883,7 +1939,7 @@ impl StagePane {
use lightningbeam_core::object::ShapeInstance;
use lightningbeam_core::actions::AddShapeAction;
// Create shape with line path
// Create shape with line path centered at origin
let path = Self::create_line_path(dx, dy);
// Lines should have stroke by default, not fill
@@ -1891,13 +1947,15 @@ impl StagePane {
.with_stroke(
ShapeColor::from_egui(*shared.stroke_color),
StrokeStyle {
width: 2.0,
width: *shared.stroke_width,
..Default::default()
}
);
// Create object at the start point
let object = ShapeInstance::new(shape.id).with_position(start_point.x, start_point.y);
// Create object at the center of the line
let center_x = (start_point.x + current_point.x) / 2.0;
let center_y = (start_point.y + current_point.y) / 2.0;
let object = ShapeInstance::new(shape.id).with_position(center_x, center_y);
// Create and execute action immediately
let action = AddShapeAction::new(active_layer_id, shape, object);
@@ -1977,7 +2035,15 @@ impl StagePane {
// Create shape with polygon path
let path = Self::create_polygon_path(num_sides, radius);
let shape = Shape::new(path).with_fill(ShapeColor::from_egui(*shared.fill_color));
use lightningbeam_core::shape::StrokeStyle;
let mut shape = Shape::new(path);
if *shared.fill_enabled {
shape = shape.with_fill(ShapeColor::from_egui(*shared.fill_color));
}
shape = shape.with_stroke(
ShapeColor::from_egui(*shared.stroke_color),
StrokeStyle { width: *shared.stroke_width, ..Default::default() }
);
// Create object at the center point
let object = ShapeInstance::new(shape.id).with_position(center.x, center.y);
@@ -2006,23 +2072,26 @@ impl StagePane {
}
}
/// Create a rectangle path from lines (easier for curve editing later)
/// Create a rectangle path centered at origin (easier for curve editing later)
fn create_rectangle_path(width: f64, height: f64) -> vello::kurbo::BezPath {
use vello::kurbo::{BezPath, Point};
let half_w = width / 2.0;
let half_h = height / 2.0;
let mut path = BezPath::new();
// Start at top-left
path.move_to(Point::new(0.0, 0.0));
// Start at top-left (centered at origin)
path.move_to(Point::new(-half_w, -half_h));
// Top-right
path.line_to(Point::new(width, 0.0));
path.line_to(Point::new(half_w, -half_h));
// Bottom-right
path.line_to(Point::new(width, height));
path.line_to(Point::new(half_w, half_h));
// Bottom-left
path.line_to(Point::new(0.0, height));
path.line_to(Point::new(-half_w, half_h));
// Close path (back to top-left)
path.close_path();
@@ -2080,17 +2149,18 @@ impl StagePane {
path
}
/// Create a line path from start to end point
/// Create a line path centered at origin
fn create_line_path(dx: f64, dy: f64) -> vello::kurbo::BezPath {
use vello::kurbo::{BezPath, Point};
let mut path = BezPath::new();
// Start at origin (object position will be the start point)
path.move_to(Point::new(0.0, 0.0));
// Line goes from -half to +half so it's centered at origin
let half_dx = dx / 2.0;
let half_dy = dy / 2.0;
// Line to end point
path.line_to(Point::new(dx, dy));
path.move_to(Point::new(-half_dx, -half_dy));
path.line_to(Point::new(half_dx, half_dy));
path
}
@@ -2238,26 +2308,29 @@ impl StagePane {
// Only create shape if path is not empty
if !path.is_empty() {
// Calculate bounding box to position the object
// Calculate bounding box center for object position
let bbox = path.bounding_box();
let position = Point::new(bbox.x0, bbox.y0);
let center_x = (bbox.x0 + bbox.x1) / 2.0;
let center_y = (bbox.y0 + bbox.y1) / 2.0;
// Translate path to be relative to position (0,0 at top-left of bbox)
// Translate path so its center is at origin (0,0)
use vello::kurbo::Affine;
let transform = Affine::translate((-bbox.x0, -bbox.y0));
let transform = Affine::translate((-center_x, -center_y));
let translated_path = transform * path;
// Create shape with both fill and stroke
// Create shape with fill (if enabled) and stroke
use lightningbeam_core::shape::StrokeStyle;
let shape = Shape::new(translated_path)
.with_fill(ShapeColor::from_egui(*shared.fill_color))
.with_stroke(
ShapeColor::from_egui(*shared.stroke_color),
StrokeStyle::default(),
);
let mut shape = Shape::new(translated_path);
if *shared.fill_enabled {
shape = shape.with_fill(ShapeColor::from_egui(*shared.fill_color));
}
shape = shape.with_stroke(
ShapeColor::from_egui(*shared.stroke_color),
StrokeStyle { width: *shared.stroke_width, ..Default::default() }
);
// Create object at the calculated position
let object = ShapeInstance::new(shape.id).with_position(position.x, position.y);
// Create object at the center position
let object = ShapeInstance::new(shape.id).with_position(center_x, center_y);
// Create and execute action immediately
let action = AddShapeAction::new(active_layer_id, shape, object);
@@ -4257,18 +4330,20 @@ impl PaneRenderer for StagePane {
};
// Use egui's custom painting callback for Vello
// document_arc() returns Arc<Document> - cheap pointer copy, not deep clone
let callback = VelloCallback::new(
rect,
self.pan_offset,
self.zoom,
self.instance_id,
shared.action_executor.document().clone(),
shared.action_executor.document_arc(),
shared.tool_state.clone(),
*shared.active_layer_id,
drag_delta,
shared.selection.clone(),
*shared.fill_color,
*shared.stroke_color,
*shared.stroke_width,
*shared.selected_tool,
self.pending_eyedropper_sample,
*shared.playback_time,