From 7470413ad87a31a29974c2b0b4be549c8daae2ad Mon Sep 17 00:00:00 2001 From: "5684185+vsariola@users.noreply.github.com" <5684185+vsariola@users.noreply.github.com> Date: Tue, 15 Oct 2024 09:37:21 +0300 Subject: [PATCH] fix(tracker): click on hex track low/high nibble selects that nibble Closes #160 --- CHANGELOG.md | 3 +++ tracker/gioui/scroll_table.go | 12 +++++------- tracker/table.go | 12 ++++++++++++ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fda6cff..f85b6aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). the command line tools. ### Fixed +- Clicking on low nibble or high nibble of a hex track selects that nibble + ([#160][i160]) - If units have useless parameters in their parameter maps, from bugs or from a malformed yaml file, they are removed and user is warned about it - Pressing a or 1 when editing note values in hex mode created a note off line @@ -257,5 +259,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). [i151]: https://github.com/vsariola/sointu/issues/151 [i154]: https://github.com/vsariola/sointu/issues/154 [i158]: https://github.com/vsariola/sointu/issues/158 +[i160]: https://github.com/vsariola/sointu/issues/160 [i162]: https://github.com/vsariola/sointu/issues/162 [i166]: https://github.com/vsariola/sointu/issues/166 \ No newline at end of file diff --git a/tracker/gioui/scroll_table.go b/tracker/gioui/scroll_table.go index 878791b..72cae6d 100644 --- a/tracker/gioui/scroll_table.go +++ b/tracker/gioui/scroll_table.go @@ -146,13 +146,11 @@ func (s *ScrollTableStyle) handleEvents(gtx layout.Context, p image.Point) { if e.Kind == pointer.Press { gtx.Execute(key.FocusCmd{Tag: s.ScrollTable}) } - dx := (int(e.Position.X) + s.ScrollTable.ColTitleList.List.Position.Offset) / gtx.Dp(s.CellWidth) - dy := (int(e.Position.Y) + s.ScrollTable.RowTitleList.List.Position.Offset) / gtx.Dp(s.CellHeight) - x := dx + s.ScrollTable.ColTitleList.List.Position.First - y := dy + s.ScrollTable.RowTitleList.List.Position.First - s.ScrollTable.Table.SetCursor( - tracker.Point{X: x, Y: y}, - ) + dx := (e.Position.X + float32(s.ScrollTable.ColTitleList.List.Position.Offset)) / float32(gtx.Dp(s.CellWidth)) + dy := (e.Position.Y + float32(s.ScrollTable.RowTitleList.List.Position.Offset)) / float32(gtx.Dp(s.CellHeight)) + x := dx + float32(s.ScrollTable.ColTitleList.List.Position.First) + y := dy + float32(s.ScrollTable.RowTitleList.List.Position.First) + s.ScrollTable.Table.SetCursorFloat(x, y) if !e.Modifiers.Contain(key.ModShift) { s.ScrollTable.Table.SetCursor2(s.ScrollTable.Table.Cursor()) } diff --git a/tracker/table.go b/tracker/table.go index e8a38eb..97808da 100644 --- a/tracker/table.go +++ b/tracker/table.go @@ -1,6 +1,8 @@ package tracker import ( + "math" + "github.com/vsariola/sointu" "gopkg.in/yaml.v3" ) @@ -15,6 +17,7 @@ type ( Cursor2() Point SetCursor(Point) SetCursor2(Point) + SetCursorFloat(x, y float32) Width() int Height() int MoveCursor(dx, dy int) (ok bool) @@ -178,6 +181,10 @@ func (m *Order) SetCursor2(p Point) { m.updateCursorRows() } +func (m *Order) SetCursorFloat(x, y float32) { + m.SetCursor(Point{int(x), int(y)}) +} + func (v *Order) updateCursorRows() { if v.Cursor() == v.Cursor2() { v.d.Cursor.PatternRow = 0 @@ -422,6 +429,11 @@ func (v *Notes) SetCursor2(p Point) { v.d.Cursor2.SongPos = v.d.Song.Score.Clamp(sointu.SongPos{PatternRow: p.Y}) } +func (m *Notes) SetCursorFloat(x, y float32) { + m.SetCursor(Point{int(x), int(y)}) + m.d.LowNibble = math.Mod(float64(x), 1.0) > 0.5 +} + func (v *Notes) Width() int { return len((*Model)(v).d.Song.Score.Tracks) }