mirror of
https://github.com/vsariola/sointu.git
synced 2025-06-04 01:28:45 -04:00
feat(gioui): make split bars snap to window edges
This commit is contained in:
parent
203e8a3ccc
commit
8a94058d44
@ -68,6 +68,7 @@ func (s *Split) Layout(gtx layout.Context, first, second layout.Widget) layout.D
|
|||||||
} else {
|
} else {
|
||||||
s.dragCoord = e.Position.Y
|
s.dragCoord = e.Position.Y
|
||||||
}
|
}
|
||||||
|
s.drag = true
|
||||||
|
|
||||||
case pointer.Drag:
|
case pointer.Drag:
|
||||||
if s.dragID != e.PointerID {
|
if s.dragID != e.PointerID {
|
||||||
@ -94,6 +95,27 @@ func (s *Split) Layout(gtx layout.Context, first, second layout.Widget) layout.D
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
low := -1 + float32(bar)/float32(coord)*2
|
||||||
|
const snapMargin = 0.1
|
||||||
|
|
||||||
|
if s.Ratio < low {
|
||||||
|
s.Ratio = low
|
||||||
|
}
|
||||||
|
|
||||||
|
if s.Ratio > 1 {
|
||||||
|
s.Ratio = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if s.Ratio < low+snapMargin {
|
||||||
|
firstSize = 0
|
||||||
|
secondOffset = bar
|
||||||
|
secondSize = coord - bar
|
||||||
|
} else if s.Ratio > 1-snapMargin {
|
||||||
|
firstSize = coord - bar
|
||||||
|
secondOffset = coord
|
||||||
|
secondSize = 0
|
||||||
|
}
|
||||||
|
|
||||||
// register for input
|
// register for input
|
||||||
var barRect image.Rectangle
|
var barRect image.Rectangle
|
||||||
if s.Axis == layout.Horizontal {
|
if s.Axis == layout.Horizontal {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user