func (a *customAdapter) Create(theme gxui.Theme, index int) gxui.Control { phase := float32(index) / 1000 c := gxui.Color{ R: 0.5 + 0.5*math.Sinf(math.TwoPi*(phase+0.000)), G: 0.5 + 0.5*math.Sinf(math.TwoPi*(phase+0.333)), B: 0.5 + 0.5*math.Sinf(math.TwoPi*(phase+0.666)), A: 1.0, } i := theme.CreateImage() i.SetBackgroundBrush(gxui.CreateBrush(c)) i.SetMargin(math.Spacing{L: 3, T: 3, R: 3, B: 3}) i.OnMouseEnter(func(ev gxui.MouseEvent) { i.SetBorderPen(gxui.CreatePen(2, gxui.Gray80)) }) i.OnMouseExit(func(ev gxui.MouseEvent) { i.SetBorderPen(gxui.TransparentPen) }) i.OnMouseDown(func(ev gxui.MouseEvent) { i.SetBackgroundBrush(gxui.CreateBrush(c.MulRGB(0.7))) }) i.OnMouseUp(func(ev gxui.MouseEvent) { i.SetBackgroundBrush(gxui.CreateBrush(c)) }) return i }
// parts.DrawPaint overrides func (b *SplitterBar) Paint(c gxui.Canvas) { r := b.outer.Size().Rect() c.DrawRect(r, gxui.CreateBrush(b.backgroundColor)) if b.foregroundColor != b.backgroundColor { c.DrawRect(r.ContractI(1), gxui.CreateBrush(b.foregroundColor)) } }
func drawMoon(canvas gxui.Canvas, center math.Point, radius float32) { c := 40 p := make(gxui.Polygon, c*2) for i := 0; i < c; i++ { frac := float32(i) / float32(c) α := math.Lerpf(math.Pi*1.2, math.Pi*-0.2, frac) p[i] = gxui.PolygonVertex{ Position: math.Point{ X: center.X + int(radius*math.Sinf(α)), Y: center.Y + int(radius*math.Cosf(α)), }, RoundedRadius: 0, } } for i := 0; i < c; i++ { frac := float32(i) / float32(c) α := math.Lerpf(math.Pi*-0.2, math.Pi*1.2, frac) r := math.Lerpf(radius, radius*0.5, math.Sinf(frac*math.Pi)) p[i+c] = gxui.PolygonVertex{ Position: math.Point{ X: center.X + int(r*math.Sinf(α)), Y: center.Y + int(r*math.Cosf(α)), }, RoundedRadius: 0, } } canvas.DrawPolygon(p, gxui.CreatePen(3, gxui.Gray80), gxui.CreateBrush(gxui.Gray40)) }
func (b *ProgressBar) SetSize(size math.Size) { b.ProgressBar.SetSize(size) b.chevrons = nil if size.Area() > 0 { b.chevrons = b.theme.Driver().CreateCanvas(size) b.chevronWidth = size.H / 2 cw := b.chevronWidth for x := -cw * 2; x < size.W; x += cw * 2 { // x0 x2 // | x1 | x3 // | | // A-----B - y0 // \ \ // \ \ // F C - y1 // / / // / / // E-----D - y2 y0, y1, y2 := 0, size.H/2, size.H x0, x1 := x, x+cw/2 x2, x3 := x0+cw, x1+cw var chevron = gxui.Polygon{ /* A */ gxui.PolygonVertex{Position: math.Point{X: x0, Y: y0}}, /* B */ gxui.PolygonVertex{Position: math.Point{X: x2, Y: y0}}, /* C */ gxui.PolygonVertex{Position: math.Point{X: x3, Y: y1}}, /* D */ gxui.PolygonVertex{Position: math.Point{X: x2, Y: y2}}, /* E */ gxui.PolygonVertex{Position: math.Point{X: x0, Y: y2}}, /* F */ gxui.PolygonVertex{Position: math.Point{X: x1, Y: y1}}, } b.chevrons.DrawPolygon(chevron, gxui.TransparentPen, gxui.CreateBrush(gxui.Gray30)) } b.chevrons.Complete() } }
func CreateProgressBar(theme *Theme) gxui.ProgressBar { b := &ProgressBar{} b.Init(b, theme) b.theme = theme b.chevronWidth = 10 b.OnAttach(func() { driver := theme.Driver() b.ticker = time.NewTicker(time.Millisecond * 50) go func() { for _ = range b.ticker.C { if !driver.Call(b.animationTick) { return } } }() }) b.OnDetach(func() { if b.chevrons != nil { b.chevrons = nil b.ticker.Stop() b.ticker = nil } }) b.SetBackgroundBrush(gxui.CreateBrush(gxui.Gray10)) b.SetBorderPen(gxui.CreatePen(1, gxui.Gray40)) return b }
func CreateStyle(fontColor, brushColor, penColor gxui.Color, penWidth float32) Style { return Style{ FontColor: fontColor, Pen: gxui.CreatePen(penWidth, penColor), Brush: gxui.CreateBrush(brushColor), } }
func (b *ProgressBar) PaintProgress(c gxui.Canvas, r math.Rect, frac float32) { r.Max.X = math.Lerp(r.Min.X, r.Max.X, frac) c.DrawRect(r, gxui.CreateBrush(gxui.Gray50)) c.Push() c.AddClip(r) c.DrawCanvas(b.chevrons, math.Point{X: b.scroll}) c.Pop() }
func (treeControlCreator) Create(theme gxui.Theme, control gxui.Control, node *mixins.TreeToListNode) gxui.Control { img := theme.CreateImage() imgSize := math.Size{W: 10, H: 10} ll := theme.CreateLinearLayout() ll.SetDirection(gxui.LeftToRight) btn := theme.CreateButton() btn.SetBackgroundBrush(gxui.TransparentBrush) btn.SetBorderPen(gxui.CreatePen(1, gxui.Gray30)) btn.SetMargin(math.Spacing{L: 1, R: 1, T: 1, B: 1}) btn.OnClick(func(ev gxui.MouseEvent) { if ev.Button == gxui.MouseButtonLeft { node.ToggleExpanded() } }) btn.AddChild(img) update := func() { expanded := node.IsExpanded() canvas := theme.Driver().CreateCanvas(imgSize) btn.SetVisible(!node.IsLeaf()) switch { case !btn.IsMouseDown(gxui.MouseButtonLeft) && expanded: canvas.DrawPolygon(expandedPoly, gxui.TransparentPen, gxui.CreateBrush(gxui.Gray70)) case !btn.IsMouseDown(gxui.MouseButtonLeft) && !expanded: canvas.DrawPolygon(collapsedPoly, gxui.TransparentPen, gxui.CreateBrush(gxui.Gray70)) case expanded: canvas.DrawPolygon(expandedPoly, gxui.TransparentPen, gxui.CreateBrush(gxui.Gray30)) case !expanded: canvas.DrawPolygon(collapsedPoly, gxui.TransparentPen, gxui.CreateBrush(gxui.Gray30)) } canvas.Complete() img.SetCanvas(canvas) } btn.OnMouseDown(func(gxui.MouseEvent) { update() }) btn.OnMouseUp(func(gxui.MouseEvent) { update() }) update() gxui.WhileAttached(btn, node.OnChange, update) ll.AddChild(btn) ll.AddChild(control) ll.SetPadding(math.Spacing{L: 16 * node.Depth()}) return ll }
func appMain(driver gxui.Driver) { theme := flags.CreateTheme(driver) label1 := theme.CreateLabel() label1.SetColor(gxui.White) label1.SetText("1x1") cell1x1 := theme.CreateLinearLayout() cell1x1.SetBackgroundBrush(gxui.CreateBrush(gxui.Blue40)) cell1x1.SetHorizontalAlignment(gxui.AlignCenter) cell1x1.AddChild(label1) label2 := theme.CreateLabel() label2.SetColor(gxui.White) label2.SetText("2x1") cell2x1 := theme.CreateLinearLayout() cell2x1.SetBackgroundBrush(gxui.CreateBrush(gxui.Green40)) cell2x1.SetHorizontalAlignment(gxui.AlignCenter) cell2x1.AddChild(label2) label3 := theme.CreateLabel() label3.SetColor(gxui.White) label3.SetText("1x2") cell1x2 := theme.CreateLinearLayout() cell1x2.SetBackgroundBrush(gxui.CreateBrush(gxui.Red40)) cell1x2.SetHorizontalAlignment(gxui.AlignCenter) cell1x2.AddChild(label3) table := theme.CreateTableLayout() table.SetGrid(3, 2) // columns, rows // row, column, horizontal span, vertical span table.SetChildAt(0, 0, 1, 1, cell1x1) table.SetChildAt(0, 1, 2, 1, cell2x1) table.SetChildAt(2, 0, 1, 2, cell1x2) window := theme.CreateWindow(800, 600, "Table") window.AddChild(table) window.OnClose(driver.Terminate) }
func drawStar(canvas gxui.Canvas, center math.Point, radius, rotation float32, points int) { p := make(gxui.Polygon, points*2) for i := 0; i < points*2; i++ { frac := float32(i) / float32(points*2) α := frac*math.TwoPi + rotation r := []float32{radius, radius / 2}[i&1] p[i] = gxui.PolygonVertex{ Position: math.Point{ X: center.X + int(r*math.Cosf(α)), Y: center.Y + int(r*math.Sinf(α)), }, RoundedRadius: []float32{0, 50}[i&1], } } canvas.DrawPolygon(p, gxui.CreatePen(3, gxui.Red), gxui.CreateBrush(gxui.Yellow)) }
func appMain(driver gxui.Driver) { theme := flags.CreateTheme(driver) font, err := driver.CreateFont(gxfont.Default, 75) if err != nil { panic(err) } window := theme.CreateWindow(380, 100, "Hi") window.SetBackgroundBrush(gxui.CreateBrush(gxui.Gray50)) label := theme.CreateLabel() label.SetFont(font) label.SetText("Hello world") window.AddChild(label) ticker := time.NewTicker(time.Millisecond * 30) go func() { phase := float32(0) for _ = range ticker.C { c := gxui.Color{ R: 0.75 + 0.25*math.Cosf((phase+0.000)*math.TwoPi), G: 0.75 + 0.25*math.Cosf((phase+0.333)*math.TwoPi), B: 0.75 + 0.25*math.Cosf((phase+0.666)*math.TwoPi), A: 0.50 + 0.50*math.Cosf(phase*10), } phase += 0.01 driver.Call(func() { label.SetColor(c) }) } }() window.OnClose(ticker.Stop) window.OnClose(driver.Terminate) }
func (b *ProgressBar) PaintProgress(c gxui.Canvas, r math.Rect, frac float32) { r.Max.X = math.Lerp(r.Min.X, r.Max.X, frac) c.DrawRect(r, gxui.CreateBrush(gxui.Gray50)) }
func (t *Tree) PaintMouseOverBackground(c gxui.Canvas, r math.Rect) { c.DrawRoundedRect(r, 2.0, 2.0, 2.0, 2.0, gxui.TransparentPen, gxui.CreateBrush(gxui.Gray15)) }
func CreateWindow(theme *Theme, width, height int, title string) gxui.Window { w := &Window{} w.Window.Init(w, theme.Driver(), width, height, title) w.SetBackgroundBrush(gxui.CreateBrush(theme.WindowBackground)) return w }
func (l *completionLabel) Paint(c gxui.Canvas) { l.Label.Paint(c) r := l.Size().Rect() c.DrawRoundedRect(r, 3, 3, 3, 3, gxui.TransparentPen, gxui.CreateBrush(completionBG)) }