kivy grid layout change column/row sizes - kivy

I have a grid layout with 2 columns, i would like to do something like:
for a grid layout of size x, y:
column 1 has width = 0.8 * x,
column 2 has width = 0.2 * x.
all rows should be the same, i still want my grid layout to be sized dynamically so i don't want to explicitly set dimensions.
I have tried setting size_hint and width for individual buttons in the grid but that basically breaks the grid layout.
Is there an easy way to do this for all elements in a column(or row) at once in a kv file?

Related

Custom UICollection view layout

I'm trying to configure a collection view to have the following custom layout shown in the attached image:
. Essentially, I want to be able to configure my collection view so it appears to be based off rows instead of columns. For example:
Row 1: 3 equally sized squares, each 1/3 the width of the screen
Row 2: 1 square that's 2/3 the width of the screen, and then 2 squares stacked on
top of each other that are each 1/3 the width of the screen.
Row 3: 1 rectangle that fills the width of the screen
Row 4: 2 equally sized squares, each 1/2 the width of the screen
I've gone through multiple UICollectionViewLayout and UICollectionViewDelegateFlowLayout tutorials, but have been unable to find the information I need.
You need to implement a custom UICollectionViewLayout.
Precompute the location of all of the squares in your repeat in prepareLayout
Return the height of your content by using the (repeat height) * (number of items in collection) / (number of items in repeat) + the height at the remainder in collectionViewContentSize (this means you should cache the content height for each item in step 1, but the height is not the height of that square (its the height of the tallest element in that row)
In layoutAttributesForElementsInRect you need to figure out what repeat row your rect starts in and what row of the repeat it ends in. You then return all of the cached layout attributes for those rows from step 1, but you have to add back a y value equal to (repeat count) / (first item index) * (repeat height).
basically its a bunch of math but when you divide it into repeating sections, the problem becomes which repeat am I in (divide) and what element within that repeat do I need (modulus), and it's much easier to solve.
I did something similar to this but with multiple repeats that could be arranged in different orders and it took a few hours to get it working without any bugs. Its a lot of math and very tedious.

iOS Charts: reduce height of grids in charts

Hello, I want to reduce height of grids in chart, how can I?
I am using iOS-Charts(Daniel Gindi).
What you want to adjust the barSpacing (Charts 2.*) or barWidth (Charts 3.0), to change the size of the bar relative to the size of the grid strip.
The intervals of the grid are calculated dynamically, and may change when you zoom in/out, but you can constraint them also with granularity. This will affect the labels intervals too.

Custom width of Vaadin GridLayout

I'm working with a 2x2 GridLayout in Vaadin.
gridLayout = new GridLayout(2, 2);
gridLayout.setWidth(100, Unit.PERCENTAGE);
gridLayout.setMargin(true);
gridLayout.setSpacing(true);
The cell in the upper-left corner contains a simple label aligned to the right. Upper-right cell contains a textfield aligned to the left. The second row simply contains a label below the textfield.
gridLayout.addComponent(captionLabel, 0, 0);
gridLayout.addComponent(inputField, 1, 0);
gridLayout.setComponentAlignment(captionLabel, Alignment.MIDDLE_RIGHT);
gridLayout.setComponentAlignment(inputField, Alignment.MIDDLE_LEFT);
Now I want to have both columns within the grid to have size set to 50% to have the whole layout aligned in the middle of my page - now it is slightly shifted to the left side and I can not figure out why...
Vaadin's wiki-page shows a related article, but I can not figure out how to work with it. Seems to be deprecated, because I can not access #getColumn(); - method?! https://vaadin.com/wiki/-/wiki/10674/Configuring+Grid+column+widths
For further info: The GridLayout is added as a separate component to a VerticalLayout.
You can influence the column width's with the grid.setColumnExpandRatio(1, 1); method.
If you wish to have both use 50% of the total width, just set the expand ration to the same value on both columns.
Please also note this:
A layout that contains components with percentual size must have a defined size!
If a layout has undefined size and a contained component has, say, 100% size, the component would fill the space given by the layout, while the layout would shrink to fit the space taken by the component, which is a paradox. This requirement holds for height and width separately.
Book of Vaadin
Solved it by adding a HorizontalLayout-wrapper for the left column containing the label. The right colum contains a VerticalLayout with all other components.
Label captionLabel = new Label(localized);
captionLabel.setSizeUndefined();
HorizontalLayout wrapper = new HorizontalLayout();
wrapper.setSizeFull();
wrapper.addComponent(captionLabel);
wrapper.setComponentAlignment(captionLabel, Alignment.TOP_RIGHT);
[...]
gridLayout.addComponent(wrapper, 0, 0);
gridLayout.addComponent(inputLayout, 1, 0);
gridLayout.setColumnExpandRatio(0, (float)0.5);
gridLayout.setColumnExpandRatio(1, (float)0.5);

Vaadin Table columns autosize/autoscale without horizontal scrollbar

I have a vaadin table, with say 5 columns.
In the last column (right-most) we have the edit/delete buttons which always take up the same amount of width.
When I set the width of the last column to a specific width, and all other columns to a specific setColumnExpandRation(10); then everything is ok, with the exception that the normal columns are not autoscaled.
When I the the last column to a specific width, and all other columns to autoscale, (setColumnWidht(-1)), then the normal columns are sized depending the content, but the whole table width is too large and shows a horizontal scrollbar.
Example of such a case in the picture below
And the java code:
Table tb= new Table();
tb.setWidth(100, Unit.PERCENTAGE);
tb.setHeight(100, Unit.PERCENTAGE);
layout.addComponent(tb);
BeanItemContainer<Person> pList =
new BeanItemContainer<>(Person.class);
for (int i=0; i < 20; i++)
{
Person p1= new Person("******", "++++++++++", "--++--++--++--++--++--++", "????", "3333 "+i, new Date());
pList.addBean(p1);
}
tb.setContainerDataSource(pList);
tb.setColumnWidth("zip", 20);
tb.setColumnExpandRatio("firstName", 1);
Is there a way to have the last column with a fixed width, but still have the other columns auto sized, to have widths depending the content?
The solution is to set table to be 100% width.
Then to set last column to have fixed widht.
Set the only one of the other columns to have expand ratio 1, to force other columns to get proper space.
Container which contains table must have 100% width.
If you get scrollbars then you must wrap text inside table.

Determine UILabel height for centering when using adjustFontSizeToFitWidth

I have the following cell design where the numeric label shrinks and the "Overall" label is directly underneath.
I have properly set the adjustFontSizeToFitWidth and minimumFontSize properties. The font is resizing correctly. However, anchoring the numeric label to the bottom is challenging. Particularly when the font shrinks the gap between the two labels widens and does not appear vertically centered.
I have tried sizeToFit, sizeThatFits, and using the font's pointSize. All unsuccessfully.
I am aware of sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode:, but don't understand why I would need it in combination with adjustFontSizeToFitWidth.
Ah, so you want to position the UILabels in the middle of the container view (both horizontally and vertically)?
I have rephrased my answer so it will make more sense to future readers.
My code is assuming that you have the 3 IBOutlets set up:
UIView *containerView; //Your nice view containing the two textfields.
UILabel *points; //The label containing the number.
UILabel *overall; //The textfield containing the text 'overall'.
You could simply set the frame of the labels after assigning the text and calling the sizeToFit.
This first line positions the UILabel points, the only change being that the y coordinate is half of containerView subtract half of the height of itself.
points.frame = CGRectMake(points.frame.origin.x, (containerView.frame.size.height / 2) - (points.frame.size.height / 2), points.frame.size.width, points.frame.size.height);
To position the overall accordingly - say there is a distance of say 6 between the number and overall labels:
int space = 6;
overall.frame = CGRectMake(overall.frame.origin.x, points.frame.origin.y + points.frame.size.height + space, overall.frame.size.width, overall.frame.size.height);
Having read your comments, I think you are after this solution. If you want both UILabels to appear in the middle; subtract (overall.frame.size.height / 2) + (space / 2) from the y value of points like so (with the code of number 2 beneath it):
int space = 6;
points.frame = CGRectMake(points.frame.origin.x, ((containerView.frame.size.height / 2) - (points.frame.size.height / 2)) - ((overall.frame.size.height / 2) + (space / 2)), points.frame.size.width, points.frame.size.height);
overall.frame = CGRectMake(overall.frame.origin.x, points.frame.origin.y + points.frame.size.height + space, overall.frame.size.width, overall.frame.size.height);
The final point will produce an output like this image. As you can see the blue line is half of the whole image, and intersects the black rectangle (which is snuggly around the two labels) at its middle point. I hope this is what you were after.
Instead of using two labels, use CATextLayer instead. You will be easily able to make one part BOLD and the other normal. plus position and adjusting size for One layer will be easy relative to placing two labels. shadow setting, line break mode, fonts you will be able to adjust everything beautifully :)

Resources