Unable to get the layer width

Currently I can’t get the layer width, I use a demo to show the problem
“layout.Size.Width” this method always returns a value of “-1”, why is that, I am very confused, I can’t get the real value

The problem :backhand_index_pointing_down:

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs
import System
import Rhino.UI
import Eto.Drawing as drawing
import Eto.Forms as forms
import Eto
drawing_Width = 400
drawing_Height = 200
drawing_Padding = 20
drawing_Spacing_Size_0 = 5
drawing_Spacing_Size_1 = 5
m_slider_Boolean_value = False
class Newwindow(forms.Dialog[bool]):
    """"Learning eto"""
    def __init__(self):
        super().__init__()
        self.ClientSize = drawing.Size(drawing_Width, drawing_Height)
        self.Title = 'New window'
        self.Padding = drawing.Padding(drawing_Padding)
        self.Resizable = True
        self.m_label = forms.Label()
        self.m_label.Text = 'd_cv'
        self.cve = forms.Button()
        self.cve.Text = "curve"
        self.DefaultButton = forms.Button()
        self.DefaultButton.Text ='OK'
        self.AbortButton = forms.Button()
        self.AbortButton.Text ='Cancel'
        #-------------------------
        drawable = forms.Drawable()
        drawable.Width = 20
        drawable.Height = 40
        #--------------------------
        layout = forms.DynamicLayout()
        layout.Spacing = drawing.Size(drawing_Spacing_Size_0, drawing_Spacing_Size_1)
        layout.AddRow(self.m_label , drawable)
        layout.AddRow(self.cve)
        layout.AddRow(self.DefaultButton,self.AbortButton)
        self.Content = layout
        #_________This👇
        print(layout.Size.Width)
def RequestRoomNumber():
    dialog = Newwindow()
    dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)

if __name__ == "__main__":
    RequestRoomNumber()

@curtisw Do you know the problem, Sir?

-1 means auto. If you haven’t set the width explicitly that’s what it returns

Didn’t the controls in the layer modify the “width”?

I’m using a custom draw and this code gets the width, but if you print it, it’s still going to print “-1”

rect_top_layout = ed.RectangleF(self.top_layout.Location.X,self.top_layout.Location.Y,self.top_layout.Width,self.top_layout.Height)

yes they change the actual width without setting it explicitly, hence the -1 / auto
If you set the width explicitly, or scale the window, you’ll get a value back that is not -1

Is there a way to get the actual “size” hidden by the layer? Because with controls there will be actual changes

I don’t think there is, no, but I agree it would be handy to have this.
RH-87086 Eto: report actual size of a control that is auto sized

There is no way to get the actual size of a control until it is loaded/shown. This is because the layout systems on both Mac and Windows/WPF is deferred. Otherwise, you can use GetPreferredSize() to get a control’s preferred size.

1 Like