Implemented middle-click drag scrolling in Timeline panel:
State fields added (state.rs): - middle_drag_panel: Option<PanelKind> — tracks panel being dragged - middle_drag_start_scroll_y: f32 — scroll at start of drag - middle_drag_start_pos: Option<egui::Pos2> — mouse position at start Drag handling (timeline.rs): - Detects middle-click mousedown when hovering over rows - Calculates vertical delta during drag - Updates scroll_y based on drag distance - Ends drag on middle-button release
This commit is contained in:
@@ -17,6 +17,7 @@ use serde_json::json;
|
|||||||
use crate::i18n::tr;
|
use crate::i18n::tr;
|
||||||
use crate::icons::{self, Icon};
|
use crate::icons::{self, Icon};
|
||||||
use crate::theme::Tokens;
|
use crate::theme::Tokens;
|
||||||
|
use crate::dock::PanelKind;
|
||||||
use crate::{EffectcraftApp, widgets};
|
use crate::{EffectcraftApp, widgets};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
@@ -1896,6 +1897,38 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
|||||||
app.ui.timeline.scroll_y = rows.iter().take(i).map(|r| row_height(r, rh)).sum();
|
app.ui.timeline.scroll_y = rows.iter().take(i).map(|r| row_height(r, rh)).sum();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Middle-click drag scrolling for testing
|
||||||
|
let middle_pressed = ctx.input(|i| {
|
||||||
|
i.events.iter().any(|e| matches!(e, egui::Event::PointerButton { button: egui::PointerButton::Middle, pressed: true, .. }))
|
||||||
|
});
|
||||||
|
let middle_released = ctx.input(|i| {
|
||||||
|
i.events.iter().any(|e| matches!(e, egui::Event::PointerButton { button: egui::PointerButton::Middle, pressed: false, .. }))
|
||||||
|
});
|
||||||
|
|
||||||
|
if middle_pressed && app.ui.timeline.middle_drag_panel.is_none() && ui.rect_contains_pointer(rows_rect) {
|
||||||
|
// Start middle-click drag
|
||||||
|
app.ui.timeline.middle_drag_panel = Some(PanelKind::Timeline);
|
||||||
|
app.ui.timeline.middle_drag_start_scroll_y = app.ui.timeline.scroll_y;
|
||||||
|
app.ui.timeline.middle_drag_start_pos = ui.input(|i| i.pointer.latest_pos());
|
||||||
|
}
|
||||||
|
|
||||||
|
// End middle-click drag on release
|
||||||
|
if middle_released && app.ui.timeline.middle_drag_panel == Some(PanelKind::Timeline) {
|
||||||
|
app.ui.timeline.middle_drag_panel = None;
|
||||||
|
app.ui.timeline.middle_drag_start_pos = None;
|
||||||
|
}
|
||||||
|
|
||||||
|
if app.ui.timeline.middle_drag_panel == Some(PanelKind::Timeline) {
|
||||||
|
// Handle middle-click drag scrolling
|
||||||
|
if let Some(start_pos) = app.ui.timeline.middle_drag_start_pos {
|
||||||
|
if let Some(current_pos) = ui.input(|i| i.pointer.latest_pos()) {
|
||||||
|
let delta = (start_pos.y - current_pos.y) as f64;
|
||||||
|
app.ui.timeline.scroll_y = (app.ui.timeline.middle_drag_start_scroll_y + delta as f32).clamp(0.0, max_scroll);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ui.rect_contains_pointer(rows_rect) {
|
if ui.rect_contains_pointer(rows_rect) {
|
||||||
let (dy, dx, zoom) = ui.input(|i| (i.smooth_scroll_delta.y, i.smooth_scroll_delta.x, i.modifiers.alt));
|
let (dy, dx, zoom) = ui.input(|i| (i.smooth_scroll_delta.y, i.smooth_scroll_delta.x, i.modifiers.alt));
|
||||||
// Ctrl/Cmd+wheel and a trackpad pinch reach egui as a zoom factor rather than a scroll
|
// Ctrl/Cmd+wheel and a trackpad pinch reach egui as a zoom factor rather than a scroll
|
||||||
@@ -1932,6 +1965,13 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
|||||||
ctx.request_repaint();
|
ctx.request_repaint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// End middle-click drag on release
|
||||||
|
if middle_released && app.ui.timeline.middle_drag_panel == Some(PanelKind::Timeline) {
|
||||||
|
app.ui.timeline.middle_drag_panel = None;
|
||||||
|
app.ui.timeline.middle_drag_start_pos = None;
|
||||||
|
}
|
||||||
|
|
||||||
app.ui.timeline.scroll_y = app.ui.timeline.scroll_y.clamp(0.0, max_scroll);
|
app.ui.timeline.scroll_y = app.ui.timeline.scroll_y.clamp(0.0, max_scroll);
|
||||||
let snap_project = app.session.project.clone();
|
let snap_project = app.session.project.clone();
|
||||||
let snap_expr = app.session.expr.clone();
|
let snap_expr = app.session.expr.clone();
|
||||||
|
|||||||
@@ -353,6 +353,13 @@ pub struct TimelineState {
|
|||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub before_fit: Option<(f64, f64)>,
|
pub before_fit: Option<(f64, f64)>,
|
||||||
pub scroll_y: f32,
|
pub scroll_y: f32,
|
||||||
|
/// Middle-click drag state for testing scroll by middle-mouse dragging.
|
||||||
|
#[serde(skip)]
|
||||||
|
pub middle_drag_panel: Option<crate::dock::PanelKind>,
|
||||||
|
#[serde(skip)]
|
||||||
|
pub middle_drag_start_scroll_y: f32,
|
||||||
|
#[serde(skip)]
|
||||||
|
pub middle_drag_start_pos: Option<egui::Pos2>,
|
||||||
/// Left column area width.
|
/// Left column area width.
|
||||||
pub columns_w: f32,
|
pub columns_w: f32,
|
||||||
/// Horizontal scroll of the outline columns (pixels) when they are wider than the pane.
|
/// Horizontal scroll of the outline columns (pixels) when they are wider than the pane.
|
||||||
@@ -442,6 +449,9 @@ impl Default for TimelineState {
|
|||||||
pps: None,
|
pps: None,
|
||||||
before_fit: None,
|
before_fit: None,
|
||||||
scroll_y: 0.0,
|
scroll_y: 0.0,
|
||||||
|
middle_drag_panel: None,
|
||||||
|
middle_drag_start_scroll_y: 0.0,
|
||||||
|
middle_drag_start_pos: None,
|
||||||
columns_w: 560.0,
|
columns_w: 560.0,
|
||||||
outline_scroll: 0.0,
|
outline_scroll: 0.0,
|
||||||
show_modes: false,
|
show_modes: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user