3

I have an application based on GoldenLayout (1.5.9). The layout is a Row containing two Columns. See below the configuration of the column I'm interested in.

let config = {
    content: [
        {
            type: "row",
            content: [
                {
                    type: "column",
                    width: 31,
                    content: [
                        {
                            type: "stack",
                            isClosable: false,
                            content: [...]
                        },
                        {
                            type: "component",
                            height: 30,
                            title: "Filters",
                            componentName: "templateComponent"
                        }
                    ]
                },
                ...
            ]
        }
    ]
}

Now I want to be able to close or hide the Component and made it reappears pushing a toolbar button (i.e. programmatically). I made various unsuccessful attempts:

  1. If I close the component using the x button, the parent Column magically disappears so a subsequent addChild on the component parent (saved somewhere) adds the component as a child of the Stack. Not what I intended.

  2. If I hide the component.element, the component disappears, but an hole remains. That is, the Stack does not resize.

  3. I don't find anywhere the documented hide() method on the Component, even if I wrap it in a Row, Column or Stack.

  4. If I manually move the separator between the Stack and the Component way down I obtain what I want (that is, to give to the Stack almost all the height) but no combination of setSize(?, ?) seems to do the same programmatically.

Any idea? Thanks!

UPDATE: If I wrap the component into another Stack, the container Column does not disappears so I can add it back:

{
    type: "stack",
    height: 30,
    id: "filtersFrame",
    isClosable: true,
    content: [
        {
            type: "component",
            title: "Filters",
            componentName: "templateComponent",
            componentState: { template: "filter-template" }
        }
    ]
}

Simply the height is ignored (the new stack is always 50% in height) and the knockout template is there but it is not run through knockout. But this is another problem.

Community
  • 1
  • 1
SiliconValley
  • 1,465
  • 17
  • 30
  • Would you show the code you are using to hide/show the container? – pithhelmet Feb 22 '18 at 21:17
  • Sure! Look at https://stackoverflow.com/questions/47900916/goldenlayout-ignored-height-when-adding-child For closing the container I rely on the X header button. To reopen it, see the other question. – SiliconValley Feb 23 '18 at 07:05

2 Answers2

1

A similar use case:

  1. User pressed a button
  2. Component hides
  3. User sees blank area but size in maintained.

Now I want to be able to close or hide the Component and made it reappears pushing a toolbar button (i.e. programmatically).

What I would do in this case is have a column or row with a stack inside it. Hide the stacks headers via the headerhieght itemconfig dimension setting. This stack has 2 items inside, one of which is empty. Then when the user clicks the button you set the empty item to be active. Then when you want it to reappear then just set the original to active.

The other use case is pretty simple where you are programmatically closing one and everything else around it resizes taking up the space. Bringing it back is also just adding it back in. I don't think you are referring to this one. Let me know.

Mark
  • 911
  • 13
  • 30
  • The second user case is exactly what I do. The problem is that the added back stack is ignoring the height setting (the knockout problem has been solved in the meantime). Is it better to open a new question? – SiliconValley Dec 19 '17 at 04:27
  • I am not sure what you mean by "ignoring the height". Are you saying that when you add it back in the stack overlaps other tabs? This should never happen if you are adding things back correctly because adding a child should call the `layout.resize()` function which resizes all of the containers. As far as asking a new question, I would say yes especially if it is a different problem. – Mark Dec 19 '17 at 15:34
  • No. I means that the re-added stack has `height: 30` (or any other percentage) and instead come up to occupy always 50% in height. When I created the layout the stack obeys the `height: 30` configuration option. Height is ignored only when it is closed and added back. – SiliconValley Dec 20 '17 at 04:08
  • Problem moved to https://stackoverflow.com/questions/47900916/goldenlayout-ignored-height-when-adding-child as "GoldenLayout: ignored height when adding child" – SiliconValley Dec 20 '17 at 07:34
1

I came across this same issue and found an easy solution: Note that I'm using Angular5, so this is in typescript, but the code is easily translatable to vanilla JS.

I found that if you simply call show/hide, the updateSize doesn't do anything, leaving a large empty hole, so you should set the size to 0/[whatever], too.

If you set the size to 0 and call updateSize() without calling hide(), the element will become thin strip.

You must do both for the full effect.

    let smartFormsRow = this._goldenLayout.root.getItemsById("smartformsrow");
    var isHidden = smartFormsRow[0].config.height == 0;
    if (isHidden) {
        smartFormsRow[0].element.show(); //jquery hide
        smartFormsRow[0].config.height = 30; //30%
    } else {
        smartFormsRow[0].element.hide(); //jquery show
        smartFormsRow[0].config.height = 0;
    }

    this._goldenLayout.updateSize();
The James
  • 465
  • 2
  • 9
  • It works! I forget to add the `[0]`. But there is a strange thing: I have to set the height to 21 to have the final height equal to the initial construction in which it was set to 30. – SiliconValley Mar 27 '18 at 07:11
  • That is strange. What's the size of the section(s) around it? Do their sizes add up to 70% or 79% after you redisplay it? – The James Mar 28 '18 at 16:58
  • Printing `myLayout.toConfig()` after `updateSize()` gives for the restored stacks: `height: 29.577464788732392` and `70.4225352112676` for the remaining part of the column. So somehow the height of the restored stack has been scaled from 21 to ~30. – SiliconValley Mar 29 '18 at 14:33
  • In the other column (this time the closurable stack is below, in the previous column the stack that has been closed was above) I want height = 27, but have to set it to 21.4. After `updateSize()` the two heights are: `70.02801120448179` and `29.9719887955182`. More distant from 27 but visually the same as the original setting of 27. If I adjust the height to ~19 I have the lower stack with height ~27, but visually it is much short than the initial setting. – SiliconValley Mar 29 '18 at 14:48
  • That's weird. I'm not experiencing anything similar to this. Maybe set both sizes (30 and 70) before calling updateSize() and see what it does. Sorry, wish I had an answer for you. – The James Mar 30 '18 at 16:21
  • Thanks! I will try soon. But could the problem be caused by the toolbar I have above the layout? I have to force the layout container height this way (toolbar height is 60): `$("#layout").height(window.innerHeight - toolbarHeight);` only then I can instantiate the layout: `const screenLayout = new GoldenLayout(config, $("#layout"));` – SiliconValley Mar 30 '18 at 18:04
  • The James, you are a wizard! Setting both heights obtains exactly the correct size. I removed the `getItemsById` call and set heights directly this way: `screenLayout.root.config.content[0].content[0].content[0].height = 73; screenLayout.root.config.content[0].content[0].content[1].height = 27;` (I have a row, that contains two columns whose left one contains two stacks). – SiliconValley Mar 30 '18 at 18:20