feat(viewer): implement keyboard and button zoom/pan controls

- Fork cosmic::iced viewer widget to enable external state control
- Add bidirectional state synchronization between viewer and AppModel
- Implement ViewerStateChanged message for mouse interaction feedback
- Fix pixel-perfect rendering at 100% zoom (ActualSize mode)
- Ensure smooth interaction between mouse, keyboard, and button controls

This allows zoom/pan to work via:
- Keyboard shortcuts (+/-, Ctrl+arrows)
- Future toolbar buttons
- Mouse wheel and drag (existing functionality preserved)

The viewer state now properly syncs in both directions:
- External controls (keyboard/buttons) → update viewer state via diff()
- Mouse interactions → update AppModel via ViewerStateChanged message

Closes: Zoom/pan via keyboard and buttons now functional
This commit is contained in:
mow 2026-01-15 18:10:57 +01:00
parent 2905a3f6f1
commit 69f22bafcd
5 changed files with 564 additions and 39 deletions

View file

@ -37,6 +37,12 @@ pub fn update(model: &mut AppModel, msg: AppMessage) {
model.view_mode = ViewMode::Fit;
model.reset_pan();
}
AppMessage::ViewerStateChanged { scale, offset_x, offset_y } => {
// Update model state from viewer (mouse interaction)
model.view_mode = ViewMode::Custom(scale);
model.pan_x = offset_x;
model.pan_y = offset_y;
}
// ===== Pan control (Ctrl + arrow keys) ===========================================
AppMessage::PanLeft => {