View Dimensions And Position

Each view may have a position and dimensions constraint. Below is the list of related view properties.

Property Description
"width" The width of the view
"height" The height of the view
"min-width" The minimum width of the view
"min-height" The minimum height of the view
"max-width" The maximum width of the view
"max-height" The maximum height of the view
"left" Left offset from the parent container
"right" Right offset from the parent container
"top" Top offset from the parent container
"bottom" Bottom offset from the parent container
"resize" Describe whether the view can be resized and in which directions

Properties "left," "right," "top," and "bottom" are used only when the view is placed in an AbsoluteLayout container.

If the "width" or "height" value is not set or is set to "auto", then corresponding view dimension is determined by its content and limited to the minimum or maximum dimensions set.

All properties listed above except "resize" accept values of SizeUnit type as well as its text representation and constants of the same type.

Examples

Go

view.Set("width", rui.Px(8))        // Set view to be 8 pixels in width
view.Set(rui.MaxHeight, "80%")      // Set the view's maximum height to 80% of the parent view's height
view.Set(rui.Height, "@viewHeight") // Set the view's height to the value defined in "viewHeight" constant

Preferred way of getting the values of such properties is to use the global functions:

Go

if width := rui.GetWidth(rootView, viewId); width != nil {
    // Do something with the value
}

if maxHeight := rui.GetMaxHeight(rootView, viewId); maxHeight != nil {
    // Do something with the value
}

if height := rui.GetHeight(rootView, viewId); height != nil {
    // Do something with the value
}

or when we have a reference to the view:

Go

width := view.Get(rui.Width)
if width, ok := value.(SizeUnit); ok {
    // Do something with the value
}

maxHeight := view.Get(rui.MaxHeight)
if maxHeight, ok := value.(SizeUnit); ok {
    // Do something with the value
}

height := view.Get(rui.Height)
if height, ok := value.(SizeUnit); ok {
    // Do something with the value
}

The "resize" property sets whether the view can be resized, and if so, in which directions. The default value for all view types except multiline EditView is rui.NoneResize or "none" which means that we can't resize them. Getting or setting the value of that property follow the same steps as for any other property. Follow View reference documentation for that property to get more information.