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
Create layout managers #10
Comments
Some thoughts about implementation from some discussion with @stratact
|
TLDR: I think container widgets being layouts would be better. @LazyOxen by widget having a layout, do you mean the container widget has a layout, like java's Swing, or the contained widgets have layout information and the container has no layout information, like Python's Tkinter? I hope the former, because tkinter's way is error prone (how do you handle a container with widgets asking for 2 different layouts? tkinter throws an exception). So, we either have:
or
I prefer (A). Different layout might need different layout information for their children. For exemple, say we have a PackLayout (stacks its children one after the other) and a GridLayout (places its children in the cells of a grid). PackLayout might not need any such information but GridLayout would require a X and Y index to specify a cell (plus optionnal cellspanX and cellspanY for exemple, to tell that a certain cell should stretch across many columns or rows). If going with option (B), you would have to add a child to the container and then also set the layout information on the Layout object for that same child. What if a layout (like GridLayout) absolutely needs that information? In the (B) case, you are not forced to give the information to the Layout object (you could forget to do it). The Layout object could also be given information for a widget that isn't even in the container. Also, what happens if, for a given container, its Layout object is changed? (and if this shouldn't be allowed, then (B) seems pointless and (A) seems like the best choice). I'm not saying it's impossible to get it to work, just that (B) is not the most elegant of the two. Going with (A), we can require the layout information when adding a child, and know for sure, at compile time, that no child widget is without it's required layout information. The downside of (A) seems that it would be less flexible than (B), but what else than a plain Container would need a Layout object anyway? and is there any value to being able to change the Layout object at runtime without changing the Container itself? No and no, at least from my point of view. Also, if it's relevant to know:
As for the case of a Window, it think it should have just one widget, which gets stretched to fill the entirety of the window: if more than one widget is needed, then the window should be given a Container as its sole widget (by the user of OrbTK). |
@simondesloges Thanks for the input! I am working on something like what you have suggested |
This would allow a developer to quickly put together an application without having to calculate positioning and could offload some of the resizing logic.
A widget could default to absolute positioning of child widgets if no layout is specified.
The text was updated successfully, but these errors were encountered: