Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into font-atlas
Browse files Browse the repository at this point in the history
  • Loading branch information
gucio321 committed Mar 22, 2022
2 parents 2880888 + 8d030d8 commit cb94aa3
Show file tree
Hide file tree
Showing 45 changed files with 1,162 additions and 430 deletions.
5 changes: 4 additions & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ body:
description: What version of giu are you running?
options:
- master
- v0.5.6 (latest)
- (latest)
- v0.6.1
- v0.6
- v0.5.6
validations:
required: true
- type: input
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- name: Checkout out source code
uses: actions/checkout@v2.3.5
uses: actions/checkout@v3
with:
fetch-depth: 0
submodules: 'true'
Expand All @@ -30,13 +30,13 @@ jobs:
sudo apt-get --allow-releaseinfo-change update
sudo apt-get install -y libgtk-3-dev libasound2-dev libxxf86vm-dev
- name: Set up Go environment
uses: actions/setup-go@v2.1.4
uses: actions/setup-go@v3
with:
go-version: 1.16.x
go-version: 1.18.x
id: go

- name: Cache Go modules
uses: actions/cache@v2.1.6
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ jobs:
run: |
sudo apt-get --allow-releaseinfo-change update
sudo apt-get install -y libgtk-3-dev libasound2-dev libxxf86vm-dev
- uses: actions/checkout@v2.3.5
- uses: actions/checkout@v3
with:
fetch-depth: 2
- uses: actions/setup-go@v2
- uses: actions/setup-go@v3
with:
go-version: '1.16'
go-version: '1.18.x'
- name: Run coverage
run: go test -race -coverprofile=coverage.txt -covermode=atomic
- name: Upload coverage to Codecov
Expand Down
13 changes: 7 additions & 6 deletions .github/workflows/golangci-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: '1.18.x'
- name: Set up LibGL, Mesa & X11 libraries
run: |
sudo apt-get --allow-releaseinfo-change update
sudo apt-get install -y libgtk-3-dev libasound2-dev libxxf86vm-dev
- uses: actions/checkout@v2.3.5
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v2.5.2
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.42.1
version: v1.45

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand All @@ -33,11 +36,9 @@ jobs:
# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true then the action will use pre-installed Go.
# skip-go-installation: true

# Optional: if set to true then the action don't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.

# skip-build-cache: true
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
# vim cache files
*.swp

# JetBrains idea configuration
.idea

# Test binary, built with `go test -c`
*.test

Expand Down
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ linters:
- prealloc
- predeclared
- promlinter
#- revive
#- revive
- rowserrcheck
- staticcheck
- structcheck
Expand Down
76 changes: 65 additions & 11 deletions Alignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,77 @@ import (
"github.com/AllenDang/imgui-go"
)

// AlignmentType represents a bype of alignment to use with AlignSetter.
type AlignmentType byte

const (
// AlignLeft is here just for clearity.
// if set, no action is taken so don't use it.
AlignLeft AlignmentType = iota
// AlignCenter centers widget.
AlignCenter
// AlignRight aligns a widget to right side of window.
AlignRight
)

type AlignmentSetter struct {
alignType AlignmentType
layout Layout
id string
// AlignManually allows to apply alignment manually.
// As long as AlignSetter is really EXPERIMENTAL feature
// and may fail randomly, the following method is supposed to
// always work, as long as you set it up correctly.
// To use it just pass a single widget with its exact width.
// be sure to apply widget's size by using "Size" method!
// forceApplyWidth argument allows you to ask giu to force-set width
// of `widget`
// NOTE that forcing width doesn't work for each widget type! For example
// Button won't work because its size is set by argument to imgui call
// not PushWidth api.
func AlignManually(alignmentType AlignmentType, widget Widget, widgetWidth float32, forceApplyWidth bool) Widget {
return Custom(func() {
spacingX, _ := GetItemSpacing()
availableW, _ := GetAvailableRegion()

var dummyX float32

switch alignmentType {
case AlignLeft:
widget.Build()
return
case AlignCenter:
dummyX = (availableW-widgetWidth)/2 - spacingX
case AlignRight:
dummyX = availableW - widgetWidth - spacingX
}

Dummy(dummyX, 0).Build()

if forceApplyWidth {
PushItemWidth(widgetWidth)
defer PopItemWidth()
}

imgui.SameLine()
widget.Build()
})
}

// Align sets widgets alignment.
var _ Widget = &AlignmentSetter{}

// AlignmentSetter allows to align to right / center a widget or widgets group.
// NOTE: Because of AlignSetter uses experimental GetWidgetWidth,
// it is experimental too.
// usage: see examples/align
//
// list of known bugs:
// - BUG: DatePickerWidget doesn't work properly
// - BUG: there is some bug with SelectableWidget
// - BUG: ComboWidget and ComboCustomWidgets doesn't work properly.
type AlignmentSetter struct {
alignType AlignmentType
layout Layout
id string
}

// Align sets widgets alignment.
func Align(at AlignmentType) *AlignmentSetter {
return &AlignmentSetter{
alignType: at,
Expand All @@ -40,13 +91,16 @@ func (a *AlignmentSetter) To(widgets ...Widget) *AlignmentSetter {
return a
}

// ID allows to manually set AlignmentSetter ID (it shouldn't be used
// in a normal conditions).
// ID allows to manually set AlignmentSetter ID
// NOTE: there isn't any known reason to use this method, however
// it is here for some random cases. YOU DON'T NEED TO USE IT
// in normal conditions.
func (a *AlignmentSetter) ID(id string) *AlignmentSetter {
a.id = id
return a
}

// Build implements Widget interface.
func (a *AlignmentSetter) Build() {
if a.layout == nil {
return
Expand Down Expand Up @@ -107,16 +161,16 @@ func (a *AlignmentSetter) Build() {
// widget will be processed)
//
// here is a list of known bugs:
// - BUG: clicking bug - when widget is clickable, it is unable to be
// clicked see:
// - BUG: user can interact with invisible widget (created by GetWidgetWidth)
// - https://github.com/AllenDang/giu/issues/341
// - https://github.com/ocornut/imgui/issues/4588
// - BUG: text pasted into input text is pasted twice
// (see: https://github.com/AllenDang/giu/issues/340)
//
// if you find anything else, please report it on
// https://github.com/AllenDang/giu Any contribution is appreciated!
func GetWidgetWidth(w Widget) (result float32) {
imgui.PushID(GenAutoID("GetWIdgetWidthMeasurement"))
defer imgui.PopID()

// save cursor position before rendering
currentPos := GetCursorPos()

Expand Down
2 changes: 1 addition & 1 deletion Canvas.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (c *Canvas) AddQuadFilled(p1, p2, p3, p4 image.Point, col color.Color) {
c.drawlist.AddQuadFilled(ToVec2(p1), ToVec2(p2), ToVec2(p3), ToVec2(p4), ToVec4Color(col))
}

// Stateful path API, add points then finish with PathFillConvex() or PathStroke()
// Stateful path API, add points then finish with PathFillConvex() or PathStroke().

func (c *Canvas) PathClear() {
c.drawlist.PathClear()
Expand Down
Loading

0 comments on commit cb94aa3

Please sign in to comment.