diff --git a/.golangci.yml b/.golangci.yml index bd44ca3e..063d17c3 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -21,7 +21,7 @@ linters: - gocyclo - err113 - gofmt - #- gofumpt + - gofumpt - goheader - goimports #- gomnd @@ -39,14 +39,18 @@ linters: - prealloc - predeclared - promlinter + - reassign #- revive - rowserrcheck - staticcheck - stylecheck + - tagliatelle + - testifylint - typecheck - unconvert - unparam - unused + - usestdlibvars - wastedassign - whitespace - wrapcheck @@ -81,6 +85,7 @@ run: timeout: 5m issues: + exclude-dirs-use-default: false skip-dirs: - .github - build diff --git a/CSS.go b/CSS.go index f53aa434..68d5e9d0 100644 --- a/CSS.go +++ b/CSS.go @@ -99,7 +99,6 @@ func ParseCSSStyleSheet(data []byte) error { err = panicToErr(func() { styleColorID = StyleColorIDFromString(styleVarName) }) - if err != nil { return ErrCSSParse{What: "style variable ID", Value: styleVarName} } diff --git a/Context.go b/Context.go index ae021c11..13bbdfe0 100644 --- a/Context.go +++ b/Context.go @@ -66,6 +66,7 @@ type context struct { m *sync.Mutex } +// CreateContext creates a new giu context. func CreateContext(b backend.Backend[glfwbackend.GLFWWindowFlags]) *context { result := context{ cssStylesheet: make(cssStylesheet), @@ -91,10 +92,13 @@ func CreateContext(b backend.Backend[glfwbackend.GLFWWindowFlags]) *context { return &result } +// IO returns the imgui.IO object. func (c *context) IO() *imgui.IO { return imgui.CurrentIO() } +// invalidAllState should be called before rendering. +// it ensures all states are marked as invalid for that moment. func (c *context) invalidAllState() { c.state.Range(func(k, v any) bool { if s, ok := v.(*state); ok { @@ -107,6 +111,8 @@ func (c *context) invalidAllState() { }) } +// cleanState removes all states that were not marked as valid during rendering. +// should be called after rendering. func (c *context) cleanState() { c.state.Range(func(k, v any) bool { if s, ok := v.(*state); ok { @@ -127,18 +133,22 @@ func (c *context) cleanState() { c.widgetIndex = make(map[string]int) } +// Backend returns the imgui.backend used by the context. func (c *context) Backend() backend.Backend[glfwbackend.GLFWWindowFlags] { return c.backend } +// SetState is a generic version of Context.SetState. func SetState[T any, PT genericDisposable[T]](c *context, id ID, data PT) { c.state.Store(id, &state{valid: true, data: data}) } +// SetState stores data in context by id. func (c *context) SetState(id ID, data Disposable) { c.state.Store(id, &state{valid: true, data: data}) } +// GetState is a generic version of Context.GetState. func GetState[T any, PT genericDisposable[T]](c *context, id ID) PT { if s, ok := c.load(id); ok { c.m.Lock() @@ -154,6 +164,7 @@ func GetState[T any, PT genericDisposable[T]](c *context, id ID) PT { return nil } +// GetState returns previously stored state by id. func (c *context) GetState(id ID) any { if s, ok := c.load(id); ok { c.m.Lock() diff --git a/ImageWidgets.go b/ImageWidgets.go index 3e667994..4d6bd67c 100644 --- a/ImageWidgets.go +++ b/ImageWidgets.go @@ -350,7 +350,7 @@ func (i *ImageWithURLWidget) Build() { // Load image from url client := &http.Client{Timeout: i.downloadTimeout} - req, err := http.NewRequestWithContext(downloadContext, "GET", i.imgURL, http.NoBody) + req, err := http.NewRequestWithContext(downloadContext, http.MethodGet, i.imgURL, http.NoBody) if err != nil { errorFn(err) return diff --git a/MasterWindow.go b/MasterWindow.go index f0fa0eda..346e9757 100644 --- a/MasterWindow.go +++ b/MasterWindow.go @@ -394,7 +394,7 @@ func (w *MasterWindow) SetShouldClose(v bool) { func (w *MasterWindow) SetInputHandler(handler InputHandler) { Context.InputHandler = handler - w.backend.SetKeyCallback(func(key, scanCode, action, modifier int) { + w.backend.SetKeyCallback(func(key, _, action, modifier int) { k, m, a := keyFromGLFWKey(glfwbackend.GLFWKey(key)), Modifier(modifier), Action(action) handler.Handle(k, m, a) diff --git a/TableWidgets.go b/TableWidgets.go index 09a991a8..dfd4b44f 100644 --- a/TableWidgets.go +++ b/TableWidgets.go @@ -6,6 +6,7 @@ import ( "github.com/AllenDang/cimgui-go/imgui" ) +// TableRowWidget represents a row in a table. type TableRowWidget struct { flags TableRowFlags minRowHeight float64 @@ -13,6 +14,9 @@ type TableRowWidget struct { bgColor color.Color } +// TableRow creates a TbleRowWidget. +// Each widget will be rendered in a separated column. +// NOTE: if you want to put multiple widgets in one cell, enclose them in Layout{}. func TableRow(widgets ...Widget) *TableRowWidget { return &TableRowWidget{ flags: 0, @@ -22,16 +26,19 @@ func TableRow(widgets ...Widget) *TableRowWidget { } } +// BgColor sets the background color of the row. func (r *TableRowWidget) BgColor(c color.Color) *TableRowWidget { r.bgColor = c return r } +// Flags sets the flags of the row. func (r *TableRowWidget) Flags(flags TableRowFlags) *TableRowWidget { r.flags = flags return r } +// MinHeight sets the minimum height of the row. func (r *TableRowWidget) MinHeight(height float64) *TableRowWidget { r.minRowHeight = height return r @@ -58,6 +65,7 @@ func (r *TableRowWidget) BuildTableRow() { } } +// TableColumnWidget allows to configure table columns headers. type TableColumnWidget struct { label string flags TableColumnFlags @@ -65,6 +73,7 @@ type TableColumnWidget struct { userID uint32 } +// TableColumn creates a new TableColumnWidget. func TableColumn(label string) *TableColumnWidget { return &TableColumnWidget{ label: Context.FontAtlas.RegisterString(label), @@ -74,16 +83,19 @@ func TableColumn(label string) *TableColumnWidget { } } +// Flags sets the flags of the column. func (c *TableColumnWidget) Flags(flags TableColumnFlags) *TableColumnWidget { c.flags = flags return c } +// InnerWidthOrWeight sets the inner width or weight of the column. func (c *TableColumnWidget) InnerWidthOrWeight(w float32) *TableColumnWidget { c.innerWidthOrWeight = w return c } +// UserID sets the user id of the column. func (c *TableColumnWidget) UserID(id uint32) *TableColumnWidget { c.userID = id return c @@ -96,6 +108,10 @@ func (c *TableColumnWidget) BuildTableColumn() { var _ Widget = &TableWidget{} +// TableWidget is a table widget. +// - Call Table to create new +// - Then use Rows method to add content +// - Use Columns method to configure columns (optional). type TableWidget struct { id ID flags TableFlags @@ -109,6 +125,7 @@ type TableWidget struct { noHeader bool } +// Table creates new TableWidget. func Table() *TableWidget { return &TableWidget{ id: GenAutoID("Table"), @@ -158,21 +175,25 @@ func (t *TableWidget) Columns(cols ...*TableColumnWidget) *TableWidget { return t } +// Rows sets the rows of the table. func (t *TableWidget) Rows(rows ...*TableRowWidget) *TableWidget { t.rows = rows return t } +// Size sets the size of the table. func (t *TableWidget) Size(width, height float32) *TableWidget { t.size = imgui.Vec2{X: width, Y: height} return t } +// InnerWidth sets the inner width of the table. func (t *TableWidget) InnerWidth(width float64) *TableWidget { t.innerWidth = width return t } +// Flags sets the flags of the table. func (t *TableWidget) Flags(flags TableFlags) *TableWidget { t.flags = flags return t diff --git a/Widgets.go b/Widgets.go index 15cde5f0..9c68fa60 100644 --- a/Widgets.go +++ b/Widgets.go @@ -56,6 +56,8 @@ func SameLine() { var _ Widget = &ChildWidget{} +// ChildWidget is a container widget. It will have a separated scroll bar. +// Use Child if you want to create a layout of e specific size. type ChildWidget struct { id ID width float32 @@ -65,36 +67,38 @@ type ChildWidget struct { layout Layout } -// Build implements Widget interface. -func (c *ChildWidget) Build() { - if imgui.BeginChildStrV(c.id.String(), imgui.Vec2{X: c.width, Y: c.height}, func() imgui.ChildFlags { - if c.border { - return imgui.ChildFlagsBorders - } - - return 0 - }(), imgui.WindowFlags(c.flags)) { - c.layout.Build() +// Child creates a new ChildWidget. +func Child() *ChildWidget { + return &ChildWidget{ + id: GenAutoID("Child"), + width: 0, + height: 0, + border: true, + flags: 0, + layout: nil, } - - imgui.EndChild() } +// Border sets whether child should have border +// You can use imgui.ChildFlagsBorders as well. func (c *ChildWidget) Border(border bool) *ChildWidget { c.border = border return c } +// Size sets child size. func (c *ChildWidget) Size(width, height float32) *ChildWidget { c.width, c.height = width, height return c } +// Flags allows to specify Child flags. func (c *ChildWidget) Flags(flags WindowFlags) *ChildWidget { c.flags = flags return c } +// Layout sets widgets that will be rendered inside of the Child. func (c *ChildWidget) Layout(widgets ...Widget) *ChildWidget { c.layout = Layout(widgets) return c @@ -106,15 +110,19 @@ func (c *ChildWidget) ID(id ID) *ChildWidget { return c } -func Child() *ChildWidget { - return &ChildWidget{ - id: GenAutoID("Child"), - width: 0, - height: 0, - border: true, - flags: 0, - layout: nil, +// Build makes a Child. +func (c *ChildWidget) Build() { + if imgui.BeginChildStrV(c.id.String(), imgui.Vec2{X: c.width, Y: c.height}, func() imgui.ChildFlags { + if c.border { + return imgui.ChildFlagsBorders + } + + return 0 + }(), imgui.WindowFlags(c.flags)) { + c.layout.Build() } + + imgui.EndChild() } var _ Widget = &ComboCustomWidget{} diff --git a/examples/CSS-styling/main.go b/examples/CSS-styling/main.go index eea4a9fa..cf1f77ba 100644 --- a/examples/CSS-styling/main.go +++ b/examples/CSS-styling/main.go @@ -22,8 +22,10 @@ func loop() { func main() { wnd := giu.NewMasterWindow("CSS Style [example]", 640, 480, 0) + if err := giu.ParseCSSStyleSheet(cssStyle); err != nil { panic(err) } + wnd.Run(loop) } diff --git a/examples/canvas/canvas.go b/examples/canvas/canvas.go index 5f50a7c1..b81c85d2 100644 --- a/examples/canvas/canvas.go +++ b/examples/canvas/canvas.go @@ -1,7 +1,6 @@ package main import ( - "fmt" "image" "image/color" @@ -11,7 +10,6 @@ import ( var texture *g.Texture func loop() { - fmt.Println(texture.ID()) g.SingleWindow().Layout( g.Label("Canvas demo"), g.Custom(func() { @@ -32,7 +30,8 @@ func loop() { p2 := pos.Add(image.Pt(120, 210)) p3 := pos.Add(image.Pt(210, 210)) p4 := pos.Add(image.Pt(210, 150)) - // canvas.AddTriangle(p1, p2, p3, col, 2) + + canvas.AddTriangle(p1, p2, p3, col, 2) canvas.AddQuad(p1, p2, p3, p4, col, 1) p1 = p1.Add(image.Pt(120, 60)) @@ -41,6 +40,7 @@ func loop() { p1 = pos.Add(image.Pt(10, 400)) p2 = pos.Add(image.Pt(50, 440)) p3 = pos.Add(image.Pt(200, 500)) + canvas.PathLineTo(p1) canvas.PathLineTo(p2) canvas.PathBezierCubicCurveTo(p2.Add(image.Pt(40, 0)), p3.Add(image.Pt(-50, 0)), p3, 0) diff --git a/examples/codeeditor/codeeditor.go b/examples/codeeditor/codeeditor.go index 6d642b76..7fe337c0 100644 --- a/examples/codeeditor/codeeditor.go +++ b/examples/codeeditor/codeeditor.go @@ -1,20 +1,20 @@ +//nolint:wsl,gocritic,staticcheck // this is disabled now. package main import ( "fmt" "github.com/AllenDang/giu" - g "github.com/AllenDang/giu" ) -var editor *g.CodeEditorWidget +var editor *giu.CodeEditorWidget // errMarkers imgui.ErrorMarkers func loop() { - g.SingleWindow().Layout( - g.Row( - g.Button("Get Text").OnClick(func() { + giu.SingleWindow().Layout( + giu.Row( + giu.Button("Get Text").OnClick(func() { if editor.HasSelection() { fmt.Println(editor.GetSelectedText()) } else { @@ -29,10 +29,10 @@ func loop() { fmt.Println("Current line is", editor.GetCurrentLineText()) }), - g.Button("Set Text").OnClick(func() { + giu.Button("Set Text").OnClick(func() { editor.Text("Set text") }), - g.Button("Set Error Marker").OnClick(func() { + giu.Button("Set Error Marker").OnClick(func() { panic("implement me!") // errMarkers.Clear() // errMarkers.Insert(1, "Error message") @@ -46,11 +46,11 @@ func loop() { } func main() { - wnd := g.NewMasterWindow("Code Editor", 800, 600, 0) + wnd := giu.NewMasterWindow("Code Editor", 800, 600, 0) // errMarkers = imgui.NewErrorMarkers() - editor = g.CodeEditor(). + editor = giu.CodeEditor(). ShowWhitespaces(false). TabSize(2). Text("select * from greeting\nwhere date > current_timestamp\norder by date"). diff --git a/examples/customwidget/customwidget.go b/examples/customwidget/customwidget.go index a4faad1d..abc6a32a 100644 --- a/examples/customwidget/customwidget.go +++ b/examples/customwidget/customwidget.go @@ -22,6 +22,7 @@ func CircleButton(id string, clicked func()) *CircleButtonWidget { func (c *CircleButtonWidget) Build() { width, height := g.CalcTextSize(c.id) + var padding float32 = 8.0 // You may want to use GetCursorPos here depending on you use case. @@ -45,6 +46,7 @@ func (c *CircleButtonWidget) Build() { if drawActive { canvas.AddCircleFilled(center, float32(radius), color.RGBA{12, 12, 200, 255}) } + canvas.AddCircle(center, float32(radius), color.RGBA{200, 12, 12, 255}, int32(radius), 2) // Draw text diff --git a/examples/discussion-648/main.go b/examples/discussion-648/main.go index b1ef4af1..7a043150 100644 --- a/examples/discussion-648/main.go +++ b/examples/discussion-648/main.go @@ -6,8 +6,10 @@ func loop() { giu.Window("wnd").Layout( giu.Custom(func() { const footerPercentage = 0.2 + _, availableH := giu.GetAvailableRegion() _, itemSpacingH := giu.GetItemSpacing() + giu.Layout{ giu.Child().Layout(giu.Label("your layout")).Size(-1, (availableH-itemSpacingH)*(1-footerPercentage)), giu.Child().Layout(giu.Label("footer")).Size(-1, (availableH-itemSpacingH)*footerPercentage), diff --git a/examples/dragdrop/dragdrop.go b/examples/dragdrop/dragdrop.go index c8922fac..ee042aa6 100644 --- a/examples/dragdrop/dragdrop.go +++ b/examples/dragdrop/dragdrop.go @@ -5,6 +5,7 @@ import ( "unsafe" "github.com/AllenDang/cimgui-go/imgui" + g "github.com/AllenDang/giu" ) @@ -15,6 +16,7 @@ func loop() { g.Row( g.Custom(func() { g.Button("Drag me: 9").Build() + if imgui.BeginDragDropSource() { data := int(9) imgui.SetDragDropPayload( @@ -28,6 +30,7 @@ func loop() { }), g.Custom(func() { g.Button("Drag me: 10").Build() + if imgui.BeginDragDropSource() { data := 10 imgui.SetDragDropPayload( @@ -45,8 +48,9 @@ func loop() { if imgui.BeginDragDropTarget() { payload := imgui.AcceptDragDropPayload("DND_DEMO") if payload != nil && payload.CData != nil { - dropTarget = fmt.Sprintf("Dropped value: %d", *(*int)(unsafe.Pointer(payload.Data()))) + dropTarget = fmt.Sprintf("Dropped value: %d", *(*int)(unsafe.Pointer(payload.Data()))) //nolint:govet // its cimgui-go design } + imgui.EndDragDropTarget() } }), diff --git a/examples/fps/main.go b/examples/fps/main.go index 23ad0be4..9b2a6bf3 100644 --- a/examples/fps/main.go +++ b/examples/fps/main.go @@ -19,8 +19,9 @@ func loop() { giu.SingleWindow().Layout( giu.Custom(func() { frames++ - timeDelta = time.Now().Sub(currentTime) + timeDelta = time.Since(currentTime) currentTime = time.Now() + fpsTime = fpsTime.Add(timeDelta) if fpsTime.Second() >= 1 { currentFPS = frames diff --git a/examples/gifdecode/gifdecode.go b/examples/gifdecode/gifdecode.go index 6b2f1c4d..f1bf0f2c 100644 --- a/examples/gifdecode/gifdecode.go +++ b/examples/gifdecode/gifdecode.go @@ -13,8 +13,6 @@ import ( //go:embed golang.gif var gifFileData []byte -const gifFilepath = "./golang.gif" - var ( frames []*giu.Texture gifImg *gif.GIF @@ -25,8 +23,6 @@ func loop() { // load textures if frames[0] == nil { for i, frame := range gifImg.Image { - // lol, this is the most magic thing in go i've ever seen :D - i := i giu.NewTextureFromRgba(giu.ImageToRgba(frame), func(t *giu.Texture) { frames[i] = t }) @@ -53,7 +49,9 @@ func main() { go func() { for { time.Sleep(time.Duration(gifImg.Delay[currentFrame]*10) * time.Millisecond) + giu.Update() + currentFrame++ if currentFrame == len(frames) { currentFrame = 0 diff --git a/examples/hugelist/hugelist.go b/examples/hugelist/hugelist.go index ef058c93..51c94737 100644 --- a/examples/hugelist/hugelist.go +++ b/examples/hugelist/hugelist.go @@ -7,9 +7,7 @@ import ( g "github.com/AllenDang/giu" ) -var ( - names []string -) +var names []string func buildRows() []*g.TableRowWidget { rows := make([]*g.TableRowWidget, len(names)) diff --git a/examples/imguidemo/imguidemo.go b/examples/imguidemo/imguidemo.go index dbdf72bb..2ccad205 100644 --- a/examples/imguidemo/imguidemo.go +++ b/examples/imguidemo/imguidemo.go @@ -2,6 +2,7 @@ package main import ( "github.com/AllenDang/cimgui-go/imgui" + g "github.com/AllenDang/giu" ) diff --git a/examples/issue-501/main.go b/examples/issue-501/main.go index a9ff8412..0f09812b 100644 --- a/examples/issue-501/main.go +++ b/examples/issue-501/main.go @@ -14,6 +14,7 @@ func loop() { giu.Custom(func() { if shouldFocus { shouldFocus = false + giu.SetKeyboardFocusHere() } }), diff --git a/examples/keyboardShortcuts/keyboardShortcuts.go b/examples/keyboardShortcuts/keyboardShortcuts.go index ec821a4b..464cacd5 100644 --- a/examples/keyboardShortcuts/keyboardShortcuts.go +++ b/examples/keyboardShortcuts/keyboardShortcuts.go @@ -29,7 +29,8 @@ func main() { giu.WindowShortcut{ Key: giu.KeyC, Modifier: giu.ModControl, - Callback: func() { checkbox1 = !checkbox1 }}, + Callback: func() { checkbox1 = !checkbox1 }, + }, ) wnd.Run(loop) diff --git a/examples/markdown/markdown.go b/examples/markdown/markdown.go index b0cf0b17..aae88401 100644 --- a/examples/markdown/markdown.go +++ b/examples/markdown/markdown.go @@ -72,6 +72,7 @@ func loop() { ), ) } + func main() { wnd := giu.NewMasterWindow("ImGui Markdown [Demo]", 640, 480, 0) wnd.Run(loop) diff --git a/examples/memoryeditor/memoryeditor.go b/examples/memoryeditor/memoryeditor.go index 3fc3795f..539bffa9 100644 --- a/examples/memoryeditor/memoryeditor.go +++ b/examples/memoryeditor/memoryeditor.go @@ -1,3 +1,4 @@ +//nolint:wsl,gocritic // this is disabled in cimgui-go package main // import ( diff --git a/examples/ondrop/ondrop.go b/examples/ondrop/ondrop.go index 30244c6c..383661ca 100644 --- a/examples/ondrop/ondrop.go +++ b/examples/ondrop/ondrop.go @@ -7,9 +7,7 @@ import ( g "github.com/AllenDang/giu" ) -var ( - dropInFiles string -) +var dropInFiles string func loop() { g.SingleWindow().Layout( @@ -25,6 +23,7 @@ func onDrop(names []string) { } dropInFiles = sb.String() + g.Update() } diff --git a/examples/plot/main.go b/examples/plot/main.go index 6c44dd0c..4cdc4ff1 100644 --- a/examples/plot/main.go +++ b/examples/plot/main.go @@ -60,6 +60,7 @@ func loop() { func main() { delta := 0.1 + for x := 0.0; x < 10; x += delta { linedata = append(linedata, math.Sin(x)) linedata2 = append(linedata2, math.Cos(x)) @@ -71,6 +72,7 @@ func main() { } delta = 1 + for x := 0.0; x < 10; x += delta { bardata = append(bardata, math.Sin(x)) bardata2 = append(bardata2, math.Sin(x)-0.2) diff --git a/examples/pushfont/main.go b/examples/pushfont/main.go index b7ecd85a..3354ad59 100644 --- a/examples/pushfont/main.go +++ b/examples/pushfont/main.go @@ -10,6 +10,7 @@ var font *giu.FontInfo func loop() { fontPushed := false + giu.Window("example").Layout( giu.Custom(func() { fontPushed = giu.PushFont(font) diff --git a/examples/rangebuilder/rangebuilder.go b/examples/rangebuilder/rangebuilder.go index 978bff61..be0e52b0 100644 --- a/examples/rangebuilder/rangebuilder.go +++ b/examples/rangebuilder/rangebuilder.go @@ -21,8 +21,7 @@ func loop() { ), g.Dummy(0, 8), g.Label("Below buttons are generated by RangeBuilder"), - g.RangeBuilder("Buttons", []interface{}{"Button1", "Button2", "Button3"}, func(i int, v interface{}) g.Widget { - str := v.(string) + g.RangeBuilder("Buttons", []string{"Button1", "Button2", "Button3"}, func(i int, str string) g.Widget { return g.Button(str).OnClick(func() { fmt.Println(str, "is clicked") }) diff --git a/examples/texturefiltering/texturefiltering.go b/examples/texturefiltering/texturefiltering.go index 72e19e29..2236f4bd 100644 --- a/examples/texturefiltering/texturefiltering.go +++ b/examples/texturefiltering/texturefiltering.go @@ -1,3 +1,4 @@ +//nolint:gocritic,wsl // this is disabled now package main // import ( diff --git a/examples/transparent/transparent.go b/examples/transparent/transparent.go index 7cf6a176..59f9fc89 100644 --- a/examples/transparent/transparent.go +++ b/examples/transparent/transparent.go @@ -5,6 +5,7 @@ import ( "image/color" "github.com/AllenDang/cimgui-go/imgui" + g "github.com/AllenDang/giu" ) @@ -16,26 +17,28 @@ func loop() { g.Custom(func() { canvas := g.GetCanvas() pos := g.GetCursorScreenPos() - color := color.RGBA{200, 75, 75, 255} - canvas.AddLine(pos, pos.Add(image.Pt(100, 100)), color, 1) - canvas.AddRect(pos.Add(image.Pt(110, 0)), pos.Add(image.Pt(200, 100)), color, 5, g.DrawFlagsRoundCornersAll, 1) - canvas.AddRectFilled(pos.Add(image.Pt(220, 0)), pos.Add(image.Pt(320, 100)), color, 0, 0) + col := color.RGBA{200, 75, 75, 255} + + canvas.AddLine(pos, pos.Add(image.Pt(100, 100)), col, 1) + canvas.AddRect(pos.Add(image.Pt(110, 0)), pos.Add(image.Pt(200, 100)), col, 5, g.DrawFlagsRoundCornersAll, 1) + canvas.AddRectFilled(pos.Add(image.Pt(220, 0)), pos.Add(image.Pt(320, 100)), col, 0, 0) pos0 := pos.Add(image.Pt(0, 110)) cp0 := pos.Add(image.Pt(80, 110)) cp1 := pos.Add(image.Pt(50, 210)) pos1 := pos.Add(image.Pt(120, 210)) - canvas.AddBezierCubic(pos0, cp0, cp1, pos1, color, 1, 0) + canvas.AddBezierCubic(pos0, cp0, cp1, pos1, col, 1, 0) p1 := pos.Add(image.Pt(160, 110)) p2 := pos.Add(image.Pt(120, 210)) p3 := pos.Add(image.Pt(210, 210)) p4 := pos.Add(image.Pt(210, 150)) - // canvas.AddTriangle(p1, p2, p3, color, 2) - canvas.AddQuad(p1, p2, p3, p4, color, 1) + + canvas.AddTriangle(p1, p2, p3, col, 2) + canvas.AddQuad(p1, p2, p3, p4, col, 1) p1 = p1.Add(image.Pt(120, 60)) - canvas.AddCircleFilled(p1, 50, color) + canvas.AddCircleFilled(p1, 50, col) }), ) g.PopStyleColor() diff --git a/examples/update/update.go b/examples/update/update.go index 01a39f6c..00883de8 100644 --- a/examples/update/update.go +++ b/examples/update/update.go @@ -8,15 +8,14 @@ import ( "github.com/AllenDang/giu" ) -var ( - counter int -) +var counter int func refresh() { ticker := time.NewTicker(time.Second * 1) for { counter = rand.Intn(100) + giu.Update() <-ticker.C