예제 #1
0
func (l *SplitterLayout) LayoutChildren() {
	s := l.outer.Size().Contract(l.Padding())
	o := l.Padding().LT()

	children := l.outer.Children()

	splitterCount := len(children) / 2

	splitterWidth := l.splitterWidth
	if l.orientation.Horizontal() {
		s.W -= splitterWidth * splitterCount
	} else {
		s.H -= splitterWidth * splitterCount
	}

	netWeight := float32(0.0)
	for i, c := range children {
		if isSplitter := (i & 1) == 1; !isSplitter {
			netWeight += l.weights[c.Control]
		}
	}

	d := 0
	for i, c := range children {
		var cr math.Rect
		if isSplitter := (i & 1) == 1; !isSplitter {
			cm := c.Control.Margin()
			frac := l.weights[c.Control] / netWeight
			if l.orientation.Horizontal() {
				cw := int(float32(s.W) * frac)
				cr = math.CreateRect(d+cm.L, cm.T, d+cw-cm.R, s.H-cm.B)
				d += cw
			} else {
				ch := int(float32(s.H) * frac)
				cr = math.CreateRect(cm.L, d+cm.T, s.W-cm.R, d+ch-cm.B)
				d += ch
			}
		} else {
			if l.orientation.Horizontal() {
				cr = math.CreateRect(d, 0, d+splitterWidth, s.H)
			} else {
				cr = math.CreateRect(0, d, s.W, d+splitterWidth)
			}
			d += splitterWidth
		}
		c.Layout(cr.Offset(o).Canon())
	}
}
예제 #2
0
파일: table_layout.go 프로젝트: nelsam/gxui
func (l *TableLayout) LayoutChildren() {
	s := l.outer.Size().Contract(l.outer.Padding())
	o := l.outer.Padding().LT()

	cw, ch := s.W/l.columns, s.H/l.rows

	var cr math.Rect

	for _, c := range l.outer.Children() {
		cm := c.Control.Margin()
		cell := l.grid[c.Control]

		x, y := cell.x*cw, cell.y*ch
		w, h := x+cell.w*cw, y+cell.h*ch

		cr = math.CreateRect(x+cm.L, y+cm.T, w-cm.R, h-cm.B)

		c.Layout(cr.Offset(o).Canon())
	}
}
예제 #3
0
파일: font.go 프로젝트: nelsam/gxui
func (f *font) align(rect math.Rect, size math.Size, ascent int, h gxui.HorizontalAlignment, v gxui.VerticalAlignment) math.Point {
	var origin math.Point
	switch h {
	case gxui.AlignLeft:
		origin.X = rect.Min.X
	case gxui.AlignCenter:
		origin.X = rect.Mid().X - (size.W / 2)
	case gxui.AlignRight:
		origin.X = rect.Max.X - size.W
	}
	switch v {
	case gxui.AlignTop:
		origin.Y = rect.Min.Y + ascent
	case gxui.AlignMiddle:
		origin.Y = rect.Mid().Y - (size.H / 2) + ascent
	case gxui.AlignBottom:
		origin.Y = rect.Max.Y - size.H + ascent
	}
	return origin
}
예제 #4
0
파일: canvas.go 프로젝트: nelsam/gxui
func (c *canvas) DrawRoundedRect(r math.Rect, tl, tr, bl, br float32, pen gxui.Pen, brush gxui.Brush) {
	if tl == 0 && tr == 0 && bl == 0 && br == 0 && pen.Color.A == 0 {
		c.DrawRect(r, brush)
		return
	}
	p := gxui.Polygon{
		gxui.PolygonVertex{Position: r.TL(), RoundedRadius: tl},
		gxui.PolygonVertex{Position: r.TR(), RoundedRadius: tr},
		gxui.PolygonVertex{Position: r.BR(), RoundedRadius: br},
		gxui.PolygonVertex{Position: r.BL(), RoundedRadius: bl},
	}
	c.DrawPolygon(p, pen, brush)
}
예제 #5
0
파일: container.go 프로젝트: nelsam/gxui
// Layout sets the Child size and offset relative to the parent.
// Layout should only be called by the Child's parent.
func (c *Child) Layout(rect math.Rect) {
	c.Offset = rect.Min
	c.Control.SetSize(rect.Size())
}