Skip to content

Commit

Permalink
add comment in canvas
Browse files Browse the repository at this point in the history
  • Loading branch information
gucio321 committed Sep 18, 2021
1 parent 5eb29c8 commit 16e485e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Canvas.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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))
}
Expand Down
1 change: 1 addition & 0 deletions Flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ const (
ColorEditFlagsInputHSV ColorEditFlags = 1 << 28
)

// TableFlags represents table flags
type TableFlags int

// Table flags enum:
Expand Down
7 changes: 7 additions & 0 deletions Plot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -133,29 +135,34 @@ 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
p.y3Flags = y3Flags
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))
Expand Down

0 comments on commit 16e485e

Please sign in to comment.