-
Notifications
You must be signed in to change notification settings - Fork 86
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
Add UIForm Element #494
Add UIForm Element #494
Conversation
Auto resizing containers added (Documentation on website is remaining)
The main question I had when looking over this is - are there circumstances where you would want a container that resizes like this, as opposed to one that resizes it's scrollable area (e.g. the way an explorer or one where you have decided the size ahead of time to fit the stuff you are going to put inside of it? Most UIs I see these days adopt a 'squish and vertical scroll' for oversized content - I suspect mainly because of the dominance of phones and tablets in browsing content. I suspect there are - but listing off some ideas as to what this would be used for in a UI would probably help clarify the design and help create an example that uses this type of container for the examples repository: |
I'll admit that I didn't have too much in mind except it would be easy to replace the |
I think the usage possibility would be when you'd require a container to extend to contained elements but not to the point where you'd need scrollbars, by restricting the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I've finally had a chance to look over this. Apologies for the delay.
I noticed while testing this that something in the rendering machinery is not ready for:
test_resizing_container = UIAutoResizingContainer(pygame.Rect(0, 0, 50, 50))
hello_button = UIButton((60, 0), 'Hello', container=test_resizing_container)
It seems to get negative dimensions passed down to it and is unhappy, so that is something to look into further.
The on_content_moved_or_resized()
function I suggested for the UIContainer may also be useful when trying to use this in the UIScrollingContainer
as we will need to trigger the code that is currently in the UIScrollingContainer
's set_scrollable_area_dimensions()
function somehow, perhaps we can have it set a flag variable 'this container has resizedthat the
UIScrollingContainer` can check.
Anyway, thanks for your hard work on this. I think it is getting somewhere useful 🎉
Co-authored-by: Dan Lawrence <[email protected]>
Hi,
These elements aren't fully completed, and I'm sure there are bugs but you'll be able to see what my approach to those elements is and guide me if necessary. You may even finish it if I am too inactive. It will atleast get the process of adding those elements going |
While renaming the Secondly, the |
The container uses relative rects for min and max rects, which should fix some bugs.
I made some changes using your suggestions. However, I can just not get the container to work properly. It seems to be having some problems with buttons and their texts, and especially with dynamic width and heights. |
I think I found the root of the problem. So what happens when we create a new button with dynamic width and height is:
So, to fix this problem, we'll have to stop the image from resizing based on if it's outside the container. Just update the clipping rect instead and as soon as the element moves update the clipping rect, and only blit the the image actually contained within the container. |
Fixed them for real this time
These containers automatically resize their scrollable containers when new elements are added
Allows the users to choose which scrollbars can be created
I finally was able to fix the problem by eleminating the if condition in |
Looks like a crop of the unit tests are failing now I've enabled them to run. |
Fixed a bug where the margins would not be set when calling UIElement._update_absolute_rect_position_from_anchors
I have tried fixing some of the failing tests with the next commit, could you try re-running the workflow? it doesn't allow me to run it myself. Also, when I run the tests in my IDE, many of them fail because the manager can't find the specified files, or the colours of the gradient don't match, etc. I don't think I have changed any code which would interfere with the colours or location of files. There is a test which specifically tests for the if condition I had removed, where in the expected image was supposed to be the I will also add the appropriate tests in a few days |
I have kicked off the tests. To run them locally you should just be able to run |
The tests are failing currently, because of a singular line which updates the dimensions of the
|
It now no longer uses set_scrollable_area_dimensions() to rely on creating scrollbars as the container automatically resizes back if there are no elements inside
Also, should we raise a warnings for certain methods which UIForm inherits from UIScrollingContainer, but aren't intended to be used with UIForm? for example, set_scrollable_area_dimensions |
Fixed a bug where the submit button would expect items in the questionnaire
A start to creating tests for this complex element
As you can see from the commit above, I started adding the tests to UIForm. You can see a list of todo comments which lists what tests are left to add/complete. Let me know if any tests are needed apart from that |
Fixed a bug where passing an keyword argument without the keyword would not raise an error
The code cov doesn't seem to be running after a whole day Edit: Now it does after the new commit, code cov seems to be slightly buggy |
Some tests seem to be failing when we put a UIForm inside a UIForm, but I suspect it has something to do with UIScrollingContainers instead. I'll remove the UIForms within UIForms, but this should be something to look into. |
Might be late to the party on replying to this. I guess the spirit of the original auto scrolling container was that it would grow & shrink based on the contents of the auto resizing container - meanwhile the I think using set_scrolling_dimensions should probably disable the auto growing and shrinking aspect of the auto resizing container - until it is explicitly turned back on (which should also be an option). But we should also update the documentation of the function to say that.
Various ways to handle this: a) make UIForm have a "has a" relationship to the UIScrolling container rather than an "is a" relationship.
Yeah, it sometimes seems to skip an update to a pull request, I've not figured out exactly why, but it is better than nothing! |
I agree with that. We can just add a getter and setter for the auto growing option. Alternatively, we could also add the option to pass in -1, -1 in set_scrollable_dimensions to turn it on.
I think I agree with this the least because it doesn't feel right to have to use 2 UIElements to do the work of 1. Also, it makes sense to me that UIForm is a scrolling container, rather than having one. We'd also have to override some functions to call the methods of the contained scrolling container anyway, and that is just extra work for no reward. Infact, it did raise confusion for me when UISelectionList was just inheriting from UIElement instead of UIContainer or some other class because it clearly does contain other elements. Also, it has a list_and_scroll_bar_container even though I think it should be the list_and_scroll_bar_container. Might be something to look at in the future, perhaps.
I feel like if someone was to call the function, it's their responsibility for what the function does. I think that would be the expected behaviour as well, instead of just blocking them from the usage of that method. The only such case where we should interfere is when calling the function breaks something about the element or crashing the program. If it is something untested, or something that we don't expect the user to use, or perhaps use a different method, then we should raise a warning, but still call the base method. If there is just one semi-reasonable way of doing something, even if we don't know why that thing would be needed, we don't need to raise a warning or block the way. We just need to try and make sure that the method does what its name suggests it should do. So in conclusion, I think it should vary between b) and c) (or a mixture of the two) for different methods. |
Also, UIScrollingContainer should be the _root_container. I don't see why we need a root container, because we anyways have to relay the set_position, set_relative_position and set_dimension calls to the root container anyway. Similar points for the UITabContainer not inheriting from UIContainer, IUIContainerLikeInterface or even IContainerLikeInterface and UIPanel, where almost every single method has to relay itself to the panel_container, although it doesn't look as wrong for UIPanel to inherit from IContainerLikeInterface instead of UIContainer or IUIContainerLikeInterface (even though it should inherit from UIContainer) But I do understand UIWindow having a container instead of being a container. It does feel like it has a lot more to it than just being a container, although it could still just have been a UIContainer instead of having a window_root_container. But I don't think it's nearly bad enough to need to change |
I was checking the recursion errors and one of them happens when the size is set to 50 or lesser in the horizontal axis or 5 or lesser in the vertical axis. I don't understand why though, and there are more errors to find which happen when UIForms are placed within UIForms. |
_get_current_values() now uses int and float functions to cast values instead of literal_eval
I think I will not have much time to work on this to complete the remaining tests unfortunately. I hope I have made sufficient enough progress that you can finish the remaining tests as I have highlighted in some TODO comments at the top of the test class. |
I think we will try merging this and see how people get on with it. I don't personally have any use cases for it in my existing games or demos so I'm just adding the test program @GimLala posted to the examples repository, |
Auto resizing containers added (Documentation on website is remaining)
These containers automatically resize when elements are added to them.
I was having some problems running tests, but I had tested them separately in a project I was using them in. More similar elements are coming like
UIAutoScrollingContainer
which uses an auto resizing container as its scrollable container instead of a normalUIContainer
.Check if you like this implementation, or maybe we could even merge
UIContainer
and the newUIAutoResizingContainer
Adding PR split list to first post:
Easy changes
Changes to existing base classes
New stuff
Using the new stuff in existing stuff