Skip to content

Commit

Permalink
Use egui's zoom
Browse files Browse the repository at this point in the history
  • Loading branch information
zakarumych committed Dec 20, 2024
1 parent 12df816 commit 5572560
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Zooming now uses egui's zoom_delta from Input.
This means that zooming is now performed by ctrl+scroll (cmd+scroll on mac) or pinching.
Previously it was performed by scrolling alone, which collided with scrolling through content in the node's widgets and didn't work for tough controls.

This comment has been minimized.

Copy link
@juh9870

juh9870 Dec 20, 2024

Probably a typo, should be for touch controls.

This comment has been minimized.

Copy link
@zakarumych

zakarumych Dec 21, 2024

Author Owner

Thanks, fixed it


### Added

- NodeLayout enum
Expand Down
10 changes: 5 additions & 5 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ impl SnarlStyle {
}

fn get_scale_velocity(&self) -> f32 {
self.scale_velocity.unwrap_or(0.005)
self.scale_velocity.unwrap_or(1.0)
}

fn get_node_frame(&self, scale: f32, style: &Style) -> Frame {
Expand Down Expand Up @@ -586,7 +586,7 @@ impl Default for SnarlStyle {
struct Input {
hover_pos: Option<Pos2>,
interact_pos: Option<Pos2>,
scroll_delta: f32,
zoom_delta: f32,
// primary_pressed: bool,
secondary_pressed: bool,
modifiers: Modifiers,
Expand Down Expand Up @@ -656,7 +656,7 @@ impl<T> Snarl<T> {
let bg_frame = style.get_bg_frame(ui.style());

let input = ui.ctx().input(|i| Input {
scroll_delta: i.raw_scroll_delta.y,
zoom_delta: i.zoom_delta(),
hover_pos: i.pointer.hover_pos(),
interact_pos: i.pointer.interact_pos(),
modifiers: i.modifiers,
Expand Down Expand Up @@ -698,9 +698,9 @@ impl<T> Snarl<T> {
Some(hover_pos)
if viewport.contains(hover_pos) && ui.rect_contains_pointer(viewport) =>
{
if input.scroll_delta != 0.0 {
if input.zoom_delta != 1.0 {
let new_scale = (snarl_state.scale()
* input.scroll_delta.mul_add(style.get_scale_velocity(), 1.0))
* input.zoom_delta.powf(style.get_scale_velocity()))
.clamp(style.get_min_scale(), style.get_max_scale());

snarl_state.set_scale(new_scale);
Expand Down

0 comments on commit 5572560

Please sign in to comment.