adafruit / Adafruit_CircuitPython_DisplayIO_Layout

A Circuitpython helper library for display element layout using displayio.
MIT License
10 stars 14 forks source link

Suggestions based on current status. #1

Open kattni opened 3 years ago

kattni commented 3 years ago

@FoamyGuy @kmatch98 Thank you so much for writing this! It made my project much simpler. Here are a few thoughts!

For context, I am currently working with this file.

The project I am using it in can be found here.

In terms of add_sub_view:

In the GridLayout constructor:

Feature requests:

These are the things that occurred to me while using the version linked above in a project. I'm sure I'll come up with more as we work through it!

FoamyGuy commented 3 years ago

On the "view" naming and concept: One thing that led to the use of "sub_view" was an attempt to avoid using parent/child relationship terms. But it turned out inconsistent, because it's still used in some places. It may be worthwhile to use them in the "add" function name to make it more clear and consistent.

The specific use of the term "view" came from my background with Android. There is an object View which represents a similar concept to how I've used it here.

I do think we have a need for some higher level object that the rest of our widgets should extend. We could use "view" or a different term ( "Widget" perhaps?) It will have the common properties like x, y, width, height, and any others that make sense. Personally I think it should have a contains() method like the one current on display_button that way all widgets can easily be made clickable if the user wants. The other one that I think should be on this object are the anchor_point and anchored_position concepts that currently exist on the labels in the display_text library.

If we make a higher level object like that and use it for all widgets moving forward it will make a nice unified API between all of the widgets that allows the user to place them how they want. One thing this unified API will allow us to do build up layout classes like grid layout that will make use of that core set of positioning APIs to do the heavy lifting of arranging views into interesting or useful ways.

With regards to child_padding: I need to test it out a bit to be sure but I think the idea is it would add extra space inside the grid cell, but outside the child ( so it would make the cell a little bigger than it needs to be to contain the child). Theoretically this might be one way to help ease the complexities of adding extra things.

But I have in mind another solution to the core problem. I am working on a new kind of label that works a bit differently from the existing ones. The new one is going to allow setting it to an arbitrary size and then it will try to fit the text within that. When this component exists how I am thinking I think it should allow you to have much easier control over spacing within the grid without having to add extra children for spaces.

Agreed about view_grid_size defaulting to 1,1. And max_children defaulting to the grid size multiplied out.

kmatch98 commented 3 years ago

Just a follow up question regarding use of anchor points inside of grid layout.

The use of anchored_position in the display_text library is defined as the pixel position on the screen. However in the case of grid_layout, I think it will need to work different. It seems like we need to have two anchor_points, one for the widget (for example button) and one for the cell. For example if you want a widget centered then set anchor_point_widget = anchor_point_cell = (0.5,0.5).

But this seems a little awkward. Also, could there be situations where you want to place widgets specifically based on pixel dimensions rather than on relative dimensions (of the widget and cell sizes)?

Just wanted to elicit y’all’s thoughts on handling widget placement issues.