Skip to content

Commit

Permalink
code: further updates
Browse files Browse the repository at this point in the history
  • Loading branch information
gucio321 committed Apr 27, 2023
1 parent 8425876 commit 9e5e595
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 70 deletions.
2 changes: 1 addition & 1 deletion ClickableWidgets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion ImageWidgets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
104 changes: 88 additions & 16 deletions Plot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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
)
}
2 changes: 1 addition & 1 deletion ProgressIndicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion SplitLayout.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
8 changes: 4 additions & 4 deletions Style.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
50 changes: 30 additions & 20 deletions StyleIDs_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 23 additions & 18 deletions StyleIDs_string2enum.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions TableWidgets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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{}
Expand Down Expand Up @@ -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()
}
Expand Down
Loading

0 comments on commit 9e5e595

Please sign in to comment.