From 9e5e595835b7573b0d0fb8f642f7e6ce1a0084de Mon Sep 17 00:00:00 2001 From: gucio321 <73652197+gucio321@users.noreply.github.com> Date: Thu, 27 Apr 2023 19:13:14 +0200 Subject: [PATCH] code: further updates --- ClickableWidgets.go | 2 +- ImageWidgets.go | 2 +- Plot.go | 104 +++++++++++++++++++++++++++++++++------- ProgressIndicator.go | 2 +- SplitLayout.go | 2 +- Style.go | 8 ++-- StyleIDs_string.go | 50 +++++++++++-------- StyleIDs_string2enum.go | 41 +++++++++------- TableWidgets.go | 8 ++-- TextWidgets.go | 8 ++-- 10 files changed, 157 insertions(+), 70 deletions(-) diff --git a/ClickableWidgets.go b/ClickableWidgets.go index 86857a1c..1f827a6c 100644 --- a/ClickableWidgets.go +++ b/ClickableWidgets.go @@ -219,7 +219,7 @@ 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.id == nil { return } diff --git a/ImageWidgets.go b/ImageWidgets.go index bc5b495a..51e6c6ca 100644 --- a/ImageWidgets.go +++ b/ImageWidgets.go @@ -84,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.id == nil { Dummy(size.X, size.Y).Build() return } diff --git a/Plot.go b/Plot.go index af349609..84bf4aca 100644 --- a/Plot.go +++ b/Plot.go @@ -204,18 +204,40 @@ func (p *PlotCanvasWidget) Build() { ) } - if imgui.PlotBeginPlot( - Context.FontAtlas.RegisterString(p.title), Context.FontAtlas.RegisterString(p.xLabel), - Context.FontAtlas.RegisterString(p.yLabel), ToVec2(image.Pt(p.width, p.height)), - imgui.PlotFlags(p.flags), imgui.PlotAxisFlags(p.xFlags), - imgui.PlotAxisFlags(p.yFlags), imgui.PlotAxisFlags(p.y2Flags), - imgui.PlotAxisFlags(p.y3Flags), Context.FontAtlas.RegisterString(p.y2Label), Context.FontAtlas.RegisterString(p.y3Label), + 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), + ) + + if imgui.PlotBeginPlotV( + Context.FontAtlas.RegisterString(p.title), + ToVec2(image.Pt(p.width, p.height)), + imgui.PlotFlags(p.flags), ) { for _, plot := range p.plots { plot.Plot() } - imgui.ImPlotEnd() + imgui.PlotEndPlot() } } } @@ -260,7 +282,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. @@ -303,7 +334,14 @@ 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) + // TODO: what plot does it refer to? + //imgui.PlotBarsH( + // Context.FontAtlas.RegisterString(p.title), + // p.data, + // p.height, + // p.shift, + // p.offset + // ) } // LinePlot represents a plot line (linear chart). @@ -352,8 +390,13 @@ 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) + // TODO: is it right function here? + //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) } // LineXYPlot adds XY plot line. @@ -388,8 +431,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. @@ -433,7 +477,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 { @@ -469,7 +524,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 { @@ -493,5 +557,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/ProgressIndicator.go b/ProgressIndicator.go index ec0e5fb9..9a09fab2 100644 --- a/ProgressIndicator.go +++ b/ProgressIndicator.go @@ -88,7 +88,7 @@ func (p *ProgressIndicatorWidget) Build() { ) color := imgui.StyleColorVec4(imgui.ColText) - rgba := Vec4ToRGBA(color) + rgba := Vec4ToRGBA(*color) canvas.AddCircle(centerPt, p.radius, rgba, int32(p.radius), p.radius/20.0) canvas.AddCircleFilled(centerPt2, p.radius/5, rgba) diff --git a/SplitLayout.go b/SplitLayout.go index 334644ec..5866415b 100644 --- a/SplitLayout.go +++ b/SplitLayout.go @@ -120,7 +120,7 @@ func (s *SplitLayoutWidget) restoreItemSpacing(layout Widget) Layout { PushFramePadding(s.originFramePaddingX, s.originFramePaddingY) // Restore Child bg color bgColor := imgui.StyleColorVec4(imgui.ColChildBg) - PushStyleColor(StyleColorChildBg, Vec4ToRGBA(bgColor)) + PushStyleColor(StyleColorChildBg, Vec4ToRGBA(*bgColor)) }), layout, Custom(func() { diff --git a/Style.go b/Style.go index b345761f..dfb2fec9 100644 --- a/Style.go +++ b/Style.go @@ -226,24 +226,24 @@ func SetMouseCursor(cursor MouseCursorType) { // GetWindowPadding returns window padding. func GetWindowPadding() (x, y float32) { - vec2 := imgui.Style().GetWindowPadding() + vec2 := imgui.CurrentStyle().WindowPadding() return vec2.X, vec2.Y } // GetItemSpacing returns current item spacing. func GetItemSpacing() (w, h float32) { - vec2 := imgui.Style().GetItemSpacing() + vec2 := imgui.CurrentStyle().ItemSpacing() return vec2.X, vec2.Y } // GetItemInnerSpacing returns current item inner spacing. func GetItemInnerSpacing() (w, h float32) { - vec2 := imgui.Style().GetItemInnerSpacing() + vec2 := imgui.CurrentStyle().ItemInnerSpacing() return vec2.X, vec2.Y } // GetFramePadding returns current frame padding. func GetFramePadding() (x, y float32) { - vec2 := imgui.Style().GetFramePadding() + vec2 := imgui.CurrentStyle().FramePadding() return vec2.X, vec2.Y } 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/TableWidgets.go b/TableWidgets.go index 5b9610b3..5a90b828 100644 --- a/TableWidgets.go +++ b/TableWidgets.go @@ -54,7 +54,7 @@ func (r *TableRowWidget) BuildTableRow() { } if r.bgColor != nil { - imgui.TableSetBgColorV(imgui.ImGuiTableBgTarget_RowBg0, uint32(imgui.GetColorU32Vec4(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.TableSetupColumnV(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{} @@ -190,13 +190,13 @@ func (t *TableWidget) Build() { } if t.fastMode { - clipper := imgui.NewImGuiListClipper() + clipper := imgui.NewListClipper() defer clipper.Destroy() clipper.Begin(int32(len(t.rows))) for clipper.Step() { - for i := clipper.GetDisplayStart(); i < clipper.GetDisplayEnd(); i++ { + for i := clipper.DisplayStart(); i < clipper.DisplayEnd(); i++ { row := t.rows[i] row.BuildTableRow() } diff --git a/TextWidgets.go b/TextWidgets.go index 5c5fb1db..93fdff89 100644 --- a/TextWidgets.go +++ b/TextWidgets.go @@ -91,8 +91,8 @@ func (i *InputTextMultilineWidget) Build() { } 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() } } @@ -239,7 +239,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() @@ -265,7 +265,7 @@ func (i *InputTextWidget) Build() { labels[i] = Label(m.Str) } - SetNextWindowPos(imgui.GetItemRectMin().X, imgui.GetItemRectMax().Y) + SetNextWindowPos(imgui.ItemRectMin().X, imgui.ItemRectMax().Y) imgui.BeginTooltip() labels.Build() imgui.EndTooltip()