Golden-layout: Programmatically resize the items?

Created on 16 Aug 2016  路  3Comments  路  Source: golden-layout/golden-layout

Is there a way to programmatically resize the items (or containers/components -- please forgive my term ignorance -- either when adding a child (with addChild()) or after the fact -- e.g., set the widths of the three items to 50%, 25%, 25% each?

By the way, golden-layout is awesome. Thanks for making it.

Most helpful comment

Firstly, you need to get the item for each container. You can use different methods for this, such as
javascript myLayout.root.getItemsById("itemId")
Available methods -

  • getItemsById
  • getItemsByFilter
  • getItemsByType

This returns a list of items matching the id, you can use the attribute ".parent" on these items to get the stack.
The width data is held in the stack config

myLayout.root.getItemsById("itemId")[0].parent.config.width

set this equal to your width for each stack, then just call update size to refresh the view.

myLayout.updateSize()

All 3 comments

I have the same question.. how can we set the size of an component thru code?

I'll join in... I need to have a component contain a video, and have the container grow proportionally in width and height when a resize event occurs. HD video is 16:9, so when height changes, I need to adjust the width to be height * 1.777778, and adjusting width should set the height to width * .5625. Any ideas?

Firstly, you need to get the item for each container. You can use different methods for this, such as
javascript myLayout.root.getItemsById("itemId")
Available methods -

  • getItemsById
  • getItemsByFilter
  • getItemsByType

This returns a list of items matching the id, you can use the attribute ".parent" on these items to get the stack.
The width data is held in the stack config

myLayout.root.getItemsById("itemId")[0].parent.config.width

set this equal to your width for each stack, then just call update size to refresh the view.

myLayout.updateSize()
Was this page helpful?
0 / 5 - 0 ratings