diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d9ae4ce3..8206c4da 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -32,7 +32,7 @@ jobs: - name: Set up Go environment uses: actions/setup-go@v4 with: - go-version: 1.19.x + go-version: 1.21.x id: go - name: Cache Go modules diff --git a/.github/workflows/golangci-lint.yaml b/.github/workflows/golangci-lint.yaml index b505bb67..8f274bda 100644 --- a/.github/workflows/golangci-lint.yaml +++ b/.github/workflows/golangci-lint.yaml @@ -28,4 +28,4 @@ jobs: - name: Lint uses: golangci/golangci-lint-action@v3 with: - version: v1.50.1 + version: v1.54.2 diff --git a/.golangci.yml b/.golangci.yml index c5054a09..5d8d5d75 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -4,7 +4,6 @@ linters: enable: - asciicheck - bodyclose - - depguard - dogsled - dupl - errcheck diff --git a/Alignment.go b/Alignment.go index e9c0610a..9d36a036 100644 --- a/Alignment.go +++ b/Alignment.go @@ -4,7 +4,7 @@ import ( "fmt" "image" - "github.com/AllenDang/imgui-go" + imgui "github.com/AllenDang/cimgui-go" ) // These constants holds information about where GetWidgetWidth should proceed their @@ -177,7 +177,7 @@ func (a *AlignmentSetter) Build() { // if you find anything else, please report it on // https://github.com/AllenDang/giu Any contribution is appreciated! func GetWidgetWidth(w Widget) (result float32) { - imgui.PushID(GenAutoID("GetWidgetWidthMeasurement")) + imgui.PushIDStr(GenAutoID("GetWidgetWidthMeasurement")) defer imgui.PopID() // save cursor position before doing anything diff --git a/Canvas.go b/Canvas.go index 9873cfc3..0f2b4828 100644 --- a/Canvas.go +++ b/Canvas.go @@ -4,7 +4,7 @@ import ( "image" "image/color" - "github.com/AllenDang/imgui-go" + imgui "github.com/AllenDang/cimgui-go" ) // Canvas represents imgui.DrawList @@ -20,103 +20,103 @@ import ( // // c := &Canvas{imgui.GetXXXDrawList()} type Canvas struct { - DrawList imgui.DrawList + DrawList *imgui.DrawList } // GetCanvas returns current draw list (for current window). // it will fail if called out of window's layout. func GetCanvas() *Canvas { return &Canvas{ - DrawList: imgui.GetWindowDrawList(), + DrawList: imgui.WindowDrawList(), } } // AddLine draws a line (from p1 to p2). func (c *Canvas) AddLine(p1, p2 image.Point, col color.Color, thickness float32) { - c.DrawList.AddLine(ToVec2(p1), ToVec2(p2), ToVec4Color(col), thickness) + c.DrawList.AddLineV(ToVec2(p1), ToVec2(p2), ColorToUint(col), thickness) } // DrawFlags represents imgui.DrawFlags. -type DrawFlags int +type DrawFlags imgui.DrawFlags // draw flags enum:. const ( - DrawFlagsNone DrawFlags = 0 + DrawFlagsNone DrawFlags = DrawFlags(imgui.DrawFlagsNone) // PathStroke(), AddPolyline(): specify that shape should be closed (note: this is always == 1 for legacy reasons). - DrawFlagsClosed DrawFlags = 1 << 0 + DrawFlagsClosed DrawFlags = DrawFlags(imgui.DrawFlagsClosed) // AddRect(), AddRectFilled(), PathRect(): enable rounding top-left corner only (when rounding > 0.0f, we default to all corners). // Was 0x01. - DrawFlagsRoundCornersTopLeft DrawFlags = 1 << 4 + DrawFlagsRoundCornersTopLeft DrawFlags = DrawFlags(imgui.DrawFlagsRoundCornersTopLeft) // AddRect(), AddRectFilled(), PathRect(): enable rounding top-right corner only (when rounding > 0.0f, we default to all corners). // Was 0x02. - DrawFlagsRoundCornersTopRight DrawFlags = 1 << 5 + DrawFlagsRoundCornersTopRight DrawFlags = DrawFlags(imgui.DrawFlagsRoundCornersTopRight) // AddRect(), AddRectFilled(), PathRect(): enable rounding bottom-left corner only (when rounding > 0.0f, we default to all corners). // Was 0x04. - DrawFlagsRoundCornersBottomLeft DrawFlags = 1 << 6 + DrawFlagsRoundCornersBottomLeft DrawFlags = DrawFlags(imgui.DrawFlagsRoundCornersBottomLeft) // AddRect(), AddRectFilled(), PathRect(): enable rounding bottom-right corner only (when rounding > 0.0f, // we default to all corners). Wax 0x08. - DrawFlagsRoundCornersBottomRight DrawFlags = 1 << 7 + DrawFlagsRoundCornersBottomRight DrawFlags = DrawFlags(imgui.DrawFlagsRoundCornersBottomRight) // AddRect(), AddRectFilled(), PathRect(): disable rounding on all corners (when rounding > 0.0f). This is NOT zero, NOT an implicit flag! - DrawFlagsRoundCornersNone DrawFlags = 1 << 8 - DrawFlagsRoundCornersTop DrawFlags = DrawFlagsRoundCornersTopLeft | DrawFlagsRoundCornersTopRight - DrawFlagsRoundCornersBottom DrawFlags = DrawFlagsRoundCornersBottomLeft | DrawFlagsRoundCornersBottomRight - DrawFlagsRoundCornersLeft DrawFlags = DrawFlagsRoundCornersBottomLeft | DrawFlagsRoundCornersTopLeft - DrawFlagsRoundCornersRight DrawFlags = DrawFlagsRoundCornersBottomRight | DrawFlagsRoundCornersTopRight - DrawFlagsRoundCornersAll DrawFlags = DrawFlagsRoundCornersTopLeft | DrawFlagsRoundCornersTopRight | - DrawFlagsRoundCornersBottomLeft | DrawFlagsRoundCornersBottomRight + DrawFlagsRoundCornersNone DrawFlags = DrawFlags(imgui.DrawFlagsRoundCornersNone) + DrawFlagsRoundCornersTop DrawFlags = DrawFlags(imgui.DrawFlagsRoundCornersTop) + DrawFlagsRoundCornersBottom DrawFlags = DrawFlags(imgui.DrawFlagsRoundCornersBottom) + DrawFlagsRoundCornersLeft DrawFlags = DrawFlags(imgui.DrawFlagsRoundCornersLeft) + DrawFlagsRoundCornersRight DrawFlags = DrawFlags(imgui.DrawFlagsRoundCornersRight) + DrawFlagsRoundCornersAll DrawFlags = DrawFlags(imgui.DrawFlagsRoundCornersAll) + // Default to ALL corners if none of the RoundCornersXX flags are specified. - DrawFlagsRoundCornersDefault DrawFlags = DrawFlagsRoundCornersAll - DrawFlagsRoundCornersMask DrawFlags = DrawFlagsRoundCornersAll | DrawFlagsRoundCornersNone + DrawFlagsRoundCornersDefault DrawFlags = DrawFlags(imgui.DrawFlagsRoundCornersDefault) + DrawFlagsRoundCornersMask DrawFlags = DrawFlags(imgui.DrawFlagsRoundCornersMask) ) // AddRect draws a rectangle. func (c *Canvas) AddRect(pMin, pMax image.Point, col color.Color, rounding float32, roundingCorners DrawFlags, thickness float32) { - c.DrawList.AddRect(ToVec2(pMin), ToVec2(pMax), ToVec4Color(col), rounding, int(roundingCorners), thickness) + c.DrawList.AddRectV(ToVec2(pMin), ToVec2(pMax), ColorToUint(col), rounding, imgui.DrawFlags(roundingCorners), thickness) } // AddRectFilled draws a rectangle filled with `col`. func (c *Canvas) AddRectFilled(pMin, pMax image.Point, col color.Color, rounding float32, roundingCorners DrawFlags) { - c.DrawList.AddRectFilled(ToVec2(pMin), ToVec2(pMax), ToVec4Color(col), rounding, int(roundingCorners)) + c.DrawList.AddRectFilledV(ToVec2(pMin), ToVec2(pMax), ColorToUint(col), rounding, imgui.DrawFlags(roundingCorners)) } // AddText draws text. func (c *Canvas) AddText(pos image.Point, col color.Color, text string) { - c.DrawList.AddText(ToVec2(pos), ToVec4Color(col), Context.FontAtlas.RegisterString(text)) + c.DrawList.AddTextVec2(ToVec2(pos), ColorToUint(col), Context.FontAtlas.RegisterString(text)) } // AddBezierCubic draws bezier cubic. -func (c *Canvas) AddBezierCubic(pos0, cp0, cp1, pos1 image.Point, col color.Color, thickness float32, numSegments int) { - c.DrawList.AddBezierCubic(ToVec2(pos0), ToVec2(cp0), ToVec2(cp1), ToVec2(pos1), ToVec4Color(col), thickness, numSegments) +func (c *Canvas) AddBezierCubic(pos0, cp0, cp1, pos1 image.Point, col color.Color, thickness float32, numSegments int32) { + c.DrawList.AddBezierCubicV(ToVec2(pos0), ToVec2(cp0), ToVec2(cp1), ToVec2(pos1), ColorToUint(col), thickness, numSegments) } // AddTriangle draws a triangle. func (c *Canvas) AddTriangle(p1, p2, p3 image.Point, col color.Color, thickness float32) { - c.DrawList.AddTriangle(ToVec2(p1), ToVec2(p2), ToVec2(p3), ToVec4Color(col), thickness) + c.DrawList.AddTriangleV(ToVec2(p1), ToVec2(p2), ToVec2(p3), ColorToUint(col), thickness) } // AddTriangleFilled draws a filled triangle. func (c *Canvas) AddTriangleFilled(p1, p2, p3 image.Point, col color.Color) { - c.DrawList.AddTriangleFilled(ToVec2(p1), ToVec2(p2), ToVec2(p3), ToVec4Color(col)) + c.DrawList.AddTriangleFilled(ToVec2(p1), ToVec2(p2), ToVec2(p3), ColorToUint(col)) } // AddCircle draws a circle. -func (c *Canvas) AddCircle(center image.Point, radius float32, col color.Color, segments int, thickness float32) { - c.DrawList.AddCircle(ToVec2(center), radius, ToVec4Color(col), segments, thickness) +func (c *Canvas) AddCircle(center image.Point, radius float32, col color.Color, segments int32, thickness float32) { + c.DrawList.AddCircleV(ToVec2(center), radius, ColorToUint(col), segments, thickness) } // AddCircleFilled draws a filled circle. func (c *Canvas) AddCircleFilled(center image.Point, radius float32, col color.Color) { - c.DrawList.AddCircleFilled(ToVec2(center), radius, ToVec4Color(col)) + c.DrawList.AddCircleFilled(ToVec2(center), radius, ColorToUint(col)) } // AddQuad draws a quad. func (c *Canvas) AddQuad(p1, p2, p3, p4 image.Point, col color.Color, thickness float32) { - c.DrawList.AddQuad(ToVec2(p1), ToVec2(p2), ToVec2(p3), ToVec2(p4), ToVec4Color(col), thickness) + c.DrawList.AddQuadV(ToVec2(p1), ToVec2(p2), ToVec2(p3), ToVec2(p4), ColorToUint(col), thickness) } // AddQuadFilled draws a filled quad. func (c *Canvas) AddQuadFilled(p1, p2, p3, p4 image.Point, col color.Color) { - c.DrawList.AddQuadFilled(ToVec2(p1), ToVec2(p2), ToVec2(p3), ToVec2(p4), ToVec4Color(col)) + c.DrawList.AddQuadFilled(ToVec2(p1), ToVec2(p2), ToVec2(p3), ToVec2(p4), ColorToUint(col)) } // Stateful path API, add points then finish with PathFillConvex() or PathStroke(). @@ -134,29 +134,29 @@ func (c *Canvas) PathLineToMergeDuplicate(pos image.Point) { } func (c *Canvas) PathFillConvex(col color.Color) { - c.DrawList.PathFillConvex(ToVec4Color(col)) + c.DrawList.PathFillConvex(ColorToUint(col)) } -func (c *Canvas) PathStroke(col color.Color, closed bool, thickness float32) { - c.DrawList.PathStroke(ToVec4Color(col), closed, thickness) +func (c *Canvas) PathStroke(col color.Color, flags DrawFlags, thickness float32) { + c.DrawList.PathStrokeV(ColorToUint(col), imgui.DrawFlags(flags), thickness) } -func (c *Canvas) PathArcTo(center image.Point, radius, min, max float32, numSegments int) { - c.DrawList.PathArcTo(ToVec2(center), radius, min, max, numSegments) +func (c *Canvas) PathArcTo(center image.Point, radius, min, max float32, numSegments int32) { + c.DrawList.PathArcToV(ToVec2(center), radius, min, max, numSegments) } -func (c *Canvas) PathArcToFast(center image.Point, radius float32, min12, max12 int) { +func (c *Canvas) PathArcToFast(center image.Point, radius float32, min12, max12 int32) { c.DrawList.PathArcToFast(ToVec2(center), radius, min12, max12) } -func (c *Canvas) PathBezierCubicCurveTo(p1, p2, p3 image.Point, numSegments int) { - c.DrawList.PathBezierCubicCurveTo(ToVec2(p1), ToVec2(p2), ToVec2(p3), numSegments) +func (c *Canvas) PathBezierCubicCurveTo(p1, p2, p3 image.Point, numSegments int32) { + c.DrawList.PathBezierCubicCurveToV(ToVec2(p1), ToVec2(p2), ToVec2(p3), numSegments) } func (c *Canvas) AddImage(texture *Texture, pMin, pMax image.Point) { - c.DrawList.AddImage(texture.id, ToVec2(pMin), ToVec2(pMax)) + c.DrawList.AddImage(texture.ID(), ToVec2(pMin), ToVec2(pMax)) } func (c *Canvas) AddImageV(texture *Texture, pMin, pMax, uvMin, uvMax image.Point, col color.Color) { - c.DrawList.AddImageV(texture.id, ToVec2(pMin), ToVec2(pMax), ToVec2(uvMin), ToVec2(uvMax), ToVec4Color(col)) + c.DrawList.AddImageV(texture.tex.ID(), ToVec2(pMin), ToVec2(pMax), ToVec2(uvMin), ToVec2(uvMax), ColorToUint(col)) } diff --git a/ClickableWidgets.go b/ClickableWidgets.go index 557c529d..a9805965 100644 --- a/ClickableWidgets.go +++ b/ClickableWidgets.go @@ -5,7 +5,7 @@ import ( "image" "image/color" - "github.com/AllenDang/imgui-go" + imgui "github.com/AllenDang/cimgui-go" "golang.org/x/image/colornames" ) @@ -64,7 +64,7 @@ func (b *ButtonWidget) ID(id string) *ButtonWidget { // Build implements Widget interface. func (b *ButtonWidget) Build() { if b.disabled { - imgui.BeginDisabled(true) + imgui.BeginDisabled() defer imgui.EndDisabled() } @@ -105,7 +105,7 @@ func (b *ArrowButtonWidget) ID(id string) *ArrowButtonWidget { // Build implements Widget interface. func (b *ArrowButtonWidget) Build() { - if imgui.ArrowButton(b.id, uint8(b.dir)) && b.onClick != nil { + if imgui.ArrowButton(b.id, imgui.Dir(b.dir)) && b.onClick != nil { b.onClick() } } @@ -224,15 +224,16 @@ func ImageButton(texture *Texture) *ImageButtonWidget { // Build implements Widget interface. func (b *ImageButtonWidget) Build() { - if b.texture == nil || b.texture.id == 0 { + if b.texture == nil || b.texture.tex == nil { return } if imgui.ImageButtonV( - b.texture.id, + fmt.Sprintf("%v", b.texture.tex.ID()), + b.texture.tex.ID(), imgui.Vec2{X: b.width, Y: b.height}, ToVec2(b.uv0), ToVec2(b.uv1), - b.framePadding, ToVec4Color(b.bgColor), + ToVec4Color(b.bgColor), ToVec4Color(b.tintColor), ) && b.onClick != nil { b.onClick() @@ -406,7 +407,7 @@ func (r *RadioButtonWidget) OnChange(onChange func()) *RadioButtonWidget { // Build implements Widget interface. func (r *RadioButtonWidget) Build() { - if imgui.RadioButton(Context.FontAtlas.RegisterString(r.text), r.active) && r.onChange != nil { + if imgui.RadioButtonBool(Context.FontAtlas.RegisterString(r.text), r.active) && r.onChange != nil { r.onChange() } } @@ -481,7 +482,7 @@ func (s *SelectableWidget) Build() { s.flags |= SelectableFlagsAllowDoubleClick } - if imgui.SelectableV(Context.FontAtlas.RegisterString(s.label), s.selected, int(s.flags), imgui.Vec2{X: s.width, Y: s.height}) && s.onClick != nil { + if imgui.SelectableBoolV(Context.FontAtlas.RegisterString(s.label), s.selected, imgui.SelectableFlags(s.flags), imgui.Vec2{X: s.width, Y: s.height}) && s.onClick != nil { s.onClick() } @@ -539,7 +540,7 @@ func (t *TreeNodeWidget) Layout(widgets ...Widget) *TreeNodeWidget { // Build implements Widget interface. func (t *TreeNodeWidget) Build() { - open := imgui.TreeNodeV(t.label, int(t.flags)) + open := imgui.TreeNodeExStrV(t.label, imgui.TreeNodeFlags(t.flags)) if t.eventHandler != nil { t.eventHandler() diff --git a/CodeEditor.go b/CodeEditor.go index 34fc3ce3..87df5f82 100644 --- a/CodeEditor.go +++ b/CodeEditor.go @@ -2,8 +2,6 @@ package giu import ( "fmt" - - "github.com/AllenDang/imgui-go" ) // LanguageDefinition represents code editor's language definition. @@ -20,7 +18,7 @@ const ( var _ Disposable = &codeEditorState{} type codeEditorState struct { - editor imgui.TextEditor + // editor imgui.TextEditor } // Dispose implements Disposable interface. @@ -41,6 +39,7 @@ type CodeEditorWidget struct { // CodeEditor creates new code editor widget. func CodeEditor() *CodeEditorWidget { + panic("Code Editor is not implemented yet!") return &CodeEditorWidget{ title: GenAutoID("##CodeEditor"), } @@ -48,6 +47,7 @@ func CodeEditor() *CodeEditorWidget { // ID allows to manually set editor's ID. // It isn't necessary to use it in a normal conditions. + func (ce *CodeEditorWidget) ID(id string) *CodeEditorWidget { ce.title = id return ce @@ -55,24 +55,25 @@ func (ce *CodeEditorWidget) ID(id string) *CodeEditorWidget { // ShowWhitespaces sets if whitespace is shown in code editor. func (ce *CodeEditorWidget) ShowWhitespaces(s bool) *CodeEditorWidget { - ce.getState().editor.SetShowWhitespaces(s) + // ce.getState().editor.SetShowWhitespaces(s) return ce } // TabSize sets editor's tab size. func (ce *CodeEditorWidget) TabSize(size int) *CodeEditorWidget { - ce.getState().editor.SetTabSize(size) + // ce.getState().editor.SetTabSize(size) return ce } // LanguageDefinition sets code editor language definition. + func (ce *CodeEditorWidget) LanguageDefinition(definition LanguageDefinition) *CodeEditorWidget { - s := ce.getState() + // s := ce.getState() lookup := map[LanguageDefinition]func(){ - LanguageDefinitionSQL: s.editor.SetLanguageDefinitionSQL, - LanguageDefinitionCPP: s.editor.SetLanguageDefinitionCPP, - LanguageDefinitionLua: s.editor.SetLanguageDefinitionLua, - LanguageDefinitionC: s.editor.SetLanguageDefinitionC, + //LanguageDefinitionSQL: s.editor.SetLanguageDefinitionSQL, + //LanguageDefinitionCPP: s.editor.SetLanguageDefinitionCPP, + //LanguageDefinitionLua: s.editor.SetLanguageDefinitionLua, + //LanguageDefinitionC: s.editor.SetLanguageDefinitionC, } setter, correctDefinition := lookup[definition] @@ -87,19 +88,19 @@ func (ce *CodeEditorWidget) LanguageDefinition(definition LanguageDefinition) *C // Text sets editor's text. func (ce *CodeEditorWidget) Text(str string) *CodeEditorWidget { - ce.getState().editor.SetText(str) + // ce.getState().editor.SetText(str) return ce } // ErrorMarkers sets error markers. -func (ce *CodeEditorWidget) ErrorMarkers(markers imgui.ErrorMarkers) *CodeEditorWidget { - ce.getState().editor.SetErrorMarkers(markers) - return ce -} +// func (ce *CodeEditorWidget) ErrorMarkers(markers imgui.ErrorMarkers) *CodeEditorWidget { +// ce.getState().editor.SetErrorMarkers(markers) +//return ce +//} // HandleKeyboardInputs sets if editor should handle keyboard input. func (ce *CodeEditorWidget) HandleKeyboardInputs(b bool) *CodeEditorWidget { - ce.getState().editor.SetHandleKeyboardInputs(b) + // ce.getState().editor.SetHandleKeyboardInputs(b) return ce } @@ -117,96 +118,105 @@ func (ce *CodeEditorWidget) Border(border bool) *CodeEditorWidget { // HasSelection returns true if some text is selected. func (ce *CodeEditorWidget) HasSelection() bool { - return ce.getState().editor.HasSelection() + // return ce.getState().editor.HasSelection() + return false } // GetSelectedText returns selected text. func (ce *CodeEditorWidget) GetSelectedText() string { - return ce.getState().editor.GetSelectedText() + // return ce.getState().editor.GetSelectedText() + return "" } // GetText returns whole text from editor. func (ce *CodeEditorWidget) GetText() string { - return ce.getState().editor.GetText() + // return ce.getState().editor.GetText() + return "" } // GetCurrentLineText returns current line. func (ce *CodeEditorWidget) GetCurrentLineText() string { - return ce.getState().editor.GetCurrentLineText() + // return ce.getState().editor.GetCurrentLineText() + return "" } // GetCursorPos returns cursor position. // (in characters). func (ce *CodeEditorWidget) GetCursorPos() (x, y int) { - return ce.getState().editor.GetCursorPos() + // return ce.getState().editor.GetCursorPos() + return 0, 0 } // GetSelectionStart returns star pos of selection. func (ce *CodeEditorWidget) GetSelectionStart() (x, y int) { - return ce.getState().editor.GetSelectionStart() + // return ce.getState().editor.GetSelectionStart() + return 0, 0 } // InsertText inserts the `text`. func (ce *CodeEditorWidget) InsertText(text string) { - ce.getState().editor.InsertText(text) + // ce.getState().editor.InsertText(text) } // GetWordUnderCursor returns the word under the cursor. func (ce *CodeEditorWidget) GetWordUnderCursor() string { - return ce.getState().editor.GetWordUnderCursor() + // return ce.getState().editor.GetWordUnderCursor() + return "" } // SelectWordUnderCursor selects the word under cursor. func (ce *CodeEditorWidget) SelectWordUnderCursor() { - ce.getState().editor.SelectWordUnderCursor() + // ce.getState().editor.SelectWordUnderCursor() } // IsTextChanged returns true if the editable text was changed in the frame. func (ce *CodeEditorWidget) IsTextChanged() bool { - return ce.getState().editor.IsTextChanged() + // return ce.getState().editor.IsTextChanged() + return false } // GetScreenCursorPos returns cursor position on the screen. // (in pixels). func (ce *CodeEditorWidget) GetScreenCursorPos() (x, y int) { - return ce.getState().editor.GetScreenCursorPos() + // return ce.getState().editor.GetScreenCursorPos() + return 0, 0 } // Copy copies selection. func (ce *CodeEditorWidget) Copy() { - ce.getState().editor.Copy() + // ce.getState().editor.Copy() } // Cut cuts selection. func (ce *CodeEditorWidget) Cut() { - ce.getState().editor.Cut() + // ce.getState().editor.Cut() } // Paste does the same as Ctrl+V. func (ce *CodeEditorWidget) Paste() { - ce.getState().editor.Paste() + // ce.getState().editor.Paste() } // Delete deletes the selection. func (ce *CodeEditorWidget) Delete() { - ce.getState().editor.Delete() + // ce.getState().editor.Delete() } // Build implements Widget interface. func (ce *CodeEditorWidget) Build() { - s := ce.getState() + // s := ce.getState() // register text in font atlas - Context.FontAtlas.RegisterString(s.editor.GetText()) + // Context.FontAtlas.RegisterString(s.editor.GetText()) // build editor - s.editor.Render(ce.title, imgui.Vec2{X: ce.width, Y: ce.height}, ce.border) + // s.editor.Render(ce.title, imgui.Vec2{X: ce.width, Y: ce.height}, ce.border) } func (ce *CodeEditorWidget) getState() (state *codeEditorState) { if state = GetState[codeEditorState](Context, ce.title); state == nil { state = &codeEditorState{ - editor: imgui.NewTextEditor(), + //editor: imgui.NewTextEditor(), } SetState(Context, ce.title, state) diff --git a/Context.go b/Context.go index d5b73941..ee4e7ce5 100644 --- a/Context.go +++ b/Context.go @@ -4,7 +4,7 @@ import ( "fmt" "sync" - "github.com/AllenDang/imgui-go" + imgui "github.com/AllenDang/cimgui-go" "gopkg.in/eapache/queue.v1" ) @@ -28,13 +28,12 @@ type state struct { } type context struct { + backend imgui.Backend[imgui.GLFWWindowFlags] + // TODO: should be handled by mainthread tbh // see https://github.com/faiface/mainthread/pull/4 isRunning bool - renderer imgui.Renderer - platform imgui.Platform - widgetIndexCounter int // Indicate whether current application is running @@ -53,22 +52,23 @@ type context struct { m *sync.Mutex } -func CreateContext(p imgui.Platform, r imgui.Renderer) *context { +func CreateContext(b imgui.Backend[imgui.GLFWWindowFlags]) *context { result := context{ - platform: p, - renderer: r, - cssStylesheet: make(cssStylesheet), - m: &sync.Mutex{}, + cssStylesheet: make(cssStylesheet), + backend: b, + FontAtlas: newFontAtlas(), + textureLoadingQueue: queue.New(), + m: &sync.Mutex{}, } - result.FontAtlas = newFontAtlas() - // Create font if len(result.FontAtlas.defaultFonts) == 0 { - io := result.IO() - io.Fonts().AddFontDefault() - fontAtlas := io.Fonts().TextureDataRGBA32() - r.SetFontTexture(fontAtlas) + fonts := result.IO().Fonts() + fonts.AddFontDefault() + fontTextureImg, w, h, _ := fonts.GetTextureDataAsRGBA32() + tex := Context.backend.CreateTexture(fontTextureImg, int(w), int(h)) + fonts.SetTexID(tex) + fonts.SetTexReady(true) } else { result.FontAtlas.shouldRebuildFontAtlas = true } @@ -76,15 +76,7 @@ func CreateContext(p imgui.Platform, r imgui.Renderer) *context { return &result } -func (c *context) GetRenderer() imgui.Renderer { - return c.renderer -} - -func (c *context) GetPlatform() imgui.Platform { - return c.platform -} - -func (c *context) IO() imgui.IO { +func (c *context) IO() *imgui.IO { return imgui.CurrentIO() } diff --git a/Context_test.go b/Context_test.go index b24e512e..9d83430b 100644 --- a/Context_test.go +++ b/Context_test.go @@ -29,7 +29,7 @@ func Test_SetGetState(t *testing.T) { for _, tc := range tests { t.Run(tc.id, func(t *testing.T) { - ctx := CreateContext(nil, nil) + ctx := CreateContext(nil) SetState(ctx, tc.id, tc.data) restored := GetState[teststate](ctx, tc.id) assert.Equal(t, tc.data, restored, "unexpected state restored") @@ -48,7 +48,7 @@ func Test_SetGetStateGeneric(t *testing.T) { for _, tc := range tests { t.Run(tc.id, func(t *testing.T) { - ctx := CreateContext(nil, nil) + ctx := CreateContext(nil) SetState(ctx, tc.id, tc.data) restored := GetState[teststate](ctx, tc.id) assert.Equal(t, tc.data, restored, "unexpected state restored") @@ -71,7 +71,7 @@ func Test_SetGetWrongStateGeneric(t *testing.T) { } func Test_invalidState(t *testing.T) { - ctx := CreateContext(nil, nil) + ctx := CreateContext(nil) state1ID := "state1" state2ID := "state2" @@ -97,7 +97,7 @@ func Test_invalidState(t *testing.T) { } func Test_GetWidgetIndex(t *testing.T) { - ctx := CreateContext(nil, nil) + ctx := CreateContext(nil) for i := 0; i <= 3; i++ { assert.Equal(t, i, ctx.GetWidgetIndex(), "widget index wasn't increased") } diff --git a/Direction.go b/Direction.go index d8876771..24b68600 100644 --- a/Direction.go +++ b/Direction.go @@ -1,12 +1,14 @@ package giu +import imgui "github.com/AllenDang/cimgui-go" + // Direction represents a ArrowButton direction. -type Direction uint8 +type Direction imgui.Dir // directions. const ( - DirectionLeft Direction = iota - DirectionRight - DirectionUp - DirectionDown + DirectionLeft Direction = imgui.DirLeft + DirectionRight Direction = imgui.DirRight + DirectionUp Direction = imgui.DirUp + DirectionDown Direction = imgui.DirDown ) diff --git a/EventHandler.go b/EventHandler.go index 49eb7834..5327f99a 100644 --- a/EventHandler.go +++ b/EventHandler.go @@ -116,7 +116,7 @@ func (eh *EventHandler) OnMouseReleased(mouseButton MouseButton, callback func() // Build implements Widget interface // -//nolint:gocognit,gocyclo // will fix later +//nolint:gocyclo // will fix later func (eh *EventHandler) Build() { isActive := IsItemActive() diff --git a/Events.go b/Events.go index 93f37760..764ca782 100644 --- a/Events.go +++ b/Events.go @@ -1,15 +1,15 @@ package giu -import "github.com/AllenDang/imgui-go" +import imgui "github.com/AllenDang/cimgui-go" // MouseButton represents imgui.MouseButton. -type MouseButton int +type MouseButton imgui.MouseButton // mouse buttons. const ( - MouseButtonLeft MouseButton = 0 - MouseButtonRight MouseButton = 1 - MouseButtonMiddle MouseButton = 2 + MouseButtonLeft MouseButton = MouseButton(imgui.MouseButtonLeft) + MouseButtonRight MouseButton = MouseButton(imgui.MouseButtonRight) + MouseButtonMiddle MouseButton = MouseButton(imgui.MouseButtonMiddle) ) // IsItemHovered returns true if mouse is over the item. @@ -20,7 +20,7 @@ func IsItemHovered() bool { // IsItemClicked returns true if mouse is clicked // NOTE: if you're looking for clicking detection, see EventHandler.go. func IsItemClicked(mouseButton MouseButton) bool { - return imgui.IsItemClicked(int(mouseButton)) + return imgui.IsItemClickedV(imgui.MouseButton(mouseButton)) } // IsItemActive returns true if item is active. @@ -30,38 +30,38 @@ func IsItemActive() bool { // IsKeyDown returns true if key `key` is down. func IsKeyDown(key Key) bool { - return imgui.IsKeyDown(int(key)) + return imgui.IsKeyDownNil(imgui.Key(key)) } // IsKeyPressed returns true if key `key` is pressed. func IsKeyPressed(key Key) bool { - return imgui.IsKeyPressed(int(key)) + return imgui.IsKeyPressedBool(imgui.Key(key)) } // IsKeyReleased returns true if key `key` is released. func IsKeyReleased(key Key) bool { - return imgui.IsKeyReleased(int(key)) + return imgui.IsKeyReleasedNil(imgui.Key(key)) } // IsMouseDown returns true if mouse button `button` is down. func IsMouseDown(button MouseButton) bool { - return imgui.IsMouseDown(int(button)) + return imgui.IsMouseDownNil(imgui.MouseButton(button)) } // IsMouseClicked returns true if mouse button `button` is clicked // NOTE: if you're looking for clicking detection, see EventHandler.go. func IsMouseClicked(button MouseButton) bool { - return imgui.IsMouseClicked(int(button)) + return imgui.IsMouseClickedBool(imgui.MouseButton(button)) } // IsMouseReleased returns true if mouse button `button` is released. func IsMouseReleased(button MouseButton) bool { - return imgui.IsMouseReleased(int(button)) + return imgui.IsMouseReleasedNil(imgui.MouseButton(button)) } // IsMouseDoubleClicked returns true if mouse button `button` is double clicked. func IsMouseDoubleClicked(button MouseButton) bool { - return imgui.IsMouseDoubleClicked(int(button)) + return imgui.IsMouseDoubleClicked(imgui.MouseButton(button)) } // IsWindowAppearing returns true if window is appearing. @@ -77,10 +77,10 @@ func IsWindowCollapsed() bool { // IsWindowFocused returns true if window is focused // NOTE: see also (*Window).HasFocus and (*Window).BringToFront. func IsWindowFocused(flags FocusedFlags) bool { - return imgui.IsWindowFocused(int(flags)) + return imgui.IsWindowFocusedV(imgui.FocusedFlags(flags)) } // IsWindowHovered returns true if the window is hovered. func IsWindowHovered(flags HoveredFlags) bool { - return imgui.IsWindowHovered(int(flags)) + return imgui.IsWindowHoveredV(imgui.HoveredFlags(flags)) } diff --git a/ExtraWidgets.go b/ExtraWidgets.go index 80c2d7ab..e8eef248 100644 --- a/ExtraWidgets.go +++ b/ExtraWidgets.go @@ -5,7 +5,7 @@ import ( "image" "time" - "github.com/AllenDang/imgui-go" + imgui "github.com/AllenDang/cimgui-go" ) var _ Widget = &SplitterWidget{} @@ -80,8 +80,7 @@ func (h *SplitterWidget) Build() { ptMin := image.Pt(centerX-width/2, centerY-height/2) ptMax := image.Pt(centerX+width/2, centerY+height/2) - style := imgui.CurrentStyle() - c := Vec4ToRGBA(style.GetColor(imgui.StyleColorScrollbarGrab)) + c := Vec4ToRGBA(*imgui.StyleColorVec4(imgui.ColScrollbarGrab)) // Place a invisible button to capture event. imgui.InvisibleButton(h.id, imgui.Vec2{X: h.width, Y: h.height}) @@ -89,9 +88,9 @@ func (h *SplitterWidget) Build() { if imgui.IsItemActive() { switch h.direction { case DirectionHorizontal: - *(h.delta) = imgui.CurrentIO().GetMouseDelta().Y + *(h.delta) = imgui.CurrentIO().MouseDelta().Y case DirectionVertical: - *(h.delta) = imgui.CurrentIO().GetMouseDelta().X + *(h.delta) = imgui.CurrentIO().MouseDelta().X } } else { *(h.delta) = 0 @@ -105,7 +104,7 @@ func (h *SplitterWidget) Build() { imgui.SetMouseCursor(imgui.MouseCursorResizeEW) } - c = Vec4ToRGBA(style.GetColor(imgui.StyleColorScrollbarGrabActive)) + c = Vec4ToRGBA(*imgui.StyleColorVec4(imgui.ColScrollbarGrabActive)) } // Draw a line in the very center @@ -200,7 +199,7 @@ func (c *ConditionWidget) Build() { func RangeBuilder(id string, values []any, builder func(int, any) Widget) Layout { var layout Layout - layout = append(layout, Custom(func() { imgui.PushID(id) })) + layout = append(layout, Custom(func() { imgui.PushIDStr(id) })) if len(values) > 0 && builder != nil { for i, v := range values { @@ -313,19 +312,19 @@ func (l *ListBoxWidget) Build() { child := Child().Border(l.border).Size(l.width, l.height).Layout(Layout{ Custom(func() { clipper := imgui.NewListClipper() - defer clipper.Delete() + defer clipper.Destroy() - clipper.Begin(len(l.items)) + clipper.Begin(int32(len(l.items))) for clipper.Step() { for i := clipper.DisplayStart(); i < clipper.DisplayEnd(); i++ { - selected := i == int(*selectedIndex) + selected := i == *selectedIndex item := l.items[i] Selectable(item).Selected(selected).Flags(SelectableFlagsAllowDoubleClick).OnClick(func() { - if *selectedIndex != int32(i) { - *selectedIndex = int32(i) + if *selectedIndex != i { + *selectedIndex = i if l.onChange != nil { - l.onChange(i) + l.onChange(int(i)) } } }).Build() @@ -341,7 +340,7 @@ func (l *ListBoxWidget) Build() { menu := m menus = append(menus, MenuItem(fmt.Sprintf("%s##%d", menu, index)).OnClick(func() { if l.onMenu != nil { - l.onMenu(index, menu) + l.onMenu(int(index), menu) } })) } @@ -437,7 +436,7 @@ func (d *DatePickerWidget) Build() { return } - imgui.PushID(d.id) + imgui.PushIDStr(d.id) defer imgui.PopID() if d.width > 0 { @@ -553,12 +552,12 @@ func (d *DatePickerWidget) getDaysGroups() (days [][]int) { func (d *DatePickerWidget) calendarField(day int) Widget { today := time.Now() - highlightColor := imgui.CurrentStyle().GetColor(imgui.StyleColorPlotHistogram) + highlightColor := imgui.StyleColorVec4(imgui.ColPlotHistogram) return Custom(func() { isToday := d.date.Year() == today.Year() && d.date.Month() == today.Month() && day == today.Day() if isToday { - imgui.PushStyleColor(imgui.StyleColorText, highlightColor) + imgui.PushStyleColorVec4(imgui.ColText, *highlightColor) } Selectable(fmt.Sprintf("%02d", day)).Selected(isToday).OnClick(func() { diff --git a/Flags.go b/Flags.go index eca9dfcc..ad1b469b 100644 --- a/Flags.go +++ b/Flags.go @@ -1,9 +1,9 @@ package giu -import "github.com/AllenDang/imgui-go" +import imgui "github.com/AllenDang/cimgui-go" // InputTextFlags represents input text flags. -type InputTextFlags int +type InputTextFlags imgui.InputTextFlags // input text flags. const ( @@ -38,7 +38,7 @@ const ( // InputTextFlagsNoHorizontalScroll disables following the cursor horizontally. InputTextFlagsNoHorizontalScroll InputTextFlags = imgui.InputTextFlagsNoHorizontalScroll // InputTextFlagsAlwaysInsertMode sets insert mode. - InputTextFlagsAlwaysInsertMode InputTextFlags = imgui.InputTextFlagsAlwaysInsertMode + // InputTextFlagsReadOnly sets read-only mode. InputTextFlagsReadOnly InputTextFlags = imgui.InputTextFlagsReadOnly // InputTextFlagsPassword sets password mode, display all characters as '*'. @@ -51,73 +51,73 @@ const ( ) // WindowFlags represents a window flags (see (*WindowWidget).Flags. -type WindowFlags int +type WindowFlags imgui.GLFWWindowFlags // window flags. const ( // WindowFlagsNone default = 0. - WindowFlagsNone WindowFlags = imgui.WindowFlagsNone + WindowFlagsNone WindowFlags = WindowFlags(imgui.WindowFlagsNone) // WindowFlagsNoTitleBar disables title-bar. - WindowFlagsNoTitleBar WindowFlags = imgui.WindowFlagsNoTitleBar + WindowFlagsNoTitleBar WindowFlags = WindowFlags(imgui.WindowFlagsNoTitleBar) // WindowFlagsNoResize disables user resizing with the lower-right grip. - WindowFlagsNoResize WindowFlags = imgui.WindowFlagsNoResize + WindowFlagsNoResize WindowFlags = WindowFlags(imgui.WindowFlagsNoResize) // WindowFlagsNoMove disables user moving the window. - WindowFlagsNoMove WindowFlags = imgui.WindowFlagsNoMove + WindowFlagsNoMove WindowFlags = WindowFlags(imgui.WindowFlagsNoMove) // WindowFlagsNoScrollbar disables scrollbars. Window can still scroll with mouse or programmatically. - WindowFlagsNoScrollbar WindowFlags = imgui.WindowFlagsNoScrollbar + WindowFlagsNoScrollbar WindowFlags = WindowFlags(imgui.WindowFlagsNoScrollbar) // WindowFlagsNoScrollWithMouse disables user vertically scrolling with mouse wheel. On child window, mouse wheel // will be forwarded to the parent unless NoScrollbar is also set. - WindowFlagsNoScrollWithMouse WindowFlags = imgui.WindowFlagsNoScrollWithMouse + WindowFlagsNoScrollWithMouse WindowFlags = WindowFlags(imgui.WindowFlagsNoScrollWithMouse) // WindowFlagsNoCollapse disables user collapsing window by double-clicking on it. - WindowFlagsNoCollapse WindowFlags = imgui.WindowFlagsNoCollapse + WindowFlagsNoCollapse WindowFlags = WindowFlags(imgui.WindowFlagsNoCollapse) // WindowFlagsAlwaysAutoResize resizes every window to its content every frame. - WindowFlagsAlwaysAutoResize WindowFlags = imgui.WindowFlagsAlwaysAutoResize + WindowFlagsAlwaysAutoResize WindowFlags = WindowFlags(imgui.WindowFlagsAlwaysAutoResize) // WindowFlagsNoBackground disables drawing background color (WindowBg, etc.) and outside border. Similar as using // SetNextWindowBgAlpha(0.0f). - WindowFlagsNoBackground WindowFlags = imgui.WindowFlagsNoBackground + WindowFlagsNoBackground WindowFlags = WindowFlags(imgui.WindowFlagsNoBackground) // WindowFlagsNoSavedSettings will never load/save settings in .ini file. - WindowFlagsNoSavedSettings WindowFlags = imgui.WindowFlagsNoSavedSettings + WindowFlagsNoSavedSettings WindowFlags = WindowFlags(imgui.WindowFlagsNoSavedSettings) // WindowFlagsNoMouseInputs disables catching mouse, hovering test with pass through. - WindowFlagsNoMouseInputs WindowFlags = imgui.WindowFlagsNoMouseInputs + WindowFlagsNoMouseInputs WindowFlags = WindowFlags(imgui.WindowFlagsNoMouseInputs) // WindowFlagsMenuBar has a menu-bar. - WindowFlagsMenuBar WindowFlags = imgui.WindowFlagsMenuBar + WindowFlagsMenuBar WindowFlags = WindowFlags(imgui.WindowFlagsMenuBar) // WindowFlagsHorizontalScrollbar allows horizontal scrollbar to appear (off by default). You may use // SetNextWindowContentSize(ImVec2(width,0.0f)); prior to calling Begin() to specify width. Read code in imgui_demo // in the "Horizontal Scrolling" section. - WindowFlagsHorizontalScrollbar WindowFlags = imgui.WindowFlagsHorizontalScrollbar + WindowFlagsHorizontalScrollbar WindowFlags = WindowFlags(imgui.WindowFlagsHorizontalScrollbar) // WindowFlagsNoFocusOnAppearing disables taking focus when transitioning from hidden to visible state. - WindowFlagsNoFocusOnAppearing WindowFlags = imgui.WindowFlagsNoFocusOnAppearing + WindowFlagsNoFocusOnAppearing WindowFlags = WindowFlags(imgui.WindowFlagsNoFocusOnAppearing) // WindowFlagsNoBringToFrontOnFocus disables bringing window to front when taking focus. e.g. clicking on it or // programmatically giving it focus. - WindowFlagsNoBringToFrontOnFocus WindowFlags = imgui.WindowFlagsNoBringToFrontOnFocus + WindowFlagsNoBringToFrontOnFocus WindowFlags = WindowFlags(imgui.WindowFlagsNoBringToFrontOnFocus) // WindowFlagsAlwaysVerticalScrollbar always shows vertical scrollbar, even if ContentSize.y < Size.y . - WindowFlagsAlwaysVerticalScrollbar WindowFlags = imgui.WindowFlagsAlwaysVerticalScrollbar + WindowFlagsAlwaysVerticalScrollbar WindowFlags = WindowFlags(imgui.WindowFlagsAlwaysVerticalScrollbar) // WindowFlagsAlwaysHorizontalScrollbar always shows horizontal scrollbar, even if ContentSize.x < Size.x . - WindowFlagsAlwaysHorizontalScrollbar WindowFlags = imgui.WindowFlagsAlwaysHorizontalScrollbar + WindowFlagsAlwaysHorizontalScrollbar WindowFlags = WindowFlags(imgui.WindowFlagsAlwaysHorizontalScrollbar) // WindowFlagsAlwaysUseWindowPadding ensures child windows without border uses style.WindowPadding (ignored by // default for non-bordered child windows, because more convenient). - WindowFlagsAlwaysUseWindowPadding WindowFlags = imgui.WindowFlagsAlwaysUseWindowPadding + WindowFlagsAlwaysUseWindowPadding WindowFlags = WindowFlags(imgui.WindowFlagsAlwaysUseWindowPadding) // WindowFlagsNoNavInputs has no gamepad/keyboard navigation within the window. - WindowFlagsNoNavInputs WindowFlags = imgui.WindowFlagsNoNavInputs + WindowFlagsNoNavInputs WindowFlags = WindowFlags(imgui.WindowFlagsNoNavInputs) // WindowFlagsNoNavFocus has no focusing toward this window with gamepad/keyboard navigation // (e.g. skipped by CTRL+TAB). - WindowFlagsNoNavFocus WindowFlags = imgui.WindowFlagsNoNavFocus + WindowFlagsNoNavFocus WindowFlags = WindowFlags(imgui.WindowFlagsNoNavFocus) // WindowFlagsUnsavedDocument appends '*' to title without affecting the ID, as a convenience to avoid using the // ### operator. When used in a tab/docking context, tab is selected on closure and closure is deferred by one // frame to allow code to cancel the closure (with a confirmation popup, etc.) without flicker. - WindowFlagsUnsavedDocument WindowFlags = imgui.WindowFlagsUnsavedDocument + WindowFlagsUnsavedDocument WindowFlags = WindowFlags(imgui.WindowFlagsUnsavedDocument) // WindowFlagsNoNav combines WindowFlagsNoNavInputs and WindowFlagsNoNavFocus. - WindowFlagsNoNav WindowFlags = imgui.WindowFlagsNoNav + WindowFlagsNoNav WindowFlags = WindowFlags(imgui.WindowFlagsNoNav) // WindowFlagsNoDecoration combines WindowFlagsNoTitleBar, WindowFlagsNoResize, WindowFlagsNoScrollbar and // WindowFlagsNoCollapse. - WindowFlagsNoDecoration WindowFlags = imgui.WindowFlagsNoDecoration + WindowFlagsNoDecoration WindowFlags = WindowFlags(imgui.WindowFlagsNoDecoration) // WindowFlagsNoInputs combines WindowFlagsNoMouseInputs, WindowFlagsNoNavInputs and WindowFlagsNoNavFocus. - WindowFlagsNoInputs WindowFlags = imgui.WindowFlagsNoInputs + WindowFlagsNoInputs WindowFlags = WindowFlags(imgui.WindowFlagsNoInputs) ) // ComboFlags represents imgui.ComboFlags. -type ComboFlags int +type ComboFlags imgui.ComboFlags // combo flags list. const ( @@ -141,7 +141,7 @@ const ( ) // SelectableFlags represents imgui.SelectableFlags. -type SelectableFlags int +type SelectableFlags imgui.SelectableFlags // selectable flags list. const ( @@ -158,7 +158,7 @@ const ( ) // TabItemFlags represents tab item flags. -type TabItemFlags int +type TabItemFlags imgui.TabItemFlags // tab item flags list. const ( @@ -175,11 +175,11 @@ const ( // (IsItemHovered() && IsMouseClicked(2)) *p_open = false. TabItemFlagsNoCloseWithMiddleMouseButton TabItemFlags = imgui.TabItemFlagsNoCloseWithMiddleMouseButton // TabItemFlagsNoPushID Don't call PushID(tab->ID)/PopID() on BeginTabItem()/EndTabItem(). - TabItemFlagsNoPushID TabItemFlags = imgui.TabItemFlagsNoPushID + ) // TabBarFlags represents imgui.TabBarFlags. -type TabBarFlags int +type TabBarFlags imgui.TabBarFlags // tab bar flags list. const ( @@ -212,7 +212,7 @@ const ( ) // TreeNodeFlags represents tree node widget flags. -type TreeNodeFlags int +type TreeNodeFlags imgui.TreeNodeFlags // tree node flags list. const ( @@ -223,7 +223,7 @@ const ( // TreeNodeFlagsFramed draws full colored frame (e.g. for CollapsingHeader). TreeNodeFlagsFramed TreeNodeFlags = imgui.TreeNodeFlagsFramed // TreeNodeFlagsAllowItemOverlap hit testing to allow subsequent widgets to overlap this one. - TreeNodeFlagsAllowItemOverlap TreeNodeFlags = imgui.TreeNodeFlagsAllowItemOverlap + TreeNodeFlagsAllowItemOverlap TreeNodeFlags = imgui.TreeNodeFlagsAllowOverlap // TreeNodeFlagsNoTreePushOnOpen doesn't do a TreePush() when open // (e.g. for CollapsingHeader) = no extra indent nor pushing on ID stack. TreeNodeFlagsNoTreePushOnOpen TreeNodeFlags = imgui.TreeNodeFlagsNoTreePushOnOpen @@ -259,7 +259,7 @@ const ( ) // FocusedFlags represents imgui.FocusedFlags. -type FocusedFlags int +type FocusedFlags imgui.FocusedFlags // focused flags list. const ( @@ -273,7 +273,7 @@ const ( ) // HoveredFlags represents a hovered flags. -type HoveredFlags int +type HoveredFlags imgui.HoveredFlags // hovered flags list. const ( @@ -302,202 +302,211 @@ type ColorEditFlags int // list of color edit flags. const ( - // ColorEditFlagsNone default = 0. - ColorEditFlagsNone ColorEditFlags = imgui.ColorEditFlagsNone - // ColorEditFlagsNoAlpha ignores Alpha component (read 3 components from the input pointer). - ColorEditFlagsNoAlpha ColorEditFlags = imgui.ColorEditFlagsNoAlpha - // ColorEditFlagsNoPicker disables picker when clicking on colored square. - ColorEditFlagsNoPicker ColorEditFlags = imgui.ColorEditFlagsNoPicker - // ColorEditFlagsNoOptions disables toggling options menu when right-clicking on inputs/small preview. - ColorEditFlagsNoOptions ColorEditFlags = imgui.ColorEditFlagsNoOptions - // ColorEditFlagsNoSmallPreview disables colored square preview next to the inputs. (e.g. to show only the inputs). - ColorEditFlagsNoSmallPreview ColorEditFlags = imgui.ColorEditFlagsNoSmallPreview - // ColorEditFlagsNoInputs disables inputs sliders/text widgets (e.g. to show only the small preview colored square). - ColorEditFlagsNoInputs ColorEditFlags = imgui.ColorEditFlagsNoInputs - // ColorEditFlagsNoTooltip disables tooltip when hovering the preview. - ColorEditFlagsNoTooltip ColorEditFlags = imgui.ColorEditFlagsNoTooltip - // ColorEditFlagsNoLabel disables display of inline text label (the label is still forwarded to the tooltip and picker). - ColorEditFlagsNoLabel ColorEditFlags = imgui.ColorEditFlagsNoLabel - // ColorEditFlagsNoDragDrop disables drag and drop target. ColorButton: disable drag and drop source. - ColorEditFlagsNoDragDrop ColorEditFlags = imgui.ColorEditFlagsNoDragDrop - - // User Options (right-click on widget to change some of them). You can set application defaults using SetColorEditOptions(). - // The idea is that you probably don't want to override them in most of your calls, let the user choose and/or call SetColorEditOptions() - // during startup. - - // ColorEditFlagsAlphaBar shows vertical alpha bar/gradient in picker. - ColorEditFlagsAlphaBar ColorEditFlags = imgui.ColorEditFlagsAlphaBar - // ColorEditFlagsAlphaPreview displays preview as a transparent color over a checkerboard, instead of opaque. - ColorEditFlagsAlphaPreview ColorEditFlags = imgui.ColorEditFlagsAlphaPreview - // ColorEditFlagsAlphaPreviewHalf displays half opaque / half checkerboard, instead of opaque. - ColorEditFlagsAlphaPreviewHalf ColorEditFlags = imgui.ColorEditFlagsAlphaPreviewHalf - // ColorEditFlagsHDR = (WIP) currently only disable 0.0f..1.0f limits in RGBA edition (note: you probably want to use - // ImGuiColorEditFlags_Float flag as well). - ColorEditFlagsHDR ColorEditFlags = imgui.ColorEditFlagsHDR - // ColorEditFlagsRGB sets the format as RGB. - ColorEditFlagsRGB ColorEditFlags = imgui.ColorEditFlagsRGB - // ColorEditFlagsHSV sets the format as HSV. - ColorEditFlagsHSV ColorEditFlags = imgui.ColorEditFlagsHSV - // ColorEditFlagsHEX sets the format as HEX. - ColorEditFlagsHEX ColorEditFlags = imgui.ColorEditFlagsHEX - // ColorEditFlagsUint8 _display_ values formatted as 0..255. - ColorEditFlagsUint8 ColorEditFlags = imgui.ColorEditFlagsUint8 - // ColorEditFlagsFloat _display_ values formatted as 0.0f..1.0f floats instead of 0..255 integers. No round-trip of value via integers. - ColorEditFlagsFloat ColorEditFlags = imgui.ColorEditFlagsFloat + ColorEditFlagsNone ColorEditFlags = ColorEditFlags(imgui.ColorEditFlagsNone) + // // ColorEdit, ColorPicker, ColorButton: ignore Alpha component (will only read 3 components from the input pointer). + ColorEditFlagsNoAlpha ColorEditFlags = ColorEditFlags(imgui.ColorEditFlagsNoAlpha) + // // ColorEdit: disable picker when clicking on color square. + ColorEditFlagsNoPicker ColorEditFlags = ColorEditFlags(imgui.ColorEditFlagsNoPicker) + // // ColorEdit: disable toggling options menu when right-clicking on inputs/small preview. + ColorEditFlagsNoOptions ColorEditFlags = ColorEditFlags(imgui.ColorEditFlagsNoOptions) + // // ColorEdit, ColorPicker: disable color square preview next to the inputs. (e.g. to show only the inputs) + ColorEditFlagsNoSmallPreview ColorEditFlags = ColorEditFlags(imgui.ColorEditFlagsNoSmallPreview) + // // ColorEdit, ColorPicker: disable inputs sliders/text widgets (e.g. to show only the small preview color square). + ColorEditFlagsNoInputs ColorEditFlags = ColorEditFlags(imgui.ColorEditFlagsNoInputs) + // // ColorEdit, ColorPicker, ColorButton: disable tooltip when hovering the preview. + ColorEditFlagsNoTooltip ColorEditFlags = ColorEditFlags(imgui.ColorEditFlagsNoTooltip) + // // ColorEdit, ColorPicker: disable display of inline text label (the label is still forwarded to the tooltip and picker). + ColorEditFlagsNoLabel ColorEditFlags = ColorEditFlags(imgui.ColorEditFlagsNoLabel) + // // ColorPicker: disable bigger color preview on right side of the picker, use small color square preview instead. + ColorEditFlagsNoSidePreview ColorEditFlags = ColorEditFlags(imgui.ColorEditFlagsNoSidePreview) + // // ColorEdit: disable drag and drop target. ColorButton: disable drag and drop source. + ColorEditFlagsNoDragDrop ColorEditFlags = ColorEditFlags(imgui.ColorEditFlagsNoDragDrop) + // // ColorButton: disable border (which is enforced by default) + ColorEditFlagsNoBorder ColorEditFlags = ColorEditFlags(imgui.ColorEditFlagsNoBorder) + // // ColorEdit, ColorPicker: show vertical alpha bar/gradient in picker. + ColorEditFlagsAlphaBar ColorEditFlags = ColorEditFlags(imgui.ColorEditFlagsAlphaBar) + // // ColorEdit, ColorPicker, ColorButton: display preview as a transparent color over a checkerboard, instead of opaque. + ColorEditFlagsAlphaPreview ColorEditFlags = ColorEditFlags(imgui.ColorEditFlagsAlphaPreview) + // // ColorEdit, ColorPicker, ColorButton: display half opaque / half checkerboard, instead of opaque. + ColorEditFlagsAlphaPreviewHalf ColorEditFlags = ColorEditFlags(imgui.ColorEditFlagsAlphaPreviewHalf) + // // (WIP) ColorEdit: Currently only disable 0.0f..1.0f limits in RGBA edition (note: you probably want to use ImGuiColorEditFlags_Float flag as well). + ColorEditFlagsHDR ColorEditFlags = ColorEditFlags(imgui.ColorEditFlagsHDR) + // [Display] // ColorEdit: override _display_ type among RGB/HSV/Hex. ColorPicker: select any combination using one or more of RGB/HSV/Hex. + ColorEditFlagsDisplayRGB ColorEditFlags = ColorEditFlags(imgui.ColorEditFlagsDisplayRGB) + // [Display] // ". + ColorEditFlagsDisplayHSV ColorEditFlags = ColorEditFlags(imgui.ColorEditFlagsDisplayHSV) + // [Display] // ". + ColorEditFlagsDisplayHex ColorEditFlags = ColorEditFlags(imgui.ColorEditFlagsDisplayHex) + // [DataType] // ColorEdit, ColorPicker, ColorButton: _display_ values formatted as 0..255. + ColorEditFlagsUint8 ColorEditFlags = ColorEditFlags(imgui.ColorEditFlagsUint8) + // [DataType] // ColorEdit, ColorPicker, ColorButton: _display_ values formatted as 0.0f..1.0f floats instead of 0..255 integers. No round-trip of value via integers. + ColorEditFlagsFloat ColorEditFlags = ColorEditFlags(imgui.ColorEditFlagsFloat) + // [Picker] // ColorPicker: bar for Hue, rectangle for Sat/Value. + ColorEditFlagsPickerHueBar ColorEditFlags = ColorEditFlags(imgui.ColorEditFlagsPickerHueBar) + // [Picker] // ColorPicker: wheel for Hue, triangle for Sat/Value. + ColorEditFlagsPickerHueWheel ColorEditFlags = ColorEditFlags(imgui.ColorEditFlagsPickerHueWheel) + // [Input] // ColorEdit, ColorPicker: input and output data in RGB format. + ColorEditFlagsInputRGB ColorEditFlags = ColorEditFlags(imgui.ColorEditFlagsInputRGB) + // [Input] // ColorEdit, ColorPicker: input and output data in HSV format. + ColorEditFlagsInputHSV ColorEditFlags = ColorEditFlags(imgui.ColorEditFlagsInputHSV) + ColorEditFlagsDefaultOptions ColorEditFlags = ColorEditFlags(imgui.ColorEditFlagsDefaultOptions) + ColorEditFlagsDisplayMask ColorEditFlags = ColorEditFlags(imgui.ColorEditFlagsDisplayMask) + ColorEditFlagsDataTypeMask ColorEditFlags = ColorEditFlags(imgui.ColorEditFlagsDataTypeMask) + ColorEditFlagsPickerMask ColorEditFlags = ColorEditFlags(imgui.ColorEditFlagsPickerMask) + ColorEditFlagsInputMask ColorEditFlags = ColorEditFlags(imgui.ColorEditFlagsInputMask) ) // TableFlags represents table flags. -type TableFlags int +type TableFlags imgui.TableFlags // Table flags enum:. const ( - TableFlagsNone TableFlags = TableFlags(imgui.TableFlags_None) - TableFlagsResizable TableFlags = TableFlags(imgui.TableFlags_Resizable) - TableFlagsReorderable TableFlags = TableFlags(imgui.TableFlags_Reorderable) - TableFlagsHideable TableFlags = TableFlags(imgui.TableFlags_Hideable) - TableFlagsSortable TableFlags = TableFlags(imgui.TableFlags_Sortable) - TableFlagsNoSavedSettings TableFlags = TableFlags(imgui.TableFlags_NoSavedSettings) - TableFlagsContextMenuInBody TableFlags = TableFlags(imgui.TableFlags_ContextMenuInBody) - TableFlagsRowBg TableFlags = TableFlags(imgui.TableFlags_RowBg) - TableFlagsBordersInnerH TableFlags = TableFlags(imgui.TableFlags_BordersInnerH) - TableFlagsBordersOuterH TableFlags = TableFlags(imgui.TableFlags_BordersOuterH) - TableFlagsBordersInnerV TableFlags = TableFlags(imgui.TableFlags_BordersInnerV) - TableFlagsBordersOuterV TableFlags = TableFlags(imgui.TableFlags_BordersOuterV) - TableFlagsBordersH TableFlags = TableFlags(imgui.TableFlags_BordersH) - TableFlagsBordersV TableFlags = TableFlags(imgui.TableFlags_BordersV) - TableFlagsBordersInner TableFlags = TableFlags(imgui.TableFlags_BordersInner) - TableFlagsBordersOuter TableFlags = TableFlags(imgui.TableFlags_BordersOuter) - TableFlagsBorders TableFlags = TableFlags(imgui.TableFlags_Borders) - TableFlagsNoBordersInBody TableFlags = TableFlags(imgui.TableFlags_NoBordersInBody) - TableFlagsNoBordersInBodyUntilResize TableFlags = TableFlags(imgui.TableFlags_NoBordersInBodyUntilResizeTableFlags) - TableFlagsSizingFixedFit TableFlags = TableFlags(imgui.TableFlags_SizingFixedFit) - TableFlagsSizingFixedSame TableFlags = TableFlags(imgui.TableFlags_SizingFixedSame) - TableFlagsSizingStretchProp TableFlags = TableFlags(imgui.TableFlags_SizingStretchProp) - TableFlagsSizingStretchSame TableFlags = TableFlags(imgui.TableFlags_SizingStretchSame) - TableFlagsNoHostExtendX TableFlags = TableFlags(imgui.TableFlags_NoHostExtendX) - TableFlagsNoHostExtendY TableFlags = TableFlags(imgui.TableFlags_NoHostExtendY) - TableFlagsNoKeepColumnsVisible TableFlags = TableFlags(imgui.TableFlags_NoKeepColumnsVisible) - TableFlagsPreciseWidths TableFlags = TableFlags(imgui.TableFlags_PreciseWidths) - TableFlagsNoClip TableFlags = TableFlags(imgui.TableFlags_NoClip) - TableFlagsPadOuterX TableFlags = TableFlags(imgui.TableFlags_PadOuterX) - TableFlagsNoPadOuterX TableFlags = TableFlags(imgui.TableFlags_NoPadOuterX) - TableFlagsNoPadInnerX TableFlags = TableFlags(imgui.TableFlags_NoPadInnerX) - TableFlagsScrollX TableFlags = TableFlags(imgui.TableFlags_ScrollX) - TableFlagsScrollY TableFlags = TableFlags(imgui.TableFlags_ScrollY) - TableFlagsSortMulti TableFlags = TableFlags(imgui.TableFlags_SortMulti) - TableFlagsSortTristate TableFlags = TableFlags(imgui.TableFlags_SortTristate) - TableFlagsSizingMask TableFlags = TableFlags(imgui.TableFlags_SizingMask_) + TableFlagsNone TableFlags = TableFlags(imgui.TableFlagsNone) + TableFlagsResizable TableFlags = TableFlags(imgui.TableFlagsResizable) + TableFlagsReorderable TableFlags = TableFlags(imgui.TableFlagsReorderable) + TableFlagsHideable TableFlags = TableFlags(imgui.TableFlagsHideable) + TableFlagsSortable TableFlags = TableFlags(imgui.TableFlagsSortable) + TableFlagsNoSavedSettings TableFlags = TableFlags(imgui.TableFlagsNoSavedSettings) + TableFlagsContextMenuInBody TableFlags = TableFlags(imgui.TableFlagsContextMenuInBody) + TableFlagsRowBg TableFlags = TableFlags(imgui.TableFlagsRowBg) + TableFlagsBordersInnerH TableFlags = TableFlags(imgui.TableFlagsBordersInnerH) + TableFlagsBordersOuterH TableFlags = TableFlags(imgui.TableFlagsBordersOuterH) + TableFlagsBordersInnerV TableFlags = TableFlags(imgui.TableFlagsBordersInnerV) + TableFlagsBordersOuterV TableFlags = TableFlags(imgui.TableFlagsBordersOuterV) + TableFlagsBordersH TableFlags = TableFlags(imgui.TableFlagsBordersH) + TableFlagsBordersV TableFlags = TableFlags(imgui.TableFlagsBordersV) + TableFlagsBordersInner TableFlags = TableFlags(imgui.TableFlagsBordersInner) + TableFlagsBordersOuter TableFlags = TableFlags(imgui.TableFlagsBordersOuter) + TableFlagsBorders TableFlags = TableFlags(imgui.TableFlagsBorders) + TableFlagsNoBordersInBody TableFlags = TableFlags(imgui.TableFlagsNoBordersInBody) + TableFlagsNoBordersInBodyUntilResize TableFlags = TableFlags(imgui.TableFlagsNoBordersInBodyUntilResize) + TableFlagsSizingFixedFit TableFlags = TableFlags(imgui.TableFlagsSizingFixedFit) + TableFlagsSizingFixedSame TableFlags = TableFlags(imgui.TableFlagsSizingFixedSame) + TableFlagsSizingStretchProp TableFlags = TableFlags(imgui.TableFlagsSizingStretchProp) + TableFlagsSizingStretchSame TableFlags = TableFlags(imgui.TableFlagsSizingStretchSame) + TableFlagsNoHostExtendX TableFlags = TableFlags(imgui.TableFlagsNoHostExtendX) + TableFlagsNoHostExtendY TableFlags = TableFlags(imgui.TableFlagsNoHostExtendY) + TableFlagsNoKeepColumnsVisible TableFlags = TableFlags(imgui.TableFlagsNoKeepColumnsVisible) + TableFlagsPreciseWidths TableFlags = TableFlags(imgui.TableFlagsPreciseWidths) + TableFlagsNoClip TableFlags = TableFlags(imgui.TableFlagsNoClip) + TableFlagsPadOuterX TableFlags = TableFlags(imgui.TableFlagsPadOuterX) + TableFlagsNoPadOuterX TableFlags = TableFlags(imgui.TableFlagsNoPadOuterX) + TableFlagsNoPadInnerX TableFlags = TableFlags(imgui.TableFlagsNoPadInnerX) + TableFlagsScrollX TableFlags = TableFlags(imgui.TableFlagsScrollX) + TableFlagsScrollY TableFlags = TableFlags(imgui.TableFlagsScrollY) + TableFlagsSortMulti TableFlags = TableFlags(imgui.TableFlagsSortMulti) + TableFlagsSortTristate TableFlags = TableFlags(imgui.TableFlagsSortTristate) + TableFlagsSizingMask TableFlags = TableFlags(imgui.TableFlagsSizingMask) ) // TableRowFlags represents table row flags. -type TableRowFlags int +type TableRowFlags imgui.TableRowFlags // table row flags:. const ( - TableRowFlagsNone TableRowFlags = TableRowFlags(imgui.TableRowFlags_None) + TableRowFlagsNone TableRowFlags = TableRowFlags(imgui.TableRowFlagsNone) // Identify header row (set default background color + width of its contents accounted different for auto column width). - TableRowFlagsHeaders TableRowFlags = TableRowFlags(imgui.TableRowFlags_Headers) + TableRowFlagsHeaders TableRowFlags = TableRowFlags(imgui.TableRowFlagsHeaders) ) // TableColumnFlags represents a flags for table column (see (*TableColumnWidget).Flags()). -type TableColumnFlags int +type TableColumnFlags imgui.TableColumnFlags // table column flags list. const ( // Input configuration flags. - TableColumnFlagsNone TableColumnFlags = TableColumnFlags(imgui.TableColumnFlags_None) - TableColumnFlagsDefaultHide TableColumnFlags = TableColumnFlags(imgui.TableColumnFlags_DefaultHide) - TableColumnFlagsDefaultSort TableColumnFlags = TableColumnFlags(imgui.TableColumnFlags_DefaultSort) - TableColumnFlagsWidthStretch TableColumnFlags = TableColumnFlags(imgui.TableColumnFlags_WidthStretch) - TableColumnFlagsWidthFixed TableColumnFlags = TableColumnFlags(imgui.TableColumnFlags_WidthFixed) - TableColumnFlagsNoResize TableColumnFlags = TableColumnFlags(imgui.TableColumnFlags_NoResize) - TableColumnFlagsNoReorder TableColumnFlags = TableColumnFlags(imgui.TableColumnFlags_NoReorder) - TableColumnFlagsNoHide TableColumnFlags = TableColumnFlags(imgui.TableColumnFlags_NoHide) - TableColumnFlagsNoClip TableColumnFlags = TableColumnFlags(imgui.TableColumnFlags_NoClip) - TableColumnFlagsNoSort TableColumnFlags = TableColumnFlags(imgui.TableColumnFlags_NoSort) - TableColumnFlagsNoSortAscending TableColumnFlags = TableColumnFlags(imgui.TableColumnFlags_NoSortAscending) - TableColumnFlagsNoSortDescending TableColumnFlags = TableColumnFlags(imgui.TableColumnFlags_NoSortDescending) - TableColumnFlagsNoHeaderWidth TableColumnFlags = TableColumnFlags(imgui.TableColumnFlags_NoHeaderWidth) - TableColumnFlagsPreferSortAscending TableColumnFlags = TableColumnFlags(imgui.TableColumnFlags_PreferSortAscending) - TableColumnFlagsPreferSortDescending TableColumnFlags = TableColumnFlags(imgui.TableColumnFlags_PreferSortDescending) - TableColumnFlagsIndentEnable TableColumnFlags = TableColumnFlags(imgui.TableColumnFlags_IndentEnable) - TableColumnFlagsIndentDisable TableColumnFlags = TableColumnFlags(imgui.TableColumnFlags_IndentDisable) + TableColumnFlagsNone TableColumnFlags = TableColumnFlags(imgui.TableColumnFlagsNone) + TableColumnFlagsDefaultHide TableColumnFlags = TableColumnFlags(imgui.TableColumnFlagsDefaultHide) + TableColumnFlagsDefaultSort TableColumnFlags = TableColumnFlags(imgui.TableColumnFlagsDefaultSort) + TableColumnFlagsWidthStretch TableColumnFlags = TableColumnFlags(imgui.TableColumnFlagsWidthStretch) + TableColumnFlagsWidthFixed TableColumnFlags = TableColumnFlags(imgui.TableColumnFlagsWidthFixed) + TableColumnFlagsNoResize TableColumnFlags = TableColumnFlags(imgui.TableColumnFlagsNoResize) + TableColumnFlagsNoReorder TableColumnFlags = TableColumnFlags(imgui.TableColumnFlagsNoReorder) + TableColumnFlagsNoHide TableColumnFlags = TableColumnFlags(imgui.TableColumnFlagsNoHide) + TableColumnFlagsNoClip TableColumnFlags = TableColumnFlags(imgui.TableColumnFlagsNoClip) + TableColumnFlagsNoSort TableColumnFlags = TableColumnFlags(imgui.TableColumnFlagsNoSort) + TableColumnFlagsNoSortAscending TableColumnFlags = TableColumnFlags(imgui.TableColumnFlagsNoSortAscending) + TableColumnFlagsNoSortDescending TableColumnFlags = TableColumnFlags(imgui.TableColumnFlagsNoSortDescending) + TableColumnFlagsNoHeaderWidth TableColumnFlags = TableColumnFlags(imgui.TableColumnFlagsNoHeaderWidth) + TableColumnFlagsPreferSortAscending TableColumnFlags = TableColumnFlags(imgui.TableColumnFlagsPreferSortAscending) + TableColumnFlagsPreferSortDescending TableColumnFlags = TableColumnFlags(imgui.TableColumnFlagsPreferSortDescending) + TableColumnFlagsIndentEnable TableColumnFlags = TableColumnFlags(imgui.TableColumnFlagsIndentEnable) + TableColumnFlagsIndentDisable TableColumnFlags = TableColumnFlags(imgui.TableColumnFlagsIndentDisable) // Output status flags read-only via TableGetColumnFlags(). - TableColumnFlagsIsEnabled TableColumnFlags = TableColumnFlags(imgui.TableColumnFlags_IsEnabled) - TableColumnFlagsIsVisible TableColumnFlags = TableColumnFlags(imgui.TableColumnFlags_IsVisible) - TableColumnFlagsIsSorted TableColumnFlags = TableColumnFlags(imgui.TableColumnFlags_IsSorted) - TableColumnFlagsIsHovered TableColumnFlags = TableColumnFlags(imgui.TableColumnFlags_IsHovered) + TableColumnFlagsIsEnabled TableColumnFlags = TableColumnFlags(imgui.TableColumnFlagsIsEnabled) + TableColumnFlagsIsVisible TableColumnFlags = TableColumnFlags(imgui.TableColumnFlagsIsVisible) + TableColumnFlagsIsSorted TableColumnFlags = TableColumnFlags(imgui.TableColumnFlagsIsSorted) + TableColumnFlagsIsHovered TableColumnFlags = TableColumnFlags(imgui.TableColumnFlagsIsHovered) // [Internal] Combinations and masks. - TableColumnFlagsWidthMask TableColumnFlags = TableColumnFlags(imgui.TableColumnFlags_WidthMask_) - TableColumnFlagsIndentMask TableColumnFlags = TableColumnFlags(imgui.TableColumnFlags_IndentMask_) - TableColumnFlagsStatusMask TableColumnFlags = TableColumnFlags(imgui.TableColumnFlags_StatusMask_) - TableColumnFlagsNoDirectResize TableColumnFlags = TableColumnFlags(imgui.TableColumnFlags_NoDirectResize_) + TableColumnFlagsWidthMask TableColumnFlags = TableColumnFlags(imgui.TableColumnFlagsWidthMask) + TableColumnFlagsIndentMask TableColumnFlags = TableColumnFlags(imgui.TableColumnFlagsIndentMask) + TableColumnFlagsStatusMask TableColumnFlags = TableColumnFlags(imgui.TableColumnFlagsStatusMask) + TableColumnFlagsNoDirectResize TableColumnFlags = TableColumnFlags(imgui.TableColumnFlagsNoDirectResize) ) -// SliderFlags represents imgui.SliderFlags -// TODO: Hard-reffer to these constants. -type SliderFlags int +// SliderFlags represents imgui.SliderFlags. +type SliderFlags imgui.SliderFlags // slider flags. const ( - SliderFlagsNone SliderFlags = 0 + SliderFlagsNone SliderFlags = imgui.SliderFlagsNone // Clamp value to min/max bounds when input manually with CTRL+Click. By default CTRL+Click allows going out of bounds. - SliderFlagsAlwaysClamp SliderFlags = 1 << 4 - // Make the widget logarithmic (linear otherwise). Consider using ImGuiSliderFlagsNoRoundToFormat with this if using + SliderFlagsAlwaysClamp SliderFlags = imgui.SliderFlagsAlwaysClamp + // Make the widget logarithmic (linear otherwise). Consider using ImGuiSliderFlagsNoRoundToFormat SliderFlags = imgui.SliderFlagsNoRoundToFormat // a format-string with small amount of digits. - SliderFlagsLogarithmic SliderFlags = 1 << 5 + SliderFlagsLogarithmic SliderFlags = imgui.SliderFlagsLogarithmic // Disable rounding underlying value to match precision of the display format string (e.g. %.3f values are rounded to those 3 digits). - SliderFlagsNoRoundToFormat SliderFlags = 1 << 6 + SliderFlagsNoRoundToFormat SliderFlags = imgui.SliderFlagsNoRoundToFormat // Disable CTRL+Click or Enter key allowing to input text directly into the widget. - SliderFlagsNoInput SliderFlags = 1 << 7 + SliderFlagsNoInput SliderFlags = imgui.SliderFlagsNoInput // [Internal] We treat using those bits as being potentially a 'float power' argument from the previous API that has got miscast // to this enum, and will trigger an assert if needed. - SliderFlagsInvalidMask SliderFlags = 0x7000000F + SliderFlagsInvalidMask SliderFlags = imgui.SliderFlagsInvalidMask ) -// PlotFlags represents imgui.ImPlotFlags. -type PlotFlags int +// PlotFlags represents imgui.PlotFlags. +type PlotFlags imgui.PlotFlags // plot flags. const ( - PlotFlagsNone = PlotFlags(imgui.ImPlotFlags_None) - PlotFlagsNoTitle = PlotFlags(imgui.ImPlotFlags_NoTitle) - PlotFlagsNoLegend = PlotFlags(imgui.ImPlotFlags_NoLegend) - PlotFlagsNoMenus = PlotFlags(imgui.ImPlotFlags_NoMenus) - PlotFlagsNoBoxSelect = PlotFlags(imgui.ImPlotFlags_NoBoxSelect) - PlotFlagsNoMousePos = PlotFlags(imgui.ImPlotFlags_NoMousePos) - PlotFlagsNoHighlight = PlotFlags(imgui.ImPlotFlags_NoHighlight) - PlotFlagsNoChild = PlotFlags(imgui.ImPlotFlags_NoChild) - PlotFlagsEqual = PlotFlags(imgui.ImPlotFlags_Equal) - PlotFlagsYAxis2 = PlotFlags(imgui.ImPlotFlags_YAxis2) - PlotFlagsYAxis3 = PlotFlags(imgui.ImPlotFlags_YAxis3) - PlotFlagsQuery = PlotFlags(imgui.ImPlotFlags_Query) - PlotFlagsCrosshairs = PlotFlags(imgui.ImPlotFlags_Crosshairs) - PlotFlagsAntiAliased = PlotFlags(imgui.ImPlotFlags_AntiAliased) - PlotFlagsCanvasOnly = PlotFlags(imgui.ImPlotFlags_CanvasOnly) + PlotFlagsNone = PlotFlags(imgui.PlotFlagsNone) + PlotFlagsNoTitle = PlotFlags(imgui.PlotFlagsNoTitle) + PlotFlagsNoLegend = PlotFlags(imgui.PlotFlagsNoLegend) + PlotFlagsNoMenus = PlotFlags(imgui.PlotFlagsNoMenus) + PlotFlagsNoBoxSelect = PlotFlags(imgui.PlotFlagsNoBoxSelect) + // PlotFlagsNoMousePos = PlotFlags(imgui.PlotFlagsNoMousePos) + // PlotFlagsNoHighlight = PlotFlags(imgui.PlotFlagsNoHighlight) + // PlotFlagsNoChild = PlotFlags(imgui.PlotFlagsNoChild). + PlotFlagsEqual = PlotFlags(imgui.PlotFlagsEqual) + // PlotFlagsYAxis2 = PlotFlags(imgui.PlotFlagsYAxis2) + // PlotFlagsYAxis3 = PlotFlags(imgui.PlotFlagsYAxis3) + // PlotFlagsQuery = PlotFlags(imgui.PlotFlagsQuery) + PlotFlagsCrosshairs = PlotFlags(imgui.PlotFlagsCrosshairs) + // PlotFlagsAntiAliased = PlotFlags(imgui.PlotFlagsAntiAliased) + PlotFlagsCanvasOnly = PlotFlags(imgui.PlotFlagsCanvasOnly) ) -// PlotAxisFlags represents imgui.ImPlotAxisFlags. -type PlotAxisFlags int +// PlotAxisFlags represents imgui.PlotAxisFlags. +type PlotAxisFlags imgui.PlotAxisFlags // plot axis flags. const ( - PlotAxisFlagsNone PlotAxisFlags = PlotAxisFlags(imgui.ImPlotAxisFlags_None) - PlotAxisFlagsNoLabel PlotAxisFlags = PlotAxisFlags(imgui.ImPlotAxisFlags_NoLabel) - PlotAxisFlagsNoGridLines PlotAxisFlags = PlotAxisFlags(imgui.ImPlotAxisFlags_NoGridLines) - PlotAxisFlagsNoTickMarks PlotAxisFlags = PlotAxisFlags(imgui.ImPlotAxisFlags_NoTickMarks) - PlotAxisFlagsNoTickLabels PlotAxisFlags = PlotAxisFlags(imgui.ImPlotAxisFlags_NoTickLabels) - PlotAxisFlagsForeground PlotAxisFlags = PlotAxisFlags(imgui.ImPlotAxisFlags_Foreground) - PlotAxisFlagsLogScale PlotAxisFlags = PlotAxisFlags(imgui.ImPlotAxisFlags_LogScale) - PlotAxisFlagsTime PlotAxisFlags = PlotAxisFlags(imgui.ImPlotAxisFlags_Time) - PlotAxisFlagsInvert PlotAxisFlags = PlotAxisFlags(imgui.ImPlotAxisFlags_Invert) - PlotAxisFlagsNoInitialFit PlotAxisFlags = PlotAxisFlags(imgui.ImPlotAxisFlags_NoInitialFit) - PlotAxisFlagsAutoFit PlotAxisFlags = PlotAxisFlags(imgui.ImPlotAxisFlags_AutoFit) - PlotAxisFlagsRangeFit PlotAxisFlags = PlotAxisFlags(imgui.ImPlotAxisFlags_RangeFit) - PlotAxisFlagsLockMin PlotAxisFlags = PlotAxisFlags(imgui.ImPlotAxisFlags_LockMin) - PlotAxisFlagsLockMax PlotAxisFlags = PlotAxisFlags(imgui.ImPlotAxisFlags_LockMax) - PlotAxisFlagsLock PlotAxisFlags = PlotAxisFlags(imgui.ImPlotAxisFlags_Lock) - PlotAxisFlagsNoDecorations PlotAxisFlags = PlotAxisFlags(imgui.ImPlotAxisFlags_NoDecorations) + PlotAxisFlagsNone PlotAxisFlags = PlotAxisFlags(imgui.PlotAxisFlagsNone) + PlotAxisFlagsNoLabel PlotAxisFlags = PlotAxisFlags(imgui.PlotAxisFlagsNoLabel) + PlotAxisFlagsNoGridLines PlotAxisFlags = PlotAxisFlags(imgui.PlotAxisFlagsNoGridLines) + PlotAxisFlagsNoTickMarks PlotAxisFlags = PlotAxisFlags(imgui.PlotAxisFlagsNoTickMarks) + PlotAxisFlagsNoTickLabels PlotAxisFlags = PlotAxisFlags(imgui.PlotAxisFlagsNoTickLabels) + PlotAxisFlagsForeground PlotAxisFlags = PlotAxisFlags(imgui.PlotAxisFlagsForeground) + // PlotAxisFlagsLogScale PlotAxisFlags = PlotAxisFlags(imgui.PlotAxisFlagsLogScale) + // PlotAxisFlagsTime PlotAxisFlags = PlotAxisFlags(imgui.PlotAxisFlagsTime) + PlotAxisFlagsInvert PlotAxisFlags = PlotAxisFlags(imgui.PlotAxisFlagsInvert) + PlotAxisFlagsNoInitialFit PlotAxisFlags = PlotAxisFlags(imgui.PlotAxisFlagsNoInitialFit) + PlotAxisFlagsAutoFit PlotAxisFlags = PlotAxisFlags(imgui.PlotAxisFlagsAutoFit) + PlotAxisFlagsRangeFit PlotAxisFlags = PlotAxisFlags(imgui.PlotAxisFlagsRangeFit) + PlotAxisFlagsLockMin PlotAxisFlags = PlotAxisFlags(imgui.PlotAxisFlagsLockMin) + PlotAxisFlagsLockMax PlotAxisFlags = PlotAxisFlags(imgui.PlotAxisFlagsLockMax) + PlotAxisFlagsLock PlotAxisFlags = PlotAxisFlags(imgui.PlotAxisFlagsLock) + PlotAxisFlagsNoDecorations PlotAxisFlags = PlotAxisFlags(imgui.PlotAxisFlagsNoDecorations) ) diff --git a/FontAtlasProsessor.go b/FontAtlasProsessor.go index a485bde6..21d5a553 100644 --- a/FontAtlasProsessor.go +++ b/FontAtlasProsessor.go @@ -6,9 +6,10 @@ import ( "runtime" "strings" "sync" + "unsafe" + imgui "github.com/AllenDang/cimgui-go" "github.com/AllenDang/go-findfont" - "github.com/AllenDang/imgui-go" ) const ( @@ -241,7 +242,7 @@ func (a *FontAtlas) rebuildFontAtlas() { } fonts := Context.IO().Fonts() - fonts.Clear() + // fonts.Clear() /// TODO: I'm commenting this out, because it produces panic. var sb strings.Builder @@ -254,7 +255,7 @@ func (a *FontAtlas) rebuildFontAtlas() { return true }) - ranges := imgui.NewGlyphRanges() + ranges := imgui.NewGlyphRange() builder := imgui.NewFontGlyphRangesBuilder() // Because we pre-registered numbers, so default string map's length should greater then 11. @@ -279,18 +280,26 @@ func (a *FontAtlas) rebuildFontAtlas() { // Scale font size with DPI scale factor if runtime.GOOS == windows { - fontInfo.size *= Context.GetPlatform().GetContentScale() + xScale, _ := Context.backend.ContentScale() + fontInfo.size *= xScale } if len(fontInfo.fontByte) == 0 { fonts.AddFontFromFileTTFV(fontInfo.fontPath, fontInfo.size, fontConfig, ranges.Data()) } else { - fonts.AddFontFromMemoryTTFV(fontInfo.fontByte, fontInfo.size, fontConfig, ranges.Data()) + fontConfig.SetFontDataOwnedByAtlas(false) + fonts.AddFontFromMemoryTTFV( + unsafe.Pointer(imgui.SliceToPtr(fontInfo.fontByte)), //nolint:gosec // we need this here + int32(len(fontInfo.fontByte)), + fontInfo.size, + fontConfig, + ranges.Data(), + ) } } // Fall back if no font is added - if fonts.GetFontCount() == 0 { + if fonts.FontCount() == 0 { fonts.AddFontDefault() } } else { @@ -301,22 +310,38 @@ func (a *FontAtlas) rebuildFontAtlas() { for _, fontInfo := range a.extraFonts { // Scale font size with DPI scale factor if runtime.GOOS == windows { - fontInfo.size *= Context.GetPlatform().GetContentScale() + xScale, _ := Context.backend.ContentScale() + fontInfo.size *= xScale } // Store imgui.Font for PushFont - var f imgui.Font + var f *imgui.Font if len(fontInfo.fontByte) == 0 { - f = fonts.AddFontFromFileTTFV(fontInfo.fontPath, fontInfo.size, imgui.DefaultFontConfig, ranges.Data()) + f = fonts.AddFontFromFileTTFV( + fontInfo.fontPath, + fontInfo.size, + imgui.NewFontConfig(), + ranges.Data(), + ) } else { - f = fonts.AddFontFromMemoryTTFV(fontInfo.fontByte, fontInfo.size, imgui.DefaultFontConfig, ranges.Data()) + fontConfig := imgui.NewFontConfig() + fontConfig.SetFontDataOwnedByAtlas(false) + f = fonts.AddFontFromMemoryTTFV( + unsafe.Pointer(imgui.SliceToPtr(fontInfo.fontByte)), //nolint:gosec // we need this here + int32(len(fontInfo.fontByte)), + fontInfo.size, + fontConfig, + ranges.Data(), + ) } - a.extraFontMap[fontInfo.String()] = &f + a.extraFontMap[fontInfo.String()] = f } - fontTextureImg := fonts.TextureDataRGBA32() - Context.renderer.SetFontTexture(fontTextureImg) + fontTextureImg, w, h, _ := fonts.GetTextureDataAsRGBA32() + tex := Context.backend.CreateTexture(fontTextureImg, int(w), int(h)) + fonts.SetTexID(tex) + fonts.SetTexReady(true) a.shouldRebuildFontAtlas = false } diff --git a/ImageWidgets.go b/ImageWidgets.go index 5b3acda6..d31590e8 100644 --- a/ImageWidgets.go +++ b/ImageWidgets.go @@ -8,7 +8,7 @@ import ( "net/http" "time" - "github.com/AllenDang/imgui-go" + imgui "github.com/AllenDang/cimgui-go" ) var _ Widget = &ImageWidget{} @@ -66,8 +66,7 @@ func (i *ImageWidget) OnClick(cb func()) *ImageWidget { // Size sets image size. func (i *ImageWidget) Size(width, height float32) *ImageWidget { // Size image with DPI scaling - factor := Context.GetPlatform().GetContentScale() - i.width, i.height = width*factor, height*factor + i.width, i.height = width, height return i } @@ -85,7 +84,7 @@ func (i *ImageWidget) Build() { size.Y = rect.Y } - if i.texture == nil || i.texture.id == 0 { + if i.texture == nil || i.texture.tex == nil { Dummy(size.X, size.Y).Build() return } @@ -103,7 +102,7 @@ func (i *ImageWidget) Build() { } } - imgui.ImageV(i.texture.id, size, i.uv0, i.uv1, ToVec4Color(i.tintColor), ToVec4Color(i.borderColor)) + imgui.ImageV(i.texture.tex.ID(), size, i.uv0, i.uv1, ToVec4Color(i.tintColor), ToVec4Color(i.borderColor)) } type imageState struct { @@ -299,13 +298,13 @@ func (i *ImageWithURLWidget) Size(width, height float32) *ImageWithURLWidget { // LayoutForLoading allows to set layout rendered while loading an image. func (i *ImageWithURLWidget) LayoutForLoading(widgets ...Widget) *ImageWithURLWidget { - i.whenLoading = Layout(widgets) + i.whenLoading = widgets return i } // LayoutForFailure allows to specify layout when image failed to download. func (i *ImageWithURLWidget) LayoutForFailure(widgets ...Widget) *ImageWithURLWidget { - i.whenFailure = Layout(widgets) + i.whenFailure = widgets return i } @@ -360,7 +359,7 @@ func (i *ImageWithURLWidget) Build() { rgba := ImageToRgba(img) - NewTextureFromRgba(rgba, func(tex *Texture) { + EnqueueNewTextureFromRgba(rgba, func(tex *Texture) { SetState(Context, i.id, &imageState{ loading: false, failure: false, diff --git a/Keycode.go b/Keycode.go index a861814f..038c81f1 100644 --- a/Keycode.go +++ b/Keycode.go @@ -1,156 +1,229 @@ package giu -import "github.com/go-gl/glfw/v3.3/glfw" +import ( + "log" -// Key represents a glfw key. -type Key glfw.Key + imgui "github.com/AllenDang/cimgui-go" +) + +// Key represents a imgui key. +type Key imgui.Key // These key codes are inspired by the USB HID Usage Tables v1.12 (p. 53-60), // but re-arranged to map to 7-bit ASCII for printable keys (function keys are // put in the 256+ range). const ( - KeyUnknown Key = Key(glfw.KeyUnknown) - KeySpace Key = Key(glfw.KeySpace) - KeyApostrophe Key = Key(glfw.KeyApostrophe) - KeyComma Key = Key(glfw.KeyComma) - KeyMinus Key = Key(glfw.KeyMinus) - KeyPeriod Key = Key(glfw.KeyPeriod) - KeySlash Key = Key(glfw.KeySlash) - Key0 Key = Key(glfw.Key0) - Key1 Key = Key(glfw.Key1) - Key2 Key = Key(glfw.Key2) - Key3 Key = Key(glfw.Key3) - Key4 Key = Key(glfw.Key4) - Key5 Key = Key(glfw.Key5) - Key6 Key = Key(glfw.Key6) - Key7 Key = Key(glfw.Key7) - Key8 Key = Key(glfw.Key8) - Key9 Key = Key(glfw.Key9) - KeySemicolon Key = Key(glfw.KeySemicolon) - KeyEqual Key = Key(glfw.KeyEqual) - KeyA Key = Key(glfw.KeyA) - KeyB Key = Key(glfw.KeyB) - KeyC Key = Key(glfw.KeyC) - KeyD Key = Key(glfw.KeyD) - KeyE Key = Key(glfw.KeyE) - KeyF Key = Key(glfw.KeyF) - KeyG Key = Key(glfw.KeyG) - KeyH Key = Key(glfw.KeyH) - KeyI Key = Key(glfw.KeyI) - KeyJ Key = Key(glfw.KeyJ) - KeyK Key = Key(glfw.KeyK) - KeyL Key = Key(glfw.KeyL) - KeyM Key = Key(glfw.KeyM) - KeyN Key = Key(glfw.KeyN) - KeyO Key = Key(glfw.KeyO) - KeyP Key = Key(glfw.KeyP) - KeyQ Key = Key(glfw.KeyQ) - KeyR Key = Key(glfw.KeyR) - KeyS Key = Key(glfw.KeyS) - KeyT Key = Key(glfw.KeyT) - KeyU Key = Key(glfw.KeyU) - KeyV Key = Key(glfw.KeyV) - KeyW Key = Key(glfw.KeyW) - KeyX Key = Key(glfw.KeyX) - KeyY Key = Key(glfw.KeyY) - KeyZ Key = Key(glfw.KeyZ) - KeyLeftBracket Key = Key(glfw.KeyLeftBracket) - KeyBackslash Key = Key(glfw.KeyBackslash) - KeyRightBracket Key = Key(glfw.KeyRightBracket) - KeyGraveAccent Key = Key(glfw.KeyGraveAccent) - KeyWorld1 Key = Key(glfw.KeyWorld1) - KeyWorld2 Key = Key(glfw.KeyWorld2) - KeyEscape Key = Key(glfw.KeyEscape) - KeyEnter Key = Key(glfw.KeyEnter) - KeyTab Key = Key(glfw.KeyTab) - KeyBackspace Key = Key(glfw.KeyBackspace) - KeyInsert Key = Key(glfw.KeyInsert) - KeyDelete Key = Key(glfw.KeyDelete) - KeyRight Key = Key(glfw.KeyRight) - KeyLeft Key = Key(glfw.KeyLeft) - KeyDown Key = Key(glfw.KeyDown) - KeyUp Key = Key(glfw.KeyUp) - KeyPageUp Key = Key(glfw.KeyPageUp) - KeyPageDown Key = Key(glfw.KeyPageDown) - KeyHome Key = Key(glfw.KeyHome) - KeyEnd Key = Key(glfw.KeyEnd) - KeyCapsLock Key = Key(glfw.KeyCapsLock) - KeyScrollLock Key = Key(glfw.KeyScrollLock) - KeyNumLock Key = Key(glfw.KeyNumLock) - KeyPrintScreen Key = Key(glfw.KeyPrintScreen) - KeyPause Key = Key(glfw.KeyPause) - KeyF1 Key = Key(glfw.KeyF1) - KeyF2 Key = Key(glfw.KeyF2) - KeyF3 Key = Key(glfw.KeyF3) - KeyF4 Key = Key(glfw.KeyF4) - KeyF5 Key = Key(glfw.KeyF5) - KeyF6 Key = Key(glfw.KeyF6) - KeyF7 Key = Key(glfw.KeyF7) - KeyF8 Key = Key(glfw.KeyF8) - KeyF9 Key = Key(glfw.KeyF9) - KeyF10 Key = Key(glfw.KeyF10) - KeyF11 Key = Key(glfw.KeyF11) - KeyF12 Key = Key(glfw.KeyF12) - KeyF13 Key = Key(glfw.KeyF13) - KeyF14 Key = Key(glfw.KeyF14) - KeyF15 Key = Key(glfw.KeyF15) - KeyF16 Key = Key(glfw.KeyF16) - KeyF17 Key = Key(glfw.KeyF17) - KeyF18 Key = Key(glfw.KeyF18) - KeyF19 Key = Key(glfw.KeyF19) - KeyF20 Key = Key(glfw.KeyF20) - KeyF21 Key = Key(glfw.KeyF21) - KeyF22 Key = Key(glfw.KeyF22) - KeyF23 Key = Key(glfw.KeyF23) - KeyF24 Key = Key(glfw.KeyF24) - KeyF25 Key = Key(glfw.KeyF25) - KeyKP0 Key = Key(glfw.KeyKP0) - KeyKP1 Key = Key(glfw.KeyKP1) - KeyKP2 Key = Key(glfw.KeyKP2) - KeyKP3 Key = Key(glfw.KeyKP3) - KeyKP4 Key = Key(glfw.KeyKP4) - KeyKP5 Key = Key(glfw.KeyKP5) - KeyKP6 Key = Key(glfw.KeyKP6) - KeyKP7 Key = Key(glfw.KeyKP7) - KeyKP8 Key = Key(glfw.KeyKP8) - KeyKP9 Key = Key(glfw.KeyKP9) - KeyKPDecimal Key = Key(glfw.KeyKPDecimal) - KeyKPDivide Key = Key(glfw.KeyKPDivide) - KeyKPMultiply Key = Key(glfw.KeyKPMultiply) - KeyKPSubtract Key = Key(glfw.KeyKPSubtract) - KeyKPAdd Key = Key(glfw.KeyKPAdd) - KeyKPEnter Key = Key(glfw.KeyKPEnter) - KeyKPEqual Key = Key(glfw.KeyKPEqual) - KeyLeftShift Key = Key(glfw.KeyLeftShift) - KeyLeftControl Key = Key(glfw.KeyLeftControl) - KeyLeftAlt Key = Key(glfw.KeyLeftAlt) - KeyLeftSuper Key = Key(glfw.KeyLeftSuper) - KeyRightShift Key = Key(glfw.KeyRightShift) - KeyRightControl Key = Key(glfw.KeyRightControl) - KeyRightAlt Key = Key(glfw.KeyRightAlt) - KeyRightSuper Key = Key(glfw.KeyRightSuper) - KeyMenu Key = Key(glfw.KeyMenu) - KeyLast Key = Key(glfw.KeyLast) + KeyNone Key = Key(imgui.KeyNone) + KeySpace Key = Key(imgui.KeySpace) + KeyApostrophe Key = Key(imgui.KeyApostrophe) + KeyComma Key = Key(imgui.KeyComma) + KeyMinus Key = Key(imgui.KeyMinus) + KeyPeriod Key = Key(imgui.KeyPeriod) + KeySlash Key = Key(imgui.KeySlash) + Key0 Key = Key(imgui.Key0) + Key1 Key = Key(imgui.Key1) + Key2 Key = Key(imgui.Key2) + Key3 Key = Key(imgui.Key3) + Key4 Key = Key(imgui.Key4) + Key5 Key = Key(imgui.Key5) + Key6 Key = Key(imgui.Key6) + Key7 Key = Key(imgui.Key7) + Key8 Key = Key(imgui.Key8) + Key9 Key = Key(imgui.Key9) + KeySemicolon Key = Key(imgui.KeySemicolon) + KeyEqual Key = Key(imgui.KeyEqual) + KeyA Key = Key(imgui.KeyA) + KeyB Key = Key(imgui.KeyB) + KeyC Key = Key(imgui.KeyC) + KeyD Key = Key(imgui.KeyD) + KeyE Key = Key(imgui.KeyE) + KeyF Key = Key(imgui.KeyF) + KeyG Key = Key(imgui.KeyG) + KeyH Key = Key(imgui.KeyH) + KeyI Key = Key(imgui.KeyI) + KeyJ Key = Key(imgui.KeyJ) + KeyK Key = Key(imgui.KeyK) + KeyL Key = Key(imgui.KeyL) + KeyM Key = Key(imgui.KeyM) + KeyN Key = Key(imgui.KeyN) + KeyO Key = Key(imgui.KeyO) + KeyP Key = Key(imgui.KeyP) + KeyQ Key = Key(imgui.KeyQ) + KeyR Key = Key(imgui.KeyR) + KeyS Key = Key(imgui.KeyS) + KeyT Key = Key(imgui.KeyT) + KeyU Key = Key(imgui.KeyU) + KeyV Key = Key(imgui.KeyV) + KeyW Key = Key(imgui.KeyW) + KeyX Key = Key(imgui.KeyX) + KeyY Key = Key(imgui.KeyY) + KeyZ Key = Key(imgui.KeyZ) + KeyLeftBracket Key = Key(imgui.KeyLeftBracket) + KeyBackslash Key = Key(imgui.KeyBackslash) + KeyRightBracket Key = Key(imgui.KeyRightBracket) + KeyGraveAccent Key = Key(imgui.KeyGraveAccent) + KeyEscape Key = Key(imgui.KeyEscape) + KeyEnter Key = Key(imgui.KeyEnter) + KeyTab Key = Key(imgui.KeyTab) + KeyBackspace Key = Key(imgui.KeyBackspace) + KeyInsert = Key(imgui.KeyInsert) + KeyDelete = Key(imgui.KeyDelete) + KeyRight = Key(imgui.KeyRightArrow) + KeyLeft = Key(imgui.KeyLeftArrow) + KeyDown = Key(imgui.KeyDownArrow) + KeyUp = Key(imgui.KeyUpArrow) + KeyPageUp = Key(imgui.KeyPageUp) + KeyPageDown = Key(imgui.KeyPageDown) + KeyHome = Key(imgui.KeyHome) + KeyEnd = Key(imgui.KeyEnd) + KeyCapsLock = Key(imgui.KeyCapsLock) + KeyScrollLock = Key(imgui.KeyScrollLock) + KeyNumLock = Key(imgui.KeyNumLock) + KeyPrintScreen = Key(imgui.KeyPrintScreen) + KeyPause = Key(imgui.KeyPause) + KeyF1 = Key(imgui.KeyF1) + KeyF2 = Key(imgui.KeyF2) + KeyF3 = Key(imgui.KeyF3) + KeyF4 = Key(imgui.KeyF4) + KeyF5 = Key(imgui.KeyF5) + KeyF6 = Key(imgui.KeyF6) + KeyF7 = Key(imgui.KeyF7) + KeyF8 = Key(imgui.KeyF8) + KeyF9 = Key(imgui.KeyF9) + KeyF10 = Key(imgui.KeyF10) + KeyF11 = Key(imgui.KeyF11) + KeyF12 = Key(imgui.KeyF12) + KeyLeftShift = Key(imgui.KeyLeftShift) + KeyLeftControl = Key(imgui.KeyLeftCtrl) + KeyLeftAlt = Key(imgui.KeyLeftAlt) + KeyLeftSuper = Key(imgui.KeyLeftSuper) + KeyRightShift = Key(imgui.KeyRightShift) + KeyRightControl = Key(imgui.KeyRightCtrl) + KeyRightAlt = Key(imgui.KeyRightAlt) + KeyRightSuper = Key(imgui.KeyRightSuper) + KeyMenu = Key(imgui.KeyMenu) ) -// Modifier represents glfw.Modifier. -type Modifier glfw.ModifierKey +// refer glfw3.h. +func keyFromGLFWKey(k imgui.GLFWKey) Key { + data := map[imgui.GLFWKey]Key{ + imgui.GLFWKeySpace: KeySpace, + imgui.GLFWKeyApostrophe: KeyApostrophe, + imgui.GLFWKeyComma: KeyComma, + imgui.GLFWKeyMinus: KeyMinus, + imgui.GLFWKeyPeriod: KeyPeriod, + imgui.GLFWKeySlash: KeySlash, + imgui.GLFWKey0: Key0, + imgui.GLFWKey1: Key1, + imgui.GLFWKey2: Key2, + imgui.GLFWKey3: Key3, + imgui.GLFWKey4: Key4, + imgui.GLFWKey5: Key5, + imgui.GLFWKey6: Key6, + imgui.GLFWKey7: Key7, + imgui.GLFWKey8: Key8, + imgui.GLFWKey9: Key9, + imgui.GLFWKeySemicolon: KeySemicolon, + imgui.GLFWKeyEqual: KeyEqual, + imgui.GLFWKeyA: KeyA, + imgui.GLFWKeyB: KeyB, + imgui.GLFWKeyC: KeyC, + imgui.GLFWKeyD: KeyD, + imgui.GLFWKeyE: KeyE, + imgui.GLFWKeyF: KeyF, + imgui.GLFWKeyG: KeyG, + imgui.GLFWKeyH: KeyH, + imgui.GLFWKeyI: KeyI, + imgui.GLFWKeyJ: KeyJ, + imgui.GLFWKeyK: KeyK, + imgui.GLFWKeyL: KeyL, + imgui.GLFWKeyM: KeyM, + imgui.GLFWKeyN: KeyN, + imgui.GLFWKeyO: KeyO, + imgui.GLFWKeyP: KeyP, + imgui.GLFWKeyQ: KeyQ, + imgui.GLFWKeyR: KeyR, + imgui.GLFWKeyS: KeyS, + imgui.GLFWKeyT: KeyT, + imgui.GLFWKeyU: KeyU, + imgui.GLFWKeyV: KeyV, + imgui.GLFWKeyW: KeyW, + imgui.GLFWKeyX: KeyX, + imgui.GLFWKeyY: KeyY, + imgui.GLFWKeyZ: KeyZ, + imgui.GLFWKeyLeftBracket: KeyLeftBracket, + imgui.GLFWKeyBackslash: KeyBackslash, + imgui.GLFWKeyRightBracket: KeyRightBracket, + imgui.GLFWKeyGraveAccent: KeyGraveAccent, + imgui.GLFWKeyEscape: KeyEscape, + imgui.GLFWKeyEnter: KeyEnter, + imgui.GLFWKeyTab: KeyTab, + imgui.GLFWKeyBackspace: KeyBackspace, + imgui.GLFWKeyInsert: KeyInsert, + imgui.GLFWKeyDelete: KeyDelete, + imgui.GLFWKeyRight: KeyRight, + imgui.GLFWKeyLeft: KeyLeft, + imgui.GLFWKeyDown: KeyDown, + imgui.GLFWKeyUp: KeyUp, + imgui.GLFWKeyPageUp: KeyPageUp, + imgui.GLFWKeyPageDown: KeyPageDown, + imgui.GLFWKeyHome: KeyHome, + imgui.GLFWKeyEnd: KeyEnd, + imgui.GLFWKeyCapsLock: KeyCapsLock, + imgui.GLFWKeyScrollLock: KeyScrollLock, + imgui.GLFWKeyNumLock: KeyNumLock, + imgui.GLFWKeyPrintScreen: KeyPrintScreen, + imgui.GLFWKeyPause: KeyPause, + imgui.GLFWKeyF1: KeyF1, + imgui.GLFWKeyF2: KeyF2, + imgui.GLFWKeyF3: KeyF3, + imgui.GLFWKeyF4: KeyF4, + imgui.GLFWKeyF5: KeyF5, + imgui.GLFWKeyF6: KeyF6, + imgui.GLFWKeyF7: KeyF7, + imgui.GLFWKeyF8: KeyF8, + imgui.GLFWKeyF9: KeyF9, + imgui.GLFWKeyF10: KeyF10, + imgui.GLFWKeyF11: KeyF11, + imgui.GLFWKeyF12: KeyF12, + imgui.GLFWKeyLeftShift: KeyLeftShift, + imgui.GLFWKeyLeftControl: KeyLeftControl, + imgui.GLFWKeyLeftAlt: KeyLeftAlt, + imgui.GLFWKeyLeftSuper: KeyLeftSuper, + imgui.GLFWKeyRightShift: KeyRightShift, + imgui.GLFWKeyRightControl: KeyRightControl, + imgui.GLFWKeyRightAlt: KeyRightAlt, + imgui.GLFWKeyRightSuper: KeyRightSuper, + imgui.GLFWKeyMenu: KeyMenu, + } + + if v, ok := data[k]; ok { + return v + } + + log.Panicf("Unknown key: %v", k) + + return 0 +} + +// Modifier represents imgui.Modifier. +type Modifier imgui.Key // modifier keys. const ( - ModNone Modifier = iota - ModControl Modifier = Modifier(glfw.ModControl) - ModAlt Modifier = Modifier(glfw.ModAlt) - ModSuper Modifier = Modifier(glfw.ModSuper) - ModShift Modifier = Modifier(glfw.ModShift) - ModCapsLock Modifier = Modifier(glfw.ModCapsLock) - ModNumLock Modifier = Modifier(glfw.ModNumLock) + ModNone Modifier = 0 + ModControl = Modifier(imgui.GLFWModControl) + ModAlt = Modifier(imgui.GLFWModAlt) + ModSuper = Modifier(imgui.GLFWModSuper) + ModShift = Modifier(imgui.GLFWModShift) + ModCapsLock = Modifier(imgui.GLFWModCapsLock) + ModNumLock = Modifier(imgui.GLFWModNumLock) ) -type Action glfw.Action +type Action int const ( - Release Action = Action(glfw.Release) - Press Action = Action(glfw.Press) - Repeat Action = Action(glfw.Repeat) + Release Action = iota + Press + Repeat ) diff --git a/ListClipper.go b/ListClipper.go index 760b8a58..55a3779d 100644 --- a/ListClipper.go +++ b/ListClipper.go @@ -1,8 +1,6 @@ package giu -import ( - "github.com/AllenDang/imgui-go" -) +import imgui "github.com/AllenDang/cimgui-go" var _ Widget = &ListClipperWrapper{} @@ -34,9 +32,9 @@ func (l *ListClipperWrapper) Build() { }) clipper := imgui.NewListClipper() - defer clipper.Delete() + defer clipper.Destroy() - clipper.Begin(len(layout)) + clipper.Begin(int32(len(layout))) for clipper.Step() { for i := clipper.DisplayStart(); i < clipper.DisplayEnd(); i++ { diff --git a/Markdown.go b/Markdown.go index df7dc11b..ca331f79 100644 --- a/Markdown.go +++ b/Markdown.go @@ -1,27 +1,18 @@ package giu -import ( - "image" - "image/color" - "net/http" - "strings" - "time" - - "github.com/AllenDang/imgui-go" - "github.com/faiface/mainthread" -) - // MarkdownWidget implements DearImGui markdown extension // https://github.com/juliettef/imgui_markdown // It is like LabelWidget but with md formatting. +// TODO: re-implement this. type MarkdownWidget struct { - md *string - linkCb func(url string) - headers []imgui.MarkdownHeaderData + md *string + linkCb func(url string) + // headers []imgui.MarkdownHeaderData } // Markdown creates new markdown widget. func Markdown(md *string) *MarkdownWidget { + panic("MarkdownWidget is not implemented yet!") return &MarkdownWidget{ md: md, linkCb: OpenURL, @@ -38,97 +29,97 @@ func (m *MarkdownWidget) OnLink(cb func(url string)) *MarkdownWidget { // NOTE: level (counting from 0!) is header level. (for instance, header `# H1` will have level 0). func (m *MarkdownWidget) Header(level int, font *FontInfo, separator bool) *MarkdownWidget { // ensure if header data are at least as long as level - if m.headers == nil { - m.headers = make([]imgui.MarkdownHeaderData, level) - } + // if m.headers == nil { + // m.headers = make([]imgui.MarkdownHeaderData, level) + //} - if level <= len(m.headers) { - m.headers = append(m.headers, make([]imgui.MarkdownHeaderData, len(m.headers)-level+1)...) - } + // if level <= len(m.headers) { + // m.headers = append(m.headers, make([]imgui.MarkdownHeaderData, len(m.headers)-level+1)...) + //} - if font != nil { - if f, ok := Context.FontAtlas.extraFontMap[font.String()]; ok { - m.headers[level].Font = *f - } - } + // if font != nil { + // if f, ok := Context.FontAtlas.extraFontMap[font.String()]; ok { + // m.headers[level].Font = *f + // } + //} - m.headers[level].HasSeparator = separator + // m.headers[level].HasSeparator = separator return m } // Build implements Widget interface. func (m *MarkdownWidget) Build() { - imgui.Markdown(Context.FontAtlas.RegisterStringPointer(m.md), m.linkCb, loadImage, m.headers) + // imgui.Markdown(Context.FontAtlas.RegisterStringPointer(m.md), m.linkCb, loadImage, m.headers) } -func loadImage(path string) imgui.MarkdownImageData { - var img *image.RGBA - - var err error - - switch { - case strings.HasPrefix(path, "http://") || strings.HasPrefix(path, "https://"): - // Load image from url - client := &http.Client{Timeout: 5 * time.Second} - resp, respErr := client.Get(path) - - if respErr != nil { - return imgui.MarkdownImageData{} - } - - defer func() { - closeErr := resp.Body.Close() - Assert((closeErr == nil), "MarkdownWidget", "loadImage", "Could not close http request!") - }() - - rgba, _, imgErr := image.Decode(resp.Body) - if imgErr != nil { - return imgui.MarkdownImageData{} - } - - img = ImageToRgba(rgba) - default: - img, err = LoadImage(path) - if err != nil { - return imgui.MarkdownImageData{} - } - } - - size := img.Bounds() - - //nolint:gocritic // TODO/BUG: figure out, why it doesn't work as expected and consider - // if current workaround is save - /* - tex := &Texture{} - NewTextureFromRgba(img, func(t *Texture) { - fmt.Println("creating texture") - tex.id = t.id - }) - */ - - var id imgui.TextureID - - mainthread.Call(func() { - var err error - id, err = Context.renderer.LoadImage(img) - if err != nil { - return - } - }) - - return imgui.MarkdownImageData{ - TextureID: &id, - Scale: true, - Size: imgui.Vec2{ - X: float32(size.Dx()), - Y: float32(size.Dy()), - }, - UseLinkCallback: true, - // default values - Uv0: ToVec2(image.Point{0, 0}), - Uv1: ToVec2(image.Point{1, 1}), - TintColor: ToVec4Color(color.RGBA{255, 255, 255, 255}), - BorderColor: ToVec4Color(color.RGBA{0, 0, 0, 0}), - } -} +//func loadImage(path string) imgui.MarkdownImageData { +// var img *image.RGBA +// +// var err error +// +// switch { +// case strings.HasPrefix(path, "http://") || strings.HasPrefix(path, "https://"): +// Load image from url +//client := &http.Client{Timeout: 5 * time.Second} +//resp, respErr := client.Get(path) +// +//if respErr != nil { +// return imgui.MarkdownImageData{} +//} +// +//defer func() { +// closeErr := resp.Body.Close() +// Assert((closeErr == nil), "MarkdownWidget", "loadImage", "Could not close http request!") +//}() +// +//rgba, _, imgErr := image.Decode(resp.Body) +//if imgErr != nil { +// return imgui.MarkdownImageData{} +//} +// +//img = ImageToRgba(rgba) +//default: +// img, err = LoadImage(path) +// if err != nil { +// return imgui.MarkdownImageData{} +// } +//} +// +//size := img.Bounds() +// +//nolint:gocritic // TODO/BUG: figure out, why it doesn't work as expected and consider +//if current workaround is save +///* +// tex := &Texture{} +// NewTextureFromRgba(img, func(t *Texture) { +// fmt.Println("creating texture") +// tex.id = t.id +// }) +//*/ +// +//var id imgui.TextureID +// +//mainthread.Call(func() { +// var err error +// id, err = Context.renderer.LoadImage(img) +// if err != nil { +// return +// } +//}) +// +//return imgui.MarkdownImageData{ +// TextureID: &id, +// Scale: true, +// Size: imgui.Vec2{ +// X: float32(size.Dx()), +// Y: float32(size.Dy()), +// }, +// UseLinkCallback: true, +// default values +//Uv0: ToVec2(image.Point{0, 0}), +//Uv1: ToVec2(image.Point{1, 1}), +//TintColor: ToVec4Color(color.RGBA{255, 255, 255, 255}), +//BorderColor: ToVec4Color(color.RGBA{0, 0, 0, 0}), +//} +//} diff --git a/MasterWindow.go b/MasterWindow.go index 278bf850..08f6831b 100644 --- a/MasterWindow.go +++ b/MasterWindow.go @@ -4,43 +4,62 @@ import ( "image" "image/color" "runtime" - "time" - "github.com/AllenDang/imgui-go" + imgui "github.com/AllenDang/cimgui-go" "github.com/faiface/mainthread" - "github.com/go-gl/glfw/v3.3/glfw" - "gopkg.in/eapache/queue.v1" + "golang.org/x/image/colornames" ) -// MasterWindowFlags wraps imgui.GLFWWindowFlags. -type MasterWindowFlags imgui.GLFWWindowFlags +// MasterWindowFlags implements BackendWindowFlags. +type MasterWindowFlags int // master window flags. const ( // Specifies the window will be fixed size. - MasterWindowFlagsNotResizable MasterWindowFlags = MasterWindowFlags(imgui.GLFWWindowFlagsNotResizable) + MasterWindowFlagsNotResizable MasterWindowFlags = 1 << iota // Specifies whether the window is maximized. - MasterWindowFlagsMaximized MasterWindowFlags = MasterWindowFlags(imgui.GLFWWindowFlagsMaximized) + MasterWindowFlagsMaximized // Specifies whether the window will be always-on-top. - MasterWindowFlagsFloating MasterWindowFlags = MasterWindowFlags(imgui.GLFWWindowFlagsFloating) + MasterWindowFlagsFloating // Specifies whether the window will be frameless. - MasterWindowFlagsFrameless MasterWindowFlags = MasterWindowFlags(imgui.GLFWWindowFlagsFrameless) + MasterWindowFlagsFrameless // Specifies whether the window will be transparent. - MasterWindowFlagsTransparent MasterWindowFlags = MasterWindowFlags(imgui.GLFWWindowFlagsTransparent) + MasterWindowFlagsTransparent ) +// parseAndApply converts MasterWindowFlags to appropriate imgui.GLFWWindowFlags. +func (m MasterWindowFlags) parseAndApply(b imgui.Backend[imgui.GLFWWindowFlags]) { + data := map[MasterWindowFlags]struct { + f imgui.GLFWWindowFlags + value int // value isn't always true (sometimes false). Also WindowHint takes int not bool + }{ + MasterWindowFlagsNotResizable: {imgui.GLFWWindowFlagsResizable, 0}, + MasterWindowFlagsMaximized: {imgui.GLFWWindowFlagsMaximized, 1}, + MasterWindowFlagsFloating: {imgui.GLFWWindowFlagsFloating, 1}, + MasterWindowFlagsFrameless: {imgui.GLFWWindowFlagsDecorated, 0}, + MasterWindowFlagsTransparent: {imgui.GLFWWindowFlagsTransparent, 1}, + } + + for flag, d := range data { + if m&flag != 0 { + b.SetWindowFlags(d.f, d.value) + } + } +} + +// TODO(gucio321) implement this in cimgui-go // DontCare could be used as an argument to (*MasterWindow).SetSizeLimits. -var DontCare int = imgui.GlfwDontCare +// var DontCare int = imgui.GlfwDontCare // MasterWindow represents a glfw master window // It is a base for a windows (see Window.go). type MasterWindow struct { + backend imgui.Backend[imgui.GLFWWindowFlags] + width int height int - clearColor [4]float32 + clearColor imgui.Vec4 title string - platform imgui.Platform - renderer imgui.Renderer context *imgui.Context io *imgui.IO updateFunc func() @@ -54,59 +73,54 @@ type MasterWindow struct { // it should be called in main function. For more details and use cases, // see examples/helloworld/. func NewMasterWindow(title string, width, height int, flags MasterWindowFlags) *MasterWindow { - context := imgui.CreateContext(nil) - imgui.ImPlotCreateContext() - imgui.ImNodesCreateContext() + imGuiContext := imgui.CreateContext() + imgui.PlotCreateContext() + // imgui.ImNodesCreateContext() // TODO after implementing ImNodes in cimgui io := imgui.CurrentIO() - io.SetConfigFlags(imgui.ConfigFlagEnablePowerSavingMode | imgui.BackendFlagsRendererHasVtxOffset) + // TODO: removed ConfigFlagEnablePowerSavingMode + io.SetConfigFlags(imgui.BackendFlagsRendererHasVtxOffset) io.SetBackendFlags(imgui.BackendFlagsRendererHasVtxOffset) // Disable imgui.ini io.SetIniFilename("") - p, err := imgui.NewGLFW(io, title, width, height, imgui.GLFWWindowFlags(flags)) - if err != nil { - panic(err) - } - - r, err := imgui.NewOpenGL3(io, 1.0) - if err != nil { - panic(err) - } - - Context = CreateContext(p, r) + backend := imgui.CreateBackend(imgui.NewGLFWBackend()) - // init texture loading queue - Context.textureLoadingQueue = queue.New() + // Create GIU context + Context = CreateContext(backend) mw := &MasterWindow{ - clearColor: [4]float32{0, 0, 0, 1}, + clearColor: imgui.Vec4{X: 0, Y: 0, Z: 0, W: 1}, width: width, height: height, title: title, - io: &io, - context: context, - platform: p, - renderer: r, + io: io, + context: imGuiContext, + backend: backend, } + backend.SetBeforeRenderHook(mw.beforeRender) + backend.SetAfterRenderHook(mw.afterRender) + backend.SetBeforeDestroyContextHook(mw.beforeDestroy) + flags.parseAndApply(backend) + backend.CreateWindow(title, width, height) + mw.SetInputHandler(newInputHandler()) - p.SetSizeChangeCallback(mw.sizeChange) + mw.backend.SetSizeChangeCallback(mw.sizeChange) - mw.setTheme() + mw.SetBgColor(colornames.Black) return mw } -func (w *MasterWindow) setTheme() { - style := imgui.CurrentStyle() - +func (w *MasterWindow) setTheme() (fin func()) { // Scale DPI in windows if runtime.GOOS == "windows" { - style.ScaleAllSizes(Context.GetPlatform().GetContentScale()) + xScale, _ := Context.backend.ContentScale() + imgui.CurrentStyle().ScaleAllSizes(xScale) } imgui.PushStyleVarFloat(imgui.StyleVarWindowRounding, 2) @@ -114,67 +128,59 @@ func (w *MasterWindow) setTheme() { imgui.PushStyleVarFloat(imgui.StyleVarGrabRounding, 4) imgui.PushStyleVarFloat(imgui.StyleVarFrameBorderSize, 1) - style.SetColor(imgui.StyleColorText, imgui.Vec4{X: 0.95, Y: 0.96, Z: 0.98, W: 1.00}) - style.SetColor(imgui.StyleColorTextDisabled, imgui.Vec4{X: 0.36, Y: 0.42, Z: 0.47, W: 1.00}) - style.SetColor(imgui.StyleColorWindowBg, imgui.Vec4{X: 0.11, Y: 0.15, Z: 0.17, W: 1.00}) - style.SetColor(imgui.StyleColorChildBg, imgui.Vec4{X: 0.15, Y: 0.18, Z: 0.22, W: 1.00}) - style.SetColor(imgui.StyleColorPopupBg, imgui.Vec4{X: 0.08, Y: 0.08, Z: 0.08, W: 0.94}) - style.SetColor(imgui.StyleColorBorder, imgui.Vec4{X: 0.08, Y: 0.10, Z: 0.12, W: 1.00}) - style.SetColor(imgui.StyleColorBorderShadow, imgui.Vec4{X: 0.00, Y: 0.00, Z: 0.00, W: 0.00}) - style.SetColor(imgui.StyleColorFrameBg, imgui.Vec4{X: 0.20, Y: 0.25, Z: 0.29, W: 1.00}) - style.SetColor(imgui.StyleColorFrameBgHovered, imgui.Vec4{X: 0.12, Y: 0.20, Z: 0.28, W: 1.00}) - style.SetColor(imgui.StyleColorFrameBgActive, imgui.Vec4{X: 0.09, Y: 0.12, Z: 0.14, W: 1.00}) - style.SetColor(imgui.StyleColorTitleBg, imgui.Vec4{X: 0.09, Y: 0.12, Z: 0.14, W: 0.65}) - style.SetColor(imgui.StyleColorTitleBgActive, imgui.Vec4{X: 0.08, Y: 0.10, Z: 0.12, W: 1.00}) - style.SetColor(imgui.StyleColorTitleBgCollapsed, imgui.Vec4{X: 0.00, Y: 0.00, Z: 0.00, W: 0.51}) - style.SetColor(imgui.StyleColorMenuBarBg, imgui.Vec4{X: 0.15, Y: 0.18, Z: 0.22, W: 1.00}) - style.SetColor(imgui.StyleColorScrollbarBg, imgui.Vec4{X: 0.02, Y: 0.02, Z: 0.02, W: 0.39}) - style.SetColor(imgui.StyleColorScrollbarGrab, imgui.Vec4{X: 0.20, Y: 0.25, Z: 0.29, W: 1.00}) - style.SetColor(imgui.StyleColorScrollbarGrabHovered, imgui.Vec4{X: 0.18, Y: 0.22, Z: 0.25, W: 1.00}) - style.SetColor(imgui.StyleColorScrollbarGrabActive, imgui.Vec4{X: 0.09, Y: 0.21, Z: 0.31, W: 1.00}) - style.SetColor(imgui.StyleColorCheckMark, imgui.Vec4{X: 0.28, Y: 0.56, Z: 1.00, W: 1.00}) - style.SetColor(imgui.StyleColorSliderGrab, imgui.Vec4{X: 0.28, Y: 0.56, Z: 1.00, W: 1.00}) - style.SetColor(imgui.StyleColorSliderGrabActive, imgui.Vec4{X: 0.37, Y: 0.61, Z: 1.00, W: 1.00}) - style.SetColor(imgui.StyleColorButton, imgui.Vec4{X: 0.20, Y: 0.25, Z: 0.29, W: 1.00}) - style.SetColor(imgui.StyleColorButtonHovered, imgui.Vec4{X: 0.28, Y: 0.56, Z: 1.00, W: 1.00}) - style.SetColor(imgui.StyleColorButtonActive, imgui.Vec4{X: 0.06, Y: 0.53, Z: 0.98, W: 1.00}) - style.SetColor(imgui.StyleColorHeader, imgui.Vec4{X: 0.20, Y: 0.25, Z: 0.29, W: 0.55}) - style.SetColor(imgui.StyleColorHeaderHovered, imgui.Vec4{X: 0.26, Y: 0.59, Z: 0.98, W: 0.80}) - style.SetColor(imgui.StyleColorHeaderActive, imgui.Vec4{X: 0.26, Y: 0.59, Z: 0.98, W: 1.00}) - style.SetColor(imgui.StyleColorSeparator, imgui.Vec4{X: 0.20, Y: 0.25, Z: 0.29, W: 1.00}) - style.SetColor(imgui.StyleColorSeparatorHovered, imgui.Vec4{X: 0.10, Y: 0.40, Z: 0.75, W: 0.78}) - style.SetColor(imgui.StyleColorSeparatorActive, imgui.Vec4{X: 0.10, Y: 0.40, Z: 0.75, W: 1.00}) - style.SetColor(imgui.StyleColorResizeGrip, imgui.Vec4{X: 0.26, Y: 0.59, Z: 0.98, W: 0.25}) - style.SetColor(imgui.StyleColorResizeGripHovered, imgui.Vec4{X: 0.26, Y: 0.59, Z: 0.98, W: 0.67}) - style.SetColor(imgui.StyleColorResizeGripActive, imgui.Vec4{X: 0.26, Y: 0.59, Z: 0.98, W: 0.95}) - style.SetColor(imgui.StyleColorTab, imgui.Vec4{X: 0.11, Y: 0.15, Z: 0.17, W: 1.00}) - style.SetColor(imgui.StyleColorTabHovered, imgui.Vec4{X: 0.26, Y: 0.59, Z: 0.98, W: 0.80}) - style.SetColor(imgui.StyleColorTabActive, imgui.Vec4{X: 0.20, Y: 0.25, Z: 0.29, W: 1.00}) - style.SetColor(imgui.StyleColorTabUnfocused, imgui.Vec4{X: 0.11, Y: 0.15, Z: 0.17, W: 1.00}) - style.SetColor(imgui.StyleColorTabUnfocusedActive, imgui.Vec4{X: 0.11, Y: 0.15, Z: 0.17, W: 1.00}) - style.SetColor(imgui.StyleColorPlotLines, imgui.Vec4{X: 0.61, Y: 0.61, Z: 0.61, W: 1.00}) - style.SetColor(imgui.StyleColorPlotLinesHovered, imgui.Vec4{X: 1.00, Y: 0.43, Z: 0.35, W: 1.00}) - style.SetColor(imgui.StyleColorPlotHistogram, imgui.Vec4{X: 0.90, Y: 0.70, Z: 0.00, W: 1.00}) - style.SetColor(imgui.StyleColorPlotHistogramHovered, imgui.Vec4{X: 1.00, Y: 0.60, Z: 0.00, W: 1.00}) - style.SetColor(imgui.StyleColorTextSelectedBg, imgui.Vec4{X: 0.26, Y: 0.59, Z: 0.98, W: 0.35}) - style.SetColor(imgui.StyleColorDragDropTarget, imgui.Vec4{X: 1.00, Y: 1.00, Z: 0.00, W: 0.90}) - style.SetColor(imgui.StyleColorNavHighlight, imgui.Vec4{X: 0.26, Y: 0.59, Z: 0.98, W: 1.00}) - style.SetColor(imgui.StyleColorNavWindowingHighlight, imgui.Vec4{X: 1.00, Y: 1.00, Z: 1.00, W: 0.70}) - style.SetColor(imgui.StyleColorTableHeaderBg, imgui.Vec4{X: 0.12, Y: 0.20, Z: 0.28, W: 1.00}) - style.SetColor(imgui.StyleColorTableBorderStrong, imgui.Vec4{X: 0.20, Y: 0.25, Z: 0.29, W: 1.00}) - style.SetColor(imgui.StyleColorTableBorderLight, imgui.Vec4{X: 0.20, Y: 0.25, Z: 0.29, W: 0.70}) -} - -// SetBgColor sets background color of master window. -func (w *MasterWindow) SetBgColor(bgColor color.Color) { - const mask = 0xffff - - r, g, b, a := bgColor.RGBA() - w.clearColor = [4]float32{ - float32(r) / mask, - float32(g) / mask, - float32(b) / mask, - float32(a) / mask, + imgui.PushStyleColorVec4(imgui.ColText, imgui.Vec4{X: 0.95, Y: 0.96, Z: 0.98, W: 1.00}) + imgui.PushStyleColorVec4(imgui.ColTextDisabled, imgui.Vec4{X: 0.36, Y: 0.42, Z: 0.47, W: 1.00}) + imgui.PushStyleColorVec4(imgui.ColWindowBg, imgui.Vec4{X: 0.11, Y: 0.15, Z: 0.17, W: 1.00}) + imgui.PushStyleColorVec4(imgui.ColChildBg, imgui.Vec4{X: 0.15, Y: 0.18, Z: 0.22, W: 1.00}) + imgui.PushStyleColorVec4(imgui.ColPopupBg, imgui.Vec4{X: 0.08, Y: 0.08, Z: 0.08, W: 0.94}) + imgui.PushStyleColorVec4(imgui.ColBorder, imgui.Vec4{X: 0.08, Y: 0.10, Z: 0.12, W: 1.00}) + imgui.PushStyleColorVec4(imgui.ColBorderShadow, imgui.Vec4{X: 0.00, Y: 0.00, Z: 0.00, W: 0.00}) + imgui.PushStyleColorVec4(imgui.ColFrameBg, imgui.Vec4{X: 0.20, Y: 0.25, Z: 0.29, W: 1.00}) + imgui.PushStyleColorVec4(imgui.ColFrameBgHovered, imgui.Vec4{X: 0.12, Y: 0.20, Z: 0.28, W: 1.00}) + imgui.PushStyleColorVec4(imgui.ColFrameBgActive, imgui.Vec4{X: 0.09, Y: 0.12, Z: 0.14, W: 1.00}) + imgui.PushStyleColorVec4(imgui.ColTitleBg, imgui.Vec4{X: 0.09, Y: 0.12, Z: 0.14, W: 0.65}) + imgui.PushStyleColorVec4(imgui.ColTitleBgActive, imgui.Vec4{X: 0.08, Y: 0.10, Z: 0.12, W: 1.00}) + imgui.PushStyleColorVec4(imgui.ColTitleBgCollapsed, imgui.Vec4{X: 0.00, Y: 0.00, Z: 0.00, W: 0.51}) + imgui.PushStyleColorVec4(imgui.ColMenuBarBg, imgui.Vec4{X: 0.15, Y: 0.18, Z: 0.22, W: 1.00}) + imgui.PushStyleColorVec4(imgui.ColScrollbarBg, imgui.Vec4{X: 0.02, Y: 0.02, Z: 0.02, W: 0.39}) + imgui.PushStyleColorVec4(imgui.ColScrollbarGrab, imgui.Vec4{X: 0.20, Y: 0.25, Z: 0.29, W: 1.00}) + imgui.PushStyleColorVec4(imgui.ColScrollbarGrabHovered, imgui.Vec4{X: 0.18, Y: 0.22, Z: 0.25, W: 1.00}) + imgui.PushStyleColorVec4(imgui.ColScrollbarGrabActive, imgui.Vec4{X: 0.09, Y: 0.21, Z: 0.31, W: 1.00}) + imgui.PushStyleColorVec4(imgui.ColCheckMark, imgui.Vec4{X: 0.28, Y: 0.56, Z: 1.00, W: 1.00}) + imgui.PushStyleColorVec4(imgui.ColSliderGrab, imgui.Vec4{X: 0.28, Y: 0.56, Z: 1.00, W: 1.00}) + imgui.PushStyleColorVec4(imgui.ColSliderGrabActive, imgui.Vec4{X: 0.37, Y: 0.61, Z: 1.00, W: 1.00}) + imgui.PushStyleColorVec4(imgui.ColButton, imgui.Vec4{X: 0.20, Y: 0.25, Z: 0.29, W: 1.00}) + imgui.PushStyleColorVec4(imgui.ColButtonHovered, imgui.Vec4{X: 0.28, Y: 0.56, Z: 1.00, W: 1.00}) + imgui.PushStyleColorVec4(imgui.ColButtonActive, imgui.Vec4{X: 0.06, Y: 0.53, Z: 0.98, W: 1.00}) + imgui.PushStyleColorVec4(imgui.ColHeader, imgui.Vec4{X: 0.20, Y: 0.25, Z: 0.29, W: 0.55}) + imgui.PushStyleColorVec4(imgui.ColHeaderHovered, imgui.Vec4{X: 0.26, Y: 0.59, Z: 0.98, W: 0.80}) + imgui.PushStyleColorVec4(imgui.ColHeaderActive, imgui.Vec4{X: 0.26, Y: 0.59, Z: 0.98, W: 1.00}) + imgui.PushStyleColorVec4(imgui.ColSeparator, imgui.Vec4{X: 0.20, Y: 0.25, Z: 0.29, W: 1.00}) + imgui.PushStyleColorVec4(imgui.ColSeparatorHovered, imgui.Vec4{X: 0.10, Y: 0.40, Z: 0.75, W: 0.78}) + imgui.PushStyleColorVec4(imgui.ColSeparatorActive, imgui.Vec4{X: 0.10, Y: 0.40, Z: 0.75, W: 1.00}) + imgui.PushStyleColorVec4(imgui.ColResizeGrip, imgui.Vec4{X: 0.26, Y: 0.59, Z: 0.98, W: 0.25}) + imgui.PushStyleColorVec4(imgui.ColResizeGripHovered, imgui.Vec4{X: 0.26, Y: 0.59, Z: 0.98, W: 0.67}) + imgui.PushStyleColorVec4(imgui.ColResizeGripActive, imgui.Vec4{X: 0.26, Y: 0.59, Z: 0.98, W: 0.95}) + imgui.PushStyleColorVec4(imgui.ColTab, imgui.Vec4{X: 0.11, Y: 0.15, Z: 0.17, W: 1.00}) + imgui.PushStyleColorVec4(imgui.ColTabHovered, imgui.Vec4{X: 0.26, Y: 0.59, Z: 0.98, W: 0.80}) + imgui.PushStyleColorVec4(imgui.ColTabActive, imgui.Vec4{X: 0.20, Y: 0.25, Z: 0.29, W: 1.00}) + imgui.PushStyleColorVec4(imgui.ColTabUnfocused, imgui.Vec4{X: 0.11, Y: 0.15, Z: 0.17, W: 1.00}) + imgui.PushStyleColorVec4(imgui.ColTabUnfocusedActive, imgui.Vec4{X: 0.11, Y: 0.15, Z: 0.17, W: 1.00}) + imgui.PushStyleColorVec4(imgui.ColPlotLines, imgui.Vec4{X: 0.61, Y: 0.61, Z: 0.61, W: 1.00}) + imgui.PushStyleColorVec4(imgui.ColPlotLinesHovered, imgui.Vec4{X: 1.00, Y: 0.43, Z: 0.35, W: 1.00}) + imgui.PushStyleColorVec4(imgui.ColPlotHistogram, imgui.Vec4{X: 0.90, Y: 0.70, Z: 0.00, W: 1.00}) + imgui.PushStyleColorVec4(imgui.ColPlotHistogramHovered, imgui.Vec4{X: 1.00, Y: 0.60, Z: 0.00, W: 1.00}) + imgui.PushStyleColorVec4(imgui.ColTextSelectedBg, imgui.Vec4{X: 0.26, Y: 0.59, Z: 0.98, W: 0.35}) + imgui.PushStyleColorVec4(imgui.ColDragDropTarget, imgui.Vec4{X: 1.00, Y: 1.00, Z: 0.00, W: 0.90}) + imgui.PushStyleColorVec4(imgui.ColNavHighlight, imgui.Vec4{X: 0.26, Y: 0.59, Z: 0.98, W: 1.00}) + imgui.PushStyleColorVec4(imgui.ColNavWindowingHighlight, imgui.Vec4{X: 1.00, Y: 1.00, Z: 1.00, W: 0.70}) + imgui.PushStyleColorVec4(imgui.ColTableHeaderBg, imgui.Vec4{X: 0.12, Y: 0.20, Z: 0.28, W: 1.00}) + imgui.PushStyleColorVec4(imgui.ColTableBorderStrong, imgui.Vec4{X: 0.20, Y: 0.25, Z: 0.29, W: 1.00}) + imgui.PushStyleColorVec4(imgui.ColTableBorderLight, imgui.Vec4{X: 0.20, Y: 0.25, Z: 0.29, W: 0.70}) + + return func() { + imgui.PopStyleColorV(49) + imgui.PopStyleVarV(4) } } @@ -182,104 +188,112 @@ func (w *MasterWindow) sizeChange(width, height int) { w.render() } -func (w *MasterWindow) render() { - if !w.platform.IsVisible() || w.platform.IsMinimized() { - return +func (w *MasterWindow) beforeRender() { + Context.invalidAllState() + Context.FontAtlas.rebuildFontAtlas() + + // process texture load requests + if Context.textureLoadingQueue != nil && Context.textureLoadingQueue.Length() > 0 { + for Context.textureLoadingQueue.Length() > 0 { + request, ok := Context.textureLoadingQueue.Remove().(textureLoadRequest) + Assert(ok, "MasterWindow", "Run", "processing texture requests: wrong type of texture request") + NewTextureFromRgba(request.img, request.cb) + } } +} - Context.invalidAllState() - defer Context.cleanState() +func (w *MasterWindow) afterRender() { + Context.cleanState() +} - Context.FontAtlas.rebuildFontAtlas() +func (w *MasterWindow) beforeDestroy() { + imgui.PlotDestroyContext() + // imgui.ImNodesDestroyContext() // TODO: after adding ImNodes (https://github.com/AllenDang/cimgui-go/issues/137) +} - p := w.platform - r := w.renderer +func (w *MasterWindow) render() { + fin := w.setTheme() + defer fin() mainStylesheet := Style() if s, found := Context.cssStylesheet["main"]; found { mainStylesheet = s } - p.NewFrame() - r.PreRender(w.clearColor) - - imgui.NewFrame() mainStylesheet.Push() w.updateFunc() mainStylesheet.Pop() - imgui.Render() - - r.Render(p.DisplaySize(), p.FramebufferSize(), imgui.RenderedDrawData()) - p.PostRender() } -// Run the main loop to create new frame, process events and call update ui func. -func (w *MasterWindow) run() { - p := w.platform - - ticker := time.NewTicker(time.Second / time.Duration(p.GetTPS())) - shouldQuit := false +// Run runs the main loop. +// loopFunc will be used to construct the ui. +// Run should be called at the end of main function, after setting +// up the master window. +func (w *MasterWindow) Run(loopFunc func()) { + mainthread.Run(func() { + Context.isRunning = true + w.updateFunc = loopFunc - for !shouldQuit { - mainthread.Call(func() { - // process texture load requests - if Context.textureLoadingQueue != nil && Context.textureLoadingQueue.Length() > 0 { - for Context.textureLoadingQueue.Length() > 0 { - request, ok := Context.textureLoadingQueue.Remove().(textureLoadRequest) - Assert(ok, "MasterWindow", "Run", "processing texture requests: wrong type of texture request") - NewTextureFromRgba(request.img, request.cb) - } - } + Context.m.Lock() + Context.isAlive = true + Context.m.Unlock() - p.ProcessEvents() - w.render() + Context.backend.Run(w.render) - shouldQuit = p.ShouldStop() - }) + Context.m.Lock() + Context.isAlive = false - <-ticker.C - } + Context.isRunning = false + Context.m.Unlock() + }) } // GetSize return size of master window. func (w *MasterWindow) GetSize() (width, height int) { - if w.platform != nil { - if glfwPlatform, ok := w.platform.(*imgui.GLFW); ok { - return glfwPlatform.GetWindow().GetSize() - } + if w.backend != nil { + w, h := w.backend.DisplaySize() + return int(w), int(h) } return w.width, w.height } +// SetBgColor sets background color of master window. +func (w *MasterWindow) SetBgColor(bgColor color.Color) { + const mask = 0xffff + + r, g, b, a := bgColor.RGBA() + w.clearColor = imgui.Vec4{ + X: float32(r) / mask, + Y: float32(g) / mask, + Z: float32(b) / mask, + W: float32(a) / mask, + } + + w.backend.SetBgColor(w.clearColor) +} + // GetPos return position of master window. func (w *MasterWindow) GetPos() (x, y int) { - if w.platform != nil { - if glfwPlatform, ok := w.platform.(*imgui.GLFW); ok { - x, y = glfwPlatform.GetWindow().GetPos() - } + var xResult, yResult int32 + if w.backend != nil { + xResult, yResult = w.backend.GetWindowPos() } - return + return int(xResult), int(yResult) } // SetPos sets position of master window. func (w *MasterWindow) SetPos(x, y int) { - if w.platform != nil { - if glfwPlatform, ok := w.platform.(*imgui.GLFW); ok { - glfwPlatform.GetWindow().SetPos(x, y) - } + if w.backend != nil { + w.backend.SetWindowPos(x, y) } } // SetSize sets size of master window. func (w *MasterWindow) SetSize(x, y int) { - if w.platform != nil { - if glfwPlatform, ok := w.platform.(*imgui.GLFW); ok { - mainthread.CallNonBlock(func() { - glfwPlatform.GetWindow().SetSize(x, y) - }) - } + if w.backend != nil { + w.backend.SetWindowSize(x, y) } } @@ -293,42 +307,14 @@ func (w *MasterWindow) SetSize(x, y int) { // Mac OS X: Selecting Quit from the application menu will trigger the close // callback for all windows. func (w *MasterWindow) SetCloseCallback(cb func() bool) { - w.platform.SetCloseCallback(cb) + w.backend.SetCloseCallback(func(b imgui.Backend[imgui.GLFWWindowFlags]) { + b.SetShouldClose(cb()) + }) } // SetDropCallback sets callback when file was dropped into the window. func (w *MasterWindow) SetDropCallback(cb func([]string)) { - w.platform.SetDropCallback(cb) -} - -// Run runs the main loop. -// loopFunc will be used to construct the ui. -// Run should be called at the end of main function, after setting -// up the master window. -func (w *MasterWindow) Run(loopFunc func()) { - mainthread.Run(func() { - Context.isRunning = true - w.updateFunc = loopFunc - - Context.isAlive = true - - w.run() - - Context.m.Lock() - Context.isAlive = false - Context.m.Unlock() - - mainthread.Call(func() { - w.renderer.Dispose() - w.platform.Dispose() - - imgui.ImNodesDestroyContext() - imgui.ImPlotDestroyContext() - w.context.Destroy() - }) - - Context.isRunning = false - }) + w.backend.SetDropCallback(cb) } // RegisterKeyboardShortcuts registers a global - master window - keyboard shortcuts. @@ -357,8 +343,8 @@ func (w *MasterWindow) RegisterKeyboardShortcuts(s ...WindowShortcut) *MasterWin // // The desired image sizes varies depending on platform and system settings. The selected // images will be rescaled as needed. Good sizes include 16x16, 32x32 and 48x48. -func (w *MasterWindow) SetIcon(icons []image.Image) { - w.platform.SetIcon(icons) +func (w *MasterWindow) SetIcon(icons ...image.Image) { + w.backend.SetIcons(icons...) } // SetSizeLimits sets the size limits of the client area of the specified window. @@ -368,12 +354,12 @@ func (w *MasterWindow) SetIcon(icons []image.Image) { // To specify only a minimum size or only a maximum one, set the other pair to giu.DontCare. // To disable size limits for a window, set them all to giu.DontCare. func (w *MasterWindow) SetSizeLimits(minw, minh, maxw, maxh int) { - w.platform.SetSizeLimits(minw, minh, maxw, maxh) + w.backend.SetWindowSizeLimits(minw, minh, maxw, maxh) } // SetTitle updates master window's title. func (w *MasterWindow) SetTitle(title string) { - w.platform.SetTitle(title) + w.backend.SetWindowTitle(title) } // Close will safely close the master window. @@ -383,7 +369,7 @@ func (w *MasterWindow) Close() { // SetShouldClose sets whether master window should be closed. func (w *MasterWindow) SetShouldClose(v bool) { - w.platform.SetShouldStop(v) + w.backend.SetShouldClose(v) } // SetInputHandler allows to change default input handler. @@ -391,8 +377,8 @@ func (w *MasterWindow) SetShouldClose(v bool) { func (w *MasterWindow) SetInputHandler(handler InputHandler) { Context.InputHandler = handler - w.platform.SetInputCallback(func(key glfw.Key, modifier glfw.ModifierKey, action glfw.Action) { - k, m, a := Key(key), Modifier(modifier), Action(action) + w.backend.SetKeyCallback(func(key, scanCode, action, modifier int) { + k, m, a := keyFromGLFWKey(imgui.GLFWKey(key)), Modifier(modifier), Action(action) handler.Handle(k, m, a) if w.additionalInputCallback != nil { w.additionalInputCallback(k, m, a) diff --git a/MemoryEditor.go b/MemoryEditor.go index 9c1a3fc4..98e43415 100644 --- a/MemoryEditor.go +++ b/MemoryEditor.go @@ -1,56 +1,64 @@ package giu -import ( - "github.com/AllenDang/imgui-go" -) - -type memoryEditorState struct { - editor imgui.MemoryEditor -} - -// Dispose implements Disposable interface. -func (s *memoryEditorState) Dispose() { - // noop -} - -// MemoryEditorWidget - Mini memory editor for Dear ImGui -// (to embed in your game/tools) -// -// Right-click anywhere to access the Options menu! -// You can adjust the keyboard repeat delay/rate in ImGuiIO. -// The code assume a mono-space font for simplicity! -// If you don't use the default font, use ImGui::PushFont()/PopFont() to switch to a mono-space font before calling this. -type MemoryEditorWidget struct { - id string - contents []byte -} - -// MemoryEditor creates nwe memory editor widget. -func MemoryEditor() *MemoryEditorWidget { - return &MemoryEditorWidget{ - id: GenAutoID("memoryEditor"), - } -} - -// Contents sets editor's contents. -func (me *MemoryEditorWidget) Contents(contents []byte) *MemoryEditorWidget { - me.contents = contents - return me -} - -// Build implements widget interface. -func (me *MemoryEditorWidget) Build() { - me.getState().editor.DrawContents(me.contents) -} - -func (me *MemoryEditorWidget) getState() (state *memoryEditorState) { - if state = GetState[memoryEditorState](Context, me.id); state == nil { - state = &memoryEditorState{ - editor: imgui.NewMemoryEditor(), - } - - SetState(Context, me.id, state) - } - - return state -} +// +// import ( +// +// "github.com/AllenDang/cimgui-go" +// +// ) +// +// type memoryEditorState struct { +// editor imgui.MemoryEditor +// } +// +// // Dispose implements Disposable interface. +// +// func (s *memoryEditorState) Dispose() { +// // noop +// } +// +// // MemoryEditorWidget - Mini memory editor for Dear ImGui +// // (to embed in your game/tools) +// // +// // Right-click anywhere to access the Options menu! +// // You can adjust the keyboard repeat delay/rate in ImGuiIO. +// // The code assume a mono-space font for simplicity! +// // If you don't use the default font, use ImGui::PushFont()/PopFont() to switch to a mono-space font before calling this. +// +// type MemoryEditorWidget struct { +// id string +// contents []byte +// } +// +// // MemoryEditor creates nwe memory editor widget. +// +// func MemoryEditor() *MemoryEditorWidget { +// return &MemoryEditorWidget{ +// id: GenAutoID("memoryEditor"), +// } +// } +// +// // Contents sets editor's contents. +// +// func (me *MemoryEditorWidget) Contents(contents []byte) *MemoryEditorWidget { +// me.contents = contents +// return me +// } +// +// // Build implements widget interface. +// +// func (me *MemoryEditorWidget) Build() { +// me.getState().editor.DrawContents(me.contents) +// } +// +// func (me *MemoryEditorWidget) getState() (state *memoryEditorState) { +// if state = GetState[memoryEditorState](Context, me.id); state == nil { +// state = &memoryEditorState{ +// editor: imgui.NewMemoryEditor(), +// } +// +// SetState(Context, me.id, state) +// } +// +// return state +// } diff --git a/Plot.go b/Plot.go index 35fa90c3..4f73f563 100644 --- a/Plot.go +++ b/Plot.go @@ -3,7 +3,7 @@ package giu import ( "image" - "github.com/AllenDang/imgui-go" + imgui "github.com/AllenDang/cimgui-go" ) // PlotWidget is implemented by all the particular plots, which can be used @@ -168,30 +168,79 @@ func (p *PlotCanvasWidget) Size(width, height int) *PlotCanvasWidget { // Build implements Widget interface. func (p *PlotCanvasWidget) Build() { - if len(p.plots) > 0 { - imgui.ImPlotSetNextPlotLimits(p.xMin, p.xMax, p.yMin, p.yMax, imgui.Condition(p.axisLimitCondition)) + if len(p.plots) == 0 { + return + } + + if imgui.PlotBeginPlotV( + Context.FontAtlas.RegisterString(p.title), + ToVec2(image.Pt(p.width, p.height)), + imgui.PlotFlags(p.flags), + ) { + imgui.PlotSetupAxisLimitsV( + imgui.AxisX1, + p.xMin, + p.xMax, + imgui.PlotCond(p.axisLimitCondition), + ) + imgui.PlotSetupAxisLimitsV( + imgui.AxisY1, + p.yMin, + p.yMax, + imgui.PlotCond(p.axisLimitCondition), + ) if len(p.xTicksValue) > 0 { - imgui.ImPlotSetNextPlotTicksX(p.xTicksValue, p.xTicksLabel, p.xTicksShowDefault) + imgui.PlotSetupAxisTicksdoubleV( + imgui.AxisX1, + p.xTicksValue[0], + p.xTicksValue[1], // <- TODO: why is it so strangely saved? + -1, // TODO: implement + p.xTicksLabel, + p.xTicksShowDefault, + ) } if len(p.yTicksValue) > 0 { - imgui.ImPlotSetNextPlotTicksY(p.yTicksValue, p.yTicksLabel, p.yTicksShowDefault, int(p.yTicksYAxis)) + imgui.PlotSetupAxisTicksdoubleV( + imgui.AxisY1, + p.xTicksValue[0], + p.xTicksValue[1], // <- TODO: why is it so strangely saved? + -1, // TODO: implement + p.xTicksLabel, + p.xTicksShowDefault, + ) } - if imgui.ImPlotBegin( - Context.FontAtlas.RegisterString(p.title), Context.FontAtlas.RegisterString(p.xLabel), - Context.FontAtlas.RegisterString(p.yLabel), ToVec2(image.Pt(p.width, p.height)), - imgui.ImPlotFlags(p.flags), imgui.ImPlotAxisFlags(p.xFlags), - imgui.ImPlotAxisFlags(p.yFlags), imgui.ImPlotAxisFlags(p.y2Flags), - imgui.ImPlotAxisFlags(p.y3Flags), Context.FontAtlas.RegisterString(p.y2Label), Context.FontAtlas.RegisterString(p.y3Label), - ) { - for _, plot := range p.plots { - plot.Plot() - } - - imgui.ImPlotEnd() + imgui.PlotSetupAxisV( + imgui.AxisX, + Context.FontAtlas.RegisterString(p.xLabel), + imgui.PlotAxisFlags(p.xFlags), + ) + + imgui.PlotSetupAxisV( + imgui.AxisY1, + Context.FontAtlas.RegisterString(p.yLabel), + imgui.PlotAxisFlags(p.yFlags), + ) + + imgui.PlotSetupAxisV( + imgui.AxisY2, + Context.FontAtlas.RegisterString(p.y2Label), + imgui.PlotAxisFlags(p.y2Flags), + ) + + imgui.PlotSetupAxisV( + imgui.AxisY3, + Context.FontAtlas.RegisterString(p.y3Label), + imgui.PlotAxisFlags(p.y3Flags), + ) + + for _, plot := range p.plots { + plot.Plot() } + + imgui.PlotEndPlot() } } @@ -235,7 +284,16 @@ func (p *BarPlot) Offset(offset int) *BarPlot { // Plot implements Plot interface. func (p *BarPlot) Plot() { - imgui.ImPlotBars(p.title, p.data, p.width, p.shift, p.offset) + imgui.PlotPlotBarsdoublePtrIntV( + p.title, + &p.data, + int32(len(p.data)), + p.width, + p.shift, + 0, // TODO: implement + int32(p.offset), + 0, // TODO: implement + ) } // BarHPlot represents a column chart on Y axis. @@ -278,7 +336,16 @@ func (p *BarHPlot) Offset(offset int) *BarHPlot { // Plot implements plot interface. func (p *BarHPlot) Plot() { - imgui.ImPlotBarsH(Context.FontAtlas.RegisterString(p.title), p.data, p.height, p.shift, p.offset) + imgui.PlotPlotBarsdoublePtrIntV( + Context.FontAtlas.RegisterString(p.title), + &p.data, + int32(len(p.data)), + p.height, + p.shift, + imgui.PlotErrorBarsFlagsHorizontal, + int32(p.offset), + 0, + ) } // LinePlot represents a plot line (linear chart). @@ -327,8 +394,19 @@ func (p *LinePlot) Offset(offset int) *LinePlot { // Plot implements Plot interface. func (p *LinePlot) Plot() { - imgui.ImPlotSetPlotYAxis(imgui.ImPlotYAxis(p.yAxis)) - imgui.ImPlotLine(Context.FontAtlas.RegisterString(p.title), p.values, p.xScale, p.x0, p.offset) + imgui.PlotSetupAxis( + imgui.PlotAxisEnum(p.yAxis), + ) + + // TODO: no idea what should it be... + // imgui.PlotDragLineX(Context.FontAtlas.RegisterString(p.title), p.values, p.xScale, p.x0, p.offset) + // imgui.PlotDragLineX( + // Context.FontAtlas.RegisterString(p.title), + // p.values, + // p.xScale, + // p.x0, + // p.offset, + //) } // LineXYPlot adds XY plot line. @@ -363,8 +441,9 @@ func (p *LineXYPlot) Offset(offset int) *LineXYPlot { // Plot implements Plot interface. func (p *LineXYPlot) Plot() { - imgui.ImPlotSetPlotYAxis(imgui.ImPlotYAxis(p.yAxis)) - imgui.ImPlotLineXY(Context.FontAtlas.RegisterString(p.title), p.xs, p.ys, p.offset) + // TODO: migrate this + // imgui.ImPlotSetPlotYAxis(imgui.ImPlotYAxis(p.yAxis)) + // imgui.ImPlotLineXY(Context.FontAtlas.RegisterString(p.title), p.xs, p.ys, p.offset) } // PieChartPlot represents a pie chart. @@ -408,7 +487,18 @@ func (p *PieChartPlot) Angle0(a float64) *PieChartPlot { } func (p *PieChartPlot) Plot() { - imgui.ImPlotPieChart(Context.FontAtlas.RegisterStringSlice(p.labels), p.values, p.x, p.y, p.radius, p.normalize, p.labelFormat, p.angle0) + // TODO: p.normalized not used anymore - replace with flags + imgui.PlotPlotPieChartdoublePtrV( + Context.FontAtlas.RegisterStringSlice(p.labels), + &p.values, + int32(len(p.values)), + p.x, + p.y, + p.radius, + p.labelFormat, + p.angle0, + imgui.PlotPieChartFlagsNormalize, + ) } type ScatterPlot struct { @@ -444,7 +534,16 @@ func (p *ScatterPlot) Offset(offset int) *ScatterPlot { } func (p *ScatterPlot) Plot() { - imgui.ImPlotScatter(Context.FontAtlas.RegisterString(p.label), p.values, p.xscale, p.x0, p.offset) + imgui.PlotPlotScatterdoublePtrIntV( + Context.FontAtlas.RegisterString(p.label), + &p.values, + int32(len(p.values)), + p.xscale, + p.x0, + 0, // TODO: implement flags + int32(p.offset), + 0, // TODO: implement + ) } type ScatterXYPlot struct { @@ -468,5 +567,13 @@ func (p *ScatterXYPlot) Offset(offset int) *ScatterXYPlot { } func (p *ScatterXYPlot) Plot() { - imgui.ImPlotScatterXY(Context.FontAtlas.RegisterString(p.label), p.xs, p.ys, p.offset) + imgui.PlotPlotScatterdoublePtrdoublePtrV( + Context.FontAtlas.RegisterString(p.label), + &p.xs, + &p.ys, + int32(len(p.xs)), + 0, // TODO: implement + int32(p.offset), + 0, // TODO: implement + ) } diff --git a/Popups.go b/Popups.go index c28464d5..2d8446ad 100644 --- a/Popups.go +++ b/Popups.go @@ -1,13 +1,13 @@ package giu import ( - "github.com/AllenDang/imgui-go" + imgui "github.com/AllenDang/cimgui-go" ) // OpenPopup opens a popup with specified id. // NOTE: you need to build this popup first (see Pop(Modal)Widget). func OpenPopup(name string) { - imgui.OpenPopup(name) + imgui.OpenPopupStr(name) } // CloseCurrentPopup closes currently opened popup. @@ -49,7 +49,7 @@ func (p *PopupWidget) Layout(widgets ...Widget) *PopupWidget { // Build implements Widget interface. func (p *PopupWidget) Build() { - if imgui.BeginPopup(p.name, int(p.flags)) { + if imgui.BeginPopupV(p.name, imgui.WindowFlags(p.flags)) { p.layout.Build() imgui.EndPopup() } @@ -98,7 +98,7 @@ func (p *PopupModalWidget) Layout(widgets ...Widget) *PopupModalWidget { // Build implements Widget interface. func (p *PopupModalWidget) Build() { - if imgui.BeginPopupModalV(p.name, p.open, int(p.flags)) { + if imgui.BeginPopupModalV(p.name, p.open, imgui.WindowFlags(p.flags)) { p.layout.Build() imgui.EndPopup() } diff --git a/ProgressIndicator.go b/ProgressIndicator.go index 9463fd76..dba0ae88 100644 --- a/ProgressIndicator.go +++ b/ProgressIndicator.go @@ -6,7 +6,7 @@ import ( "sync" "time" - "github.com/AllenDang/imgui-go" + imgui "github.com/AllenDang/cimgui-go" ) var _ Disposable = &progressIndicatorState{} @@ -108,10 +108,10 @@ func (p *ProgressIndicatorWidget) Build() { int(float64(p.radius)*math.Cos(angle)+float64(centerPt.Y)), ) - color := imgui.CurrentStyle().GetColor(imgui.StyleColorText) - rgba := Vec4ToRGBA(color) + color := imgui.StyleColorVec4(imgui.ColText) + rgba := Vec4ToRGBA(*color) - canvas.AddCircle(centerPt, p.radius, rgba, int(p.radius), p.radius/20.0) + canvas.AddCircle(centerPt, p.radius, rgba, int32(p.radius), p.radius/20.0) canvas.AddCircleFilled(centerPt2, p.radius/5, rgba) // Draw text diff --git a/SliderWidgets.go b/SliderWidgets.go index ee11f2d5..53478257 100644 --- a/SliderWidgets.go +++ b/SliderWidgets.go @@ -3,7 +3,7 @@ package giu import ( "fmt" - "github.com/AllenDang/imgui-go" + imgui "github.com/AllenDang/cimgui-go" ) var _ Widget = &SliderIntWidget{} @@ -72,7 +72,7 @@ func (s *SliderIntWidget) Build() { defer PopItemWidth() } - if imgui.SliderIntV(Context.FontAtlas.RegisterString(s.label), s.value, s.min, s.max, s.format) && s.onChange != nil { + if imgui.SliderIntV(Context.FontAtlas.RegisterString(s.label), s.value, s.min, s.max, s.format, 0) && s.onChange != nil { s.onChange() } } @@ -150,7 +150,7 @@ func (vs *VSliderIntWidget) Build() { vs.min, vs.max, vs.format, - int(vs.flags), + imgui.SliderFlags(vs.flags), ) && vs.onChange != nil { vs.onChange() } diff --git a/SplitLayout.go b/SplitLayout.go index a11a6b25..87f1d002 100644 --- a/SplitLayout.go +++ b/SplitLayout.go @@ -3,7 +3,7 @@ package giu import ( "image/color" - "github.com/AllenDang/imgui-go" + imgui "github.com/AllenDang/cimgui-go" ) // SplitDirection represents a direction (vertical/horizontal) of splitting layout. @@ -119,8 +119,8 @@ func (s *SplitLayoutWidget) restoreItemSpacing(layout Widget) Layout { PushItemSpacing(s.originItemSpacingX, s.originItemSpacingY) PushFramePadding(s.originFramePaddingX, s.originFramePaddingY) // Restore Child bg color - bgColor := imgui.CurrentStyle().GetColor(imgui.StyleColorChildBg) - PushStyleColor(StyleColorChildBg, Vec4ToRGBA(bgColor)) + bgColor := imgui.StyleColorVec4(imgui.ColChildBg) + PushStyleColor(StyleColorChildBg, Vec4ToRGBA(*bgColor)) }), layout, Custom(func() { diff --git a/StackWidget.go b/StackWidget.go index 99d8c327..bce8a2dd 100644 --- a/StackWidget.go +++ b/StackWidget.go @@ -1,6 +1,6 @@ package giu -import "github.com/AllenDang/imgui-go" +import imgui "github.com/AllenDang/cimgui-go" var _ Widget = &StackWidget{} diff --git a/Style.go b/Style.go index 0ca1418b..68aadf0e 100644 --- a/Style.go +++ b/Style.go @@ -3,7 +3,7 @@ package giu import ( "image/color" - "github.com/AllenDang/imgui-go" + imgui "github.com/AllenDang/cimgui-go" ) // You may want to use styles in order to make your app looking more beautiful. @@ -46,7 +46,7 @@ func PushFont(font *FontInfo) bool { } if f, ok := Context.FontAtlas.extraFontMap[font.String()]; ok { - imgui.PushFont(*f) + imgui.PushFont(f) return true } @@ -58,52 +58,52 @@ func PopFont() { imgui.PopFont() } -// PushStyleColor wraps imgui.PushStyleColor +// PushStyleColor wraps imgui.PushStyleColorVec4 // NOTE: don't forget to call PopStyleColor()! func PushStyleColor(id StyleColorID, col color.Color) { - imgui.PushStyleColor(imgui.StyleColorID(id), ToVec4Color(col)) + imgui.PushStyleColorVec4(imgui.Col(id), ToVec4Color(col)) } // PushColorText calls PushStyleColor(StyleColorText,...) // NOTE: don't forget to call PopStyleColor()! func PushColorText(col color.Color) { - imgui.PushStyleColor(imgui.StyleColorText, ToVec4Color(col)) + imgui.PushStyleColorVec4(imgui.ColText, ToVec4Color(col)) } // PushColorTextDisabled calls PushStyleColor(StyleColorTextDisabled,...) // NOTE: don't forget to call PopStyleColor()! func PushColorTextDisabled(col color.Color) { - imgui.PushStyleColor(imgui.StyleColorTextDisabled, ToVec4Color(col)) + imgui.PushStyleColorVec4(imgui.ColTextDisabled, ToVec4Color(col)) } // PushColorWindowBg calls PushStyleColor(StyleColorWindowBg,...) // NOTE: don't forget to call PopStyleColor()! func PushColorWindowBg(col color.Color) { - imgui.PushStyleColor(imgui.StyleColorWindowBg, ToVec4Color(col)) + imgui.PushStyleColorVec4(imgui.ColWindowBg, ToVec4Color(col)) } // PushColorFrameBg calls PushStyleColor(StyleColorFrameBg,...) // NOTE: don't forget to call PopStyleColor()! func PushColorFrameBg(col color.Color) { - imgui.PushStyleColor(imgui.StyleColorFrameBg, ToVec4Color(col)) + imgui.PushStyleColorVec4(imgui.ColFrameBg, ToVec4Color(col)) } // PushColorButton calls PushStyleColor(StyleColorButton,...) // NOTE: don't forget to call PopStyleColor()! func PushColorButton(col color.Color) { - imgui.PushStyleColor(imgui.StyleColorButton, ToVec4Color(col)) + imgui.PushStyleColorVec4(imgui.ColButton, ToVec4Color(col)) } // PushColorButtonHovered calls PushStyleColor(StyleColorButtonHovered,...) // NOTE: don't forget to call PopStyleColor()! func PushColorButtonHovered(col color.Color) { - imgui.PushStyleColor(imgui.StyleColorButtonHovered, ToVec4Color(col)) + imgui.PushStyleColorVec4(imgui.ColButtonHovered, ToVec4Color(col)) } // PushColorButtonActive calls PushStyleColor(StyleColorButtonActive,...) // NOTE: don't forget to call PopStyleColor()! func PushColorButtonActive(col color.Color) { - imgui.PushStyleColor(imgui.StyleColorButtonActive, ToVec4Color(col)) + imgui.PushStyleColorVec4(imgui.ColButtonActive, ToVec4Color(col)) } // PushWindowPadding calls PushStyleVar(StyleWindowPadding,...) @@ -141,7 +141,7 @@ func PopStyle() { // PopStyleV does similarly to PopStyle, but allows to specify number // of styles you're going to pop. func PopStyleV(count int) { - imgui.PopStyleVarV(count) + imgui.PopStyleVarV(int32(count)) } // PopStyleColor is used to stop applying colors styles. @@ -155,7 +155,7 @@ func PopStyleColor() { // PopStyleColorV does similar to PopStyleColor, but allows to specify // how much style colors would you like to pop. func PopStyleColorV(count int) { - imgui.PopStyleColorV(count) + imgui.PopStyleColorV(int32(count)) } // AlignTextToFramePadding vertically aligns upcoming text baseline to @@ -194,34 +194,34 @@ func PopTextWrapPos() { } // MouseCursorType represents a type (layout) of mouse cursor. -type MouseCursorType int +type MouseCursorType imgui.MouseCursor // cursor types. const ( // MouseCursorNone no mouse cursor. - MouseCursorNone MouseCursorType = -1 + MouseCursorNone MouseCursorType = imgui.MouseCursorNone // MouseCursorArrow standard arrow mouse cursor. - MouseCursorArrow MouseCursorType = 0 + MouseCursorArrow MouseCursorType = imgui.MouseCursorArrow // MouseCursorTextInput when hovering over InputText, etc. - MouseCursorTextInput MouseCursorType = 1 + MouseCursorTextInput MouseCursorType = imgui.MouseCursorTextInput // MouseCursorResizeAll (Unused by imgui functions). - MouseCursorResizeAll MouseCursorType = 2 + MouseCursorResizeAll MouseCursorType = imgui.MouseCursorResizeAll // MouseCursorResizeNS when hovering over an horizontal border. - MouseCursorResizeNS MouseCursorType = 3 + MouseCursorResizeNS MouseCursorType = imgui.MouseCursorResizeNS // MouseCursorResizeEW when hovering over a vertical border or a column. - MouseCursorResizeEW MouseCursorType = 4 + MouseCursorResizeEW MouseCursorType = imgui.MouseCursorResizeEW // MouseCursorResizeNESW when hovering over the bottom-left corner of a window. - MouseCursorResizeNESW MouseCursorType = 5 + MouseCursorResizeNESW MouseCursorType = imgui.MouseCursorResizeNESW // MouseCursorResizeNWSE when hovering over the bottom-right corner of a window. - MouseCursorResizeNWSE MouseCursorType = 6 + MouseCursorResizeNWSE MouseCursorType = imgui.MouseCursorResizeNWSE // MouseCursorHand (Unused by imgui functions. Use for e.g. hyperlinks). - MouseCursorHand MouseCursorType = 7 - MouseCursorCount MouseCursorType = 8 + MouseCursorHand MouseCursorType = imgui.MouseCursorHand + MouseCursorCount MouseCursorType = imgui.MouseCursorCOUNT ) // SetMouseCursor sets mouse cursor layout. func SetMouseCursor(cursor MouseCursorType) { - imgui.SetMouseCursor(int(cursor)) + imgui.SetMouseCursor(imgui.MouseCursor(cursor)) } // GetWindowPadding returns window padding. diff --git a/StyleIDs.go b/StyleIDs.go index f195cfd4..65ef313d 100644 --- a/StyleIDs.go +++ b/StyleIDs.go @@ -1,6 +1,6 @@ package giu -import "github.com/AllenDang/imgui-go" +import imgui "github.com/AllenDang/cimgui-go" // Here are the style IDs for styling imgui apps. // For details about each of attributes read comment above them. @@ -11,69 +11,69 @@ import "github.com/AllenDang/imgui-go" //go:generate string2enum -samepkg -type=StyleColorID,StyleVarID -output=StyleIDs_string2enum.go -linecomment // StyleColorID identifies a color in the UI style. -type StyleColorID imgui.StyleColorID +type StyleColorID imgui.Col // StyleColor identifier. // NOTE: comments are used for CSS conversion and are generated by stringer and string2enum. const ( - StyleColorText = StyleColorID(imgui.StyleColorText) // color - StyleColorTextDisabled = StyleColorID(imgui.StyleColorTextDisabled) // disabled-color - StyleColorWindowBg = StyleColorID(imgui.StyleColorWindowBg) // background-color - StyleColorChildBg = StyleColorID(imgui.StyleColorChildBg) // child-background-color - StyleColorPopupBg = StyleColorID(imgui.StyleColorPopupBg) // popup-background-color - StyleColorBorder = StyleColorID(imgui.StyleColorBorder) // border-color - StyleColorBorderShadow = StyleColorID(imgui.StyleColorBorderShadow) // border-shadow-color - StyleColorFrameBg = StyleColorID(imgui.StyleColorFrameBg) // frame-background-color - StyleColorFrameBgHovered = StyleColorID(imgui.StyleColorFrameBgHovered) // frame-background-hovered-color - StyleColorFrameBgActive = StyleColorID(imgui.StyleColorFrameBgActive) // frame-background-active-color - StyleColorTitleBg = StyleColorID(imgui.StyleColorTitleBg) // title-background-color - StyleColorTitleBgActive = StyleColorID(imgui.StyleColorTitleBgActive) // title-background-active-color - StyleColorTitleBgCollapsed = StyleColorID(imgui.StyleColorTitleBgCollapsed) // title-background-collapsed-color - StyleColorMenuBarBg = StyleColorID(imgui.StyleColorMenuBarBg) // menu-bar-background-color - StyleColorScrollbarBg = StyleColorID(imgui.StyleColorScrollbarBg) // scrollbar-background-color - StyleColorScrollbarGrab = StyleColorID(imgui.StyleColorScrollbarGrab) // scrollbar-grab-color - StyleColorScrollbarGrabHovered = StyleColorID(imgui.StyleColorScrollbarGrabHovered) // scrollbar-grab-hovered-color - StyleColorScrollbarGrabActive = StyleColorID(imgui.StyleColorScrollbarGrabActive) // scrollbar-grab-active-color - StyleColorCheckMark = StyleColorID(imgui.StyleColorCheckMark) // checkmark-color - StyleColorSliderGrab = StyleColorID(imgui.StyleColorSliderGrab) // slider-grab-color - StyleColorSliderGrabActive = StyleColorID(imgui.StyleColorSliderGrabActive) // slider-grab-active-color - StyleColorButton = StyleColorID(imgui.StyleColorButton) // button-color - StyleColorButtonHovered = StyleColorID(imgui.StyleColorButtonHovered) // button-hovered-color - StyleColorButtonActive = StyleColorID(imgui.StyleColorButtonActive) // button-active-color - StyleColorHeader = StyleColorID(imgui.StyleColorHeader) // header-color - StyleColorHeaderHovered = StyleColorID(imgui.StyleColorHeaderHovered) // header-hovered-color - StyleColorHeaderActive = StyleColorID(imgui.StyleColorHeaderActive) // header-active-color - StyleColorSeparator = StyleColorID(imgui.StyleColorSeparator) // separator-color - StyleColorSeparatorHovered = StyleColorID(imgui.StyleColorSeparatorHovered) // separator-hovered-color - StyleColorSeparatorActive = StyleColorID(imgui.StyleColorSeparatorActive) // separator-active-color - StyleColorResizeGrip = StyleColorID(imgui.StyleColorResizeGrip) // resize-grip-color - StyleColorResizeGripHovered = StyleColorID(imgui.StyleColorResizeGripHovered) // resize-grip-hovered-color - StyleColorResizeGripActive = StyleColorID(imgui.StyleColorResizeGripActive) // resize-grip-active-color - StyleColorTab = StyleColorID(imgui.StyleColorTab) // tab-color - StyleColorTabHovered = StyleColorID(imgui.StyleColorTabHovered) // tab-hovered-color - StyleColorTabActive = StyleColorID(imgui.StyleColorTabActive) // tab-active-color - StyleColorTabUnfocused = StyleColorID(imgui.StyleColorTabUnfocused) // tab-unfocused-color - StyleColorTabUnfocusedActive = StyleColorID(imgui.StyleColorTabUnfocusedActive) // tab-unfocused-active-color - StyleColorPlotLines = StyleColorID(imgui.StyleColorPlotLines) // plot-lines-color - StyleColorPlotLinesHovered = StyleColorID(imgui.StyleColorPlotLinesHovered) // plot-lines-hovered-color - StyleColorProgressBarActive = StyleColorPlotLinesHovered // progress-bar-active-color - StyleColorPlotHistogram = StyleColorID(imgui.StyleColorPlotHistogram) // plot-histogram-color - StyleColorPlotHistogramHovered = StyleColorID(imgui.StyleColorPlotHistogramHovered) // plot-histogram-hovered-color - StyleColorTableHeaderBg = StyleColorID(imgui.StyleColorTableHeaderBg) // table-header-background-color - StyleColorTableBorderStrong = StyleColorID(imgui.StyleColorTableBorderStrong) // table-border-strong-color - StyleColorTableBorderLight = StyleColorID(imgui.StyleColorTableBorderLight) // table-border-light-color - StyleColorTableRowBg = StyleColorID(imgui.StyleColorTableRowBg) // table-row-background-color - StyleColorTableRowBgAlt = StyleColorID(imgui.StyleColorTableRowBgAlt) // table-row-alternate-background-color - StyleColorTextSelectedBg = StyleColorID(imgui.StyleColorTextSelectedBg) // text-selected-background-color - StyleColorDragDropTarget = StyleColorID(imgui.StyleColorDragDropTarget) // drag-drop-target-color - StyleColorNavHighlight = StyleColorID(imgui.StyleColorNavHighlight) // navigation-highlight-color - StyleColorNavWindowingHighlight = StyleColorID(imgui.StyleColorNavWindowingHighlight) // windowing-highlight-color - StyleColorNavWindowingDimBg = StyleColorID(imgui.StyleColorNavWindowingDimBg) // windowing-dim-background-color - StyleColorModalWindowDimBg = StyleColorID(imgui.StyleColorModalWindowDimBg) // modal-window-dim-background-color + StyleColorText = StyleColorID(imgui.ColText) // color + StyleColorTextDisabled = StyleColorID(imgui.ColTextDisabled) // disabled-color + StyleColorWindowBg = StyleColorID(imgui.ColWindowBg) // background-color + StyleColorChildBg = StyleColorID(imgui.ColChildBg) // child-background-color + StyleColorPopupBg = StyleColorID(imgui.ColPopupBg) // popup-background-color + StyleColorBorder = StyleColorID(imgui.ColBorder) // border-color + StyleColorBorderShadow = StyleColorID(imgui.ColBorderShadow) // border-shadow-color + StyleColorFrameBg = StyleColorID(imgui.ColFrameBg) // frame-background-color + StyleColorFrameBgHovered = StyleColorID(imgui.ColFrameBgHovered) // frame-background-hovered-color + StyleColorFrameBgActive = StyleColorID(imgui.ColFrameBgActive) // frame-background-active-color + StyleColorTitleBg = StyleColorID(imgui.ColTitleBg) // title-background-color + StyleColorTitleBgActive = StyleColorID(imgui.ColTitleBgActive) // title-background-active-color + StyleColorTitleBgCollapsed = StyleColorID(imgui.ColTitleBgCollapsed) // title-background-collapsed-color + StyleColorMenuBarBg = StyleColorID(imgui.ColMenuBarBg) // menu-bar-background-color + StyleColorScrollbarBg = StyleColorID(imgui.ColScrollbarBg) // scrollbar-background-color + StyleColorScrollbarGrab = StyleColorID(imgui.ColScrollbarGrab) // scrollbar-grab-color + StyleColorScrollbarGrabHovered = StyleColorID(imgui.ColScrollbarGrabHovered) // scrollbar-grab-hovered-color + StyleColorScrollbarGrabActive = StyleColorID(imgui.ColScrollbarGrabActive) // scrollbar-grab-active-color + StyleColorCheckMark = StyleColorID(imgui.ColCheckMark) // checkmark-color + StyleColorSliderGrab = StyleColorID(imgui.ColSliderGrab) // slider-grab-color + StyleColorSliderGrabActive = StyleColorID(imgui.ColSliderGrabActive) // slider-grab-active-color + StyleColorButton = StyleColorID(imgui.ColButton) // button-color + StyleColorButtonHovered = StyleColorID(imgui.ColButtonHovered) // button-hovered-color + StyleColorButtonActive = StyleColorID(imgui.ColButtonActive) // button-active-color + StyleColorHeader = StyleColorID(imgui.ColHeader) // header-color + StyleColorHeaderHovered = StyleColorID(imgui.ColHeaderHovered) // header-hovered-color + StyleColorHeaderActive = StyleColorID(imgui.ColHeaderActive) // header-active-color + StyleColorSeparator = StyleColorID(imgui.ColSeparator) // separator-color + StyleColorSeparatorHovered = StyleColorID(imgui.ColSeparatorHovered) // separator-hovered-color + StyleColorSeparatorActive = StyleColorID(imgui.ColSeparatorActive) // separator-active-color + StyleColorResizeGrip = StyleColorID(imgui.ColResizeGrip) // resize-grip-color + StyleColorResizeGripHovered = StyleColorID(imgui.ColResizeGripHovered) // resize-grip-hovered-color + StyleColorResizeGripActive = StyleColorID(imgui.ColResizeGripActive) // resize-grip-active-color + StyleColorTab = StyleColorID(imgui.ColTab) // tab-color + StyleColorTabHovered = StyleColorID(imgui.ColTabHovered) // tab-hovered-color + StyleColorTabActive = StyleColorID(imgui.ColTabActive) // tab-active-color + StyleColorTabUnfocused = StyleColorID(imgui.ColTabUnfocused) // tab-unfocused-color + StyleColorTabUnfocusedActive = StyleColorID(imgui.ColTabUnfocusedActive) // tab-unfocused-active-color + StyleColorPlotLines = StyleColorID(imgui.ColPlotLines) // plot-lines-color + StyleColorPlotLinesHovered = StyleColorID(imgui.ColPlotLinesHovered) // plot-lines-hovered-color + StyleColorProgressBarActive = StyleColorPlotLinesHovered // progress-bar-active-color + StyleColorPlotHistogram = StyleColorID(imgui.ColPlotHistogram) // plot-histogram-color + StyleColorPlotHistogramHovered = StyleColorID(imgui.ColPlotHistogramHovered) // plot-histogram-hovered-color + StyleColorTableHeaderBg = StyleColorID(imgui.ColTableHeaderBg) // table-header-background-color + StyleColorTableBorderStrong = StyleColorID(imgui.ColTableBorderStrong) // table-border-strong-color + StyleColorTableBorderLight = StyleColorID(imgui.ColTableBorderLight) // table-border-light-color + StyleColorTableRowBg = StyleColorID(imgui.ColTableRowBg) // table-row-background-color + StyleColorTableRowBgAlt = StyleColorID(imgui.ColTableRowBgAlt) // table-row-alternate-background-color + StyleColorTextSelectedBg = StyleColorID(imgui.ColTextSelectedBg) // text-selected-background-color + StyleColorDragDropTarget = StyleColorID(imgui.ColDragDropTarget) // drag-drop-target-color + StyleColorNavHighlight = StyleColorID(imgui.ColNavHighlight) // navigation-highlight-color + StyleColorNavWindowingHighlight = StyleColorID(imgui.ColNavWindowingHighlight) // windowing-highlight-color + StyleColorNavWindowingDimBg = StyleColorID(imgui.ColNavWindowingDimBg) // windowing-dim-background-color + StyleColorModalWindowDimBg = StyleColorID(imgui.ColModalWindowDimBg) // modal-window-dim-background-color ) // StyleVarID identifies a style variable in the UI style. -type StyleVarID imgui.StyleVarID +type StyleVarID imgui.StyleVar // Style IDs. // comments at same line is a CSS name. diff --git a/StyleIDs_string.go b/StyleIDs_string.go index e392a237..96f7447a 100644 --- a/StyleIDs_string.go +++ b/StyleIDs_string.go @@ -46,33 +46,43 @@ func _() { _ = x[StyleColorTabActive-35] _ = x[StyleColorTabUnfocused-36] _ = x[StyleColorTabUnfocusedActive-37] - _ = x[StyleColorPlotLines-38] - _ = x[StyleColorPlotLinesHovered-39] - _ = x[StyleColorProgressBarActive-39] - _ = x[StyleColorPlotHistogram-40] - _ = x[StyleColorPlotHistogramHovered-41] - _ = x[StyleColorTableHeaderBg-42] - _ = x[StyleColorTableBorderStrong-43] - _ = x[StyleColorTableBorderLight-44] - _ = x[StyleColorTableRowBg-45] - _ = x[StyleColorTableRowBgAlt-46] - _ = x[StyleColorTextSelectedBg-47] - _ = x[StyleColorDragDropTarget-48] - _ = x[StyleColorNavHighlight-49] - _ = x[StyleColorNavWindowingHighlight-50] - _ = x[StyleColorNavWindowingDimBg-51] - _ = x[StyleColorModalWindowDimBg-52] + _ = x[StyleColorPlotLines-40] + _ = x[StyleColorPlotLinesHovered-41] + _ = x[StyleColorPlotHistogram-42] + _ = x[StyleColorPlotHistogramHovered-43] + _ = x[StyleColorTableHeaderBg-44] + _ = x[StyleColorTableBorderStrong-45] + _ = x[StyleColorTableBorderLight-46] + _ = x[StyleColorTableRowBg-47] + _ = x[StyleColorTableRowBgAlt-48] + _ = x[StyleColorTextSelectedBg-49] + _ = x[StyleColorDragDropTarget-50] + _ = x[StyleColorNavHighlight-51] + _ = x[StyleColorNavWindowingHighlight-52] + _ = x[StyleColorNavWindowingDimBg-53] + _ = x[StyleColorModalWindowDimBg-54] } -const _StyleColorID_name = "colordisabled-colorbackground-colorchild-background-colorpopup-background-colorborder-colorborder-shadow-colorframe-background-colorframe-background-hovered-colorframe-background-active-colortitle-background-colortitle-background-active-colortitle-background-collapsed-colormenu-bar-background-colorscrollbar-background-colorscrollbar-grab-colorscrollbar-grab-hovered-colorscrollbar-grab-active-colorcheckmark-colorslider-grab-colorslider-grab-active-colorbutton-colorbutton-hovered-colorbutton-active-colorheader-colorheader-hovered-colorheader-active-colorseparator-colorseparator-hovered-colorseparator-active-colorresize-grip-colorresize-grip-hovered-colorresize-grip-active-colortab-colortab-hovered-colortab-active-colortab-unfocused-colortab-unfocused-active-colorplot-lines-colorplot-lines-hovered-colorplot-histogram-colorplot-histogram-hovered-colortable-header-background-colortable-border-strong-colortable-border-light-colortable-row-background-colortable-row-alternate-background-colortext-selected-background-colordrag-drop-target-colornavigation-highlight-colorwindowing-highlight-colorwindowing-dim-background-colormodal-window-dim-background-color" +const ( + _StyleColorID_name_0 = "colordisabled-colorbackground-colorchild-background-colorpopup-background-colorborder-colorborder-shadow-colorframe-background-colorframe-background-hovered-colorframe-background-active-colortitle-background-colortitle-background-active-colortitle-background-collapsed-colormenu-bar-background-colorscrollbar-background-colorscrollbar-grab-colorscrollbar-grab-hovered-colorscrollbar-grab-active-colorcheckmark-colorslider-grab-colorslider-grab-active-colorbutton-colorbutton-hovered-colorbutton-active-colorheader-colorheader-hovered-colorheader-active-colorseparator-colorseparator-hovered-colorseparator-active-colorresize-grip-colorresize-grip-hovered-colorresize-grip-active-colortab-colortab-hovered-colortab-active-colortab-unfocused-colortab-unfocused-active-color" + _StyleColorID_name_1 = "plot-lines-colorplot-lines-hovered-colorplot-histogram-colorplot-histogram-hovered-colortable-header-background-colortable-border-strong-colortable-border-light-colortable-row-background-colortable-row-alternate-background-colortext-selected-background-colordrag-drop-target-colornavigation-highlight-colorwindowing-highlight-colorwindowing-dim-background-colormodal-window-dim-background-color" +) -var _StyleColorID_index = [...]uint16{0, 5, 19, 35, 57, 79, 91, 110, 132, 162, 191, 213, 242, 274, 299, 325, 345, 373, 400, 415, 432, 456, 468, 488, 507, 519, 539, 558, 573, 596, 618, 635, 660, 684, 693, 710, 726, 745, 771, 787, 811, 831, 859, 888, 913, 937, 963, 999, 1029, 1051, 1077, 1102, 1132, 1165} +var ( + _StyleColorID_index_0 = [...]uint16{0, 5, 19, 35, 57, 79, 91, 110, 132, 162, 191, 213, 242, 274, 299, 325, 345, 373, 400, 415, 432, 456, 468, 488, 507, 519, 539, 558, 573, 596, 618, 635, 660, 684, 693, 710, 726, 745, 771} + _StyleColorID_index_1 = [...]uint16{0, 16, 40, 60, 88, 117, 142, 166, 192, 228, 258, 280, 306, 331, 361, 394} +) func (i StyleColorID) String() string { - if i < 0 || i >= StyleColorID(len(_StyleColorID_index)-1) { + switch { + case 0 <= i && i <= 37: + return _StyleColorID_name_0[_StyleColorID_index_0[i]:_StyleColorID_index_0[i+1]] + case 40 <= i && i <= 54: + i -= 40 + return _StyleColorID_name_1[_StyleColorID_index_1[i]:_StyleColorID_index_1[i+1]] + default: return "StyleColorID(" + strconv.FormatInt(int64(i), 10) + ")" } - return _StyleColorID_name[_StyleColorID_index[i]:_StyleColorID_index[i+1]] } func _() { // An "invalid array index" compiler error signifies that the constant values have changed. diff --git a/StyleIDs_string2enum.go b/StyleIDs_string2enum.go index f6921d7b..92ce946b 100644 --- a/StyleIDs_string2enum.go +++ b/StyleIDs_string2enum.go @@ -9,9 +9,14 @@ func StyleColorIDFromString(s string) StyleColorID { if len(s) == 0 { return 0 } - for i := range _StyleColorID_index[:len(_StyleColorID_index)-1] { - if s == _StyleColorID_name[_StyleColorID_index[i]:_StyleColorID_index[i+1]] { - return StyleColorID(i) + for i := range _StyleColorID_index_0[:len(_StyleColorID_index_0)-1] { + if s == _StyleColorID_name_0[_StyleColorID_index_0[i]:_StyleColorID_index_0[i+1]] { + return StyleColorID(i + 0) + } + } + for i := range _StyleColorID_index_1[:len(_StyleColorID_index_1)-1] { + if s == _StyleColorID_name_1[_StyleColorID_index_1[i]:_StyleColorID_index_1[i+1]] { + return StyleColorID(i + 40) } } panic(fmt.Errorf("unable to locate StyleColorID enum corresponding to %q", s)) @@ -96,35 +101,35 @@ func _(s string) { case "tab-unfocused-color": // 37 case "tab-unfocused-active-color": - // 38 + // 40 case "plot-lines-color": - // 39 + // 41 case "plot-lines-hovered-color": - // 40 + // 42 case "plot-histogram-color": - // 41 + // 43 case "plot-histogram-hovered-color": - // 42 + // 44 case "table-header-background-color": - // 43 + // 45 case "table-border-strong-color": - // 44 + // 46 case "table-border-light-color": - // 45 + // 47 case "table-row-background-color": - // 46 + // 48 case "table-row-alternate-background-color": - // 47 + // 49 case "text-selected-background-color": - // 48 + // 50 case "drag-drop-target-color": - // 49 + // 51 case "navigation-highlight-color": - // 50 + // 52 case "windowing-highlight-color": - // 51 + // 53 case "windowing-dim-background-color": - // 52 + // 54 case "modal-window-dim-background-color": } } diff --git a/StyleSetter.go b/StyleSetter.go index 6466ebd5..3f9f3500 100644 --- a/StyleSetter.go +++ b/StyleSetter.go @@ -3,7 +3,7 @@ package giu import ( "image/color" - "github.com/AllenDang/imgui-go" + imgui "github.com/AllenDang/cimgui-go" ) var _ Widget = &StyleSetter{} @@ -149,7 +149,7 @@ func (ss *StyleSetter) Build() { func (ss *StyleSetter) Push() { // Push colors for k, v := range ss.colors { - imgui.PushStyleColor(imgui.StyleColorID(k), ToVec4Color(v)) + imgui.PushStyleColorVec4(imgui.Col(k), ToVec4Color(v)) } // push style vars @@ -163,7 +163,7 @@ func (ss *StyleSetter) Push() { value = imgui.Vec2{X: typed, Y: typed} } - imgui.PushStyleVarVec2(imgui.StyleVarID(k), value) + imgui.PushStyleVarVec2(imgui.StyleVar(k), value) } else { var value float32 switch typed := v.(type) { @@ -173,7 +173,7 @@ func (ss *StyleSetter) Push() { value = typed.X } - imgui.PushStyleVarFloat(imgui.StyleVarID(k), value) + imgui.PushStyleVarFloat(imgui.StyleVar(k), value) } } @@ -182,7 +182,9 @@ func (ss *StyleSetter) Push() { ss.isFontPushed = PushFont(ss.font) } - imgui.BeginDisabled(ss.disabled) + if ss.disabled { + imgui.BeginDisabled() + } } // Pop allows to manually pop the whole StyleSetter (use after Push!) @@ -191,7 +193,10 @@ func (ss *StyleSetter) Pop() { imgui.PopFont() } - imgui.EndDisabled() - imgui.PopStyleColorV(len(ss.colors)) - imgui.PopStyleVarV(len(ss.styles)) + if ss.disabled { + imgui.EndDisabled() + } + + imgui.PopStyleColorV(int32(len(ss.colors))) + imgui.PopStyleVarV(int32(len(ss.styles))) } diff --git a/TableWidgets.go b/TableWidgets.go index 8ea380fd..d314ce44 100644 --- a/TableWidgets.go +++ b/TableWidgets.go @@ -3,7 +3,7 @@ package giu import ( "image/color" - "github.com/AllenDang/imgui-go" + imgui "github.com/AllenDang/cimgui-go" ) type TableRowWidget struct { @@ -39,7 +39,7 @@ func (r *TableRowWidget) MinHeight(height float64) *TableRowWidget { // BuildTableRow executes table row build steps. func (r *TableRowWidget) BuildTableRow() { - imgui.TableNextRow(imgui.TableRowFlags(r.flags), r.minRowHeight) + imgui.TableNextRowV(imgui.TableRowFlags(r.flags), float32(r.minRowHeight)) for _, w := range r.layout { switch w.(type) { @@ -54,7 +54,7 @@ func (r *TableRowWidget) BuildTableRow() { } if r.bgColor != nil { - imgui.TableSetBgColor(imgui.TableBgTarget_RowBg0, uint32(imgui.GetColorU32(ToVec4Color(r.bgColor))), -1) + imgui.TableSetBgColorV(imgui.TableBgTargetRowBg0, imgui.ColorU32Vec4(ToVec4Color(r.bgColor)), -1) } } @@ -91,7 +91,7 @@ func (c *TableColumnWidget) UserID(id uint32) *TableColumnWidget { // BuildTableColumn executes table column build steps. func (c *TableColumnWidget) BuildTableColumn() { - imgui.TableSetupColumn(c.label, imgui.TableColumnFlags(c.flags), c.innerWidthOrWeight, c.userID) + imgui.TableSetupColumnV(c.label, imgui.TableColumnFlags(c.flags), c.innerWidthOrWeight, imgui.ID(c.userID)) } var _ Widget = &TableWidget{} @@ -172,9 +172,9 @@ func (t *TableWidget) Build() { colCount = len(t.rows[0].layout) } - if imgui.BeginTable(t.id, colCount, imgui.TableFlags(t.flags), t.size, t.innerWidth) { + if imgui.BeginTableV(t.id, int32(colCount), imgui.TableFlags(t.flags), t.size, float32(t.innerWidth)) { if t.freezeColumn >= 0 && t.freezeRow >= 0 { - imgui.TableSetupScrollFreeze(t.freezeColumn, t.freezeRow) + imgui.TableSetupScrollFreeze(int32(t.freezeColumn), int32(t.freezeRow)) } if len(t.columns) > 0 { @@ -187,9 +187,9 @@ func (t *TableWidget) Build() { if t.fastMode { clipper := imgui.NewListClipper() - defer clipper.Delete() + defer clipper.Destroy() - clipper.Begin(len(t.rows)) + clipper.Begin(int32(len(t.rows))) for clipper.Step() { for i := clipper.DisplayStart(); i < clipper.DisplayEnd(); i++ { @@ -239,15 +239,15 @@ func (ttr *TreeTableRowWidget) Flags(flags TreeNodeFlags) *TreeTableRowWidget { // BuildTreeTableRow executes table row building steps. func (ttr *TreeTableRowWidget) BuildTreeTableRow() { - imgui.TableNextRow(0, 0) + imgui.TableNextRowV(0, 0) imgui.TableNextColumn() open := false if len(ttr.children) > 0 { - open = imgui.TreeNodeV(Context.FontAtlas.RegisterString(ttr.label), int(ttr.flags)) + open = imgui.TreeNodeExStrV(Context.FontAtlas.RegisterString(ttr.label), imgui.TreeNodeFlags(ttr.flags)) } else { ttr.flags |= TreeNodeFlagsLeaf | TreeNodeFlagsNoTreePushOnOpen - imgui.TreeNodeV(Context.FontAtlas.RegisterString(ttr.label), int(ttr.flags)) + imgui.TreeNodeExStrV(Context.FontAtlas.RegisterString(ttr.label), imgui.TreeNodeFlags(ttr.flags)) } for _, w := range ttr.layout { @@ -337,9 +337,9 @@ func (tt *TreeTableWidget) Build() { colCount = len(tt.rows[0].layout) + 1 } - if imgui.BeginTable(tt.id, colCount, imgui.TableFlags(tt.flags), tt.size, 0) { + if imgui.BeginTableV(tt.id, int32(colCount), imgui.TableFlags(tt.flags), tt.size, 0) { if tt.freezeColumn >= 0 && tt.freezeRow >= 0 { - imgui.TableSetupScrollFreeze(tt.freezeColumn, tt.freezeRow) + imgui.TableSetupScrollFreeze(int32(tt.freezeColumn), int32(tt.freezeRow)) } if len(tt.columns) > 0 { diff --git a/TextWidgets.go b/TextWidgets.go index bf324b06..4053eba2 100644 --- a/TextWidgets.go +++ b/TextWidgets.go @@ -6,7 +6,7 @@ import ( "golang.org/x/image/colornames" - "github.com/AllenDang/imgui-go" + imgui "github.com/AllenDang/cimgui-go" "github.com/sahilm/fuzzy" ) @@ -80,21 +80,21 @@ func (i *InputTextMultilineWidget) AutoScrollToBottom(b bool) *InputTextMultilin // Build implements Widget interface. func (i *InputTextMultilineWidget) Build() { - if imgui.InputTextMultilineV( + if imgui.InputTextMultiline( Context.FontAtlas.RegisterString(i.label), Context.FontAtlas.RegisterStringPointer(i.text), imgui.Vec2{ X: i.width, Y: i.height, }, - int(i.flags), i.cb, + imgui.InputTextFlags(i.flags), i.cb, ) && i.onChange != nil { i.onChange() } if i.scrollToBottom { - imgui.BeginChild(i.label) - imgui.SetScrollHereY(1.0) + imgui.BeginChildStr(i.label) // TODO: there is a V version + imgui.SetScrollHereYV(1.0) imgui.EndChild() } } @@ -243,7 +243,7 @@ func (i *InputTextWidget) Build() { defer PopItemWidth() } - isChanged := imgui.InputTextWithHint(i.label, i.hint, Context.FontAtlas.RegisterStringPointer(i.value), int(i.flags), i.cb) + isChanged := imgui.InputTextWithHint(i.label, i.hint, Context.FontAtlas.RegisterStringPointer(i.value), imgui.InputTextFlags(i.flags), i.cb) if isChanged && i.onChange != nil { i.onChange() @@ -283,7 +283,7 @@ func (i *InputTextWidget) handleAutoComplete(state *inputTextState) { } } - SetNextWindowPos(imgui.GetItemRectMin().X, imgui.GetItemRectMax().Y) + SetNextWindowPos(imgui.ItemRectMin().X, imgui.ItemRectMax().Y) imgui.BeginTooltip() labels.Build() imgui.EndTooltip() @@ -386,7 +386,13 @@ func (i *InputIntWidget) Build() { defer PopItemWidth() } - if imgui.InputIntV(i.label, i.value, i.step, i.stepFast, int(i.flags)) && i.onChange != nil { + if imgui.InputIntV( + i.label, + i.value, + int32(i.step), + int32(i.stepFast), + imgui.InputTextFlags(i.flags), + ) && i.onChange != nil { i.onChange() } } @@ -472,7 +478,14 @@ func (i *InputFloatWidget) Build() { defer PopItemWidth() } - if imgui.InputFloatV(i.label, i.value, i.step, i.stepFast, i.format, int(i.flags)) && i.onChange != nil { + if imgui.InputFloatV( + i.label, + i.value, + i.step, + i.stepFast, + i.format, + imgui.InputTextFlags(i.flags), + ) && i.onChange != nil { i.onChange() } } diff --git a/Texture.go b/Texture.go index db9f7e54..955cbd80 100644 --- a/Texture.go +++ b/Texture.go @@ -1,18 +1,15 @@ package giu import ( - "fmt" "image" - "runtime" - "github.com/AllenDang/imgui-go" - "github.com/faiface/mainthread" + imgui "github.com/AllenDang/cimgui-go" ) // Texture represents imgui.TextureID. // It is base unit of images in imgui. type Texture struct { - id imgui.TextureID + tex *imgui.Texture } type textureLoadRequest struct { @@ -20,11 +17,6 @@ type textureLoadRequest struct { cb func(*Texture) } -type loadImageResult struct { - id imgui.TextureID - err error -} - // EnqueueNewTextureFromRgba adds loading texture request to loading queue // it allows us to run this method in main loop // NOTE: remember to call it after NewMasterWindow! @@ -35,45 +27,21 @@ func EnqueueNewTextureFromRgba(rgba image.Image, loadCb func(t *Texture)) { // NewTextureFromRgba creates a new texture from image.Image and, when it is done, calls loadCallback(loadedTexture). func NewTextureFromRgba(rgba image.Image, loadCallback func(*Texture)) { - loadTexture(rgba, loadCallback) + tex := imgui.NewTextureFromRgba(ImageToRgba(rgba)) + loadCallback(&Texture{ + tex, + }) } -func loadTexture(rgba image.Image, loadCallback func(*Texture)) { - go func() { - Update() - - result := mainthread.CallVal(func() any { - texID, err := Context.renderer.LoadImage(ImageToRgba(rgba)) - return &loadImageResult{id: texID, err: err} - }) - - tid, ok := result.(*loadImageResult) - - switch { - case !ok: - panic("giu: NewTextureFromRgba: unexpected error occurred") - case tid.err != nil: - panic(fmt.Sprintf("giu: NewTextureFromRgba: error loading texture: %v", tid.err)) - } - - texture := Texture{id: tid.id} - - // Set finalizer - runtime.SetFinalizer(&texture, (*Texture).release) - - // execute callback - loadCallback(&texture) - }() +// ToTexture converts imgui.Texture to Texture. +func ToTexture(texture *imgui.Texture) *Texture { + return &Texture{tex: texture} } -// ToTexture converts imgui.TextureID to Texture. -func ToTexture(textureID imgui.TextureID) *Texture { - return &Texture{id: textureID} -} +func (t *Texture) ID() imgui.TextureID { + if t.tex != nil { + return t.tex.ID() + } -func (t *Texture) release() { - Update() - mainthread.Call(func() { - Context.renderer.ReleaseImage(t.id) - }) + return nil } diff --git a/Utils.go b/Utils.go index f4aa651e..9edcc635 100644 --- a/Utils.go +++ b/Utils.go @@ -10,7 +10,7 @@ import ( "os" "path/filepath" - "github.com/AllenDang/imgui-go" + imgui "github.com/AllenDang/cimgui-go" "github.com/pkg/browser" ) @@ -91,7 +91,7 @@ func Update() { defer Context.m.Unlock() if Context.isAlive { - Context.platform.Update() + Context.backend.Refresh() } } @@ -137,7 +137,12 @@ func CalcTextSize(text string) (width, height float32) { // CalcTextSizeV calculates text dimensions. func CalcTextSizeV(text string, hideAfterDoubleHash bool, wrapWidth float32) (w, h float32) { - size := imgui.CalcTextSize(text, hideAfterDoubleHash, wrapWidth) + size := imgui.CalcTextSizeV( + text, + hideAfterDoubleHash, + wrapWidth, + ) + return size.X, size.Y } @@ -146,15 +151,15 @@ func SetNextWindowSize(width, height float32) { imgui.SetNextWindowSize(imgui.Vec2{X: width, Y: height}) } -// ExecCondition represents imgui.Condition. -type ExecCondition imgui.Condition +// ExecCondition represents imgui.Cond. +type ExecCondition imgui.Cond // imgui conditions. const ( - ConditionAlways ExecCondition = ExecCondition(imgui.ConditionAlways) - ConditionOnce ExecCondition = ExecCondition(imgui.ConditionOnce) - ConditionFirstUseEver ExecCondition = ExecCondition(imgui.ConditionFirstUseEver) - ConditionAppearing ExecCondition = ExecCondition(imgui.ConditionAppearing) + ConditionAlways ExecCondition = ExecCondition(imgui.CondAlways) + ConditionOnce ExecCondition = ExecCondition(imgui.CondOnce) + ConditionFirstUseEver ExecCondition = ExecCondition(imgui.CondFirstUseEver) + ConditionAppearing ExecCondition = ExecCondition(imgui.CondAppearing) ) // SetNextWindowPos sets position of next window. @@ -162,14 +167,14 @@ func SetNextWindowPos(x, y float32) { imgui.SetNextWindowPos(imgui.Vec2{X: x, Y: y}) } -// SetNextWindowSizeV does similar to SetNextWIndowSize but allows to specify imgui.Condition. +// SetNextWindowSizeV does similar to SetNextWIndowSize but allows to specify imgui.Cond. func SetNextWindowSizeV(width, height float32, condition ExecCondition) { imgui.SetNextWindowSizeV( imgui.Vec2{ X: width, Y: height, }, - imgui.Condition(condition), + imgui.Cond(condition), ) } @@ -185,7 +190,7 @@ func SetKeyboardFocusHere() { // SetKeyboardFocusHereV sets keyboard on the next widget. Use positive 'offset' to access sub components of a multiple component widget. Use -1 to access previous widget. func SetKeyboardFocusHereV(i int) { - imgui.SetKeyboardFocusHereV(i) + imgui.SetKeyboardFocusHereV(int32(i)) } // PushClipRect pushes a clipping rectangle for both ImGui logic (hit-testing etc.) and low-level ImDrawList rendering. @@ -219,3 +224,28 @@ func OpenURL(url string) { log.Printf("Error opening %s: %v", url, err) } } + +// ColorToUint converts GO color into Uint32 color +// it is 0xRRGGBBAA. +func ColorToUint(col color.Color) uint32 { + r, g, b, a := col.RGBA() + mask := uint32(0xff) + + return r&mask<<24 + g&mask<<16 + b&mask<<8 + a&mask +} + +// UintToColor converts uint32 of form 0xRRGGBB into color.RGBA. +func UintToColor(col uint32) *color.RGBA { + mask := 0xff + r := byte(col >> 24 & uint32(mask)) + g := byte(col >> 16 & uint32(mask)) + b := byte(col >> 8 & uint32(mask)) + a := byte(col >> 0 & uint32(mask)) + + return &color.RGBA{ + R: r, + G: g, + B: b, + A: a, + } +} diff --git a/Utils_test.go b/Utils_test.go index 05810a2a..cf29505b 100644 --- a/Utils_test.go +++ b/Utils_test.go @@ -5,7 +5,7 @@ import ( "image/color" "testing" - "github.com/AllenDang/imgui-go" + imgui "github.com/AllenDang/cimgui-go" "github.com/stretchr/testify/assert" ) diff --git a/Widgets.go b/Widgets.go index 61d23cc3..4631f4b5 100644 --- a/Widgets.go +++ b/Widgets.go @@ -4,7 +4,7 @@ import ( "fmt" "image/color" - "github.com/AllenDang/imgui-go" + imgui "github.com/AllenDang/cimgui-go" ) // GenAutoID automatically generates fidget's id. @@ -72,7 +72,7 @@ type ChildWidget struct { // Build implements Widget interface. func (c *ChildWidget) Build() { - if imgui.BeginChildV(c.id, imgui.Vec2{X: c.width, Y: c.height}, c.border, int(c.flags)) { + if imgui.BeginChildStrV(c.id, imgui.Vec2{X: c.width, Y: c.height}, c.border, imgui.WindowFlags(c.flags)) { c.layout.Build() } @@ -163,7 +163,7 @@ func (cc *ComboCustomWidget) Build() { defer imgui.PopItemWidth() } - if imgui.BeginComboV(Context.FontAtlas.RegisterString(cc.label), cc.previewValue, int(cc.flags)) { + if imgui.BeginComboV(Context.FontAtlas.RegisterString(cc.label), cc.previewValue, imgui.ComboFlags(cc.flags)) { cc.layout.Build() imgui.EndCombo() } @@ -203,9 +203,9 @@ func (c *ComboWidget) Build() { defer imgui.PopItemWidth() } - if imgui.BeginComboV(Context.FontAtlas.RegisterString(c.label), c.previewValue, int(c.flags)) { + if imgui.BeginComboV(Context.FontAtlas.RegisterString(c.label), c.previewValue, imgui.ComboFlags(c.flags)) { for i, item := range c.items { - if imgui.Selectable(item) { + if imgui.SelectableBool(item) { *c.selected = int32(i) if c.onChange != nil { c.onChange() @@ -268,7 +268,7 @@ func (c *ContextMenuWidget) ID(id string) *ContextMenuWidget { // Build implements Widget interface. func (c *ContextMenuWidget) Build() { - if imgui.BeginPopupContextItemV(c.id, int(c.mouseButton)) { + if imgui.BeginPopupContextItemV(c.id, imgui.PopupFlags(c.mouseButton)) { c.layout.Build() imgui.EndPopup() } @@ -308,7 +308,7 @@ func (d *DragIntWidget) Format(format string) *DragIntWidget { // Build implements Widget interface. func (d *DragIntWidget) Build() { - imgui.DragIntV(Context.FontAtlas.RegisterString(d.label), d.value, d.speed, d.min, d.max, d.format) + imgui.DragIntV(Context.FontAtlas.RegisterString(d.label), d.value, d.speed, d.min, d.max, d.format, 0) } var _ Widget = &ColumnWidget{} @@ -430,7 +430,7 @@ func (m *MenuItemWidget) OnClick(onClick func()) *MenuItemWidget { // Build implements Widget interface. func (m *MenuItemWidget) Build() { - if imgui.MenuItemV(Context.FontAtlas.RegisterString(m.label), m.shortcut, m.selected, m.enabled) && m.onClick != nil { + if imgui.MenuItemBoolV(Context.FontAtlas.RegisterString(m.label), m.shortcut, m.selected, m.enabled) && m.onClick != nil { m.onClick() } } @@ -609,7 +609,7 @@ func (t *TabItemWidget) Layout(widgets ...Widget) *TabItemWidget { // BuildTabItem executes tab item build steps. func (t *TabItemWidget) BuildTabItem() { - if imgui.BeginTabItemV(t.label, t.open, int(t.flags)) { + if imgui.BeginTabItemV(t.label, t.open, imgui.TabItemFlags(t.flags)) { t.layout.Build() imgui.EndTabItem() } @@ -652,7 +652,7 @@ func (t *TabBarWidget) TabItems(items ...*TabItemWidget) *TabBarWidget { // Build implements Widget interface. func (t *TabBarWidget) Build() { - if imgui.BeginTabBarV(t.id, int(t.flags)) { + if imgui.BeginTabBarV(t.id, imgui.TabBarFlags(t.flags)) { for _, ti := range t.tabItems { ti.BuildTabItem() } @@ -730,7 +730,7 @@ func ColorEdit(label string, c *color.RGBA) *ColorEditWidget { return &ColorEditWidget{ label: GenAutoID(label), color: c, - flags: ColorEditFlagsNone, + // flags: ColorEditFlagsNone, } } @@ -766,7 +766,7 @@ func (ce *ColorEditWidget) Build() { if imgui.ColorEdit4V( Context.FontAtlas.RegisterString(ce.label), &col, - int(ce.flags), + imgui.ColorEditFlags(ce.flags), ) { *ce.color = Vec4ToRGBA(imgui.Vec4{ X: col[0], diff --git a/Window.go b/Window.go index 2d7def68..50f20980 100644 --- a/Window.go +++ b/Window.go @@ -3,39 +3,43 @@ package giu import ( "fmt" - "github.com/AllenDang/imgui-go" + imgui "github.com/AllenDang/cimgui-go" ) // SingleWindow creates one window filling all available space // in MasterWindow. If SingleWindow is set up, no other windows may be // defined. func SingleWindow() *WindowWidget { - size := Context.platform.DisplaySize() + pos := imgui.MainViewport().Pos() + sizeX, sizeY := Context.backend.DisplaySize() title := fmt.Sprintf("SingleWindow_%d", Context.GetWidgetIndex()) return Window(title). Flags( - imgui.WindowFlagsNoTitleBar| - imgui.WindowFlagsNoCollapse| - imgui.WindowFlagsNoScrollbar| - imgui.WindowFlagsNoMove| - imgui.WindowFlagsNoResize). - Size(size[0], size[1]) + WindowFlags(imgui.WindowFlagsNoTitleBar)| + WindowFlags(imgui.WindowFlagsNoCollapse)| + WindowFlags(imgui.WindowFlagsNoScrollbar)| + WindowFlags(imgui.WindowFlagsNoMove)| + WindowFlags(imgui.WindowFlagsNoResize), + ). + Pos(pos.X, pos.Y).Size(float32(sizeX), float32(sizeY)) } // SingleWindowWithMenuBar creates a SingleWindow and allows to add menubar on its top. func SingleWindowWithMenuBar() *WindowWidget { - size := Context.platform.DisplaySize() + pos := imgui.MainViewport().Pos() + sizeX, sizeY := Context.backend.DisplaySize() title := fmt.Sprintf("SingleWindow_%d", Context.GetWidgetIndex()) return Window(title). Flags( - imgui.WindowFlagsNoTitleBar| - imgui.WindowFlagsNoCollapse| - imgui.WindowFlagsNoScrollbar| - imgui.WindowFlagsNoMove| - imgui.WindowFlagsMenuBar| - imgui.WindowFlagsNoResize).Size(size[0], size[1]) + WindowFlags(imgui.WindowFlagsNoTitleBar)| + WindowFlags(imgui.WindowFlagsNoCollapse)| + WindowFlags(imgui.WindowFlagsNoScrollbar)| + WindowFlags(imgui.WindowFlagsNoMove)| + WindowFlags(imgui.WindowFlagsMenuBar)| + WindowFlags(imgui.WindowFlagsNoResize), + ).Size(float32(sizeX), float32(sizeY)).Pos(pos.X, pos.Y) } var _ Disposable = &windowState{} @@ -66,9 +70,11 @@ type WindowWidget struct { // Window creates a WindowWidget. func Window(title string) *WindowWidget { - return &WindowWidget{ + defaultPos := imgui.MainViewport().Pos() + + return (&WindowWidget{ title: title, - } + }).Pos(defaultPos.X, defaultPos.Y) } // IsOpen sets if window widget is `opened` (minimized). @@ -109,12 +115,12 @@ func (w *WindowWidget) Layout(widgets ...Widget) { ws := w.getState() - if w.flags&imgui.WindowFlagsNoMove != 0 && w.flags&imgui.WindowFlagsNoResize != 0 { + if w.flags&WindowFlags(imgui.WindowFlagsNoMove) != 0 && w.flags&WindowFlags(imgui.WindowFlagsNoResize) != 0 { imgui.SetNextWindowPos(imgui.Vec2{X: w.x, Y: w.y}) imgui.SetNextWindowSize(imgui.Vec2{X: w.width, Y: w.height}) } else { - imgui.SetNextWindowPosV(imgui.Vec2{X: w.x, Y: w.y}, imgui.ConditionFirstUseEver, imgui.Vec2{X: 0, Y: 0}) - imgui.SetNextWindowSizeV(imgui.Vec2{X: w.width, Y: w.height}, imgui.ConditionFirstUseEver) + imgui.SetNextWindowPosV(imgui.Vec2{X: w.x, Y: w.y}, imgui.CondFirstUseEver, imgui.Vec2{X: 0, Y: 0}) + imgui.SetNextWindowSizeV(imgui.Vec2{X: w.width, Y: w.height}, imgui.CondFirstUseEver) } if w.bringToFront { @@ -137,7 +143,7 @@ func (w *WindowWidget) Layout(widgets ...Widget) { }), ) - showed := imgui.BeginV(Context.FontAtlas.RegisterString(w.title), w.open, int(w.flags)) + showed := imgui.BeginV(Context.FontAtlas.RegisterString(w.title), w.open, imgui.WindowFlags(w.flags)) if showed { Layout(widgets).Build() diff --git a/examples/canvas/canvas.go b/examples/canvas/canvas.go index 4b21ff90..8e821c2c 100644 --- a/examples/canvas/canvas.go +++ b/examples/canvas/canvas.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "image" "image/color" @@ -10,6 +11,7 @@ import ( var texture *g.Texture func loop() { + fmt.Println(texture.ID()) g.SingleWindow().Layout( g.Label("Canvas demo"), g.Custom(func() { @@ -42,7 +44,7 @@ func loop() { canvas.PathLineTo(p1) canvas.PathLineTo(p2) canvas.PathBezierCubicCurveTo(p2.Add(image.Pt(40, 0)), p3.Add(image.Pt(-50, 0)), p3, 0) - canvas.PathStroke(color, false, 1) + canvas.PathStroke(color, 0, 1) if texture != nil { canvas.AddImage(texture, image.Pt(350, 25), image.Pt(500, 125)) @@ -55,7 +57,7 @@ func main() { wnd := g.NewMasterWindow("Canvas", 600, 600, g.MasterWindowFlagsNotResizable) img, _ := g.LoadImage("gopher.png") - g.NewTextureFromRgba(img, func(tex *g.Texture) { + g.EnqueueNewTextureFromRgba(img, func(tex *g.Texture) { texture = tex }) diff --git a/examples/codeeditor/codeeditor.go b/examples/codeeditor/codeeditor.go index 65c129ce..6d642b76 100644 --- a/examples/codeeditor/codeeditor.go +++ b/examples/codeeditor/codeeditor.go @@ -5,13 +5,11 @@ import ( "github.com/AllenDang/giu" g "github.com/AllenDang/giu" - "github.com/AllenDang/imgui-go" ) -var ( - editor *g.CodeEditorWidget - errMarkers imgui.ErrorMarkers -) +var editor *g.CodeEditorWidget + +// errMarkers imgui.ErrorMarkers func loop() { g.SingleWindow().Layout( @@ -35,11 +33,12 @@ func loop() { editor.Text("Set text") }), g.Button("Set Error Marker").OnClick(func() { - errMarkers.Clear() - errMarkers.Insert(1, "Error message") - fmt.Println("ErrMarkers Size:", errMarkers.Size()) + panic("implement me!") + // errMarkers.Clear() + // errMarkers.Insert(1, "Error message") + // fmt.Println("ErrMarkers Size:", errMarkers.Size()) - editor.ErrorMarkers(errMarkers) + // editor.ErrorMarkers(errMarkers) }), ), editor, @@ -49,7 +48,7 @@ func loop() { func main() { wnd := g.NewMasterWindow("Code Editor", 800, 600, 0) - errMarkers = imgui.NewErrorMarkers() + // errMarkers = imgui.NewErrorMarkers() editor = g.CodeEditor(). ShowWhitespaces(false). diff --git a/examples/customwidget/customwidget.go b/examples/customwidget/customwidget.go index de19d5b5..a4faad1d 100644 --- a/examples/customwidget/customwidget.go +++ b/examples/customwidget/customwidget.go @@ -24,7 +24,9 @@ func (c *CircleButtonWidget) Build() { width, height := g.CalcTextSize(c.id) var padding float32 = 8.0 - pos := g.GetCursorPos() + // You may want to use GetCursorPos here depending on you use case. + // We use ScreenPos here, because it is relative to MasterWindow (CursorPos seems to be relative to Viewport?) + pos := g.GetCursorScreenPos() // Calculate the center point radius := int(width/2 + padding*2) @@ -43,7 +45,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}, radius, 2) + canvas.AddCircle(center, float32(radius), color.RGBA{200, 12, 12, 255}, int32(radius), 2) // Draw text canvas.AddText(center.Sub(image.Pt(int((width)/2), int(height/2))), color.RGBA{255, 255, 255, 255}, c.id) diff --git a/examples/discussion-648/main.go b/examples/discussion-648/main.go new file mode 100644 index 00000000..b1ef4af1 --- /dev/null +++ b/examples/discussion-648/main.go @@ -0,0 +1,22 @@ +package main + +import "github.com/AllenDang/giu" + +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), + }.Build() + }), + ) +} + +func main() { + wnd := giu.NewMasterWindow("How do I make this Child show as a footer? #648", 640, 480, 0) + wnd.Run(loop) +} diff --git a/examples/discussion-652/main.go b/examples/discussion-652/main.go new file mode 100644 index 00000000..7372f8db --- /dev/null +++ b/examples/discussion-652/main.go @@ -0,0 +1,23 @@ +package main + +import "github.com/AllenDang/giu" + +func loop() { + giu.SingleWindow().Layout( + giu.Table().Columns( + giu.TableColumn("State").InnerWidthOrWeight(20).Flags(giu.TableColumnFlagsWidthFixed), + ).Rows( + giu.TableRow( + giu.Label("1"), + ), + giu.TableRow( + giu.Label("2"), + ), + ), + ) +} + +func main() { + wnd := giu.NewMasterWindow("Width of table column [discussion 652]", 640, 480, 0) + wnd.Run(loop) +} diff --git a/examples/dragdrop/dragdrop.go b/examples/dragdrop/dragdrop.go index 9cb92c3a..40ce4b4b 100644 --- a/examples/dragdrop/dragdrop.go +++ b/examples/dragdrop/dragdrop.go @@ -2,14 +2,13 @@ package main import ( "fmt" + "unsafe" + imgui "github.com/AllenDang/cimgui-go" g "github.com/AllenDang/giu" - "github.com/AllenDang/imgui-go" ) -var ( - dropTarget string = "Drop here" -) +var dropTarget string = "Drop here" func loop() { g.SingleWindow().Layout( @@ -17,7 +16,12 @@ func loop() { g.Custom(func() { g.Button("Drag me: 9").Build() if imgui.BeginDragDropSource() { - imgui.SetDragDropPayload("DND_DEMO", 9) + data := 9 + imgui.SetDragDropPayload( + "DND_DEMO", + unsafe.Pointer(&data), + 0, + ) g.Label("9").Build() imgui.EndDragDropSource() } @@ -25,7 +29,12 @@ func loop() { g.Custom(func() { g.Button("Drag me: 10").Build() if imgui.BeginDragDropSource() { - imgui.SetDragDropPayload("DND_DEMO", 10) + data := 10 + imgui.SetDragDropPayload( + "DND_DEMO", + unsafe.Pointer(&data), + 0, + ) g.Label("10").Build() imgui.EndDragDropSource() } @@ -35,7 +44,7 @@ func loop() { g.Custom(func() { if imgui.BeginDragDropTarget() { payload := imgui.AcceptDragDropPayload("DND_DEMO") - if payload != 0 { + if payload != nil { dropTarget = fmt.Sprintf("Dropped value: %d", payload.Data()) } imgui.EndDragDropTarget() diff --git a/examples/imguidemo/imguidemo.go b/examples/imguidemo/imguidemo.go index 17f685c8..b9eb72b1 100644 --- a/examples/imguidemo/imguidemo.go +++ b/examples/imguidemo/imguidemo.go @@ -1,12 +1,12 @@ package main import ( + "github.com/AllenDang/cimgui-go" g "github.com/AllenDang/giu" - "github.com/AllenDang/imgui-go" ) func loop() { - imgui.ShowDemoWindow(nil) + imgui.ShowDemoWindow() } func main() { diff --git a/examples/loadimage/loadimage.go b/examples/loadimage/loadimage.go index ef36a0cb..1eec537b 100644 --- a/examples/loadimage/loadimage.go +++ b/examples/loadimage/loadimage.go @@ -70,6 +70,6 @@ func main() { g.EnqueueNewTextureFromRgba(rgba, func(t *g.Texture) { tex = t }) - wnd.SetIcon([]image.Image{rgba}) + wnd.SetIcon(rgba) wnd.Run(loop) } diff --git a/examples/markdown/markdown.go b/examples/markdown/markdown.go index aae88401..b0cf0b17 100644 --- a/examples/markdown/markdown.go +++ b/examples/markdown/markdown.go @@ -72,7 +72,6 @@ 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 e92462e6..3fc3795f 100644 --- a/examples/memoryeditor/memoryeditor.go +++ b/examples/memoryeditor/memoryeditor.go @@ -1,27 +1,31 @@ package main -import ( - "fmt" - - g "github.com/AllenDang/giu" -) - -var ( - buf []uint8 - content string -) - -func loop() { - g.SingleWindow().Layout( - g.Button("Print data value").OnClick(func() { - fmt.Println(buf) - }), - g.MemoryEditor().Contents(buf), - ) -} - +// import ( +// +// "fmt" +// +// g "github.com/AllenDang/giu" +// +// ) +// +// var ( +// +// buf []uint8 +// content string +// +// ) +// +// func loop() { +// g.SingleWindow().Layout( +// g.Button("Print data value").OnClick(func() { +// fmt.Println(buf) +// }), +// g.MemoryEditor().Contents(buf), +// ) +// } func main() { - buf = []uint8{1, 2, 3, 4, 5, 6, 7} - wnd := g.NewMasterWindow("Memory Editor", 800, 600, 0) - wnd.Run(loop) + panic("Memory editor is disabled in giu, since it is not implemented in cimgui yet.") + // buf = []uint8{1, 2, 3, 4, 5, 6, 7} + // wnd := g.NewMasterWindow("Memory Editor", 800, 600, 0) + // wnd.Run(loop) } diff --git a/examples/multiplefonts/multiplefonts.go b/examples/multiplefonts/multiplefonts.go index b2566027..74701e53 100644 --- a/examples/multiplefonts/multiplefonts.go +++ b/examples/multiplefonts/multiplefonts.go @@ -32,12 +32,13 @@ func loop() { } func main() { + wnd := g.NewMasterWindow("Multiple fonts", 600, 400, g.MasterWindowFlagsNotResizable) + // Change the default font g.Context.FontAtlas.SetDefaultFont("Arial.ttf", 12) // Add a new font and manually set it when needed bigFont = g.Context.FontAtlas.AddFont("Menlo.ttc", 24) - wnd := g.NewMasterWindow("Multiple fonts", 600, 400, g.MasterWindowFlagsNotResizable) wnd.Run(loop) } diff --git a/examples/plot/main.go b/examples/plot/main.go index 700d1fd5..12faea76 100644 --- a/examples/plot/main.go +++ b/examples/plot/main.go @@ -31,7 +31,7 @@ func loop() { g.Line("Plot Line2", linedata2), g.Scatter("Scatter 散点图", scatterdata), ), - g.Plot("Plot Time Axe 时间线").AxisLimits(timeDataMin, timeDataMax, 0, 1, g.ConditionOnce).XAxeFlags(g.PlotAxisFlagsTime).Plots( + g.Plot("Plot Time Axe 时间线").AxisLimits(timeDataMin, timeDataMax, 0, 1, g.ConditionOnce).Plots( g.LineXY("Time Line 时间线", timeDataX, timeDataY), g.ScatterXY("Time Scatter 时间散点图", timeDataX, timeScatterY), ), @@ -45,7 +45,7 @@ func loop() { g.BarH("Plot Bar H 水平柱状图", bardata3), ), g.Plot("Pie Chart"). - Flags(g.PlotFlagsEqual|g.PlotFlagsNoMousePos). + Flags(g.PlotFlagsEqual). Size(250, 250). XAxeFlags(g.PlotAxisFlagsNoDecorations). YAxeFlags(g.PlotAxisFlagsNoDecorations, 0, 0). diff --git a/examples/texturefiltering/texturefiltering.go b/examples/texturefiltering/texturefiltering.go index 8cfa4160..72e19e29 100644 --- a/examples/texturefiltering/texturefiltering.go +++ b/examples/texturefiltering/texturefiltering.go @@ -1,96 +1,100 @@ package main -import ( - _ "image/jpeg" - _ "image/png" - - g "github.com/AllenDang/giu" -) - -var ( - spriteTexture *g.Texture - largeTexture *g.Texture -) - -func loop() { - g.SingleWindow().Layout( - g.Column( - g.Label("15x20 pixel image"), - g.Row( - g.Column( - g.Label("50%"), - g.Image(spriteTexture).Size(8, 10), - ), - g.Column( - g.Label("100%"), - g.Image(spriteTexture).Size(15, 20), - ), - g.Column( - g.Label("800%"), - g.Image(spriteTexture).Size(120, 160), - ), - ), - ), - g.Column( - g.Label("215x140 image"), - g.Row( - g.Column( - g.Label("50%"), - g.Image(largeTexture).Size(215/2, 140/2), - ), - g.Column( - g.Label("100%"), - g.Image(largeTexture).Size(215, 140), - ), - g.Column( - g.Label("200%"), - g.Image(largeTexture).Size(215*2, 140*2), - ), - ), - ), - g.Row( - g.Button("Minify Filter Nearest").OnClick(func() { - _ = g.Context.GetRenderer().SetTextureMinFilter(g.TextureFilterNearest) - }), - g.Button("Minify Filter Linear").OnClick(func() { - _ = g.Context.GetRenderer().SetTextureMinFilter(g.TextureFilterLinear) - }), - /*g.Button("Nearest Mipmap Nearest", func() { - g.Context.GetRenderer().SetTextureMinFilter(g.TextureFilterNearestMipmapNearest) - }), - g.Button("Linear Mipmap Nearest", func() { - g.Context.GetRenderer().SetTextureMinFilter(g.TextureFilterLinearMipmapNearest) - }), - g.Button("Nearest Mipmap Linear", func() { - g.Context.GetRenderer().SetTextureMinFilter(g.TextureFilterNearestMipmapLinear) - }), - g.Button("Linear Mipmap Linear", func() { - g.Context.GetRenderer().SetTextureMinFilter(g.TextureFilterLinearMipmapLinear) - }),*/ - ), - g.Row( - g.Button("Magnify Filter Nearest").OnClick(func() { - _ = g.Context.GetRenderer().SetTextureMagFilter(g.TextureFilterNearest) - }), - g.Button("Magnify Filter Linear").OnClick(func() { - _ = g.Context.GetRenderer().SetTextureMagFilter(g.TextureFilterLinear) - }), - ), - ) -} - +// import ( +// +// _ "image/jpeg" +// _ "image/png" +// +// g "github.com/AllenDang/giu" +// +// ) +// +// var ( +// +// spriteTexture *g.Texture +// largeTexture *g.Texture +// +// ) +// +// func loop() { +// g.SingleWindow().Layout( +// g.Column( +// g.Label("15x20 pixel image"), +// g.Row( +// g.Column( +// g.Label("50%"), +// g.Image(spriteTexture).Size(8, 10), +// ), +// g.Column( +// g.Label("100%"), +// g.Image(spriteTexture).Size(15, 20), +// ), +// g.Column( +// g.Label("800%"), +// g.Image(spriteTexture).Size(120, 160), +// ), +// ), +// ), +// g.Column( +// g.Label("215x140 image"), +// g.Row( +// g.Column( +// g.Label("50%"), +// g.Image(largeTexture).Size(215/2, 140/2), +// ), +// g.Column( +// g.Label("100%"), +// g.Image(largeTexture).Size(215, 140), +// ), +// g.Column( +// g.Label("200%"), +// g.Image(largeTexture).Size(215*2, 140*2), +// ), +// ), +// ), +// g.Row( +// g.Button("Minify Filter Nearest").OnClick(func() { +// _ = g.Context.GetRenderer().SetTextureMinFilter(g.TextureFilterNearest) +// }), +// g.Button("Minify Filter Linear").OnClick(func() { +// _ = g.Context.GetRenderer().SetTextureMinFilter(g.TextureFilterLinear) +// }), +// /*g.Button("Nearest Mipmap Nearest", func() { +// g.Context.GetRenderer().SetTextureMinFilter(g.TextureFilterNearestMipmapNearest) +// }), +// g.Button("Linear Mipmap Nearest", func() { +// g.Context.GetRenderer().SetTextureMinFilter(g.TextureFilterLinearMipmapNearest) +// }), +// g.Button("Nearest Mipmap Linear", func() { +// g.Context.GetRenderer().SetTextureMinFilter(g.TextureFilterNearestMipmapLinear) +// }), +// g.Button("Linear Mipmap Linear", func() { +// g.Context.GetRenderer().SetTextureMinFilter(g.TextureFilterLinearMipmapLinear) +// }),*/ +// ), +// g.Row( +// g.Button("Magnify Filter Nearest").OnClick(func() { +// _ = g.Context.GetRenderer().SetTextureMagFilter(g.TextureFilterNearest) +// }), +// g.Button("Magnify Filter Linear").OnClick(func() { +// _ = g.Context.GetRenderer().SetTextureMagFilter(g.TextureFilterLinear) +// }), +// ), +// ) +// } func main() { - wnd := g.NewMasterWindow("Texture Filtering", 800, 600, g.MasterWindowFlagsNotResizable) - - spriteImg, _ := g.LoadImage("gopher-sprite.png") - largeImg, _ := g.LoadImage("gopher.png") - - g.NewTextureFromRgba(spriteImg, func(tex *g.Texture) { - spriteTexture = tex - }) - g.NewTextureFromRgba(largeImg, func(tex *g.Texture) { - largeTexture = tex - }) - - wnd.Run(loop) + panic("Texture filtering is currently disabled in giu, since it is not implemented in cimgui-go yet.") + // wnd := g.NewMasterWindow("Texture Filtering", 800, 600, g.MasterWindowFlagsNotResizable) + // + // spriteImg, _ := g.LoadImage("gopher-sprite.png") + // largeImg, _ := g.LoadImage("gopher.png") + // + // g.NewTextureFromRgba(spriteImg, func(tex *g.Texture) { + // spriteTexture = tex + // }) + // g.NewTextureFromRgba(largeImg, func(tex *g.Texture) { + // largeTexture = tex + // }) + // + // wnd.Run(loop) } diff --git a/examples/transparent/transparent.go b/examples/transparent/transparent.go index 0062b711..e7f3ae5f 100644 --- a/examples/transparent/transparent.go +++ b/examples/transparent/transparent.go @@ -4,8 +4,8 @@ import ( "image" "image/color" + "github.com/AllenDang/cimgui-go" g "github.com/AllenDang/giu" - "github.com/AllenDang/imgui-go" ) func loop() { diff --git a/examples/widgets/widgets.go b/examples/widgets/widgets.go index 15b6f162..e449b2e3 100644 --- a/examples/widgets/widgets.go +++ b/examples/widgets/widgets.go @@ -111,7 +111,7 @@ func loop() { g.ColorEdit("<- Click the black square. I'm changing a color for you##colorChanger", col). Size(100). - Flags(g.ColorEditFlagsHEX). + Flags(g.ColorEditFlagsDisplayHex). OnChange(func() { fmt.Println(col) }), diff --git a/examples/widgets/widgets.zip b/examples/widgets/widgets.zip new file mode 100644 index 00000000..84a6dc67 Binary files /dev/null and b/examples/widgets/widgets.zip differ diff --git a/go.mod b/go.mod index a7de51c6..748b6c78 100644 --- a/go.mod +++ b/go.mod @@ -1,12 +1,11 @@ module github.com/AllenDang/giu -go 1.18 +go 1.21 require ( + github.com/AllenDang/cimgui-go v0.0.0-20230918114712-675654f053d9 github.com/AllenDang/go-findfont v0.0.0-20200702051237-9f180485aeb8 - github.com/AllenDang/imgui-go v1.12.1-0.20221124025851-59b862ca5a0c github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3 - github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b github.com/mazznoer/csscolorparser v0.1.3 github.com/napsy/go-css v0.0.0-20221107082635-4ed403047a64 github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 @@ -18,7 +17,6 @@ require ( require ( github.com/davecgh/go-spew v1.1.1 // indirect - github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6 // indirect github.com/kylelemons/godebug v1.1.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect golang.org/x/sys v0.5.0 // indirect diff --git a/go.sum b/go.sum index 5798e878..b7763ca1 100644 --- a/go.sum +++ b/go.sum @@ -1,17 +1,11 @@ +github.com/AllenDang/cimgui-go v0.0.0-20230918114712-675654f053d9 h1:tITzow7xji/fjyoGZcji6+XazqAtTUiO5T5+YJBbqh8= +github.com/AllenDang/cimgui-go v0.0.0-20230918114712-675654f053d9/go.mod h1:UH0IZCbsJKA1hAVQQU6AIDfamqTk0/d3VucaN8lp1Gs= github.com/AllenDang/go-findfont v0.0.0-20200702051237-9f180485aeb8 h1:dKZMqib/yUDoCFigmz2agG8geZ/e3iRq304/KJXqKyw= github.com/AllenDang/go-findfont v0.0.0-20200702051237-9f180485aeb8/go.mod h1:b4uuDd0s6KRIPa84cEEchdQ9ICh7K0OryZHbSzMca9k= -github.com/AllenDang/imgui-go v1.12.1-0.20221124025851-59b862ca5a0c h1:kiXjH0n0KzOpvhgy3nDFkPmKfg4A+QWsEOwxwWy6yuI= -github.com/AllenDang/imgui-go v1.12.1-0.20221124025851-59b862ca5a0c/go.mod h1:kuPs9RWleaUuK7D49bE6HPxyRA36Lp4ICKGp+5OnnbY= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3 h1:baVdMKlASEHrj19iqjARrPbaRisD7EuZEVJj6ZMLl1Q= github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3/go.mod h1:VEPNJUlxl5KdWjDvz6Q1l+rJlxF2i6xqDeGuGAxa87M= -github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6 h1:zDw5v7qm4yH7N8C8uWd+8Ii9rROdgWxQuGoJ9WDXxfk= -github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6/go.mod h1:9YTyiznxEY1fVinfM7RvRcjRHbw2xLBJ3AAGIT0I4Nw= -github.com/go-gl/glfw/v3.3/glfw v0.0.0-20211213063430-748e38ca8aec/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= -github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b h1:GgabKamyOYguHqHjSkDACcgoPIz3w0Dis/zJ1wyHHHU= -github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/mazznoer/csscolorparser v0.1.3 h1:vug4zh6loQxAUxfU1DZEu70gTPufDPspamZlHAkKcxE= @@ -24,8 +18,6 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sahilm/fuzzy v0.1.0 h1:FzWGaw2Opqyu+794ZQ9SYifWv2EIXpwP4q8dY1kDAwI= github.com/sahilm/fuzzy v0.1.0/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= @@ -67,6 +59,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/eapache/queue.v1 v1.1.0 h1:EldqoJEGtXYiVCMRo2C9mePO2UUGnYn2+qLmlQSqPdc= gopkg.in/eapache/queue.v1 v1.1.0/go.mod h1:wNtmx1/O7kZSR9zNT1TTOJ7GLpm3Vn7srzlfylFbQwU= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/migration.txt b/migration.txt new file mode 100644 index 00000000..b14522de --- /dev/null +++ b/migration.txt @@ -0,0 +1,4 @@ +API Changes: +- remove InputTextFlagsAlwaysInsertMode +- remove TabItemFlagsNoPushID +- create: UintToColor and ColorToUint