-
-
Notifications
You must be signed in to change notification settings - Fork 685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix divider strech #1540
Fix divider strech #1540
Conversation
Signed-off-by: Bruno Rino <bruno.rino@gmail.com>
Signed-off-by: Bruno Rino <bruno.rino@gmail.com>
Signed-off-by: Bruno Rino <bruno.rino@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't argue that this has the desired effect for the specific case you've provided, but I'm not comfortable with it as a general solution. It may look like an innocuous change, but it's fairly radical - you're adding a specific interpretation of "intrinsic height = 0" (and similarly for width). Furthermore, you're using this interpretation after the pass computing the height of the widget has (theoretically) been completed; the logic you're altering should only be setting the position of the child inside the parent, not changing the height of widgets.
I think your comments about using all available width aren't entirely accurate - in this case, the calculation of available width should be identical, because the "at_least" clause will result in available width being computed as the full available width (due to the max
on L147).
I'm also unclear why we need to make a special case of "0" as a height (which is at the very least, misleading); why can't we use at_least()
as a marker? At least at the declaration level, it would seem to make more sense.
I'm not fundamentally opposed to making this change if it is necessary, but we need to be careful about making such changes. If we do make this change, it's something that will also need a change in the algorithmic description in the docs, as well as a new collection of tests exercising this specific layout situation.
Signed-off-by: Bruno Rino <bruno.rino@gmail.com>
Codecov Report
|
The special case of "0" was derived from my interpretation of the code. I was actually hoping for "oh yeah, you're right, I had meant to do that". But it was also partly because of my misunderstanding of So here is my updated solution. Gone is the special case of "0". Instead the check is: But the location of the code has to be there. The error happens when the widgets container does not have a predetermined width or height. That is calculated in step 3. Only then can the children be stretched. |
I'm not convinced the example you've provided is a bug. You're correct that the first box doesn't set width or flex (L17). That means it defaults to flex=0. The third box has a fixed width; it's children expand to fill the available space in the parent. The second box is the only flexible element in the row, so it absorbs all available space in the row. The first box has flex=0, so it gets a flex allocation of 0, and is thus assigned the minimum intrinsic width - the width of the label. If you add flex=1 to the first box, it will have a non-zero flex allocation, and so the width of the first box will the maximum of the minimum intrinsic width and the flex allocation, so the TextInput will expand to the available space in the box. Regarding the updated check - |
Fixes #1529
Only dividers inside boxes with predefined size (like the the top-level box in a window) would stretch their child Dividers along their direction. In the other cases, a single 1x1 pixel (on macOS) would be drawn.
While I can't claim to fully grasp the pack layout code, a debug statement in
_layout_node
mentions that ifnode.width
andnode.intrinsic.width
are falsy, the widget should "USE ALL AVAILABLE WIDTH" (toga/src/core/toga/style/pack.py
Line 153 in b32e8bd
But for this to be true in boxes without a predefined size, some code was missing. Those are my edits to the layout algorithm.
It also requires changing the widget implementation, to set
intrinsic.width
andintrinsic.height
to 0 instead ofat_least(...)
I only have a macOS, hence I only edited the cocoa widget. I did update the example code, so the other platforms implementation should be updated as well before merging these changes.
PR Checklist: