Esempio n. 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())
	}
}
Esempio n. 2
0
func (b *blitter) blitGlyph(ctx *context, tc *textureContext, c gxui.Color, srcRect, dstRect math.Rect, ds *drawState) {
	dstRect = dstRect.Offset(ds.OriginPixels)

	if b.glyphBatch.GlyphPage != tc {
		b.commitGlyphs(ctx)
		b.glyphBatch.GlyphPage = tc
	}
	i := uint16(len(b.glyphBatch.DstRects)) / 2
	clip := []float32{
		float32(ds.ClipPixels.Min.X),
		float32(ds.ClipPixels.Min.Y),
		float32(ds.ClipPixels.Max.X),
		float32(ds.ClipPixels.Max.Y),
	}
	b.glyphBatch.DstRects = append(b.glyphBatch.DstRects,
		float32(dstRect.Min.X), float32(dstRect.Min.Y),
		float32(dstRect.Max.X), float32(dstRect.Min.Y),
		float32(dstRect.Min.X), float32(dstRect.Max.Y),
		float32(dstRect.Max.X), float32(dstRect.Max.Y),
	)
	b.glyphBatch.SrcRects = append(b.glyphBatch.SrcRects,
		float32(srcRect.Min.X), float32(srcRect.Min.Y),
		float32(srcRect.Max.X), float32(srcRect.Min.Y),
		float32(srcRect.Min.X), float32(srcRect.Max.Y),
		float32(srcRect.Max.X), float32(srcRect.Max.Y),
	)
	b.glyphBatch.ClipRects = append(b.glyphBatch.ClipRects,
		clip[0], clip[1], clip[2], clip[3],
		clip[0], clip[1], clip[2], clip[3],
		clip[0], clip[1], clip[2], clip[3],
		clip[0], clip[1], clip[2], clip[3],
	)

	c = c.MulRGB(c.A) // PMA
	b.glyphBatch.Colors = append(b.glyphBatch.Colors,
		c.R, c.G, c.B, c.A,
		c.R, c.G, c.B, c.A,
		c.R, c.G, c.B, c.A,
		c.R, c.G, c.B, c.A,
	)
	b.glyphBatch.Indices = append(b.glyphBatch.Indices,
		i, i+1, i+2,
		i+2, i+1, i+3,
	)
}
Esempio n. 3
0
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
}
Esempio n. 4
0
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)
}
Esempio n. 5
0
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())
	}
}
Esempio n. 6
0
func (b *blitter) blitRect(ctx *context, dstRect math.Rect, color gxui.Color, ds *drawState) {
	b.commitGlyphs(ctx)
	dstRect = dstRect.Offset(ds.OriginPixels)
	dw, dh := ctx.sizePixels.WH()
	mPos := math.CreateMat3(
		+2.0*float32(dstRect.W())/float32(dw), 0, 0,
		0, -2.0*float32(dstRect.H())/float32(dh), 0,
		-1.0+2.0*float32(dstRect.Min.X)/float32(dw),
		+1.0-2.0*float32(dstRect.Min.Y)/float32(dh), 1,
	)

	b.quad.draw(ctx, b.colorShader, uniformBindings{
		"mPos":  mPos,
		"Color": color,
	})
	b.stats.drawCallCount++
}
Esempio n. 7
0
// 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())
}
Esempio n. 8
0
func (b *blitter) blit(ctx *context, tc *textureContext, srcRect, dstRect math.Rect, ds *drawState) {
	b.commitGlyphs(ctx)

	dstRect = dstRect.Offset(ds.OriginPixels)
	sw, sh := tc.sizePixels.WH()
	dw, dh := ctx.sizePixels.WH()

	var mUV math.Mat3
	if tc.flipY {
		mUV = math.CreateMat3(
			float32(srcRect.W())/float32(sw), 0, 0,
			0, -float32(srcRect.H())/float32(sh), 0,
			float32(srcRect.Min.X)/float32(sw),
			1.0-float32(srcRect.Min.Y)/float32(sh), 1,
		)
	} else {
		mUV = math.CreateMat3(
			float32(srcRect.W())/float32(sw), 0, 0,
			0, float32(srcRect.H())/float32(sh), 0,
			float32(srcRect.Min.X)/float32(sw),
			float32(srcRect.Min.Y)/float32(sh), 1,
		)
	}
	mPos := math.CreateMat3(
		+2.0*float32(dstRect.W())/float32(dw), 0, 0,
		0, -2.0*float32(dstRect.H())/float32(dh), 0,
		-1.0+2.0*float32(dstRect.Min.X)/float32(dw),
		+1.0-2.0*float32(dstRect.Min.Y)/float32(dh), 1,
	)
	if !tc.pma {
		gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	}
	b.quad.draw(ctx, b.copyShader, uniformBindings{
		"source": tc,
		"mUV":    mUV,
		"mPos":   mPos,
	})
	if !tc.pma {
		gl.BlendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA)
	}
	b.stats.drawCallCount++
}