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

WBox with horizontalAlignment set to RIGHT will automatically expand when a widget is added. #174

Open
xiaocihua opened this issue Sep 26, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@xiaocihua
Copy link

Describe the bug
The number of pixels expanded to the right is the same as the horizontal size of the insets.

To Reproduce
Add these code to the subclass of LightweightGuiDescription:

var root = new WBox(Axis.HORIZONTAL);
setRootPanel(root);
root.setSize(200, 240);
root.setInsets(Insets.ROOT_PANEL);
root.setHorizontalAlignment(HorizontalAlignment.RIGHT);
root.add(new WButton());
root.validate(this);
System.out.println(root.getWidth());

If horizontalAlignment is LEFT, the width is 200; If it's RIGHT, the width is 207.

Expected behavior
Fix the width of WBox.

Version of the (please complete the following information):
-LibGui 6.3.0
-Fabric api 0.61.0
-Minecraft 1.19.2

Additional context
This problem can be solved by moving the setSize call after validate.

@xiaocihua xiaocihua added the bug Something isn't working label Sep 26, 2022
@xiaocihua
Copy link
Author

xiaocihua commented Sep 26, 2022

This problem can be solved by moving the setSize call after validate.

But there is still a problem when adding a WBox to another Wbox.

var root = new WBox(Axis.HORIZONTAL);
setRootPanel(root);
var box = new WBox(Axis.HORIZONTAL);
box.setInsets(Insets.ROOT_PANEL);
box.setHorizontalAlignment(HorizontalAlignment.RIGHT);
box.add(new WButton());
root.add(box, 200, 40);
root.validate(this);
root.setSize(200, 240);

If horizontalAlignment is LEFT, there is a gap between the button and the left border; If it's RIGHT, no gap between the button and the right border.
I found that change line 90 of WBox.java to dimension = getWidth() - widgetWidth - insets.right(); can solve these problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant