Is there a way to enforce inequality constraints on widget size? - gwt

I have a CellTable widget which displays some data.
If there are many rows, I want the height of the widget to be capped at (say) 300 pixels (I can accomplish this by wrapping with a ScrollPanel).
However, if there are only a few rows, I don't want the ScrollPanel to use all 300 pixels of height. I just want it to be tall enough to contain all the data.
It seems like I want to set a ScrollPanel height which means "as large as the data requires, but no larger than 300px."
Is there a simple way to do this, or do I need to manually re-set the height in accordance with this constraint every time the celltable's rowdata changes?

The simplest way is to put the CellTable in a <div> or FlowPanel and set a CSS max-height: 300px for that container.

Related

Widget that takes up a fixed maximum of space, but shrinks to make room for other widgets inside Row

My Flutter UI has a Row widget with and arbitrary number Widgets in it. I would like to move all of those widgets over to the right by a fixed amount. But the caveat is, if the other widgets grow in width such that the available horizontal space is consumed, the spacing widget will relinquish its space.
The Spacer widget does not work for me, as it does not allow you to specify a fix maximum. It only allows a flex value, which is a function of the width of the other content in the row. I want this spacer to take up a fixed amount of space regardless of the width of the other content of the row (unless all the room is used up).
Try using sizedBox or FractionallySizedBox as explained in this answer
https://stackoverflow.com/a/63430801/8213343

How to adjust the width of the ag-grid container based on its contents?

In ag-grid, the value of domLayout can be set to autoHeight in order to disable vertical scrolling of the ag-grid panel. Instead, the entire page adapts its height to show all the rows.
How can I have the same behavior for the horizontal scrolling?
There is the suppressHorizontalScroll option when set to true hides the horizontal scroll bar, but this doesn't force the entire page to have a scroll. Instead, the overflowing content is just hidden.
you can do this to some extent by juggling the minWidth, maxWidth, and width attributes on your columns while setting the width of the columns automatically based on their content using the gridColumnApi.autoSizeColumns(colId) method.
I say to some extent because it is quite hard, with agGrid, to set different row sizes for rows with certain cells having a lot of text or big images in them. This would force some columns to expand to accommodate for the content, or just clip it completely. Thus forcing the horizontal scroll.
Note : for the method above to work, you need to call gridColumnApi.autoSizeColumns(colId) after you get your rows setUp.

How to calculate size of children

If I want to implement Widget which sizes itself by sizing children, how do I do it?
Somehow I need to defer sizing until all children have figure out their size.
You can create a custom layout, using CustomMultiChildLayout or CustomSingleChildLayout.
Or, if this fits your needs, use IntrinsicWidth/IntrinsicHeight widgets.
Custom layouts are basically a Stack with only positionned children. Children pick their size and then the layout choose their position.
BUT it has a limitation. The layout size can't depend on it's children size.
Instrinsinc widgets are much simpler but also more limited.
A use case would be to wrap a Row widget in IntrincWidget, to simulate the css display: flex; align-items: stretch;
If you need something more complex, you'll need to create your own RenderObject.
Yup, this is counter-intuitive.

GWT DataGrid resizes the columns

From what I understand the DataGrid auto resizes the columns.
What I would like is DataGrid to respect the column widths I set, and to show the horizontal scrollers accordingly. Is there a way to achieve this?
DataGrid gives you complete control over the width of its columns.
For example, if you set the width of all columns in pixels except for one column which has a width equal to 100%, then all columns will have exactly the width you specified, except for the percentage column which will shrink or expand based on the width of a DataGrid itself. If you want all columns to have fixed width, then you should set the width of the entire DataGrid explicitly in pixels.
There is also an important .setMinimumTableWidth method. You can use it to tell the DataGrid that it can resize with the width of its parent container, but never be smaller than a certain number of pixels. In this case, if a parent container is too small to accommodate all columns at their desired width, the horizontal scrollbar will appear.

Gwt VerticalPanel Cell Height

I have a horizontalpanel with 3 verticalpanels inside.
In the verticalpanels there are custom widgets
I need all verticalpanels has the same height (even if they have different number of widgets inside) and a button in the empty space.
So, I put all panels height = 100% and the buttons height = 100%.
The problem is that the verticalpanel cells height are bigger than my widgets, so it left a space between all verticalpanels widgets.
Here is an example
How can I adjust the verticalpanels cells height to my widgets height. My widgets are not images like in the example, so i can't know the widgets height.
I have a lot of time in this problem, anyidea will help
Thx!!!!
Haven't tried it, but this should work or at least give you something to start:
VerticalPanel.setCellHeight(yourWidget, Integer.toString(yourWidget.getElement().getOffsetHeight())+"px");
What it does:
setCellHeight() sets the height of the cell the widget is in you pass to the function.
The second parameter in the function is the height of that cell. This gets a little tricky because you don't know the height.
With the getElement() you get the Element of that widget in the DOM of the browser, on that element you can call getOffsetHeight().
getOffsetHeight() returns an integer so you need to cast it into a String and concatenate "px" to it so the browser knows it's pixel and not em or something like that.