Skip to content

Commit

Permalink
Add const giu.Auto for widget.Size method
Browse files Browse the repository at this point in the history
  • Loading branch information
AllenDang committed Aug 4, 2021
1 parent b505600 commit 00f0350
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 30 deletions.
5 changes: 5 additions & 0 deletions Layout.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package giu

const (
// Auto is used to widget.Size to indicate height or width to occupy available spaces
Auto float32 = -1
)

type Widget interface {
Build()
}
Expand Down
45 changes: 24 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ Compare to other Dear ImGui golang bindings, giu has following features:
- Small executable file size (<3MB after UPX compression for the example/helloworld demo).
- Live-updating during the resizing of OS window (implemented on GLFW 3.3 and OpenGL 3.2).
- Support for displaying various languages without any font setting. Giu will rebuild font atlas incrementally according to texts in UI between frames. Below is the list of languages currently supported:
* macOS
1. English
2. Simplified Chinese
3. Japanese
4. Korean
* Windows
1. English
2. Simplified Chinese
3. Japanese
* Kali Linux
1. English
* Need your help to add more language support by creating a PR or telling me the OS default font name for your language.
- macOS
1. English
2. Simplified Chinese
3. Japanese
4. Korean
- Windows
1. English
2. Simplified Chinese
3. Japanese
- Kali Linux
1. English
- Need your help to add more language support by creating a PR or telling me the OS default font name for your language.
- Redraws only when user event occurred. Costs only 0.5% CPU usage with 60FPS.
- Declarative UI (see examples for more detail).
- DPI awareness (auto scaling font and UI to adapt high DPI monitor).
Expand Down Expand Up @@ -87,9 +87,9 @@ Here is 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("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.

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.
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.

### The layout and sizing system

Expand All @@ -99,7 +99,7 @@ To create a row of widgets (aka place widgets one by one horizontally), use the

To creata a column of widgets (aka place widgets one by one vertically) inside a row, use the `Column()` method.

Any widget that has a `Size()` method, could set its size explicitly. Note that you could pass a negative value to `Size()`, which will fill the remaining width/height value. For example, `InputText(...).Size(-1)` will create a input text box with longest width that its container has left.
Any widget that has a `Size()` method, could set its size explicitly. Note that you could pass a negative value to `Size()`, which will fill the remaining width/height value. For example, `InputText(...).Size(giu.Auto)` will create a input text box with longest width that its container has left.

### Containers

Expand All @@ -125,25 +125,27 @@ The backend of giu depends on OpenGL 3.3, make sure your environment supports it

### MacOS

``` sh
```sh
xcode-select --install
go get github.com/AllenDang/giu
```

### Windows

1. Install mingw [download here](https://github.com/brechtsanders/winlibs_mingw/releases/tag/10.2.0-11.0.0-8.0.0-r8). Thanks @alchem1ster!
2. Add the binaries folder of mingw to the path (usually is *\mingw64\bin*).
2. Add the binaries folder of mingw to the path (usually is _\mingw64\bin_).
3. go get github.com/AllenDang/giu

Or, install [TDM-GCC](https://jmeubank.github.io/tdm-gcc/).

### Linux

First you need to install required dependencies:

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

Then, a simple `go build` will work.

Cross-compiling is a bit more complicated. Let's say that you want to build for arm64. That's what you would need to do:
Expand All @@ -160,26 +162,27 @@ $ GOOS=linux GOARCH=arm64 CGO_ENABLED=1 CC=aarch64-linux-gnu-gcc CXX=aarch64-lin

### Build MacOS version on MacOS.

``` sh
```sh
go build -ldflags "-s -w" .
```

### Build Windows version on Windows.

``` sh
```sh
go build -ldflags "-s -w -H=windowsgui -extldflags=-static" .
```

### Build Windows version on MacOS.

1. Install mingw-64.
``` sh

```sh
brew install mingw-w64
```

2. Prepare and embed application icon to executable and build.

``` sh
```sh
cat > YourExeName.rc << EOL
id ICON "./res/app_win.ico"
GLFW_ICON ICON "./res/app_win.ico"
Expand Down
6 changes: 3 additions & 3 deletions examples/dragdrop/dragdrop.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ var (
func loop() {
g.SingleWindow().Layout(
g.Row(
g.Button("Drag me: 9"),
g.Custom(func() {
g.Button("Drag me: 9").Build()
if imgui.BeginDragDropSource() {
imgui.SetDragDropPayload("DND_DEMO", 9)
g.Label("9").Build()
imgui.EndDragDropSource()
}
}),
g.Button("Drag me: 10"),
g.Custom(func() {
g.Button("Drag me: 10").Build()
if imgui.BeginDragDropSource() {
imgui.SetDragDropPayload("DND_DEMO", 10)
g.Label("10").Build()
imgui.EndDragDropSource()
}
}),
),
g.InputTextMultiline(&dropTarget).Size(-1, -1).Flags(g.InputTextFlagsReadOnly),
g.InputTextMultiline(&dropTarget).Size(g.Auto, g.Auto).Flags(g.InputTextFlagsReadOnly),
g.Custom(func() {
if imgui.BeginDragDropTarget() {
payload := imgui.AcceptDragDropPayload("DND_DEMO")
Expand Down
2 changes: 1 addition & 1 deletion examples/helloworld/helloworld.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var (
func loop() {
g.SingleWindow().Layout(
g.Label("Hello world from giu"),
g.InputTextMultiline(&content).Size(-1, -1),
g.InputTextMultiline(&content).Size(g.Auto, g.Auto),
)
}

Expand Down
2 changes: 1 addition & 1 deletion examples/multiplefonts/multiplefonts.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func loop() {
g.Label("你好啊!世界"),

// Change font for input area
g.InputTextMultiline(&content).Size(-1, -1),
g.InputTextMultiline(&content).Size(g.Auto, g.Auto),
)
}

Expand Down
2 changes: 1 addition & 1 deletion examples/ondrop/ondrop.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var (
func loop() {
g.SingleWindow().Layout(
g.Label("Drop file to this window"),
g.InputTextMultiline(&dropInFiles).Size(-1, -1).Flags(g.InputTextFlagsReadOnly),
g.InputTextMultiline(&dropInFiles).Size(g.Auto, g.Auto).Flags(g.InputTextFlagsReadOnly),
)
}

Expand Down
6 changes: 3 additions & 3 deletions examples/widgets/widgets.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func loop() {
g.RadioButton("Radio 3", radioOp == 2).OnChange(func() { radioOp = 2 }),
),

g.ProgressBar(0.8).Size(-1, 0).Overlay("Progress"),
g.ProgressBar(0.8).Size(g.Auto, 0).Overlay("Progress"),
g.DragInt("DragInt", &dragInt, 0, 100),
g.SliderInt("Slider", &dragInt, 0, 100),

Expand Down Expand Up @@ -144,7 +144,7 @@ func loop() {
g.TabBar().TabItems(
g.TabItem("Multiline Input").Layout(
g.Label("This is first tab with a multiline input text field"),
g.InputTextMultiline(&multiline).Size(-1, -1),
g.InputTextMultiline(&multiline).Size(g.Auto, g.Auto),
),
g.TabItem("Tree").Layout(
g.TreeNode("TreeNode1").Flags(g.TreeNodeFlagsCollapsingHeader|g.TreeNodeFlagsDefaultOpen).Layout(
Expand Down Expand Up @@ -191,7 +191,7 @@ func loop() {
),
}...,
).
Size(-1, -1),
Size(g.Auto, g.Auto),
),
g.TabItem("ListBox").Layout(
g.ListBox("ListBox1", []string{"List item 1", "List item 2", "List item 3"}),
Expand Down

0 comments on commit 00f0350

Please sign in to comment.