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

Infinite loop because constraintlayout use int and maui use double #23

Closed
xtuzy opened this issue Apr 21, 2023 · 2 comments
Closed

Infinite loop because constraintlayout use int and maui use double #23

xtuzy opened this issue Apr 21, 2023 · 2 comments

Comments

@xtuzy
Copy link
Owner

xtuzy commented Apr 21, 2023

Problem:
i update maui example in f2d46a3, a grid split to two part, one part is a constraintlayout, but constraintlayout can't deal with it, because if grid split give a not int value, constraintlayout alway return int, that let layout will infinite loop because result have bias.

For solve this problem, i would try use px as unit when measure and layout in constraintlayout, but set property and fluentlayoytconstraintset use dp, return size to maui a dp value, that will let it not always is int.

@xtuzy
Copy link
Owner Author

xtuzy commented Apr 21, 2023

初步在usepx分支修改后,依然无限循环。使用","时, grid传递给child的大小总是grid的大小,这导致constraintlayout也用这个大小去布局,我觉得传下来的高度应该是grid的一半,看maui的issue,造成无限循环它也可能不是我的问题,见
dotnet/maui#14694
此处是说单位转换有偏差,需要处理,
dotnet/maui#14520 此处是说新版本造成grid不对,

我需要把例子调回net6再运行下看是否是版本的问题

@xtuzy
Copy link
Owner Author

xtuzy commented Apr 22, 2023

重新运行主分支的例子, 我看到Log中285.5 变成了285:

MeasureLayout View=ConstraintLayout Id=-1132297589 availableSize={Width=484 Height=285.5} Spec=(MeasureSpec: EXACTLY 484 x MeasureSpec: EXACTLY 285)

这是因为:

int availableWidth = (int)availableSize.Width;

修改成:

int availableWidth = (int)(availableSize.Width + 0.5);
int availableHeight = (int)(availableSize.Height + 0.5);

Log中285.5 变成了286:

MeasureLayout View=ConstraintLayout Id=-1132297589 availableSize={Width=484 Height=285.5} Spec=(MeasureSpec: EXACTLY 484 x MeasureSpec: EXACTLY 286)

之后运行成功.

fix in 5afb519 , 我还增加了点对其它doube to int的修改, 暂时不知道影响, 其它测试的外观都还正常
test in a816e75 , FitGridTest的结果可以看到最终分配的大小还是按照Grid的设置分的, 所以对于ConstraintLayout来说, 内部会有1dp的偏差, 如果使用px, 偏差应该减小到1px, 但当前未打算修改

  • convert dp and px

@xtuzy xtuzy closed this as completed Apr 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant