Painting UX: unified color/brush tools, tablet buttons, layer opacity
Addresses a batch of issues found during a painting test. Tools - Paint bucket used the background color unconditionally. It now picks FG/BG like the brush does, via a shared Color: [FG][BG] row that every color-using tool renders (brush, bucket, eyedropper). - The eyedropper previously inferred its target swatch from active_color_mode, which was only ever set as a side effect of opening a color picker — so where a sample landed depended on invisible state. It now has an explicit toggle, and active_color_mode is gone. - Effect brushes (dodge/burn, sponge, blur, smudge, clone, heal, pattern) were stuck on a hardcoded Gaussian dab. Replaced ~20 flat per-tool fields with a BrushKind -> BrushSlot model: every dab-painting tool now owns its size/strength/hardness/spacing, its .myb preset, and its FG/BG choice, and gets the full brush library. base_settings already flowed into the dab engine independently of blend_mode, so this needed no core or WGSL changes. Cursors - Rebuilt around three kinds instead of "icon = cursor": System (real OS cursor for Select/Transform), Precise (glyph with a real tip, e.g. pencil/pipette), and Badge (crosshair marks the click point, glyph sits to its bottom-right) for icons with no focus point. - Cursors are now OS-composited via egui::CursorImage rather than painted into the scene, so they no longer lag the pointer. Glyphs are rasterized from egui's font atlas using epaint's own placement maths, so they land where painter.text put them. Drops the SVG cursor rasterization path. Tablet - The Wayland backend never handled zwp_tablet_tool_v2 Button events, so stylus barrel buttons were silently dropped. Both Wayland and X11 now emit them, with actions bound in Preferences (Pan/Eyedropper/Eraser). A pan-bound button suppresses the tool the way Alt+drag does, since the pen tip is still down while panning. Also adds middle-mouse panning. Timeline - Raster layers had no opacity control; the slider always drove volume, which is meaningless on them. The layer row is now three tiers, and each layer only shows controls that apply to it: Vector/Video get both volume and opacity (they can hold movie clips with audio), Raster/Text get opacity, Audio gets volume. Mute/solo are hidden where there's no audio. - Layer toggles use Lucide icons with tooltips, and gain a visibility (eye) toggle. LayerProperty::Visible already existed but was only reachable from the info panel. - Below 1.5x the layer-header width, the track area is dropped and the headers take the full pane. Panes - Color picker popups closed on any click (including on their own hue slider) and would not close on a drag — so drawing on the stage left one open. Shared color_swatch widget closes on a press outside instead. - Stage header gains undo/redo buttons for tablet use, and taller targets. - Toolbar is real egui layout (horizontal_wrapped) instead of absolute rect math, so it scrolls when the pane is too short. - Tools with no SVG icon use Lucide glyphs instead of a TODO placeholder.
This commit is contained in:
@@ -160,27 +160,27 @@ pub fn gradient_stop_editor(
|
||||
delete_idx = Some(i);
|
||||
}
|
||||
|
||||
// Color picker popup — opens on click, closes on click-outside.
|
||||
egui::containers::Popup::from_toggle_button_response(&resp)
|
||||
.show(|ui| {
|
||||
ui.spacing_mut().slider_width = 200.0;
|
||||
let stop = &mut gradient.stops[i];
|
||||
let mut c32 = Color32::from_rgba_unmultiplied(
|
||||
stop.color.r, stop.color.g, stop.color.b, stop.color.a,
|
||||
);
|
||||
if egui::color_picker::color_picker_color32(
|
||||
ui, &mut c32, egui::color_picker::Alpha::OnlyBlend,
|
||||
) {
|
||||
// Color32 stores premultiplied RGB; unmultiply before storing
|
||||
// as straight-alpha ShapeColor to avoid darkening on round-trip.
|
||||
let [pr, pg, pb, a] = c32.to_array();
|
||||
let unpm = |c: u8| -> u8 {
|
||||
if a == 0 { 0 } else { ((c as u32 * 255 + a as u32 / 2) / a as u32).min(255) as u8 }
|
||||
};
|
||||
stop.color = ShapeColor::rgba(unpm(pr), unpm(pg), unpm(pb), a);
|
||||
changed = true;
|
||||
}
|
||||
});
|
||||
// Color picker popup — opens on click, closes on a press outside it.
|
||||
let stop_color = gradient.stops[i].color;
|
||||
let mut c32 = Color32::from_rgba_unmultiplied(
|
||||
stop_color.r, stop_color.g, stop_color.b, stop_color.a,
|
||||
);
|
||||
if crate::widgets::color_swatch::color_picker_popup(
|
||||
ui,
|
||||
resp.id.with("stop_color_popup"),
|
||||
&resp,
|
||||
&mut c32,
|
||||
resp.rect,
|
||||
) {
|
||||
// Color32 stores premultiplied RGB; unmultiply before storing as straight-alpha
|
||||
// ShapeColor to avoid darkening on round-trip.
|
||||
let [pr, pg, pb, a] = c32.to_array();
|
||||
let unpm = |c: u8| -> u8 {
|
||||
if a == 0 { 0 } else { ((c as u32 * 255 + a as u32 / 2) / a as u32).min(255) as u8 }
|
||||
};
|
||||
gradient.stops[i].color = ShapeColor::rgba(unpm(pr), unpm(pg), unpm(pb), a);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Apply drag to whichever stop selected_stop points at.
|
||||
|
||||
@@ -28,14 +28,9 @@ pub struct InfopanelPane {
|
||||
tool_section_open: bool,
|
||||
/// Whether the shape properties section is expanded
|
||||
shape_section_open: bool,
|
||||
/// Index of the selected paint brush preset (None = custom / unset)
|
||||
selected_brush_preset: Option<usize>,
|
||||
/// Whether the paint brush picker is expanded
|
||||
brush_picker_expanded: bool,
|
||||
/// Index of the selected eraser brush preset
|
||||
selected_eraser_preset: Option<usize>,
|
||||
/// Whether the eraser brush picker is expanded
|
||||
eraser_picker_expanded: bool,
|
||||
/// Whether each tool's brush picker is expanded. The *selected* preset lives on the tool's
|
||||
/// `BrushSlot`, since it's part of the document-independent tool state, not panel chrome.
|
||||
brush_picker_expanded: std::collections::HashMap<crate::tools::BrushKind, bool>,
|
||||
/// Cached preview textures, one per preset (populated lazily).
|
||||
brush_preview_textures: Vec<egui::TextureHandle>,
|
||||
/// Selected stop index for gradient editor in shape section.
|
||||
@@ -61,15 +56,10 @@ impl InfopanelPane {
|
||||
// Kick off background loading of the font-picker fonts at startup so the dropdown
|
||||
// is ready without a hitch by the time the user opens it.
|
||||
lightningbeam_core::fonts::start_preload();
|
||||
let presets = bundled_brushes();
|
||||
let default_eraser_idx = presets.iter().position(|p| p.name == "Brush");
|
||||
Self {
|
||||
tool_section_open: true,
|
||||
shape_section_open: true,
|
||||
selected_brush_preset: None,
|
||||
brush_picker_expanded: false,
|
||||
selected_eraser_preset: default_eraser_idx,
|
||||
eraser_picker_expanded: false,
|
||||
brush_picker_expanded: std::collections::HashMap::new(),
|
||||
brush_preview_textures: Vec::new(),
|
||||
selected_shape_gradient_stop: None,
|
||||
selected_tool_gradient_stop: None,
|
||||
@@ -251,7 +241,7 @@ impl InfopanelPane {
|
||||
|| is_raster_select || is_raster_shape || matches!(
|
||||
tool,
|
||||
Tool::PaintBucket | Tool::RegionSelect | Tool::MagicWand | Tool::QuickSelect
|
||||
| Tool::Warp | Tool::Liquify | Tool::Gradient
|
||||
| Tool::Warp | Tool::Liquify | Tool::Gradient | Tool::Eyedropper
|
||||
);
|
||||
|
||||
if !has_options {
|
||||
@@ -285,12 +275,11 @@ impl InfopanelPane {
|
||||
return;
|
||||
}
|
||||
|
||||
// Raster paint tool: delegate to per-tool impl.
|
||||
// Raster paint tool: tool-unique controls, then the shared brush controls
|
||||
// (library, color, size/strength/hardness/spacing) that every brush tool gets.
|
||||
if let Some(def) = raster_tool_def {
|
||||
def.render_ui(ui, shared.raster_settings);
|
||||
if def.show_brush_preset_picker() {
|
||||
self.render_raster_tool_options(ui, shared, def.is_eraser());
|
||||
}
|
||||
self.render_raster_tool_options(ui, shared, def);
|
||||
}
|
||||
|
||||
match tool {
|
||||
@@ -344,7 +333,14 @@ impl InfopanelPane {
|
||||
ui.checkbox(shared.fill_enabled, "Fill Shape");
|
||||
}
|
||||
|
||||
Tool::Eyedropper => {
|
||||
// Which swatch the sampled color lands in.
|
||||
render_color_slot_row(ui, &mut shared.raster_settings.eyedropper_use_fg);
|
||||
}
|
||||
|
||||
Tool::PaintBucket => {
|
||||
render_color_slot_row(ui, &mut shared.raster_settings.fill_use_fg);
|
||||
|
||||
if active_is_raster {
|
||||
use crate::tools::FillThresholdMode;
|
||||
ui.horizontal(|ui| {
|
||||
@@ -603,68 +599,66 @@ impl InfopanelPane {
|
||||
});
|
||||
}
|
||||
|
||||
/// Render all options for a raster paint tool (brush picker + sliders).
|
||||
/// `is_eraser` drives which shared state is read/written.
|
||||
/// Render the shared controls every dab-painting tool has: the brush library, the FG/BG
|
||||
/// color choice, and size/strength/hardness/spacing/angle. `def` supplies the tool's brush
|
||||
/// slot and the label for the one slider whose meaning varies (opacity vs. exposure vs.
|
||||
/// flow vs. strength).
|
||||
fn render_raster_tool_options(
|
||||
&mut self,
|
||||
ui: &mut Ui,
|
||||
shared: &mut SharedPaneState,
|
||||
is_eraser: bool,
|
||||
def: &'static dyn crate::tools::RasterToolDef,
|
||||
) {
|
||||
self.render_brush_preset_grid(ui, shared, is_eraser);
|
||||
let kind = def.brush_kind();
|
||||
self.render_brush_preset_grid(ui, shared, kind);
|
||||
ui.add_space(2.0);
|
||||
|
||||
let rs = &mut shared.raster_settings;
|
||||
|
||||
if !is_eraser {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Color:");
|
||||
ui.selectable_value(&mut rs.brush_use_fg, true, "FG");
|
||||
ui.selectable_value(&mut rs.brush_use_fg, false, "BG");
|
||||
});
|
||||
if def.uses_color() {
|
||||
render_color_slot_row(ui, &mut shared.raster_settings.brush_mut(kind).use_fg);
|
||||
}
|
||||
|
||||
macro_rules! field {
|
||||
($eraser:ident, $brush:ident) => {
|
||||
if is_eraser { &mut rs.$eraser } else { &mut rs.$brush }
|
||||
}
|
||||
}
|
||||
let slot = shared.raster_settings.brush_mut(kind);
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Size:");
|
||||
ui.add(egui::Slider::new(field!(eraser_radius, brush_radius), 1.0_f32..=200.0).logarithmic(true).suffix(" px"));
|
||||
ui.add(egui::Slider::new(&mut slot.radius, 1.0_f32..=500.0)
|
||||
.logarithmic(true)
|
||||
.suffix(" px"));
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Opacity:");
|
||||
ui.add(egui::Slider::new(field!(eraser_opacity, brush_opacity), 0.0_f32..=1.0)
|
||||
ui.label(format!("{}:", def.strength_label()));
|
||||
ui.add(egui::Slider::new(&mut slot.strength, 0.0_f32..=1.0)
|
||||
.custom_formatter(|v, _| format!("{:.0}%", v * 100.0)));
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Hardness:");
|
||||
ui.add(egui::Slider::new(field!(eraser_hardness, brush_hardness), 0.0_f32..=1.0)
|
||||
ui.add(egui::Slider::new(&mut slot.hardness, 0.0_f32..=1.0)
|
||||
.custom_formatter(|v, _| format!("{:.0}%", v * 100.0)));
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Spacing:");
|
||||
ui.add(egui::Slider::new(field!(eraser_spacing, brush_spacing), 0.01_f32..=1.0)
|
||||
ui.add(egui::Slider::new(&mut slot.spacing, 0.01_f32..=20.0)
|
||||
.logarithmic(true)
|
||||
.custom_formatter(|v, _| format!("{:.0}%", v * 100.0)));
|
||||
.custom_formatter(|v, _| format!("{:.2}", v)));
|
||||
});
|
||||
|
||||
let bs = if is_eraser { &rs.active_eraser_settings } else { &rs.active_brush_settings };
|
||||
if bs.elliptical_dab_ratio > 1.001 {
|
||||
if slot.settings.elliptical_dab_ratio > 1.001 {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Angle:");
|
||||
ui.add(egui::Slider::new(&mut rs.brush_angle_offset, -180.0_f32..=180.0)
|
||||
ui.add(egui::Slider::new(&mut slot.angle_offset, -180.0_f32..=180.0)
|
||||
.suffix("°")
|
||||
.custom_formatter(|v, _| format!("{:.0}°", v)));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// Render the brush preset thumbnail grid (collapsible).
|
||||
/// `is_eraser` drives which picker state and which shared settings are updated.
|
||||
fn render_brush_preset_grid(&mut self, ui: &mut Ui, shared: &mut SharedPaneState, is_eraser: bool) {
|
||||
/// Render the brush preset thumbnail grid (collapsible) for one tool's brush slot.
|
||||
fn render_brush_preset_grid(
|
||||
&mut self,
|
||||
ui: &mut Ui,
|
||||
shared: &mut SharedPaneState,
|
||||
kind: crate::tools::BrushKind,
|
||||
) {
|
||||
let presets = bundled_brushes();
|
||||
if presets.is_empty() { return; }
|
||||
|
||||
@@ -690,8 +684,8 @@ impl InfopanelPane {
|
||||
}
|
||||
|
||||
// Read picker state into locals to avoid multiple &mut self borrows.
|
||||
let mut expanded = if is_eraser { self.eraser_picker_expanded } else { self.brush_picker_expanded };
|
||||
let mut selected = if is_eraser { self.selected_eraser_preset } else { self.selected_brush_preset };
|
||||
let mut expanded = self.brush_picker_expanded.get(&kind).copied().unwrap_or(false);
|
||||
let selected = shared.raster_settings.brush(kind).preset;
|
||||
|
||||
let gap = 3.0;
|
||||
let cols = 2usize;
|
||||
@@ -762,25 +756,14 @@ impl InfopanelPane {
|
||||
egui::FontId::proportional(9.5),
|
||||
if is_sel { egui::Color32::from_rgb(140, 190, 255) } else { egui::Color32::from_gray(160) });
|
||||
if resp.clicked() {
|
||||
selected = Some(idx);
|
||||
expanded = false;
|
||||
let s = &preset.settings;
|
||||
let rs = &mut shared.raster_settings;
|
||||
if is_eraser {
|
||||
rs.eraser_opacity = s.opaque.clamp(0.0, 1.0);
|
||||
rs.eraser_hardness = s.hardness.clamp(0.0, 1.0);
|
||||
rs.eraser_spacing = s.dabs_per_radius;
|
||||
rs.active_eraser_settings = s.clone();
|
||||
} else {
|
||||
rs.brush_opacity = s.opaque.clamp(0.0, 1.0);
|
||||
rs.brush_hardness = s.hardness.clamp(0.0, 1.0);
|
||||
rs.brush_spacing = s.dabs_per_radius;
|
||||
rs.active_brush_settings = s.clone();
|
||||
// If the user was on a preset-backed tool (Pencil/Pen/Airbrush)
|
||||
// and manually picked a different brush, revert to the generic tool.
|
||||
if matches!(*shared.selected_tool, Tool::Pencil | Tool::Pen | Tool::Airbrush) {
|
||||
*shared.selected_tool = Tool::Draw;
|
||||
}
|
||||
shared.raster_settings.brush_mut(kind).apply_preset(idx, &preset.settings);
|
||||
// If the user was on a preset-backed tool (Pencil/Pen/Airbrush)
|
||||
// and manually picked a different brush, revert to the generic tool.
|
||||
if kind == crate::tools::BrushKind::Paint
|
||||
&& matches!(*shared.selected_tool, Tool::Pencil | Tool::Pen | Tool::Airbrush)
|
||||
{
|
||||
*shared.selected_tool = Tool::Draw;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -789,14 +772,9 @@ impl InfopanelPane {
|
||||
}
|
||||
}
|
||||
|
||||
// Write back picker state.
|
||||
if is_eraser {
|
||||
self.eraser_picker_expanded = expanded;
|
||||
self.selected_eraser_preset = selected;
|
||||
} else {
|
||||
self.brush_picker_expanded = expanded;
|
||||
self.selected_brush_preset = selected;
|
||||
}
|
||||
// The selected preset lives on the slot itself (written by apply_preset above); only the
|
||||
// expand/collapse state is panel-local.
|
||||
self.brush_picker_expanded.insert(kind, expanded);
|
||||
}
|
||||
|
||||
// Transform section: deferred to Phase 2 (DCEL elements don't have instance transforms)
|
||||
@@ -1933,3 +1911,17 @@ impl PaneRenderer for InfopanelPane {
|
||||
"Info Panel"
|
||||
}
|
||||
}
|
||||
|
||||
/// The FG/BG selector shared by every tool that reads or writes a color (brush, paint bucket,
|
||||
/// eyedropper, …), so the choice is made the same way and in the same place regardless of tool.
|
||||
/// The wording stays neutral because the eyedropper *writes* to the chosen swatch while the
|
||||
/// painting tools *read* from it.
|
||||
fn render_color_slot_row(ui: &mut Ui, use_fg: &mut bool) {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Color:");
|
||||
ui.selectable_value(use_fg, true, "FG")
|
||||
.on_hover_text("Foreground (stroke) color");
|
||||
ui.selectable_value(use_fg, false, "BG")
|
||||
.on_hover_text("Background (fill) color");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -189,8 +189,6 @@ pub struct SharedPaneState<'a> {
|
||||
pub selected_tool: &'a mut Tool,
|
||||
pub fill_color: &'a mut egui::Color32,
|
||||
pub stroke_color: &'a mut egui::Color32,
|
||||
/// Tracks which color (fill or stroke) was last interacted with, for eyedropper tool
|
||||
pub active_color_mode: &'a mut ColorMode,
|
||||
pub pending_view_action: &'a mut Option<crate::menu::MenuAction>,
|
||||
/// Tracks the priority of the best fallback pane for view actions
|
||||
/// Lower number = higher priority. None = no fallback pane seen yet
|
||||
|
||||
@@ -5715,9 +5715,14 @@ impl StagePane {
|
||||
screen_pos: egui::Pos2,
|
||||
shared: &mut SharedPaneState,
|
||||
) {
|
||||
// On click, store the screen position and color mode for sampling
|
||||
// On click, store the screen position and which swatch the sample lands in.
|
||||
if self.rsp_clicked(response) {
|
||||
self.pending_eyedropper_sample = Some((screen_pos, *shared.active_color_mode));
|
||||
let mode = if shared.raster_settings.eyedropper_use_fg {
|
||||
super::ColorMode::Stroke
|
||||
} else {
|
||||
super::ColorMode::Fill
|
||||
};
|
||||
self.pending_eyedropper_sample = Some((screen_pos, mode));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6485,15 +6490,16 @@ impl StagePane {
|
||||
b.dabs_per_radius = spacing;
|
||||
if matches!(blend_mode, RasterBlendMode::Smudge) {
|
||||
b.dabs_per_actual_radius = 0.0;
|
||||
b.smudge_radius_log = shared.raster_settings.smudge_strength;
|
||||
b.smudge_radius_log =
|
||||
shared.raster_settings.brush(crate::tools::BrushKind::Smudge).strength;
|
||||
}
|
||||
if matches!(blend_mode, RasterBlendMode::BlurSharpen) {
|
||||
b.dabs_per_actual_radius = 0.0;
|
||||
}
|
||||
let color = if matches!(blend_mode, RasterBlendMode::Erase) {
|
||||
let color = if !def.uses_color() {
|
||||
[1.0f32, 1.0, 1.0, 1.0]
|
||||
} else {
|
||||
let c = if shared.raster_settings.brush_use_fg {
|
||||
let c = if shared.raster_settings.brush(def.brush_kind()).use_fg {
|
||||
*shared.stroke_color
|
||||
} else {
|
||||
*shared.fill_color
|
||||
@@ -6702,7 +6708,8 @@ impl StagePane {
|
||||
b.dabs_per_actual_radius = 0.0;
|
||||
// strength controls how far behind the stroke to sample (smudge_dist multiplier).
|
||||
// smudge_dist = radius * exp(smudge_radius_log), so log(strength) gives the ratio.
|
||||
b.smudge_radius_log = shared.raster_settings.smudge_strength; // linear [0,1] strength
|
||||
b.smudge_radius_log =
|
||||
shared.raster_settings.brush(crate::tools::BrushKind::Smudge).strength;
|
||||
}
|
||||
if matches!(blend_mode, lightningbeam_core::raster_layer::RasterBlendMode::BlurSharpen) {
|
||||
// Zero dabs_per_actual_radius so the spacing slider is the sole density control.
|
||||
@@ -6711,10 +6718,14 @@ impl StagePane {
|
||||
b
|
||||
};
|
||||
|
||||
let color = if matches!(blend_mode, lightningbeam_core::raster_layer::RasterBlendMode::Erase) {
|
||||
let color = if !def.uses_color() {
|
||||
[1.0f32, 1.0, 1.0, 1.0]
|
||||
} else {
|
||||
let c = if shared.raster_settings.brush_use_fg { *shared.stroke_color } else { *shared.fill_color };
|
||||
let c = if shared.raster_settings.brush(def.brush_kind()).use_fg {
|
||||
*shared.stroke_color
|
||||
} else {
|
||||
*shared.fill_color
|
||||
};
|
||||
let s2l = |v: u8| -> f32 {
|
||||
let f = v as f32 / 255.0;
|
||||
if f <= 0.04045 { f / 12.92 } else { ((f + 0.055) / 1.055).powf(2.4) }
|
||||
@@ -7429,7 +7440,7 @@ impl StagePane {
|
||||
use lightningbeam_core::actions::PaintBucketAction;
|
||||
use vello::kurbo::Point;
|
||||
let click_point = Point::new(world_pos.x as f64, world_pos.y as f64);
|
||||
let fill_color = ShapeColor::from_egui(*shared.fill_color);
|
||||
let fill_color = ShapeColor::from_egui(bucket_color(shared));
|
||||
let action = PaintBucketAction::new(
|
||||
active_layer_id,
|
||||
*shared.playback_time,
|
||||
@@ -7483,7 +7494,7 @@ impl StagePane {
|
||||
return;
|
||||
}
|
||||
|
||||
let fill_egui = *shared.fill_color;
|
||||
let fill_egui = bucket_color(shared);
|
||||
let fill_color = [fill_egui.r(), fill_egui.g(), fill_egui.b(), fill_egui.a()];
|
||||
let threshold = shared.raster_settings.fill_threshold;
|
||||
let softness = shared.raster_settings.fill_softness;
|
||||
@@ -11580,7 +11591,11 @@ impl StagePane {
|
||||
|
||||
// Handle tool input (only if not using Alt modifier for panning, and not while a
|
||||
// double-tap-drag marquee is actively dragging so the tool doesn't act during the gesture).
|
||||
if !alt_held && !self.marquee_gesture_active {
|
||||
// A pen barrel button bound to Pan suppresses the tool the same way Alt does — the pen
|
||||
// tip is still down while panning, so without this the brush would paint as you pan.
|
||||
let pen_panning = crate::tablet::active_button_action()
|
||||
== Some(crate::config::TabletButtonAction::Pan);
|
||||
if !alt_held && !pen_panning && !self.marquee_gesture_active {
|
||||
use lightningbeam_core::tool::Tool;
|
||||
|
||||
// On a shape-tween in-between frame the active vector layer's geometry is an
|
||||
@@ -11743,9 +11758,21 @@ impl StagePane {
|
||||
self.pan_offset.y += scroll_delta.y;
|
||||
}
|
||||
|
||||
// Handle panning with Alt+Drag
|
||||
if alt_held && response.dragged() {
|
||||
// Alt+Click+Drag panning
|
||||
// Middle-mouse drag pans, independent of the stage's own drag sense.
|
||||
let middle_down = ui.input(|i| i.pointer.middle_down());
|
||||
if middle_down {
|
||||
let delta = ui.input(|i| i.pointer.delta());
|
||||
self.pan_offset += delta;
|
||||
self.is_panning = true;
|
||||
}
|
||||
|
||||
// Holding a pen barrel button bound to Pan turns the pen drag into a pan instead of
|
||||
// a stroke (the tip is still down, so this is a normal primary drag).
|
||||
let pen_pan = crate::tablet::active_button_action()
|
||||
== Some(crate::config::TabletButtonAction::Pan);
|
||||
|
||||
// Handle panning with Alt+Drag (or a pan-bound pen button)
|
||||
if (alt_held || pen_pan) && response.dragged() {
|
||||
if let Some(last_pos) = self.last_pan_pos {
|
||||
if let Some(current_pos) = response.interact_pointer_pos() {
|
||||
let delta = current_pos - last_pos;
|
||||
@@ -11755,7 +11782,7 @@ impl StagePane {
|
||||
self.last_pan_pos = response.interact_pointer_pos();
|
||||
self.is_panning = true;
|
||||
} else {
|
||||
if !response.dragged() {
|
||||
if !response.dragged() && !middle_down {
|
||||
self.is_panning = false;
|
||||
self.last_pan_pos = None;
|
||||
}
|
||||
@@ -12099,26 +12126,22 @@ impl StagePane {
|
||||
let r = shared.raster_settings.quick_select_radius;
|
||||
(r, r, 0.0_f32)
|
||||
} else if let Some(def) = crate::tools::raster_tool_def(shared.selected_tool) {
|
||||
// Every brush tool can carry an elliptical library brush, so shape the cursor from
|
||||
// whichever slot the active tool paints with.
|
||||
let slot = shared.raster_settings.brush(def.brush_kind());
|
||||
let r = def.cursor_radius(shared.raster_settings);
|
||||
// For the standard paint brush, also account for elliptical shape.
|
||||
if matches!(*shared.selected_tool,
|
||||
Tool::Draw | Tool::Pencil | Tool::Pen | Tool::Airbrush)
|
||||
{
|
||||
let bs = &shared.raster_settings.active_brush_settings;
|
||||
let ratio = bs.elliptical_dab_ratio.max(1.0);
|
||||
let expand = 1.0 + bs.offset_by_random;
|
||||
let angle = (bs.elliptical_dab_angle + shared.raster_settings.brush_angle_offset).to_radians();
|
||||
(r * expand, r * expand / ratio, angle)
|
||||
} else {
|
||||
(r, r, 0.0_f32)
|
||||
}
|
||||
} else {
|
||||
let bs = &shared.raster_settings.active_brush_settings;
|
||||
let r = shared.raster_settings.brush_radius;
|
||||
let bs = &slot.settings;
|
||||
let ratio = bs.elliptical_dab_ratio.max(1.0);
|
||||
let expand = 1.0 + bs.offset_by_random;
|
||||
let angle = (bs.elliptical_dab_angle + shared.raster_settings.brush_angle_offset).to_radians();
|
||||
let angle = (bs.elliptical_dab_angle + slot.angle_offset).to_radians();
|
||||
(r * expand, r * expand / ratio, angle)
|
||||
} else {
|
||||
let slot = shared.raster_settings.brush(crate::tools::BrushKind::Paint);
|
||||
let bs = &slot.settings;
|
||||
let ratio = bs.elliptical_dab_ratio.max(1.0);
|
||||
let expand = 1.0 + bs.offset_by_random;
|
||||
let angle = (bs.elliptical_dab_angle + slot.angle_offset).to_radians();
|
||||
(slot.radius * expand, slot.radius * expand / ratio, angle)
|
||||
};
|
||||
|
||||
let a = a_world * self.zoom; // major semi-axis in screen pixels
|
||||
@@ -12163,9 +12186,84 @@ impl StagePane {
|
||||
|
||||
impl PaneRenderer for StagePane {
|
||||
fn render_header(&mut self, ui: &mut egui::Ui, shared: &mut SharedPaneState) -> bool {
|
||||
ui.horizontal(|ui| {
|
||||
// Zoom to fit button
|
||||
if ui.button("⊡ Fit").on_hover_text("Zoom to fit canvas in view").clicked() {
|
||||
// Fill most of the 40px header so the buttons are a comfortable tablet-sized target
|
||||
// rather than the ~20px egui default.
|
||||
const BTN_H: f32 = 27.0;
|
||||
let btn_size = egui::vec2(32.0, BTN_H);
|
||||
|
||||
// Lay the row out in a full-width band of exactly BTN_H centred in the header, so the
|
||||
// buttons sit vertically centred instead of dropping to the bottom of the taller header
|
||||
// rect. Horizontally they still start at the left, as before.
|
||||
let avail = ui.max_rect();
|
||||
let band = egui::Rect::from_min_size(
|
||||
egui::pos2(avail.min.x, avail.center().y - BTN_H / 2.0),
|
||||
egui::vec2(avail.width(), BTN_H),
|
||||
);
|
||||
|
||||
ui.scope_builder(
|
||||
egui::UiBuilder::new()
|
||||
.max_rect(band)
|
||||
.layout(egui::Layout::left_to_right(egui::Align::Center)),
|
||||
|ui| {
|
||||
// Undo / redo — duplicated here so tablet users don't need the keyboard.
|
||||
let can_undo = shared.action_executor.can_undo();
|
||||
let can_redo = shared.action_executor.can_redo();
|
||||
let icon_btn = |glyph: &str| {
|
||||
egui::Button::new(
|
||||
egui::RichText::new(glyph).font(crate::mobile::icons::font(16.0)),
|
||||
)
|
||||
.min_size(btn_size)
|
||||
};
|
||||
|
||||
if ui
|
||||
.add_enabled(can_undo, icon_btn(crate::mobile::icons::UNDO_2))
|
||||
.on_hover_text("Undo")
|
||||
.clicked()
|
||||
{
|
||||
shared.pending_menu_actions.push(crate::menu::MenuAction::Undo);
|
||||
}
|
||||
if ui
|
||||
.add_enabled(can_redo, icon_btn(crate::mobile::icons::REDO_2))
|
||||
.on_hover_text("Redo")
|
||||
.clicked()
|
||||
{
|
||||
shared.pending_menu_actions.push(crate::menu::MenuAction::Redo);
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
|
||||
// Zoom to fit: Lucide "maximize" glyph followed by the label. Two fonts in one
|
||||
// button means building the layout job by hand.
|
||||
let fit_label = {
|
||||
let mut job = egui::text::LayoutJob::default();
|
||||
let color = ui.visuals().widgets.inactive.fg_stroke.color;
|
||||
job.append(
|
||||
crate::mobile::icons::MAXIMIZE,
|
||||
0.0,
|
||||
egui::TextFormat {
|
||||
font_id: crate::mobile::icons::font(15.0),
|
||||
color,
|
||||
valign: egui::Align::Center,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
job.append(
|
||||
"Fit",
|
||||
6.0,
|
||||
egui::TextFormat {
|
||||
font_id: egui::TextStyle::Button.resolve(ui.style()),
|
||||
color,
|
||||
valign: egui::Align::Center,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
job
|
||||
};
|
||||
if ui
|
||||
.add(egui::Button::new(fit_label).min_size(egui::vec2(0.0, BTN_H)))
|
||||
.on_hover_text("Zoom to fit canvas in view")
|
||||
.clicked()
|
||||
{
|
||||
self.zoom_to_fit(shared);
|
||||
}
|
||||
|
||||
@@ -12175,7 +12273,8 @@ impl PaneRenderer for StagePane {
|
||||
let text_style = shared.theme.style(".text-primary", ui.ctx());
|
||||
let text_color = text_style.text_color.unwrap_or(egui::Color32::from_gray(200));
|
||||
ui.colored_label(text_color, format!("Zoom: {:.0}%", self.zoom * 100.0));
|
||||
});
|
||||
},
|
||||
);
|
||||
true
|
||||
}
|
||||
|
||||
@@ -13104,3 +13203,13 @@ impl PaneRenderer for StagePane {
|
||||
"Stage"
|
||||
}
|
||||
}
|
||||
|
||||
/// The color the paint bucket fills with. Like the brush, the bucket chooses between the
|
||||
/// foreground (stroke) and background (fill) swatch — see `RasterToolSettings::fill_use_fg`.
|
||||
fn bucket_color(shared: &SharedPaneState) -> egui::Color32 {
|
||||
if shared.raster_settings.fill_use_fg {
|
||||
*shared.stroke_color
|
||||
} else {
|
||||
*shared.fill_color
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,8 +10,35 @@ use eframe::egui;
|
||||
use daw_backend::{Beats, Seconds};
|
||||
use lightningbeam_core::clip::ClipInstance;
|
||||
use lightningbeam_core::layer::{AnyLayer, AudioLayerType, GroupLayer, LayerTrait};
|
||||
use crate::mobile::icons;
|
||||
use super::{DragClipType, NodePath, PaneRenderer, SharedPaneState};
|
||||
|
||||
/// A layer-row toggle button drawn as a Lucide glyph.
|
||||
fn icon_button(glyph: &str) -> egui::Button<'static> {
|
||||
egui::Button::new(egui::RichText::new(glyph).font(icons::font(13.0)))
|
||||
}
|
||||
|
||||
/// Label a layer-row slider with a Lucide glyph just to its left — the sliders are unlabelled
|
||||
/// otherwise, and volume vs. opacity are indistinguishable on layers that have both.
|
||||
fn draw_slider_icon(
|
||||
ui: &egui::Ui,
|
||||
theme: &crate::theme::Theme,
|
||||
slider_rect: egui::Rect,
|
||||
glyph: &str,
|
||||
) {
|
||||
ui.painter().text(
|
||||
egui::pos2(slider_rect.min.x - 5.0, slider_rect.center().y),
|
||||
egui::Align2::RIGHT_CENTER,
|
||||
glyph,
|
||||
icons::font(12.0),
|
||||
theme.text_color(
|
||||
&["#timeline", ".slider-icon"],
|
||||
ui.ctx(),
|
||||
egui::Color32::from_gray(140),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
const RULER_HEIGHT: f32 = 30.0;
|
||||
const LAYER_HEIGHT: f32 = 60.0;
|
||||
const LAYER_HEADER_WIDTH: f32 = 200.0;
|
||||
@@ -2363,32 +2390,53 @@ impl TimelinePane {
|
||||
|
||||
let Some(layer_for_controls) = any_layer_for_controls else { continue; };
|
||||
|
||||
// Layer controls: volume slider top-right, buttons below it
|
||||
// Layer controls, right-aligned in three stacked tiers: volume, opacity, buttons.
|
||||
// A layer only shows the sliders that mean something for it (a raster layer has no
|
||||
// volume; an audio layer has no opacity), but the buttons sit at a fixed offset so
|
||||
// they line up across rows regardless of which sliders are present.
|
||||
let controls_right = header_rect.max.x - 8.0;
|
||||
let button_size = egui::vec2(20.0, 20.0);
|
||||
let slider_width = 60.0;
|
||||
let slider_height = 14.0;
|
||||
|
||||
let volume_slider_rect = egui::Rect::from_min_size(
|
||||
egui::pos2(controls_right - slider_width, header_rect.min.y + 4.0),
|
||||
egui::vec2(slider_width, 20.0),
|
||||
egui::pos2(controls_right - slider_width, header_rect.min.y + 2.0),
|
||||
egui::vec2(slider_width, slider_height),
|
||||
);
|
||||
let opacity_slider_rect = egui::Rect::from_min_size(
|
||||
egui::pos2(controls_right - slider_width, header_rect.min.y + 17.0),
|
||||
egui::vec2(slider_width, slider_height),
|
||||
);
|
||||
|
||||
// Buttons sit below the slider, right-aligned to match it
|
||||
let buttons_top = volume_slider_rect.max.y + 4.0;
|
||||
let lock_button_rect = egui::Rect::from_min_size(
|
||||
egui::pos2(controls_right - button_size.x, buttons_top),
|
||||
button_size,
|
||||
);
|
||||
// Which controls apply to this layer. Vector and Video layers can hold movie clips
|
||||
// with audio *and* draw pixels, so they get both.
|
||||
let (has_volume, has_opacity) = match layer_for_controls {
|
||||
lightningbeam_core::layer::AnyLayer::Raster(_)
|
||||
| lightningbeam_core::layer::AnyLayer::Text(_) => (false, true),
|
||||
lightningbeam_core::layer::AnyLayer::Audio(_) => (true, false),
|
||||
_ => (true, true),
|
||||
};
|
||||
let is_video_layer =
|
||||
matches!(layer_for_controls, lightningbeam_core::layer::AnyLayer::Video(_));
|
||||
|
||||
let solo_button_rect = egui::Rect::from_min_size(
|
||||
egui::pos2(lock_button_rect.min.x - button_size.x - 4.0, buttons_top),
|
||||
button_size,
|
||||
);
|
||||
// Buttons are laid out right-to-left, and a layer only gets the ones that mean
|
||||
// something for it: [eye] [mute | camera] [solo] [lock].
|
||||
let buttons_top = header_rect.min.y + 34.0;
|
||||
let mut next_x = controls_right;
|
||||
let mut next_button_rect = || {
|
||||
next_x -= button_size.x;
|
||||
let r = egui::Rect::from_min_size(egui::pos2(next_x, buttons_top), button_size);
|
||||
next_x -= 4.0;
|
||||
r
|
||||
};
|
||||
|
||||
let mute_button_rect = egui::Rect::from_min_size(
|
||||
egui::pos2(solo_button_rect.min.x - button_size.x - 4.0, buttons_top),
|
||||
button_size,
|
||||
);
|
||||
let lock_button_rect = next_button_rect();
|
||||
let solo_button_rect = has_volume.then(&mut next_button_rect);
|
||||
// Video layers use this slot for the camera toggle instead of a mute button.
|
||||
let mute_button_rect =
|
||||
(has_volume && !is_video_layer).then(&mut next_button_rect);
|
||||
let camera_button_rect = is_video_layer.then(&mut next_button_rect);
|
||||
let visibility_button_rect = has_opacity.then(&mut next_button_rect);
|
||||
|
||||
// Get layer ID and current property values from the layer we already have
|
||||
// Check if there's a Volume automation lane; use it to drive the slider
|
||||
@@ -2416,30 +2464,66 @@ impl TimelinePane {
|
||||
let is_soloed = layer_for_controls.soloed();
|
||||
let is_locked = layer_for_controls.locked();
|
||||
|
||||
// Mute button — or camera toggle for video layers
|
||||
let is_video_layer = matches!(layer_for_controls, lightningbeam_core::layer::AnyLayer::Video(_));
|
||||
let camera_enabled = if let lightningbeam_core::layer::AnyLayer::Video(v) = layer_for_controls {
|
||||
v.camera_enabled
|
||||
} else {
|
||||
false
|
||||
};
|
||||
// Visibility toggle — on any layer that draws something.
|
||||
if let Some(rect) = visibility_button_rect {
|
||||
let is_visible = layer_for_controls.visible();
|
||||
let response = ui.scope_builder(egui::UiBuilder::new().max_rect(rect), |ui| {
|
||||
let button = icon_button(if is_visible { icons::EYE } else { icons::EYE_OFF })
|
||||
.fill(if is_visible {
|
||||
theme.bg_color(&["#timeline", ".btn-toggle"], ui.ctx(), egui::Color32::from_gray(40))
|
||||
} else {
|
||||
theme.bg_color(&["#timeline", ".btn-hidden", ".active"], ui.ctx(), egui::Color32::from_rgba_unmultiplied(120, 120, 120, 100))
|
||||
})
|
||||
.stroke(egui::Stroke::NONE);
|
||||
ui.add(button)
|
||||
.on_hover_text(if is_visible { "Hide layer" } else { "Show layer" })
|
||||
}).inner;
|
||||
|
||||
let first_btn_response = ui.scope_builder(egui::UiBuilder::new().max_rect(mute_button_rect), |ui| {
|
||||
if is_video_layer {
|
||||
// Camera toggle for video layers
|
||||
let cam_text = if camera_enabled { "📹" } else { "📷" };
|
||||
let button = egui::Button::new(cam_text)
|
||||
if response.clicked() {
|
||||
self.layer_control_clicked = true;
|
||||
pending_actions.push(Box::new(
|
||||
lightningbeam_core::actions::SetLayerPropertiesAction::new(
|
||||
layer_id,
|
||||
lightningbeam_core::actions::LayerProperty::Visible(!is_visible),
|
||||
)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// Camera toggle — video layers only.
|
||||
if let Some(rect) = camera_button_rect {
|
||||
let camera_enabled =
|
||||
matches!(layer_for_controls, lightningbeam_core::layer::AnyLayer::Video(v) if v.camera_enabled);
|
||||
let response = ui.scope_builder(egui::UiBuilder::new().max_rect(rect), |ui| {
|
||||
let button = icon_button(if camera_enabled { icons::VIDEO } else { icons::VIDEO_OFF })
|
||||
.fill(if camera_enabled {
|
||||
theme.bg_color(&["#timeline", ".btn-toggle", ".active"], ui.ctx(), egui::Color32::from_rgba_unmultiplied(100, 200, 100, 100))
|
||||
} else {
|
||||
theme.bg_color(&["#timeline", ".btn-toggle"], ui.ctx(), egui::Color32::from_gray(40))
|
||||
})
|
||||
.stroke(egui::Stroke::NONE);
|
||||
ui.add(button)
|
||||
} else {
|
||||
// Mute button for non-video layers
|
||||
let mute_text = if is_muted { "🔇" } else { "🔊" };
|
||||
let button = egui::Button::new(mute_text)
|
||||
ui.add(button).on_hover_text(if camera_enabled {
|
||||
"Disable camera preview"
|
||||
} else {
|
||||
"Enable camera preview"
|
||||
})
|
||||
}).inner;
|
||||
|
||||
if response.clicked() {
|
||||
self.layer_control_clicked = true;
|
||||
pending_actions.push(Box::new(
|
||||
lightningbeam_core::actions::SetLayerPropertiesAction::new(
|
||||
layer_id,
|
||||
lightningbeam_core::actions::LayerProperty::CameraEnabled(!camera_enabled),
|
||||
)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// Mute button — only where there's audio to mute.
|
||||
if let Some(rect) = mute_button_rect {
|
||||
let response = ui.scope_builder(egui::UiBuilder::new().max_rect(rect), |ui| {
|
||||
let button = icon_button(if is_muted { icons::VOLUME_X } else { icons::VOLUME_2 })
|
||||
.fill(if is_muted {
|
||||
theme.bg_color(&["#timeline", ".btn-mute", ".active"], ui.ctx(), egui::Color32::from_rgba_unmultiplied(255, 100, 100, 100))
|
||||
} else {
|
||||
@@ -2447,19 +2531,11 @@ impl TimelinePane {
|
||||
})
|
||||
.stroke(egui::Stroke::NONE);
|
||||
ui.add(button)
|
||||
}
|
||||
}).inner;
|
||||
.on_hover_text(if is_muted { "Unmute layer" } else { "Mute layer" })
|
||||
}).inner;
|
||||
|
||||
if first_btn_response.clicked() {
|
||||
self.layer_control_clicked = true;
|
||||
if is_video_layer {
|
||||
pending_actions.push(Box::new(
|
||||
lightningbeam_core::actions::SetLayerPropertiesAction::new(
|
||||
layer_id,
|
||||
lightningbeam_core::actions::LayerProperty::CameraEnabled(!camera_enabled),
|
||||
)
|
||||
));
|
||||
} else {
|
||||
if response.clicked() {
|
||||
self.layer_control_clicked = true;
|
||||
pending_actions.push(Box::new(
|
||||
lightningbeam_core::actions::SetLayerPropertiesAction::new(
|
||||
layer_id,
|
||||
@@ -2470,33 +2546,34 @@ impl TimelinePane {
|
||||
}
|
||||
|
||||
// Solo button
|
||||
// TODO: Replace with SVG headphones icon
|
||||
let solo_response = ui.scope_builder(egui::UiBuilder::new().max_rect(solo_button_rect), |ui| {
|
||||
let button = egui::Button::new("🎧")
|
||||
.fill(if is_soloed {
|
||||
theme.bg_color(&["#timeline", ".btn-solo", ".active"], ui.ctx(), egui::Color32::from_rgba_unmultiplied(100, 200, 100, 100))
|
||||
} else {
|
||||
theme.bg_color(&["#timeline", ".btn-toggle"], ui.ctx(), egui::Color32::from_gray(40))
|
||||
})
|
||||
.stroke(egui::Stroke::NONE);
|
||||
ui.add(button)
|
||||
}).inner;
|
||||
// Solo is an audio control, so it follows mute: only where there's audio.
|
||||
if let Some(rect) = solo_button_rect {
|
||||
let solo_response = ui.scope_builder(egui::UiBuilder::new().max_rect(rect), |ui| {
|
||||
let button = icon_button(icons::HEADPHONES)
|
||||
.fill(if is_soloed {
|
||||
theme.bg_color(&["#timeline", ".btn-solo", ".active"], ui.ctx(), egui::Color32::from_rgba_unmultiplied(100, 200, 100, 100))
|
||||
} else {
|
||||
theme.bg_color(&["#timeline", ".btn-toggle"], ui.ctx(), egui::Color32::from_gray(40))
|
||||
})
|
||||
.stroke(egui::Stroke::NONE);
|
||||
ui.add(button)
|
||||
.on_hover_text(if is_soloed { "Unsolo layer" } else { "Solo layer" })
|
||||
}).inner;
|
||||
|
||||
if solo_response.clicked() {
|
||||
self.layer_control_clicked = true;
|
||||
pending_actions.push(Box::new(
|
||||
lightningbeam_core::actions::SetLayerPropertiesAction::new(
|
||||
layer_id,
|
||||
lightningbeam_core::actions::LayerProperty::Soloed(!is_soloed),
|
||||
)
|
||||
));
|
||||
if solo_response.clicked() {
|
||||
self.layer_control_clicked = true;
|
||||
pending_actions.push(Box::new(
|
||||
lightningbeam_core::actions::SetLayerPropertiesAction::new(
|
||||
layer_id,
|
||||
lightningbeam_core::actions::LayerProperty::Soloed(!is_soloed),
|
||||
)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// Lock button
|
||||
// TODO: Replace with SVG lock/lock-open icons
|
||||
let lock_response = ui.scope_builder(egui::UiBuilder::new().max_rect(lock_button_rect), |ui| {
|
||||
let lock_text = if is_locked { "🔒" } else { "🔓" };
|
||||
let button = egui::Button::new(lock_text)
|
||||
let button = icon_button(if is_locked { icons::LOCK } else { icons::LOCK_OPEN })
|
||||
.fill(if is_locked {
|
||||
theme.bg_color(&["#timeline", ".btn-lock", ".active"], ui.ctx(), egui::Color32::from_rgba_unmultiplied(200, 150, 100, 100))
|
||||
} else {
|
||||
@@ -2504,6 +2581,7 @@ impl TimelinePane {
|
||||
})
|
||||
.stroke(egui::Stroke::NONE);
|
||||
ui.add(button)
|
||||
.on_hover_text(if is_locked { "Unlock layer" } else { "Lock layer (prevent edits)" })
|
||||
}).inner;
|
||||
|
||||
if lock_response.clicked() {
|
||||
@@ -2516,9 +2594,40 @@ impl TimelinePane {
|
||||
));
|
||||
}
|
||||
|
||||
// Opacity slider.
|
||||
if has_opacity {
|
||||
draw_slider_icon(ui, theme, opacity_slider_rect, icons::BLEND);
|
||||
let current_opacity = layer_for_controls.opacity() as f32;
|
||||
let mut new_opacity = current_opacity;
|
||||
let opacity_response = ui.scope_builder(
|
||||
egui::UiBuilder::new().max_rect(opacity_slider_rect),
|
||||
|ui| {
|
||||
ui.spacing_mut().slider_width = slider_width;
|
||||
ui.add(egui::Slider::new(&mut new_opacity, 0.0..=1.0).show_value(false))
|
||||
},
|
||||
).inner
|
||||
.on_hover_text(format!("Opacity: {:.0}%", current_opacity * 100.0));
|
||||
|
||||
// Block layer drag while interacting with the slider
|
||||
if opacity_response.dragged() || opacity_response.has_focus() {
|
||||
self.layer_control_clicked = true;
|
||||
}
|
||||
if opacity_response.changed() {
|
||||
self.layer_control_clicked = true;
|
||||
pending_actions.push(Box::new(
|
||||
lightningbeam_core::actions::SetLayerPropertiesAction::new(
|
||||
layer_id,
|
||||
lightningbeam_core::actions::LayerProperty::Opacity(new_opacity as f64),
|
||||
)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// Volume slider (nonlinear: 0-70% slider = 0-100% volume, 70-100% slider = 100-200% volume)
|
||||
// Disabled when the user has edited the Volume automation curve beyond the default single keyframe
|
||||
let volume_response = ui.scope_builder(egui::UiBuilder::new().max_rect(volume_slider_rect), |ui| {
|
||||
if has_volume {
|
||||
draw_slider_icon(ui, theme, volume_slider_rect, icons::VOLUME_2);
|
||||
let mut volume_response = ui.scope_builder(egui::UiBuilder::new().max_rect(volume_slider_rect), |ui| {
|
||||
ui.spacing_mut().slider_width = slider_width;
|
||||
// Map volume (0.0-2.0) to slider position (0.0-1.0)
|
||||
let slider_value = if current_volume <= 1.0 {
|
||||
@@ -2537,6 +2646,12 @@ impl TimelinePane {
|
||||
(response, temp_slider_value)
|
||||
}).inner;
|
||||
|
||||
volume_response.0 = volume_response.0.on_hover_text(if volume_is_automated {
|
||||
format!("Volume: {:.0}% (automated)", current_volume * 100.0)
|
||||
} else {
|
||||
format!("Volume: {:.0}%", current_volume * 100.0)
|
||||
});
|
||||
|
||||
// Block layer drag while interacting with the slider
|
||||
if volume_response.0.dragged() || volume_response.0.has_focus() {
|
||||
self.layer_control_clicked = true;
|
||||
@@ -2590,13 +2705,11 @@ impl TimelinePane {
|
||||
}
|
||||
}
|
||||
|
||||
// Input gain slider for sampled audio layers (below volume slider)
|
||||
// Input gain slider for sampled audio layers. Audio layers have no opacity, so this
|
||||
// takes the opacity tier.
|
||||
if let lightningbeam_core::layer::AnyLayer::Audio(audio_layer) = layer_for_controls {
|
||||
if audio_layer.audio_layer_type == lightningbeam_core::layer::AudioLayerType::Sampled {
|
||||
let gain_slider_rect = egui::Rect::from_min_size(
|
||||
egui::pos2(controls_right - slider_width, volume_slider_rect.max.y + 4.0),
|
||||
egui::vec2(slider_width, 16.0),
|
||||
);
|
||||
let gain_slider_rect = opacity_slider_rect;
|
||||
let current_gain = audio_layer.layer.input_gain;
|
||||
|
||||
// Map gain (0.0-4.0) to slider (0.0-1.0): linear
|
||||
@@ -2624,8 +2737,8 @@ impl TimelinePane {
|
||||
|
||||
// Label
|
||||
let label_rect = egui::Rect::from_min_size(
|
||||
egui::pos2(gain_slider_rect.min.x - 26.0, volume_slider_rect.max.y + 4.0),
|
||||
egui::vec2(24.0, 16.0),
|
||||
egui::pos2(gain_slider_rect.min.x - 26.0, gain_slider_rect.min.y),
|
||||
egui::vec2(24.0, gain_slider_rect.height()),
|
||||
);
|
||||
ui.painter().text(
|
||||
label_rect.center(),
|
||||
@@ -2637,6 +2750,8 @@ impl TimelinePane {
|
||||
}
|
||||
}
|
||||
|
||||
} // end volume/gain sliders
|
||||
|
||||
// Per-layer VU meter bar (4px tall at bottom of header)
|
||||
{
|
||||
// Look up the track level for this layer
|
||||
@@ -5795,8 +5910,14 @@ impl PaneRenderer for TimelinePane {
|
||||
|
||||
// Split into layer header column (left) and timeline content (right). On mobile the header
|
||||
// column collapses to a minimal color-swatch width.
|
||||
//
|
||||
// Once the pane gets narrow enough that the track area would be a useless sliver, drop it
|
||||
// entirely and give the whole pane to the layer headers — a mixer-style view.
|
||||
let headers_only = !shared.is_mobile && rect.width() < LAYER_HEADER_WIDTH * 1.5;
|
||||
let header_width = if shared.is_mobile {
|
||||
MOBILE_LAYER_HEADER_WIDTH
|
||||
} else if headers_only {
|
||||
rect.width()
|
||||
} else {
|
||||
LAYER_HEADER_WIDTH
|
||||
};
|
||||
@@ -5848,20 +5969,29 @@ impl PaneRenderer for TimelinePane {
|
||||
ui.set_clip_rect(layer_headers_rect.intersect(original_clip_rect));
|
||||
self.render_layer_headers(ui, layer_headers_rect, shared.theme, shared.active_layer_id, shared.focus, &mut shared.pending_actions, document, &context_layers, shared.layer_to_track_map, shared.track_levels, shared.input_level, *shared.playback_time, header_width, shared.is_mobile);
|
||||
|
||||
// Render time ruler (clip to ruler rect)
|
||||
ui.set_clip_rect(ruler_rect.intersect(original_clip_rect));
|
||||
let cycle = document
|
||||
.cycle_enabled
|
||||
.then(|| self.shown_cycle_region(document));
|
||||
self.render_ruler(ui, ruler_rect, shared.theme, document.tempo_map(), &document.time_signature, document.framerate, cycle);
|
||||
// The track area only exists when the pane is wide enough for it. The interaction code
|
||||
// further down is naturally inert in headers-only mode, since it all gates on
|
||||
// `content_rect.contains(..)` and the rect is zero-width.
|
||||
let (video_clip_hovers, pending_lane_renders) = if headers_only {
|
||||
(Vec::new(), Vec::new())
|
||||
} else {
|
||||
// Render time ruler (clip to ruler rect)
|
||||
ui.set_clip_rect(ruler_rect.intersect(original_clip_rect));
|
||||
let cycle = document
|
||||
.cycle_enabled
|
||||
.then(|| self.shown_cycle_region(document));
|
||||
self.render_ruler(ui, ruler_rect, shared.theme, document.tempo_map(), &document.time_signature, document.framerate, cycle);
|
||||
|
||||
// Render layer rows with clipping
|
||||
ui.set_clip_rect(content_rect.intersect(original_clip_rect));
|
||||
let (video_clip_hovers, pending_lane_renders) = self.render_layers(ui, content_rect, shared.theme, document, shared.active_layer_id, shared.focus, shared.selection, shared.midi_event_cache, shared.raw_audio_cache, shared.waveform_gpu_dirty, shared.waveform_minmax_pools, shared.target_format, shared.waveform_stereo, &context_layers, shared.video_manager, *shared.playback_time);
|
||||
// Render layer rows with clipping
|
||||
ui.set_clip_rect(content_rect.intersect(original_clip_rect));
|
||||
let rendered = self.render_layers(ui, content_rect, shared.theme, document, shared.active_layer_id, shared.focus, shared.selection, shared.midi_event_cache, shared.raw_audio_cache, shared.waveform_gpu_dirty, shared.waveform_minmax_pools, shared.target_format, shared.waveform_stereo, &context_layers, shared.video_manager, *shared.playback_time);
|
||||
|
||||
// Render playhead on top (clip to timeline area)
|
||||
ui.set_clip_rect(timeline_rect.intersect(original_clip_rect));
|
||||
self.render_playhead(ui, timeline_rect, shared.theme, *shared.playback_time);
|
||||
// Render playhead on top (clip to timeline area)
|
||||
ui.set_clip_rect(timeline_rect.intersect(original_clip_rect));
|
||||
self.render_playhead(ui, timeline_rect, shared.theme, *shared.playback_time);
|
||||
|
||||
rendered
|
||||
};
|
||||
|
||||
// Restore original clip rect
|
||||
ui.set_clip_rect(original_clip_rect);
|
||||
|
||||
@@ -29,10 +29,48 @@ impl PaneRenderer for ToolbarPane {
|
||||
path: &NodePath,
|
||||
shared: &mut SharedPaneState,
|
||||
) {
|
||||
let button_size = 60.0;
|
||||
let button_padding = 8.0;
|
||||
let button_spacing = 4.0;
|
||||
// `ui` spans the whole window, not this pane — bind a child Ui to the pane's content rect
|
||||
// first, or the ScrollArea would start at the window's top (under the pane header) and
|
||||
// size itself against the window's height (so it would never need to scroll).
|
||||
// Salt by path: widget ids inside are auto-generated from the Ui's id, so two toolbar
|
||||
// panes would otherwise fight over the same ids.
|
||||
let mut content_ui = ui.new_child(
|
||||
egui::UiBuilder::new()
|
||||
.id_salt(("toolbar", path))
|
||||
.max_rect(rect)
|
||||
.layout(egui::Layout::top_down(egui::Align::Min)),
|
||||
);
|
||||
|
||||
egui::ScrollArea::vertical()
|
||||
.id_salt(("toolbar_scroll", path))
|
||||
.auto_shrink([false; 2])
|
||||
.show(&mut content_ui, |ui| {
|
||||
self.render_toolbar(ui, path, shared);
|
||||
});
|
||||
}
|
||||
|
||||
fn name(&self) -> &str {
|
||||
"Toolbar"
|
||||
}
|
||||
}
|
||||
|
||||
const BUTTON_SIZE: f32 = 60.0;
|
||||
const BUTTON_PADDING: f32 = 8.0;
|
||||
const BUTTON_SPACING: f32 = 4.0;
|
||||
const COLOR_BUTTON_SIZE: f32 = 50.0;
|
||||
const COLOR_LABEL_WIDTH: f32 = 40.0;
|
||||
|
||||
impl ToolbarPane {
|
||||
/// Laid out with real egui widgets (`horizontal_wrapped` for the tool grid) rather than
|
||||
/// absolute rect math, so the ScrollArea above can measure the content and scroll it when the
|
||||
/// pane is too short. Buttons are still painted by hand — `allocate_exact_size` reserves the
|
||||
/// space and gives us the Response, and we draw into the rect egui hands back.
|
||||
fn render_toolbar(
|
||||
&mut self,
|
||||
ui: &mut egui::Ui,
|
||||
path: &NodePath,
|
||||
shared: &mut SharedPaneState,
|
||||
) {
|
||||
// Determine which tools to show based on the active layer type
|
||||
let active_layer_type: Option<LayerType> = shared.active_layer_id
|
||||
.and_then(|id| shared.action_executor.document().get_layer(&id))
|
||||
@@ -52,320 +90,273 @@ impl PaneRenderer for ToolbarPane {
|
||||
*shared.selected_tool = Tool::Select;
|
||||
}
|
||||
|
||||
// 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
|
||||
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 {
|
||||
shared.theme.bg_color(&["#toolbar", ".tool-button", ".selected"], ui.ctx(), egui::Color32::from_rgb(70, 100, 150))
|
||||
} else {
|
||||
shared.theme.bg_color(&["#toolbar", ".tool-button"], ui.ctx(), 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,
|
||||
);
|
||||
}
|
||||
|
||||
// Draw sub-tool arrow indicator for tools with modes
|
||||
let has_sub_tools = matches!(tool, Tool::RegionSelect | Tool::SelectLasso);
|
||||
if has_sub_tools {
|
||||
let arrow_size = 6.0;
|
||||
let margin = 4.0;
|
||||
let corner = button_rect.right_bottom() - egui::vec2(margin, margin);
|
||||
let tri = [
|
||||
corner,
|
||||
corner - egui::vec2(arrow_size, 0.0),
|
||||
corner - egui::vec2(0.0, arrow_size),
|
||||
];
|
||||
ui.painter().add(egui::Shape::convex_polygon(
|
||||
tri.to_vec(),
|
||||
shared.theme.text_color(&["#toolbar", ".tool-button"], ui.ctx(), egui::Color32::from_gray(200)),
|
||||
egui::Stroke::NONE,
|
||||
));
|
||||
}
|
||||
|
||||
// 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;
|
||||
// Preset-backed tools: auto-select the matching bundled brush.
|
||||
let preset_name = match tool {
|
||||
Tool::Pencil => Some("Pencil"),
|
||||
Tool::Pen => Some("Pen"),
|
||||
Tool::Airbrush => Some("Airbrush"),
|
||||
_ => None,
|
||||
};
|
||||
if let Some(name) = preset_name {
|
||||
if let Some(preset) = bundled_brushes().iter().find(|p| p.name == name) {
|
||||
let s = &preset.settings;
|
||||
shared.raster_settings.brush_opacity = s.opaque.clamp(0.0, 1.0);
|
||||
shared.raster_settings.brush_hardness = s.hardness.clamp(0.0, 1.0);
|
||||
shared.raster_settings.brush_spacing = s.dabs_per_radius;
|
||||
shared.raster_settings.active_brush_settings = s.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Right-click context menu for tools with sub-options
|
||||
if has_sub_tools {
|
||||
response.context_menu(|ui| {
|
||||
match tool {
|
||||
Tool::RegionSelect => {
|
||||
ui.set_min_width(120.0);
|
||||
if ui.selectable_label(
|
||||
*shared.region_select_mode == RegionSelectMode::Rectangle,
|
||||
"Rectangle",
|
||||
).clicked() {
|
||||
*shared.region_select_mode = RegionSelectMode::Rectangle;
|
||||
*shared.selected_tool = Tool::RegionSelect;
|
||||
ui.close();
|
||||
}
|
||||
if ui.selectable_label(
|
||||
*shared.region_select_mode == RegionSelectMode::Lasso,
|
||||
"Lasso",
|
||||
).clicked() {
|
||||
*shared.region_select_mode = RegionSelectMode::Lasso;
|
||||
*shared.selected_tool = Tool::RegionSelect;
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
Tool::SelectLasso => {
|
||||
ui.set_min_width(130.0);
|
||||
if ui.selectable_label(
|
||||
*shared.lasso_mode == LassoMode::Freehand,
|
||||
"Freehand",
|
||||
).clicked() {
|
||||
*shared.lasso_mode = LassoMode::Freehand;
|
||||
*shared.selected_tool = Tool::SelectLasso;
|
||||
ui.close();
|
||||
}
|
||||
if ui.selectable_label(
|
||||
*shared.lasso_mode == LassoMode::Polygonal,
|
||||
"Polygonal",
|
||||
).clicked() {
|
||||
*shared.lasso_mode = LassoMode::Polygonal;
|
||||
*shared.selected_tool = Tool::SelectLasso;
|
||||
ui.close();
|
||||
}
|
||||
if ui.selectable_label(
|
||||
*shared.lasso_mode == LassoMode::Magnetic,
|
||||
"Magnetic",
|
||||
).clicked() {
|
||||
*shared.lasso_mode = LassoMode::Magnetic;
|
||||
*shared.selected_tool = Tool::SelectLasso;
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if response.hovered() {
|
||||
ui.painter().rect_stroke(
|
||||
button_rect,
|
||||
4.0,
|
||||
egui::Stroke::new(2.0, shared.theme.border_color(&["#toolbar", ".tool-button", ".hover"], ui.ctx(), egui::Color32::from_gray(180))),
|
||||
egui::StrokeKind::Middle,
|
||||
);
|
||||
}
|
||||
|
||||
// Show tooltip with tool name and shortcut (consumes response).
|
||||
// Hint text is pulled from the live keymap so it reflects user remappings.
|
||||
let hint = tool_app_action(*tool)
|
||||
.and_then(|action| shared.keymap.get(action))
|
||||
.map(|s| format!(" ({})", s.hint_text()))
|
||||
.unwrap_or_default();
|
||||
let tooltip = if *tool == Tool::RegionSelect {
|
||||
let mode = match *shared.region_select_mode {
|
||||
RegionSelectMode::Rectangle => "Rectangle",
|
||||
RegionSelectMode::Lasso => "Lasso",
|
||||
};
|
||||
format!("{} - {}{}\nRight-click for options", tool.display_name(), mode, hint)
|
||||
} else if *tool == Tool::SelectLasso {
|
||||
let mode = match *shared.lasso_mode {
|
||||
LassoMode::Freehand => "Freehand",
|
||||
LassoMode::Polygonal => "Polygonal",
|
||||
LassoMode::Magnetic => "Magnetic",
|
||||
};
|
||||
format!("{} - {}{}\nRight-click for options", tool.display_name(), mode, hint)
|
||||
} else {
|
||||
format!("{}{}", tool.display_name(), hint)
|
||||
};
|
||||
response.on_hover_text(tooltip);
|
||||
|
||||
// Draw selection border
|
||||
if is_selected {
|
||||
ui.painter().rect_stroke(
|
||||
button_rect,
|
||||
4.0,
|
||||
egui::Stroke::new(2.0, shared.theme.border_color(&["#toolbar", ".tool-button", ".selected"], ui.ctx(), egui::Color32::from_rgb(100, 150, 255))),
|
||||
egui::StrokeKind::Middle,
|
||||
);
|
||||
}
|
||||
|
||||
// Move to next column in this row
|
||||
x += button_size + button_spacing;
|
||||
}
|
||||
|
||||
// Move to next row
|
||||
y += button_size + button_spacing;
|
||||
}
|
||||
|
||||
let is_raster = matches!(active_layer_type, Some(LayerType::Raster));
|
||||
let show_colors = matches!(active_layer_type, None | Some(LayerType::Vector) | Some(LayerType::Raster));
|
||||
|
||||
// Add color pickers below the tool buttons
|
||||
if show_colors {
|
||||
y += button_spacing * 2.0; // Extra spacing
|
||||
ui.spacing_mut().item_spacing = egui::vec2(BUTTON_SPACING, BUTTON_SPACING);
|
||||
ui.add_space(BUTTON_PADDING);
|
||||
|
||||
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;
|
||||
// Centre the grid as a block. Work out how many columns fit, then lay the buttons out in
|
||||
// a band of exactly that width, positioned to centre it. The band has to be an explicit
|
||||
// max_rect on the child Ui — a `horizontal_wrapped` nested inside a `horizontal` inherits
|
||||
// the parent's available width and wraps against that, not against the width we set.
|
||||
let full_width = ui.available_width();
|
||||
let avail = full_width - BUTTON_PADDING * 2.0;
|
||||
let columns = (((avail + BUTTON_SPACING) / (BUTTON_SIZE + BUTTON_SPACING)).floor() as usize)
|
||||
.max(1)
|
||||
.min(tools.len().max(1));
|
||||
let grid_width =
|
||||
columns as f32 * BUTTON_SIZE + (columns.saturating_sub(1)) as f32 * BUTTON_SPACING;
|
||||
let indent = ((full_width - grid_width) / 2.0).max(0.0);
|
||||
let rows = (tools.len() + columns - 1) / columns;
|
||||
|
||||
// Two color swatches:
|
||||
let cursor = ui.cursor().min;
|
||||
let band = egui::Rect::from_min_size(
|
||||
egui::pos2(cursor.x + indent, cursor.y),
|
||||
egui::vec2(grid_width, rows as f32 * (BUTTON_SIZE + BUTTON_SPACING)),
|
||||
);
|
||||
ui.scope_builder(
|
||||
egui::UiBuilder::new().max_rect(band).layout(
|
||||
egui::Layout::left_to_right(egui::Align::Min).with_main_wrap(true),
|
||||
),
|
||||
|ui| {
|
||||
ui.spacing_mut().item_spacing = egui::vec2(BUTTON_SPACING, BUTTON_SPACING);
|
||||
for tool in tools.iter() {
|
||||
self.render_tool_button(ui, tool, shared);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// Colour swatches below the tools.
|
||||
// Stroke/FG always on top, Fill/BG always on bottom.
|
||||
// Raster layers label them "FG" / "BG"; vector layers label them "Stroke" / "Fill".
|
||||
{
|
||||
let stroke_label = if is_raster { "FG" } else { "Stroke" };
|
||||
let label_color = shared.theme.text_color(&["#toolbar", ".text-secondary"], ui.ctx(), egui::Color32::from_gray(200));
|
||||
ui.painter().text(
|
||||
egui::pos2(color_x + fill_label_width / 2.0, y + color_button_size / 2.0),
|
||||
egui::Align2::CENTER_CENTER,
|
||||
stroke_label,
|
||||
egui::FontId::proportional(14.0),
|
||||
label_color,
|
||||
);
|
||||
if show_colors {
|
||||
ui.add_space(BUTTON_SPACING * 2.0);
|
||||
|
||||
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_color_button(ui, stroke_button_rect, *shared.stroke_color);
|
||||
egui::containers::Popup::from_toggle_button_response(&stroke_response)
|
||||
.show(|ui| {
|
||||
ui.spacing_mut().slider_width = 275.0;
|
||||
let changed = egui::color_picker::color_picker_color32(ui, shared.stroke_color, egui::color_picker::Alpha::OnlyBlend);
|
||||
if changed {
|
||||
*shared.active_color_mode = super::ColorMode::Stroke;
|
||||
}
|
||||
let row_width = COLOR_LABEL_WIDTH + COLOR_BUTTON_SIZE + BUTTON_SPACING;
|
||||
let color_indent = ((ui.available_width() - row_width) / 2.0).max(0.0);
|
||||
|
||||
for (label, is_stroke) in [
|
||||
(if is_raster { "FG" } else { "Stroke" }, true),
|
||||
(if is_raster { "BG" } else { "Fill" }, false),
|
||||
] {
|
||||
ui.horizontal(|ui| {
|
||||
ui.add_space(color_indent);
|
||||
|
||||
let (label_rect, _) = ui.allocate_exact_size(
|
||||
egui::vec2(COLOR_LABEL_WIDTH, COLOR_BUTTON_SIZE),
|
||||
egui::Sense::hover(),
|
||||
);
|
||||
let label_color = shared.theme.text_color(
|
||||
&["#toolbar", ".text-secondary"],
|
||||
ui.ctx(),
|
||||
egui::Color32::from_gray(200),
|
||||
);
|
||||
ui.painter().text(
|
||||
label_rect.center(),
|
||||
egui::Align2::CENTER_CENTER,
|
||||
label,
|
||||
egui::FontId::proportional(14.0),
|
||||
label_color,
|
||||
);
|
||||
|
||||
let (swatch_rect, _) = ui.allocate_exact_size(
|
||||
egui::vec2(COLOR_BUTTON_SIZE, COLOR_BUTTON_SIZE),
|
||||
egui::Sense::hover(),
|
||||
);
|
||||
let (id_key, color) = if is_stroke {
|
||||
("stroke_color_button", &mut *shared.stroke_color)
|
||||
} else {
|
||||
("fill_color_button", &mut *shared.fill_color)
|
||||
};
|
||||
let button_id = ui.id().with((id_key, path));
|
||||
crate::widgets::color_swatch::color_swatch(ui, button_id, swatch_rect, color);
|
||||
});
|
||||
|
||||
y += color_button_size + button_spacing;
|
||||
}
|
||||
}
|
||||
|
||||
// Fill/BG color swatch
|
||||
{
|
||||
let fill_label = if is_raster { "BG" } else { "Fill" };
|
||||
let label_color = shared.theme.text_color(&["#toolbar", ".text-secondary"], ui.ctx(), egui::Color32::from_gray(200));
|
||||
ui.add_space(BUTTON_PADDING);
|
||||
}
|
||||
|
||||
fn render_tool_button(
|
||||
&mut self,
|
||||
ui: &mut egui::Ui,
|
||||
tool: &Tool,
|
||||
shared: &mut SharedPaneState,
|
||||
) {
|
||||
let (button_rect, response) = ui.allocate_exact_size(
|
||||
egui::vec2(BUTTON_SIZE, BUTTON_SIZE),
|
||||
egui::Sense::click(),
|
||||
);
|
||||
|
||||
let is_selected = *shared.selected_tool == *tool;
|
||||
|
||||
// Button background
|
||||
let bg_color = if is_selected {
|
||||
shared.theme.bg_color(&["#toolbar", ".tool-button", ".selected"], ui.ctx(), egui::Color32::from_rgb(70, 100, 150))
|
||||
} else {
|
||||
shared.theme.bg_color(&["#toolbar", ".tool-button"], ui.ctx(), egui::Color32::from_rgb(50, 50, 50))
|
||||
};
|
||||
ui.painter().rect_filled(button_rect, 4.0, bg_color);
|
||||
|
||||
// Tool icon: tools without a bundled SVG fall back to a Lucide glyph rather than the
|
||||
// shared TODO placeholder.
|
||||
if let Some(glyph) = crate::mobile::icons::tool_glyph(*tool) {
|
||||
ui.painter().text(
|
||||
egui::pos2(color_x + fill_label_width / 2.0, y + color_button_size / 2.0),
|
||||
button_rect.center(),
|
||||
egui::Align2::CENTER_CENTER,
|
||||
fill_label,
|
||||
egui::FontId::proportional(14.0),
|
||||
label_color,
|
||||
);
|
||||
|
||||
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_color_button(ui, fill_button_rect, *shared.fill_color);
|
||||
egui::containers::Popup::from_toggle_button_response(&fill_response)
|
||||
.show(|ui| {
|
||||
ui.spacing_mut().slider_width = 275.0;
|
||||
let changed = egui::color_picker::color_picker_color32(ui, shared.fill_color, egui::color_picker::Alpha::OnlyBlend);
|
||||
if changed {
|
||||
*shared.active_color_mode = super::ColorMode::Fill;
|
||||
}
|
||||
});
|
||||
}
|
||||
} // end color pickers
|
||||
}
|
||||
|
||||
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,
|
||||
glyph,
|
||||
crate::mobile::icons::font(26.0),
|
||||
shared.theme.text_color(
|
||||
&["#toolbar", ".tool-button"],
|
||||
ui.ctx(),
|
||||
egui::Color32::from_gray(220),
|
||||
),
|
||||
egui::vec2(checker_size, checker_size),
|
||||
).intersect(rect);
|
||||
ui.painter().rect_filled(checker_rect, 0.0, checker_color);
|
||||
);
|
||||
} else 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,
|
||||
);
|
||||
}
|
||||
|
||||
// Draw sub-tool arrow indicator for tools with modes
|
||||
let has_sub_tools = matches!(tool, Tool::RegionSelect | Tool::SelectLasso);
|
||||
if has_sub_tools {
|
||||
let arrow_size = 6.0;
|
||||
let margin = 4.0;
|
||||
let corner = button_rect.right_bottom() - egui::vec2(margin, margin);
|
||||
let tri = [
|
||||
corner,
|
||||
corner - egui::vec2(arrow_size, 0.0),
|
||||
corner - egui::vec2(0.0, arrow_size),
|
||||
];
|
||||
ui.painter().add(egui::Shape::convex_polygon(
|
||||
tri.to_vec(),
|
||||
shared.theme.text_color(&["#toolbar", ".tool-button"], ui.ctx(), egui::Color32::from_gray(200)),
|
||||
egui::Stroke::NONE,
|
||||
));
|
||||
}
|
||||
|
||||
if response.clicked() {
|
||||
*shared.selected_tool = *tool;
|
||||
// Preset-backed tools: auto-select the matching bundled brush.
|
||||
let preset_name = match tool {
|
||||
Tool::Pencil => Some("Pencil"),
|
||||
Tool::Pen => Some("Pen"),
|
||||
Tool::Airbrush => Some("Airbrush"),
|
||||
_ => None,
|
||||
};
|
||||
if let Some(name) = preset_name {
|
||||
if let Some(idx) = bundled_brushes().iter().position(|p| p.name == name) {
|
||||
let settings = bundled_brushes()[idx].settings.clone();
|
||||
shared
|
||||
.raster_settings
|
||||
.brush_mut(crate::tools::BrushKind::Paint)
|
||||
.apply_preset(idx, &settings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Right-click context menu for tools with sub-options
|
||||
if has_sub_tools {
|
||||
response.context_menu(|ui| {
|
||||
match tool {
|
||||
Tool::RegionSelect => {
|
||||
ui.set_min_width(120.0);
|
||||
if ui.selectable_label(
|
||||
*shared.region_select_mode == RegionSelectMode::Rectangle,
|
||||
"Rectangle",
|
||||
).clicked() {
|
||||
*shared.region_select_mode = RegionSelectMode::Rectangle;
|
||||
*shared.selected_tool = Tool::RegionSelect;
|
||||
ui.close();
|
||||
}
|
||||
if ui.selectable_label(
|
||||
*shared.region_select_mode == RegionSelectMode::Lasso,
|
||||
"Lasso",
|
||||
).clicked() {
|
||||
*shared.region_select_mode = RegionSelectMode::Lasso;
|
||||
*shared.selected_tool = Tool::RegionSelect;
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
Tool::SelectLasso => {
|
||||
ui.set_min_width(130.0);
|
||||
if ui.selectable_label(
|
||||
*shared.lasso_mode == LassoMode::Freehand,
|
||||
"Freehand",
|
||||
).clicked() {
|
||||
*shared.lasso_mode = LassoMode::Freehand;
|
||||
*shared.selected_tool = Tool::SelectLasso;
|
||||
ui.close();
|
||||
}
|
||||
if ui.selectable_label(
|
||||
*shared.lasso_mode == LassoMode::Polygonal,
|
||||
"Polygonal",
|
||||
).clicked() {
|
||||
*shared.lasso_mode = LassoMode::Polygonal;
|
||||
*shared.selected_tool = Tool::SelectLasso;
|
||||
ui.close();
|
||||
}
|
||||
if ui.selectable_label(
|
||||
*shared.lasso_mode == LassoMode::Magnetic,
|
||||
"Magnetic",
|
||||
).clicked() {
|
||||
*shared.lasso_mode = LassoMode::Magnetic;
|
||||
*shared.selected_tool = Tool::SelectLasso;
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if response.hovered() {
|
||||
ui.painter().rect_stroke(
|
||||
button_rect,
|
||||
4.0,
|
||||
egui::Stroke::new(2.0, shared.theme.border_color(&["#toolbar", ".tool-button", ".hover"], ui.ctx(), egui::Color32::from_gray(180))),
|
||||
egui::StrokeKind::Middle,
|
||||
);
|
||||
}
|
||||
|
||||
// Draw selection border
|
||||
if is_selected {
|
||||
ui.painter().rect_stroke(
|
||||
button_rect,
|
||||
4.0,
|
||||
egui::Stroke::new(2.0, shared.theme.border_color(&["#toolbar", ".tool-button", ".selected"], ui.ctx(), egui::Color32::from_rgb(100, 150, 255))),
|
||||
egui::StrokeKind::Middle,
|
||||
);
|
||||
}
|
||||
|
||||
// Show tooltip with tool name and shortcut (consumes response).
|
||||
// Hint text is pulled from the live keymap so it reflects user remappings.
|
||||
let hint = tool_app_action(*tool)
|
||||
.and_then(|action| shared.keymap.get(action))
|
||||
.map(|s| format!(" ({})", s.hint_text()))
|
||||
.unwrap_or_default();
|
||||
let tooltip = if *tool == Tool::RegionSelect {
|
||||
let mode = match *shared.region_select_mode {
|
||||
RegionSelectMode::Rectangle => "Rectangle",
|
||||
RegionSelectMode::Lasso => "Lasso",
|
||||
};
|
||||
format!("{} - {}{}\nRight-click for options", tool.display_name(), mode, hint)
|
||||
} else if *tool == Tool::SelectLasso {
|
||||
let mode = match *shared.lasso_mode {
|
||||
LassoMode::Freehand => "Freehand",
|
||||
LassoMode::Polygonal => "Polygonal",
|
||||
LassoMode::Magnetic => "Magnetic",
|
||||
};
|
||||
format!("{} - {}{}\nRight-click for options", tool.display_name(), mode, hint)
|
||||
} else {
|
||||
format!("{}{}", tool.display_name(), hint)
|
||||
};
|
||||
response.on_hover_text(tooltip);
|
||||
}
|
||||
|
||||
// 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)),
|
||||
egui::StrokeKind::Middle,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user