AllenDang / giu

Cross platform rapid GUI framework for golang based on Dear ImGui.
MIT License
2.11k stars 127 forks source link

[bug] g.Auto doesn't take tab bar height into account #802

Closed samuelchristlie closed 2 weeks ago

samuelchristlie commented 3 weeks ago

What happend?

I'm following the recommendation from https://github.com/AllenDang/giu/issues/177 to create a spacer, but used g.Auto instead since it should automatically fill the space. What I got is this:

image image

What I think is happening is that it doesn't take the height of the tab bar into account.

Code example

return g.TabBar().TabItems(
        g.TabItem("Edit").Layout(
            g.Column(
                        g.Row(g.Label("Name"), g.InputText(&name)),
                        g.Row(g.Label("Address"), g.InputTextMultiline(&address)),
                        g.Dummy(g.Auto, g.Auto),
                        g.Button("Submit"),
                    )
        ),
        g.TabItem("New"),
    )

To Reproduce

  1. Run the code
  2. g.Auto exceeds the height

Version

master

OS

Linux Mint 21.3 x86_64

samuelchristlie commented 3 weeks ago

I'm not sure if this is an expected behavior

const (
    // Auto is used to widget.Size to indicate height or width to occupy available spaces.
    Auto [float32](https://pkg.go.dev/builtin#float32) = -1
)

On one hand, it does fill the available space, but I was thinking the sizes would get calculated after other widgets.

gucio321 commented 2 weeks ago

@samuelchristlie sorry for late raply This works as expected. Think about this like that: giu calls widgets one by one, so at the moment of calling your dummy (spacer) it does not know that you're going to add your submit button.

In order to calculate your dummy's height, you need to use giu.GetAvailableRegion and decrease it by height of your button

samuelchristlie commented 2 weeks ago

Ahh, that makes sense. Thank you :+1: