Skip to content

Commit

Permalink
Merge from origin/master
Browse files Browse the repository at this point in the history
  • Loading branch information
AllenDang committed Mar 22, 2022
2 parents 106202c + a79b838 commit 8d030d8
Show file tree
Hide file tree
Showing 17 changed files with 89 additions and 67 deletions.
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.2.0
uses: actions/setup-go@v3
with:
go-version: 1.17.x
go-version: 1.18.x
id: go

- name: Cache Go modules
uses: actions/cache@v2.1.7
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.2.0
- 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.44.0
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
8 changes: 4 additions & 4 deletions ClickableWidgets.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func Button(label string) *ButtonWidget {

// Buttonf creates button with formated label
// NOTE: works like fmt.Sprintf (see `go doc fmt`).
func Buttonf(format string, args ...interface{}) *ButtonWidget {
func Buttonf(format string, args ...any) *ButtonWidget {
return Button(fmt.Sprintf(format, args...))
}

Expand Down Expand Up @@ -123,7 +123,7 @@ func SmallButton(id string) *SmallButtonWidget {

// SmallButtonf allows to set formated label for small button.
// It calls SmallButton(fmt.Sprintf(label, args...)).
func SmallButtonf(format string, args ...interface{}) *SmallButtonWidget {
func SmallButtonf(format string, args ...any) *SmallButtonWidget {
return SmallButton(fmt.Sprintf(format, args...))
}

Expand Down Expand Up @@ -436,7 +436,7 @@ func Selectable(label string) *SelectableWidget {
}

// Selectablef creates a selectable widget with formated label.
func Selectablef(format string, args ...interface{}) *SelectableWidget {
func Selectablef(format string, args ...any) *SelectableWidget {
return Selectable(fmt.Sprintf(format, args...))
}

Expand Down Expand Up @@ -511,7 +511,7 @@ func TreeNode(label string) *TreeNodeWidget {
}

// TreeNodef adds TreeNode with formatted label.
func TreeNodef(format string, args ...interface{}) *TreeNodeWidget {
func TreeNodef(format string, args ...any) *TreeNodeWidget {
return TreeNode(fmt.Sprintf(format, args...))
}

Expand Down
6 changes: 3 additions & 3 deletions Context.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (c *context) IO() imgui.IO {
}

func (c *context) invalidAllState() {
c.state.Range(func(k, v interface{}) bool {
c.state.Range(func(k, v any) bool {
if s, ok := v.(*state); ok {
s.valid = false
}
Expand All @@ -64,7 +64,7 @@ func (c *context) invalidAllState() {
}

func (c *context) cleanState() {
c.state.Range(func(k, v interface{}) bool {
c.state.Range(func(k, v any) bool {
if s, ok := v.(*state); ok {
if !s.valid {
c.state.Delete(k)
Expand All @@ -82,7 +82,7 @@ func (c *context) SetState(id string, data Disposable) {
c.state.Store(id, &state{valid: true, data: data})
}

func (c *context) GetState(id string) interface{} {
func (c *context) GetState(id string) any {
if v, ok := c.state.Load(id); ok {
if s, ok := v.(*state); ok {
s.valid = true
Expand Down
2 changes: 1 addition & 1 deletion ExtraWidgets.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ func (c *ConditionWidget) Build() {
}

// RangeBuilder batch create widgets and render only which is visible.
func RangeBuilder(id string, values []interface{}, builder func(int, interface{}) Widget) Layout {
func RangeBuilder(id string, values []any, builder func(int, any) Widget) Layout {
var layout Layout

layout = append(layout, Custom(func() { imgui.PushID(id) }))
Expand Down
11 changes: 10 additions & 1 deletion FontAtlasProsessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,15 @@ func (f *FontInfo) String() string {
func (f *FontInfo) SetSize(size float32) *FontInfo {
result := *f
result.size = size

for _, i := range extraFonts {
if i.String() == result.String() {
return &result
}
}

extraFonts = append(extraFonts, result)
shouldRebuildFontAtlas = true

return &result
}
Expand Down Expand Up @@ -219,7 +227,7 @@ func rebuildFontAtlas() {

var sb strings.Builder

stringMap.Range(func(k, v interface{}) bool {
stringMap.Range(func(k, v any) bool {
stringMap.Store(k, true)
if ks, ok := k.(rune); ok {
sb.WriteRune(ks)
Expand Down Expand Up @@ -285,6 +293,7 @@ func rebuildFontAtlas() {
} else {
f = fonts.AddFontFromMemoryTTFV(fontInfo.fontByte, fontInfo.size, imgui.DefaultFontConfig, ranges.Data())
}

extraFontMap[fontInfo.String()] = &f
}

Expand Down
28 changes: 21 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Here is the result:

### What is immediate mode GUI?

Immediate mode GUI system means the UI control doesn't retain its state and value. For example, calling `giu.InputText("ID", &str)` will display a input text box on screen, and the user entered value will be stored in `&str`. Input text box doesn't know anything about it.
Immediate mode GUI system means the UI control doesn't retain its state and value. For example, calling `giu.InputText(&str)` will display a input text box on screen, and the user entered value will be stored in `&str`. Input text box doesn't know anything about it.

And the `loop` method in the _Hello world_ example is in charge of **drawing** all widgets based on the parameters passed into them. This method will be invoked 30 times per second to reflect interactive states (like clicked, hovered, value-changed, etc.). It will be the place you define the UI structure.

Expand Down Expand Up @@ -144,19 +144,26 @@ Or, install [TDM-GCC](https://jmeubank.github.io/tdm-gcc/).
First you need to install the required dependencies:

```bash
# apt install libx11-dev libxcursor-dev libxrandr-dev libxinerama-dev libxi-dev libglx-dev libgl1-mesa-dev libxxf86vm-dev
sudo apt install libx11-dev libxcursor-dev libxrandr-dev libxinerama-dev libxi-dev libglx-dev libgl1-mesa-dev libxxf86vm-dev
```

on Red Hat based distributions:
```bash
sudo dnf install libX11-devel libXcursor-devel libXrandr-devel libXinerama-devel libXi-devel libGL-devel libXxf86vm-devel
```

you may also need to install C/C++ compiller (like g++) if it isn't already installed. Follow go compilator prompts.

Then, a simple `go build` will work.

Cross-compiling is a bit more complicated. Let's say that you want to build for arm64. This is what you would need to do:

```bash
# dpkg --add-architecture arm64
# apt update
# apt install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu \
sudo dpkg --add-architecture arm64
sudo apt update
sudo apt install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu \
libx11-dev:arm64 libxcursor-dev:arm64 libxrandr-dev:arm64 libxinerama-dev:arm64 libxi-dev:arm64 libglx-dev:arm64 libgl1-mesa-dev:arm64 libxxf86vm-dev:arm64
$ GOOS=linux GOARCH=arm64 CGO_ENABLED=1 CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ HOST=aarch64-linux-gnu go build -v
GOOS=linux GOARCH=arm64 CGO_ENABLED=1 CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ HOST=aarch64-linux-gnu go build -v
```

## Deploying
Expand All @@ -173,14 +180,21 @@ go build -ldflags "-s -w" .
go build -ldflags "-s -w -H=windowsgui -extldflags=-static" .
```

### Build Windows version on MacOS.
### Build Windows version on MacOS/Linux.

1. Install mingw-64.

on Mac:
```sh
brew install mingw-w64
```

on Linux:

```sh
sudo dnf install mingw64-gcc mingw64-gcc-c++ mingw-winpthreads-static
```

2. Prepare and embed the application icon into the executable and build.

```sh
Expand Down
6 changes: 3 additions & 3 deletions SliderWidgets.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (s *SliderIntWidget) Label(label string) *SliderIntWidget {
}

// Labelf sets formated label.
func (s *SliderIntWidget) Labelf(format string, args ...interface{}) *SliderIntWidget {
func (s *SliderIntWidget) Labelf(format string, args ...any) *SliderIntWidget {
return s.Label(fmt.Sprintf(format, args...))
}

Expand Down Expand Up @@ -136,7 +136,7 @@ func (vs *VSliderIntWidget) Label(label string) *VSliderIntWidget {
}

// Labelf sets formated label.
func (vs *VSliderIntWidget) Labelf(format string, args ...interface{}) *VSliderIntWidget {
func (vs *VSliderIntWidget) Labelf(format string, args ...any) *VSliderIntWidget {
return vs.Label(fmt.Sprintf(format, args...))
}

Expand Down Expand Up @@ -209,7 +209,7 @@ func (sf *SliderFloatWidget) Label(label string) *SliderFloatWidget {
}

// Labelf sets formated label.
func (sf *SliderFloatWidget) Labelf(format string, args ...interface{}) *SliderFloatWidget {
func (sf *SliderFloatWidget) Labelf(format string, args ...any) *SliderFloatWidget {
return sf.Label(fmt.Sprintf(format, args...))
}

Expand Down
19 changes: 6 additions & 13 deletions Style.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ var _ Widget = &StyleSetter{}
// StyleSetter is a user-friendly way to manage imgui styles.
type StyleSetter struct {
colors map[StyleColorID]color.Color
styles map[StyleVarID]interface{}
styles map[StyleVarID]any
font *FontInfo
disabled bool
layout Layout
Expand All @@ -369,7 +369,7 @@ type StyleSetter struct {
func Style() *StyleSetter {
var ss StyleSetter
ss.colors = make(map[StyleColorID]color.Color)
ss.styles = make(map[StyleVarID]interface{})
ss.styles = make(map[StyleVarID]any)

return &ss
}
Expand Down Expand Up @@ -411,11 +411,7 @@ func (ss *StyleSetter) SetFontSize(size float32) *StyleSetter {
font = defaultFonts[0]
}

font.size = size

extraFonts = append(extraFonts, font)

ss.font = &font
ss.font = font.SetSize(size)

return ss
}
Expand Down Expand Up @@ -466,9 +462,10 @@ func (ss *StyleSetter) Build() {
}
}

isFontPushed := false
if ss.font != nil {
isFontPushed = PushFont(ss.font)
if PushFont(ss.font) {
defer PopFont()
}
}

imgui.BeginDisabled(ss.disabled)
Expand All @@ -477,10 +474,6 @@ func (ss *StyleSetter) Build() {

imgui.EndDisabled()

if isFontPushed {
PopFont()
}

imgui.PopStyleColorV(len(ss.colors))
imgui.PopStyleVarV(len(ss.styles))
}
12 changes: 6 additions & 6 deletions TextWidgets.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (i *InputTextMultilineWidget) Label(label string) *InputTextMultilineWidget
}

// Labelf is formatting version of Label.
func (i *InputTextMultilineWidget) Labelf(format string, args ...interface{}) *InputTextMultilineWidget {
func (i *InputTextMultilineWidget) Labelf(format string, args ...any) *InputTextMultilineWidget {
return i.Label(fmt.Sprintf(format, args...))
}

Expand Down Expand Up @@ -116,7 +116,7 @@ func BulletText(text string) *BulletTextWidget {
}

// BulletTextf is a formatting version of BulletText.
func BulletTextf(format string, args ...interface{}) *BulletTextWidget {
func BulletTextf(format string, args ...any) *BulletTextWidget {
return BulletText(fmt.Sprintf(format, args...))
}

Expand Down Expand Up @@ -170,7 +170,7 @@ func (i *InputTextWidget) Label(label string) *InputTextWidget {
}

// Labelf adds formatted label.
func (i *InputTextWidget) Labelf(format string, args ...interface{}) *InputTextWidget {
func (i *InputTextWidget) Labelf(format string, args ...any) *InputTextWidget {
return i.Label(fmt.Sprintf(format, args...))
}

Expand Down Expand Up @@ -300,7 +300,7 @@ func (i *InputIntWidget) Label(label string) *InputIntWidget {
}

// Labelf sets formatted label.
func (i *InputIntWidget) Labelf(format string, args ...interface{}) *InputIntWidget {
func (i *InputIntWidget) Labelf(format string, args ...any) *InputIntWidget {
return i.Label(fmt.Sprintf(format, args...))
}

Expand Down Expand Up @@ -365,7 +365,7 @@ func (i *InputFloatWidget) Label(label string) *InputFloatWidget {
}

// Labelf sets formatted label.
func (i *InputFloatWidget) Labelf(format string, args ...interface{}) *InputFloatWidget {
func (i *InputFloatWidget) Labelf(format string, args ...any) *InputFloatWidget {
return i.Label(fmt.Sprintf(format, args...))
}

Expand Down Expand Up @@ -423,7 +423,7 @@ func Label(label string) *LabelWidget {
}

// Labelf allows to add formatted label.
func Labelf(format string, args ...interface{}) *LabelWidget {
func Labelf(format string, args ...any) *LabelWidget {
return Label(fmt.Sprintf(format, args...))
}

Expand Down
Loading

0 comments on commit 8d030d8

Please sign in to comment.