News for hackers. Stuff that matters.
Re:SwiftUI for Mac 2024 by meindnoch on Thursday August 22, 2024 @10:03AM (#41320387)
I'd like you to demonstrate your approach with this jsfiddle: https://jsfiddle.net/nbdowrcm/

As you can see, the middle element is not centered.

Re:SwiftUI for Mac 2024 by emadda on Thursday August 22, 2024 @01:13PM (#41322322)
I see.

https://jsfiddle.net/Lah5g3vb/

Changes:

- each col is now 1fr (3 cols, 33% each)

- the child elements align inside the col using `justify-self: start | center | end`

Re:SwiftUI for Mac 2024 by meindnoch on Thursday August 22, 2024 @04:44PM (#41324249)
Not good, because now the elements are limited to 33% width of the container.

See: https://jsfiddle.net/e0un5Lxk/

The middle content is unnecessarily wrapped into two lines, even though there's plenty of space available.

Re:SwiftUI for Mac 2024 by emadda on Thursday August 22, 2024 @06:27PM (#41324836)
You can also use `minmax(min-content, max-content)` for the center col: (https://jsfiddle.net/y193p2b6/).

But this does not keep the center col exactly centered, but it does allow the content to take the free white space and then wrap when needed.

In your original post with Swift, what happens?

I am not familiar with auto layout so I do not know the exact behaviour vs CSS. Do you have a few screen shots of how it would handle different sized content?

Re:SwiftUI for Mac 2024 by meindnoch on Thursday August 22, 2024 @07:46PM (#41325203)
But now you just added `whitespace: no-wrap` to the middle element, with `overflow: visible`, to force it into a single line. That's hardly a generic solution, because it makes assumptions about the contained items... i.e. applying `whitespace: no-wrap` and `overflow: visible` will typically break the appearance of things.

Regarding AutoLayout: the six constraints from my original comment, don't say anything about the relationship between the left/middle/right items, so they will simply overlap if there isn't enough space. This can be remedied by adding two extra constraints:

1. left.right < middle.left

2. middle.right < right.left

It's just a bunch of equations. No weird tricks, no special cases, no hacks. You describe what you want with equations, and the solver spits out the solution.

Re:SwiftUI for Mac 2024 by emadda on Thursday August 22, 2024 @08:00PM (#41325254)
Yeh, I edited my reply, I realised what you meant afterwards.

Auto layout does sound neat.

Re:SwiftUI for Mac 2024 by emadda on Friday August 23, 2024 @08:31AM (#41328440)
Do you have an email? I am thinking of doing a blog post comparing css/auto layout, and would like your input?
Re:SwiftUI for Mac 2024 by meindnoch on Sunday August 25, 2024 @02:59AM (#41345069)