Skip to content

A way to get the size of layout #74

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

Open
Nedok opened this issue Nov 26, 2018 · 4 comments
Open

A way to get the size of layout #74

Nedok opened this issue Nov 26, 2018 · 4 comments

Comments

@Nedok
Copy link

Nedok commented Nov 26, 2018

Currently it's quite hard to get the bounding box of a layout. (Top left and bottom right points.)
This is useful for placing backdrops for dynamic generated GUI (like item lists), as well as for creating scroll enabled GUI.

A solution could be to add a boundingSize() function to layout that return x, y, width, height where x,y points to the absolut top position of the layout.

@cdwfs
Copy link

cdwfs commented Dec 30, 2024

I came here to ask for the same feature, and I see it was requested six years ago. @vrld are you still accepting PRs for this project? I'll probably end up implementing a Layout:boundingBox() method in my fork, and would be happy to pass it along when it's done.

@vrld
Copy link
Owner

vrld commented Dec 30, 2024

I am not maintaining this project anymore. However, there is Layout:size() and you can access the origin with layout._x, layout._y.

@cdwfs
Copy link

cdwfs commented Dec 30, 2024

Thank you for clarifying; I won't bother with the PRs then. I'm grateful that you've provided this project in the first place; overall I've had no trouble integrating it into my game, and feel confident that I can extend and fix things as necessary from here. I've already hacked in some primitive support for modal dialogs.

I did see Layout:size(), but as far as I could tell the _x,_y,_w,_h values tracked by Layout are the bounding box of the most recently returned cell, not of the layout as a whole. I believe that a better solution for immediate layouts would be to add min and max x/y fields to the Layout struct, track the largest & smallest values returned by any of the other methods, and add a new boundingBox() method that returns the accumulated min and max extents. Precomputed layouts could just precompute the overall extents at init time, of course. It's still probably not 100% bulletproof, since users could theoretically ask for cell coordinates with nextRow() and nextCol() and then not use them, but it's probably good enough for most cases.

@vrld
Copy link
Owner

vrld commented Dec 30, 2024

You're right. Truth is I haven't looked at this code in a long time, so I am not sure what the right approach is here. Tracking the extent like you described sounds like a good option.

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

3 participants