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()) } }
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++ }
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, ) }
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++ }
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()) } }