diff --git a/Canvas.go b/Canvas.go index d8aceedb..82d8507e 100644 --- a/Canvas.go +++ b/Canvas.go @@ -7,16 +7,20 @@ import ( "github.com/AllenDang/imgui-go" ) +// Canvas represents imgui.DrawList +// for more details see examples/canvas type Canvas struct { drawlist imgui.DrawList } +// GetCanvas creates new Canvas func GetCanvas() *Canvas { return &Canvas{ drawlist: imgui.GetWindowDrawList(), } } +// AddLine draws a line (from p1 to p2) func (c *Canvas) AddLine(p1, p2 image.Point, color color.RGBA, thickness float32) { c.drawlist.AddLine(ToVec2(p1), ToVec2(p2), ToVec4Color(color), thickness) } @@ -42,42 +46,52 @@ const ( DrawFlagsRoundCornersMask DrawFlags = DrawFlagsRoundCornersAll | DrawFlagsRoundCornersNone ) +// AddRect draws a rectangle func (c *Canvas) AddRect(pMin, pMax image.Point, color color.RGBA, rounding float32, roundingCorners DrawFlags, thickness float32) { c.drawlist.AddRect(ToVec2(pMin), ToVec2(pMax), ToVec4Color(color), rounding, int(roundingCorners), thickness) } +// AddRectFilled draws a rectangle filled with `color` func (c *Canvas) AddRectFilled(pMin, pMax image.Point, color color.RGBA, rounding float32, roundingCorners DrawFlags) { c.drawlist.AddRectFilled(ToVec2(pMin), ToVec2(pMax), ToVec4Color(color), rounding, int(roundingCorners)) } +// AddText draws text func (c *Canvas) AddText(pos image.Point, color color.RGBA, text string) { c.drawlist.AddText(ToVec2(pos), ToVec4Color(color), tStr(text)) } +// AddBezierCubic draws bezier cubic func (c *Canvas) AddBezierCubic(pos0, cp0, cp1, pos1 image.Point, color color.RGBA, thickness float32, numSegments int) { c.drawlist.AddBezierCubic(ToVec2(pos0), ToVec2(cp0), ToVec2(cp1), ToVec2(pos1), ToVec4Color(color), thickness, numSegments) } +// AddTriangle draws a triangle func (c *Canvas) AddTriangle(p1, p2, p3 image.Point, color color.RGBA, thickness float32) { c.drawlist.AddTriangle(ToVec2(p1), ToVec2(p2), ToVec2(p3), ToVec4Color(color), thickness) } +// AddTriangleFilled draws a filled triangle func (c *Canvas) AddTriangleFilled(p1, p2, p3 image.Point, color color.RGBA) { c.drawlist.AddTriangleFilled(ToVec2(p1), ToVec2(p2), ToVec2(p3), ToVec4Color(color)) } +// AddCircle draws a circle func (c *Canvas) AddCircle(center image.Point, radius float32, color color.RGBA, segments int, thickness float32) { c.drawlist.AddCircle(ToVec2(center), radius, ToVec4Color(color), segments, thickness) } +// AddCircleFilled draws a filled circle func (c *Canvas) AddCircleFilled(center image.Point, radius float32, color color.RGBA) { c.drawlist.AddCircleFilled(ToVec2(center), radius, ToVec4Color(color)) } +// AddQuad draws a quad func (c *Canvas) AddQuad(p1, p2, p3, p4 image.Point, color color.RGBA, thickness float32) { c.drawlist.AddQuad(ToVec2(p1), ToVec2(p2), ToVec2(p3), ToVec2(p4), ToVec4Color(color), thickness) } +// AddQuadFilled draws a filled quad func (c *Canvas) AddQuadFilled(p1, p2, p3, p4 image.Point, color color.RGBA) { c.drawlist.AddQuadFilled(ToVec2(p1), ToVec2(p2), ToVec2(p3), ToVec2(p4), ToVec4Color(color)) } diff --git a/Flags.go b/Flags.go index 66ab2c25..dec943a2 100644 --- a/Flags.go +++ b/Flags.go @@ -328,6 +328,7 @@ const ( ColorEditFlagsInputHSV ColorEditFlags = 1 << 28 ) +// TableFlags represents table flags type TableFlags int // Table flags enum: diff --git a/Plot.go b/Plot.go index 1bd12275..5b78a3ae 100644 --- a/Plot.go +++ b/Plot.go @@ -75,6 +75,7 @@ func Plot(title string) *PlotCanvasWidget { } } +// AxisLimits sets X and Y axis limits func (p *PlotCanvasWidget) AxisLimits(xmin, xmax, ymin, ymax float64, cond ExecCondition) *PlotCanvasWidget { p.xMin = xmin p.xMax = xmax @@ -85,6 +86,7 @@ func (p *PlotCanvasWidget) AxisLimits(xmin, xmax, ymin, ymax float64, cond ExecC return p } +// XTicks sets x axis ticks func (p *PlotCanvasWidget) XTicks(ticks []PlotTicker, showDefault bool) *PlotCanvasWidget { length := len(ticks) if length == 0 { @@ -133,11 +135,13 @@ func (p *PlotCanvasWidget) Flags(flags PlotFlags) *PlotCanvasWidget { return p } +// XAxeFlags sets x axis fags func (p *PlotCanvasWidget) XAxeFlags(flags PlotAxisFlags) *PlotCanvasWidget { p.xFlags = flags return p } +// YAxeFlags sets y axis flags func (p *PlotCanvasWidget) YAxeFlags(yFlags, y2Flags, y3Flags PlotAxisFlags) *PlotCanvasWidget { p.yFlags = yFlags p.y2Flags = y2Flags @@ -145,17 +149,20 @@ func (p *PlotCanvasWidget) YAxeFlags(yFlags, y2Flags, y3Flags PlotAxisFlags) *Pl return p } +// Plots adds plots to plot canvas func (p *PlotCanvasWidget) Plots(plots ...PlotWidget) *PlotCanvasWidget { p.plots = plots return p } +// Size set canvas size func (p *PlotCanvasWidget) Size(width, height int) *PlotCanvasWidget { p.width = width p.height = height return p } +// 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))