Skip to content

Commit

Permalink
Merge pull request #326 from gucio321/golangci-lin-action
Browse files Browse the repository at this point in the history
github/workflows: add golangci-lint workflow
  • Loading branch information
AllenDang authored Sep 22, 2021
2 parents 77748a6 + 4f5a1a8 commit c0bfa9f
Show file tree
Hide file tree
Showing 29 changed files with 1,133 additions and 354 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
- v*
branches:
- master
- main
pull_request:

jobs:
Expand Down
101 changes: 101 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
---
linters-settings:
dupl:
threshold: 100
funlen:
lines: 100
statements: 50
goconst:
min-len: 2
min-occurrences: 2
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
gocyclo:
min-complexity: 15
goimports:
local-prefixes: github.com/AllenDang/giu
govet:
check-shadowing: true
lll:
line-length: 140
maligned:
suggest-new: true
misspell:
locale: US

linters:
disable-all: true
enable:
- asciicheck
- bodyclose
- deadcode
- depguard
- dogsled
- dupl
- errcheck
- errorlint
- exportloopref
#- forcetypeassert
#- funlen
- gci
#- godot
#- gochecknoglobals
#- gochecknoinits
- gocognit
- goconst
- gocritic
- gocyclo
#- godox
- goerr113
- gofmt
- gofumpt
- goheader
- goimports
#- gomnd
- goprintffuncname
- gosec
- gosimple
- govet
- ifshort
- importas
- ineffassign
- lll
- makezero
- misspell
- nakedret
- nilerr
- nolintlint
- prealloc
- predeclared
- promlinter
#- revive
- rowserrcheck
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
- wastedassign
- whitespace
#- wrapcheck
#- wsl

run:
timeout: 5m
skip-dirs:
- .github
- build
- web

issues:
max-same-issues: 0
exclude-use-default: false
8 changes: 6 additions & 2 deletions Alignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@ func Align(at AlignmentType) *AlignmentSetter {
}
}

// To sets a layout, alignment should be applied to
func (a *AlignmentSetter) To(widgets ...Widget) *AlignmentSetter {
a.layout = Layout(widgets)
return a
}

// ID allows to manually set AlignmentSetter ID (it shouldn't be used
// in a normal conditions)
func (a *AlignmentSetter) ID(id string) *AlignmentSetter {
a.id = id
return a
Expand All @@ -59,6 +62,7 @@ func (a *AlignmentSetter) Build() {
}

// exclude some widgets from alignment process
// nolint:gocritic // could have more cases later
switch item.(type) {
case *CustomWidget:
item.Build()
Expand All @@ -84,9 +88,9 @@ func (a *AlignmentSetter) Build() {
case AlignLeft:
SetCursorPos(currentPos)
case AlignCenter:
SetCursorPos(image.Pt(int(availableW/2-w/2), int(currentPos.Y)))
SetCursorPos(image.Pt(int(availableW/2-w/2), currentPos.Y))
case AlignRight:
SetCursorPos(image.Pt(int(availableW-w), int(currentPos.Y)))
SetCursorPos(image.Pt(int(availableW-w), currentPos.Y))
default:
panic(fmt.Sprintf("giu: (*AlignSetter).Build: unknown align type %d", a.alignType))
}
Expand Down
124 changes: 76 additions & 48 deletions Canvas.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,77 +7,105 @@ 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(),
}
}

func (c *Canvas) AddLine(p1, p2 image.Point, color color.RGBA, thickness float32) {
c.drawlist.AddLine(ToVec2(p1), ToVec2(p2), ToVec4Color(color), thickness)
// AddLine draws a line (from p1 to p2)
func (c *Canvas) AddLine(p1, p2 image.Point, col color.RGBA, thickness float32) {
c.drawlist.AddLine(ToVec2(p1), ToVec2(p2), ToVec4Color(col), thickness)
}

// DrawFlags represents imgui.DrawFlags
type DrawFlags int

// draw flags enum:
const (
DrawFlagsNone DrawFlags = 0
DrawFlagsClosed DrawFlags = 1 << 0 // PathStroke(), AddPolyline(): specify that shape should be closed (portant: this is always == 1 for legacy reason)
DrawFlagsRoundCornersTopLeft DrawFlags = 1 << 4 // AddRect(), AddRectFilled(), PathRect(): enable rounding top-left corner only (when rounding > 0.0f, we default to all corners). Was 0x01.
DrawFlagsRoundCornersTopRight DrawFlags = 1 << 5 // AddRect(), AddRectFilled(), PathRect(): enable rounding top-right corner only (when rounding > 0.0f, we default to all corners). Was 0x02.
DrawFlagsRoundCornersBottomLeft DrawFlags = 1 << 6 // AddRect(), AddRectFilled(), PathRect(): enable rounding bottom-left corner only (when rounding > 0.0f, we default to all corners). Was 0x04.
DrawFlagsRoundCornersBottomRight DrawFlags = 1 << 7 // AddRect(), AddRectFilled(), PathRect(): enable rounding bottom-right corner only (when rounding > 0.0f, we default to all corners). Wax 0x08.
DrawFlagsRoundCornersNone DrawFlags = 1 << 8 // AddRect(), AddRectFilled(), PathRect(): disable rounding on all corners (when rounding > 0.0f). This is NOT zero, NOT an implicit flag!
DrawFlagsRoundCornersTop DrawFlags = DrawFlagsRoundCornersTopLeft | DrawFlagsRoundCornersTopRight
DrawFlagsRoundCornersBottom DrawFlags = DrawFlagsRoundCornersBottomLeft | DrawFlagsRoundCornersBottomRight
DrawFlagsRoundCornersLeft DrawFlags = DrawFlagsRoundCornersBottomLeft | DrawFlagsRoundCornersTopLeft
DrawFlagsRoundCornersRight DrawFlags = DrawFlagsRoundCornersBottomRight | DrawFlagsRoundCornersTopRight
DrawFlagsRoundCornersAll DrawFlags = DrawFlagsRoundCornersTopLeft | DrawFlagsRoundCornersTopRight | DrawFlagsRoundCornersBottomLeft | DrawFlagsRoundCornersBottomRight
DrawFlagsRoundCornersDefault DrawFlags = DrawFlagsRoundCornersAll // Default to ALL corners if none of the RoundCornersXX flags are specified.
DrawFlagsRoundCornersMask DrawFlags = DrawFlagsRoundCornersAll | DrawFlagsRoundCornersNone
DrawFlagsNone DrawFlags = 0
// PathStroke(), AddPolyline(): specify that shape should be closed (portant: this is always == 1 for legacy reason)
DrawFlagsClosed DrawFlags = 1 << 0
// AddRect(), AddRectFilled(), PathRect(): enable rounding top-left corner only (when rounding > 0.0f, we default to all corners).
// Was 0x01.
DrawFlagsRoundCornersTopLeft DrawFlags = 1 << 4
// AddRect(), AddRectFilled(), PathRect(): enable rounding top-right corner only (when rounding > 0.0f, we default to all corners).
// Was 0x02.
DrawFlagsRoundCornersTopRight DrawFlags = 1 << 5
// AddRect(), AddRectFilled(), PathRect(): enable rounding bottom-left corner only (when rounding > 0.0f, we default to all corners).
// Was 0x04.
DrawFlagsRoundCornersBottomLeft DrawFlags = 1 << 6
// AddRect(), AddRectFilled(), PathRect(): enable rounding bottom-right corner only (when rounding > 0.0f,
// we default to all corners). Wax 0x08.
DrawFlagsRoundCornersBottomRight DrawFlags = 1 << 7
// 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
// Default to ALL corners if none of the RoundCornersXX flags are specified.
DrawFlagsRoundCornersDefault DrawFlags = DrawFlagsRoundCornersAll
DrawFlagsRoundCornersMask DrawFlags = DrawFlagsRoundCornersAll | DrawFlagsRoundCornersNone
)

func (c *Canvas) AddRect(pMin, pMax image.Point, color color.RGBA, rounding float32, rounding_corners DrawFlags, thickness float32) {
c.drawlist.AddRect(ToVec2(pMin), ToVec2(pMax), ToVec4Color(color), rounding, int(rounding_corners), thickness)
// AddRect draws a rectangle
func (c *Canvas) AddRect(pMin, pMax image.Point, col color.RGBA, rounding float32, roundingCorners DrawFlags, thickness float32) {
c.drawlist.AddRect(ToVec2(pMin), ToVec2(pMax), ToVec4Color(col), rounding, int(roundingCorners), thickness)
}

func (c *Canvas) AddRectFilled(pMin, pMax image.Point, color color.RGBA, rounding float32, rounding_corners DrawFlags) {
c.drawlist.AddRectFilled(ToVec2(pMin), ToVec2(pMax), ToVec4Color(color), rounding, int(rounding_corners))
// AddRectFilled draws a rectangle filled with `col`
func (c *Canvas) AddRectFilled(pMin, pMax image.Point, col color.RGBA, rounding float32, roundingCorners DrawFlags) {
c.drawlist.AddRectFilled(ToVec2(pMin), ToVec2(pMax), ToVec4Color(col), rounding, int(roundingCorners))
}

func (c *Canvas) AddText(pos image.Point, color color.RGBA, text string) {
c.drawlist.AddText(ToVec2(pos), ToVec4Color(color), tStr(text))
// AddText draws text
func (c *Canvas) AddText(pos image.Point, col color.RGBA, text string) {
c.drawlist.AddText(ToVec2(pos), ToVec4Color(col), tStr(text))
}

func (c *Canvas) AddBezierCubic(pos0, cp0, cp1, pos1 image.Point, color color.RGBA, thickness float32, num_segments int) {
c.drawlist.AddBezierCubic(ToVec2(pos0), ToVec2(cp0), ToVec2(cp1), ToVec2(pos1), ToVec4Color(color), thickness, num_segments)
// AddBezierCubic draws bezier cubic
func (c *Canvas) AddBezierCubic(pos0, cp0, cp1, pos1 image.Point, col color.RGBA, thickness float32, numSegments int) {
c.drawlist.AddBezierCubic(ToVec2(pos0), ToVec2(cp0), ToVec2(cp1), ToVec2(pos1), ToVec4Color(col), thickness, numSegments)
}

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)
// AddTriangle draws a triangle
func (c *Canvas) AddTriangle(p1, p2, p3 image.Point, col color.RGBA, thickness float32) {
c.drawlist.AddTriangle(ToVec2(p1), ToVec2(p2), ToVec2(p3), ToVec4Color(col), thickness)
}

func (c *Canvas) AddTriangleFilled(p1, p2, p3 image.Point, color color.RGBA) {
c.drawlist.AddTriangleFilled(ToVec2(p1), ToVec2(p2), ToVec2(p3), ToVec4Color(color))
// AddTriangleFilled draws a filled triangle
func (c *Canvas) AddTriangleFilled(p1, p2, p3 image.Point, col color.RGBA) {
c.drawlist.AddTriangleFilled(ToVec2(p1), ToVec2(p2), ToVec2(p3), ToVec4Color(col))
}

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)
// AddCircle draws a circle
func (c *Canvas) AddCircle(center image.Point, radius float32, col color.RGBA, segments int, thickness float32) {
c.drawlist.AddCircle(ToVec2(center), radius, ToVec4Color(col), segments, thickness)
}

func (c *Canvas) AddCircleFilled(center image.Point, radius float32, color color.RGBA) {
c.drawlist.AddCircleFilled(ToVec2(center), radius, ToVec4Color(color))
// AddCircleFilled draws a filled circle
func (c *Canvas) AddCircleFilled(center image.Point, radius float32, col color.RGBA) {
c.drawlist.AddCircleFilled(ToVec2(center), radius, ToVec4Color(col))
}

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)
// AddQuad draws a quad
func (c *Canvas) AddQuad(p1, p2, p3, p4 image.Point, col color.RGBA, thickness float32) {
c.drawlist.AddQuad(ToVec2(p1), ToVec2(p2), ToVec2(p3), ToVec2(p4), ToVec4Color(col), thickness)
}

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))
// AddQuadFilled draws a filled quad
func (c *Canvas) AddQuadFilled(p1, p2, p3, p4 image.Point, col color.RGBA) {
c.drawlist.AddQuadFilled(ToVec2(p1), ToVec2(p2), ToVec2(p3), ToVec2(p4), ToVec4Color(col))
}

// Stateful path API, add points then finish with PathFillConvex() or PathStroke()
Expand All @@ -94,30 +122,30 @@ func (c *Canvas) PathLineToMergeDuplicate(pos image.Point) {
c.drawlist.PathLineToMergeDuplicate(ToVec2(pos))
}

func (c *Canvas) PathFillConvex(color color.RGBA) {
c.drawlist.PathFillConvex(ToVec4Color(color))
func (c *Canvas) PathFillConvex(col color.RGBA) {
c.drawlist.PathFillConvex(ToVec4Color(col))
}

func (c *Canvas) PathStroke(color color.RGBA, closed bool, thickness float32) {
c.drawlist.PathStroke(ToVec4Color(color), closed, thickness)
func (c *Canvas) PathStroke(col color.RGBA, closed bool, thickness float32) {
c.drawlist.PathStroke(ToVec4Color(col), closed, thickness)
}

func (c *Canvas) PathArcTo(center image.Point, radius, a_min, a_max float32, num_segments int) {
c.drawlist.PathArcTo(ToVec2(center), radius, a_min, a_max, num_segments)
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) PathArcToFast(center image.Point, radius float32, a_min_of_12, a_max_of_12 int) {
c.drawlist.PathArcToFast(ToVec2(center), radius, a_min_of_12, a_max_of_12)
func (c *Canvas) PathArcToFast(center image.Point, radius float32, min12, max12 int) {
c.drawlist.PathArcToFast(ToVec2(center), radius, min12, max12)
}

func (c *Canvas) PathBezierCubicCurveTo(p1, p2, p3 image.Point, num_segments int) {
c.drawlist.PathBezierCubicCurveTo(ToVec2(p1), ToVec2(p2), ToVec2(p3), num_segments)
func (c *Canvas) PathBezierCubicCurveTo(p1, p2, p3 image.Point, numSegments int) {
c.drawlist.PathBezierCubicCurveTo(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))
}

func (c *Canvas) AddImageV(texture *Texture, pMin, pMax image.Point, uvMin, uvMax image.Point, color color.RGBA) {
c.drawlist.AddImageV(texture.id, ToVec2(pMin), ToVec2(pMax), ToVec2(uvMin), ToVec2(uvMax), ToVec4Color(color))
func (c *Canvas) AddImageV(texture *Texture, pMin, pMax, uvMin, uvMax image.Point, col color.RGBA) {
c.drawlist.AddImageV(texture.id, ToVec2(pMin), ToVec2(pMax), ToVec2(uvMin), ToVec2(uvMax), ToVec4Color(col))
}
Loading

0 comments on commit c0bfa9f

Please sign in to comment.