From 8245fbda24a75a934ba20d8c34a82a9750ff2028 Mon Sep 17 00:00:00 2001 From: "5684185+vsariola@users.noreply.github.com" <5684185+vsariola@users.noreply.github.com> Date: Thu, 1 May 2025 19:16:39 +0300 Subject: [PATCH] feat(track/gioui): ctrl + scrollwheel adjusts global GUI zoom Closes #153 --- CHANGELOG.md | 2 ++ tracker/gioui/tracker.go | 23 ++++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2b6763..804dc36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] ### Added +- Ctrl + scroll wheel adjusts the global scaling of the GUI ([#153][i153]) - The loudness detection supports LUFS, A-weighting, C-weighting or RMS-weighting, and peak detection supports true peak or sample peak detection. The loudness and peak values are displayed in the song panel ([#186][i186]) @@ -313,6 +314,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). [i149]: https://github.com/vsariola/sointu/issues/149 [i150]: https://github.com/vsariola/sointu/issues/150 [i151]: https://github.com/vsariola/sointu/issues/151 +[i153]: https://github.com/vsariola/sointu/issues/153 [i154]: https://github.com/vsariola/sointu/issues/154 [i155]: https://github.com/vsariola/sointu/issues/155 [i156]: https://github.com/vsariola/sointu/issues/156 diff --git a/tracker/gioui/tracker.go b/tracker/gioui/tracker.go index 030b28d..3e95be6 100644 --- a/tracker/gioui/tracker.go +++ b/tracker/gioui/tracker.go @@ -10,6 +10,7 @@ import ( "gioui.org/app" "gioui.org/io/event" "gioui.org/io/key" + "gioui.org/io/pointer" "gioui.org/io/system" "gioui.org/io/transfer" "gioui.org/layout" @@ -35,6 +36,7 @@ type ( KeyPlaying map[key.Name]tracker.NoteID MidiNotePlaying []byte PopupAlert *PopupAlert + Zoom int SaveChangesDialog *Dialog WaveTypeDialog *Dialog @@ -65,6 +67,8 @@ const ( ConfirmNew ) +var ZoomFactors = []float32{.25, 1. / 3, .5, 2. / 3, .75, .8, 1, 1.1, 1.25, 1.5, 1.75, 2, 2.5, 3, 4, 5} + func NewTracker(model *tracker.Model) *Tracker { t := &Tracker{ Theme: material.NewTheme(), @@ -84,6 +88,8 @@ func NewTracker(model *tracker.Model) *Tracker { TrackEditor: NewNoteEditor(model), SongPanel: NewSongPanel(model), + Zoom: 6, + Model: model, filePathString: model.FilePath().String(), @@ -184,7 +190,13 @@ func titleFromPath(path string) string { } func (t *Tracker) Layout(gtx layout.Context, w *app.Window) { - paint.FillShape(gtx.Ops, backgroundColor, clip.Rect(image.Rect(0, 0, gtx.Constraints.Max.X, gtx.Constraints.Max.Y)).Op()) + zoomFactor := ZoomFactors[t.Zoom] + gtx.Metric.PxPerDp *= zoomFactor + gtx.Metric.PxPerSp *= zoomFactor + defer clip.Rect(image.Rectangle{Max: gtx.Constraints.Max}).Push(gtx.Ops).Pop() + paint.Fill(gtx.Ops, backgroundColor) + event.Op(gtx.Ops, t) // area for capturing scroll events + if t.InstrumentEditor.enlargeBtn.Bool.Value() { t.layoutTop(gtx) } else { @@ -203,11 +215,20 @@ func (t *Tracker) Layout(gtx layout.Context, w *app.Window) { key.Filter{Name: "", Optional: key.ModAlt | key.ModCommand | key.ModShift | key.ModShortcut | key.ModSuper}, key.Filter{Name: key.NameTab, Optional: key.ModShift}, transfer.TargetFilter{Target: t, Type: "application/text"}, + pointer.Filter{Target: t, Kinds: pointer.Scroll, ScrollY: pointer.ScrollRange{Min: -1, Max: 1}}, ) if !ok { break } switch e := ev.(type) { + case pointer.Event: + switch e.Kind { + case pointer.Scroll: + if e.Modifiers.Contain(key.ModShortcut) { + t.Zoom = min(max(t.Zoom-int(e.Scroll.Y), 0), len(ZoomFactors)-1) + t.Alerts().AddNamed("ZoomFactor", fmt.Sprintf("%.0f%%", ZoomFactors[t.Zoom]*100), tracker.Info) + } + } case key.Event: t.KeyEvent(e, gtx) case transfer.DataEvent: