Example #1
0
func (s *ScrollBar) MouseDown(ev gxui.MouseEvent) {
	if s.barRect.Contains(ev.Point) {
		initialOffset := ev.Point.Sub(s.barRect.Min)
		var mms, mus gxui.EventSubscription
		mms = ev.Window.OnMouseMove(func(we gxui.MouseEvent) {
			p := gxui.WindowToChild(we.WindowPoint, s.outer)
			s.SetScrollPosition(s.rangeAt(p.Sub(initialOffset)))
		})
		mus = ev.Window.OnMouseUp(func(we gxui.MouseEvent) {
			mms.Unlisten()
			mus.Unlisten()
		})
	}
	s.InputEventHandler.MouseDown(ev)
}
Example #2
0
func (l *SplitterLayout) SplitterDragged(splitter gxui.Control, wndPnt math.Point) {
	o := l.orientation
	p := gxui.WindowToChild(wndPnt, l.outer)
	children := l.Container.Children()
	splitterIndex := children.IndexOf(splitter)
	childA, childB := children[splitterIndex-1], children[splitterIndex+1]
	boundsA, boundsB := childA.Bounds(), childB.Bounds()

	min, max := o.Major(boundsA.Min.XY()), o.Major(boundsB.Max.XY())
	frac := math.RampSat(float32(o.Major(p.XY())), float32(min), float32(max))

	netWeight := l.weights[childA.Control] + l.weights[childB.Control]
	l.weights[childA.Control] = netWeight * frac
	l.weights[childB.Control] = netWeight * (1.0 - frac)
	l.LayoutChildren()
}