giu icon indicating copy to clipboard operation
giu copied to clipboard

how to get widget size

Open gucio321 opened this issue 4 years ago • 5 comments

Hi there, I'm thinking about a package-level Align method. it could look like:

g.Align(giu.AlignToCenter).To(/* any widgets*/),

is there any way to get a size (width, height) of any widget? e.g. I can get label size by CalcTextSize:

// ...
if label, isLabel := widget.(*Label); isLabel {
   width,height = CalcTextSize(label.label)
}
// ...

Is there any way to do it for any layout? maybe with GetCursorPos?

gucio321 avatar Sep 03 '21 17:09 gucio321

okey, I got it: imgui.GetItemRectSize()

gucio321 avatar Sep 03 '21 18:09 gucio321

hmm, well, but is there anything like CalcItemRectSize? I need to get this value before rendering a widget

gucio321 avatar Sep 03 '21 18:09 gucio321

@gucio321 Check this https://github.com/ocornut/imgui/issues/3714

AllenDang avatar Sep 04 '21 05:09 AllenDang

okey. so there is workaround code:

        startPos := GetCursorPos()

        var widgetWidth float32

        // render widget with 0 alpha and store thems widths
        imgui.PushStyleVarFloat(imgui.StyleVarID(StyleVarAlpha), 0)
        mywidget.Build()
         size := imgui.GetItemRectSize()
         widgetWidth = size.X
        imgui.PopStyleVar()

        // reset cursor pos
        SetCursorPos(startPos)

@allenDang should we keep the issue open?

gucio321 avatar Sep 04 '21 12:09 gucio321

@gucio321 I think we should keep it open until upstream solution comes.

AllenDang avatar Sep 04 '21 13:09 AllenDang