-
Notifications
You must be signed in to change notification settings - Fork 83
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
Auto layout containers #252
Comments
Hi. but for the image you can set an image for default buttons in the theme file and also set an image for a specific button using its "object_id" and theming its image in the theme file too. And do you have any other Ideas that can be useful for the Auto container ? |
Hello guys, here is the code of the auto layout container class in the link: and u can use it like this for example: ui_window = pygame_gui.elements.ui_window.UIWindow(
rect=pygame.Rect(0, 0, 400, 400),
window_display_title="Test",
resizable=False,
manager=ui_manager,
object_id="#TEST")
auto_sort_container = AutoSortContainer(default_elements_spacing=4)
auto_sort_container.add_same_raw_spacing(ui_window, 20)
element_width, element_height = 75, 60
pos_x, pos_y, anchors = auto_sort_container.generate_element_pos(ui_window,
element_size=(element_width, element_height))
pygame_gui.elements.UIButton(
relative_rect=pygame.Rect(pos_x, pos_y, element_width, element_height),
anchors=anchors,
text="element",
manager=ui_manager,
container=ui_window
) |
@Karam-Sabbagh could you repost the original code - I can't find it |
@wadsworj Hello. yeah so the code have been quite edited and it's cleaner now(even if it needs more cleaning I think), and now using it works in a different way. Auto_layout_positioning_generator.txt and yeah here is a little example on how to use it: window_size = 300, 260
window = pygame_gui.elements.ui_window.UIWindow(pygame.Rect(200, 200, window_size[0], window_size[1]),
window_display_title="Set dynamic rect properties",
resizable=False, manager=self.ui_manager,
object_id="#Set_dynamic_rect_properties_window")
auto_positioning_generator = Auto_layout_positioning_generator.AutoLayoutPositioningGenerator(container=window,
default_elements_spacing=7)
button_1 = pygame_gui.elements.UIButton(relative_rect=pygame.Rect((0, 0, 75, 30)), text="Button_1",
manager=self.ui_manager, container=window, object_id="#Button_1")
auto_positioning_generator.generate_and_set_element_pos(element=button_1)
auto_positioning_generator.add_vertical_spacing(vertical_spacing=10)
button_2 = pygame_gui.elements.UIButton(relative_rect=pygame.Rect((0, 0, 75, 30)), text="Button_2",
manager=self.ui_manager, container=window, object_id="#Button_2")
auto_positioning_generator.generate_and_set_element_pos(element=button_2) I hope that this is helpful, tell me if you are having some issues with it. |
I hope UIelement has a component based design pattern. This way, multiple functions can be implemented simultaneously on a UIElement. For example, the click effect component, with this component, the elements can handle clicks, so that any UI element can generate a click event. Or it could be a container component, adding this component allows any UI element to have its own child components. |
So is it possible to decide the position of elements when |
I would like to see a container that automatically laid out gui elements without having to do manual positioning which can waist time some times.
So If I have some thing like this as shown in the image below I would like it to be done automatically:
and it would be a bigger problem and more waist of time if the container even have more buttons(which can happen alot I made that image just fast for an example) ,
and ofc the gui element doesn't have to be a button it can be anything and also with different sizes not the same as the image and that would be even harder for the user.
So I think an Auto container is so good and useful for this cases and lets the user focus more on the thing he really wanna develop.
And I also think that the Auto container is so possible without even having to let the user do anything manually,
And if the user like to set a default spacing between the gui elements in the Auto container this is possible by making like a parameter in the make_Auto_container function that he is free to set or not as if not the spacing will be set to default,
And if the user want a specific element to be in a new line alone there it's also possible to make a function like "add_line_spacing(30 pixels)",
And also if the user want a specific item to be a bit far away it is also possible to make a function like
"add_spacing(10 pixles)",
And ofc the names can be not the same this is just like an idea,
So making this functions will make the user to not be limited with that either !
So it can be easier and at the same time doesn't limit the user alot with the style.
So what do you think about this idea?
The text was updated successfully, but these errors were encountered: