SwiftUI Tell the # of columns assigned in an adaptive LazyVGrid? - swiftui

Is there a way to tell the # of columns that are created in a SwiftUI Adaptive Grid? For example the left view with an iPhone 14 Pro has 4 buttons across, while an iPhone 12 mini on the right fits 3 buttons.
If I can tell the # of items, then I can tell if there are fewer items than can be displayed on a full screen, then create a LazyHStack for the % resulting leftover items which presents the additional items centered. The smaller iPhone with 3 buttons across shows the effect I'm trying to achieve - which I can do if I fix GridItems to 3 columns. I'd like this to be dynamic so, for example, I can tell I have 3 of 4 buttons across & can put them all in the single, centered LazyHStack of my last column.
Thanks for advice!

Related

Product colour swatches connected to colour selection

The way that colour selection works is it's not connected when a customer clicks on a certain selection it won't bring up the product swatch to match the colour they've selected, I'm only allowed 5 templates that they have to manually swipe through with the inability to show all colours past 5 as well. Is there a solution or possibly a way to incorporate a new feature on the big cartel e-commerce platform to allow this?

Resize the super view with respect to the sub view in swift3

How to resize the UIVIEW according to it's subview(Label)?
My Image is here
I have a label inside a UIVIEW. I want the label to take maximum number 5 lines and the label size should be according to the number of lines (it may be 1 or 2 or 3 or 4 or 5) and the view should resize automatically according to the size of label in swift3.
How to make it please help me.
You need to add Equal height constraints from uiview to uilabel and set constraints multiplier from value 1 to 5 as per your requirements.

The scroll viewer lags for a second when there is lot of data in silverlight

I have a Grid and there are 7 columns and 6 rows. And there is listbox added for each row and column combination. Each list box is having arround 5 items (as default is 5, not increase above that). Each listbox item is having complex template. If i bind whole data then it takes 4 to 5 second to load. So to make fast loading, i am binding only that listbox which is visible on screen. so now it loads fast within a second. But when i scroll down, then the another data loads. But the scroll viewer lags for a second. So how can i scroll smothely ?
Any idea ?

iCarousel type linear, breaks UI

When I use iCarousel type linear, and wrap is true. I am getting an UI like below:
The problem, I am facing is at the top the number 998 UI is broken, but I want visible 998 number without increasing iCarousel height. So, how can I achieve this? and one more thing I don't bother about UI might break for number 2, if I want a visible 998 number.
There are two reasons why your carousel item is cut off:
1) Your carousel view is not vertically centered in the window. If you center it, 0 will be dead centre and 998 and 2 will both be cut off, but equally
2) You need to set the item view size to exactly fit your view. You're currently using the default images that come with the example project which are 200x200 pixels in size. Presumably you will eventually replace these with your own views. When you do, make sure the size of those views is an exact division of the height of your window, so for example if your windows is 1024 pixels high, and you want to show 5 views, then they need to be 1024/5 pixels high (204.8 px). Obviously that's not a nice number, but you can make them a bit smaller so that they are a nice round number and then adding some spacing between them using the carousel delegate method.

QGridLayout vs QHBoxLayout & QVBoxLayout

I have recently come back to Qt (tried it for previous projects and opted against it) and am really liking everything about it thus far. I am writing a TV Guide style application that will display Episode Guide Data (EPG) for anywhere from 3-7 days, and this data will be fed in from a Database source.
Right now I am having a hard time determining if I should use a QGridLayout or a combination of QHBoxLayouts (for the episode data) with a single QVBoxLayout on the left side (for the channel name/icons). My main concern with QGridLayout is that I would break it up into “30 minute” blocks, but when programs started at say 3:45, I am not sure it would work correctly. To give a better idea of what I am going for with the GUI, this screenshot can be viewed…
http://www.itvt.com/files/u3/AT&T-u-verse-tv-epg-2009.jpg
Just on a side note, if I want to only display a segment of this (i.e. 3:00AM – 4:30AM) and say 10 channels, which option would it be easier to implement vertical/horizontal scrolling with? Would I need to stick them in a different widget for that behavior?
Use QGridLayout.
Explanations:
With QVBoxLayout and QHBoxLayout, the number of column per rows is not fixed (or the inverse if you use these layout the other way), for example you can have something like:
|----------------------|
|------|------|--------|
|----------|-----------|
If you add an item to a row, the row will relayout without interfering with others, so column are not aligned anymore. It can be really convenient for some GUI, but for what you want I think it's not practical.
Then you have QGridLayout, which is the way to go for your GUI: all columns are aligned. So you can divide the grid in columns of 15 min, and then span widgets on several columns. Example:
0 15 30 45 60 75 90
|----|----|----|----|----|----| 6 x 15 min episodes
|---------|-------------------| 30 min + 1 hour episodes
|-----------------------------| 1h30 episode
|----|---------|---------|----| 2 x 15 min + 2 x 30 min episodes
Alignment is automatic.
Note: with QVBoxLayout and QHBoxLayout, the previous example would have been (without specific code):
0 15 30 45 60 75 90
|----|----|----|----|----|----|
|--------------|--------------|
|-----------------------------|
|------|-------|-------|------|
Notice how all cells in a row have the same size. This can be changed, but requires you to handle cell size manually...
I recommend QGridLayout because it will keep everything aligned easier than if you used a bunch of QBoxLayouts. With QGridLayout, your addWidget and addLayout methods have an optional columnSpan that you can make good use of. For example, you could have each column be 15 minutes, so a 45 minute show would span 3 columns.
You don't typically implement scrolling with QLayouts. I don't recommend it. Instead you can set QGridLayout's rowMinimumHeight and rowMaximumHeight to the same value so that you can ensure each row is the same height, then do the same for columns. Then you can put the layout (and encasing widget) into a QAbstractScrollArea and set the step size of the scroll bars to the row and column heights, so that as you scroll, it steps from channel to channel and time segment to time segment, rather than scrolling continuously.