Skip to content
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

Strange layout behavior when size not explicitly set #102

Closed
arifu-dev opened this issue Oct 27, 2024 · 9 comments
Closed

Strange layout behavior when size not explicitly set #102

arifu-dev opened this issue Oct 27, 2024 · 9 comments
Assignees
Labels

Comments

@arifu-dev
Copy link

I'm trying to understand if this is intended behavior with layout, so here's the code:

    <draw:Canvas VerticalOptions="Fill" HorizontalOptions="Fill" WidthRequest="300" HeightRequest="300"> <draw:SkiaLayout Type="Column"  HorizontalOptions="Center" Margin="40" Spacing="25" BackgroundColor="Blue">
            <draw:SkiaLabel Text="Test" HorizontalOptions="Center" FontSize="28"/>
            <draw:SkiaShape VerticalOptions="Center" HorizontalOptions="Center" WidthRequest="100" HeightRequest="100" Type="Circle" BackgroundColor="Red"/>
        </draw:SkiaLayout>
    </draw:Canvas>

this results in the following:
image

The SkiaLayout (blue) seems to size itself correctly, but the children within are positioned out of bounds
However once I set the WidthRequest=100 on the layout it looks like this:

image

The horizontal positioning is now correct and the blue area is now 162px in size and if I set HeightRequest=162

image

It all fits correctly.
Is this intentional? Because it seems like the layout sizes itself correctly to fit the children, but does not take it's own size into account when positioning them.

@taublast taublast self-assigned this Oct 27, 2024
@taublast
Copy link
Owner

taublast commented Oct 27, 2024

Not at all. This all looks bugged as hell if you ask me. Just a huge thanks for bringing this out, on it.

Looks like it's centering along the whole canvas width instead of the parent layout width. And this wasn't showing in my apps where I had mostly parent layout HorizontalOptions = "Fill"..

@arifu-dev
Copy link
Author

Looks more like it double centers, once against the canvas (green) and then adds the position offset from centering within the layout (blue):

image

@taublast
Copy link
Owner

Yep same as here, but i didn't got the idea initially #94

Bugs inside AdaptCachedLayout, a hard one.

@arifu-dev
Copy link
Author

Upon a second look today I realized that it's not actually doubling anything, rather it thinks that it can occupy all the remaining width and height of the canvas from the layout's position, instead of the measured layout:
image

I suspect that when measuring the children the parent passes width/height request rather than the measured size and since I didn't set anything it thinks it has all the available space. After a quick glance at the code I'd guess it's probably the values passed to PostArrange that are the issue rather than AdaptCachedLayout, but I'll test it out when I have the time unless you're able to figure something out first.

@taublast
Copy link
Owner

Thanks so much! I have found the reason and locations where the bug is happening. Would say it's a design issue. I'm currently thinking how to overcome this without reworking totally the layout system haha..

@arifu-dev
Copy link
Author

So just a quick observation, maybe it can help you come up with a solution:
In the SetMeasured function if you lock in the WidthRequest and HeightRequest with the measured size like so:

if (WidthRequest == -1)
    WidthRequest = Width;
if (HeightRequest == -1)
    HeightRequest = Height;

MeasuredSize = ScaledSize.FromPixels(width, height, widthCut, heightCut, scale);

Then everything actually works correctly (at least in the example that was causing problems).
Perhaps a solution could be introducing variables MeasuredWidth and MeasuredHeight, replace the current usage of WidthRequest and HeightRequest with the new variables and simply invalidate them when either the request variables change or when the layout changes.

@taublast
Copy link
Owner

Yeah that a quick cheat that works for this specific case and breaks other cases unfortunately :))
But this idea helps moving forward indeed, thanks so much for this.

@taublast
Copy link
Owner

Got a fix ready, now need to check other types of layout other that column/row and ill push to repo and nuget :)

@taublast
Copy link
Owner

Must be resolved with #105

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants