예제 #1
0
파일: panel_holder.go 프로젝트: liulnn/gxui
func insertIndex(holder gxui.PanelHolder, at math.Point) int {
	count := holder.PanelCount()
	bestIndex := count
	bestScore := float32(1e20)
	score := func(point math.Point, index int) {
		score := point.Sub(at).Len()
		if score < bestScore {
			bestIndex = index
			bestScore = score
		}
	}
	for i := 0; i < holder.PanelCount(); i++ {
		tab := holder.Tab(i)
		size := tab.Size()
		ml := math.Point{Y: size.H / 2}
		mr := math.Point{Y: size.H / 2, X: size.W}
		score(gxui.TransformCoordinate(ml, tab, holder), i)
		score(gxui.TransformCoordinate(mr, tab, holder), i+1)
	}
	return bestIndex
}
예제 #2
0
파일: panel_holder.go 프로젝트: liulnn/gxui
func beginTabDragging(holder gxui.PanelHolder, panel gxui.Control, name string, window gxui.Window) {
	var mms, mos gxui.EventSubscription
	mms = window.OnMouseMove(func(ev gxui.MouseEvent) {
		for _, c := range gxui.TopControlsUnder(ev.WindowPoint, ev.Window) {
			if over, ok := c.C.(gxui.PanelHolder); ok {
				insertAt := insertIndex(over, c.P)
				if over == holder {
					if insertAt > over.PanelIndex(panel) {
						insertAt--
					}
				}
				holder.RemovePanel(panel)
				holder = over
				holder.AddPanelAt(panel, name, insertAt)
				holder.Select(insertAt)
			}
		}
	})
	mos = window.OnMouseUp(func(gxui.MouseEvent) {
		mms.Unlisten()
		mos.Unlisten()
	})
}