diff --git a/Layout.go b/Layout.go index 84b3c0ee..dd41406c 100644 --- a/Layout.go +++ b/Layout.go @@ -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() } diff --git a/README.md b/README.md index 00001824..ed43540b 100644 --- a/README.md +++ b/README.md @@ -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). @@ -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 @@ -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 @@ -125,7 +125,7 @@ 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 ``` @@ -133,7 +133,7 @@ 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/). @@ -141,9 +141,11 @@ 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: @@ -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" diff --git a/examples/dragdrop/dragdrop.go b/examples/dragdrop/dragdrop.go index 7351f92b..9cb92c3a 100644 --- a/examples/dragdrop/dragdrop.go +++ b/examples/dragdrop/dragdrop.go @@ -14,16 +14,16 @@ 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() @@ -31,7 +31,7 @@ func loop() { } }), ), - 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") diff --git a/examples/helloworld/helloworld.go b/examples/helloworld/helloworld.go index 0870a2e1..8280be54 100644 --- a/examples/helloworld/helloworld.go +++ b/examples/helloworld/helloworld.go @@ -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), ) } diff --git a/examples/multiplefonts/multiplefonts.go b/examples/multiplefonts/multiplefonts.go index 23d75aec..391aa66c 100644 --- a/examples/multiplefonts/multiplefonts.go +++ b/examples/multiplefonts/multiplefonts.go @@ -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), ) } diff --git a/examples/ondrop/ondrop.go b/examples/ondrop/ondrop.go index f04c7b74..30244c6c 100644 --- a/examples/ondrop/ondrop.go +++ b/examples/ondrop/ondrop.go @@ -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), ) } diff --git a/examples/widgets/widgets.go b/examples/widgets/widgets.go index 61e47396..e24788c4 100644 --- a/examples/widgets/widgets.go +++ b/examples/widgets/widgets.go @@ -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), @@ -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( @@ -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"}),