ab5tract / Terminal-Print

Terminal::Print is a pure Raku layer for printing to terminal screens
Other
25 stars 18 forks source link

Positional constructors for widgets: above, below, left-of, right-of #77

Closed jjatria closed 4 years ago

jjatria commented 4 years ago

Do you think something like this would be useful?

I'm thinking maybe we could use a set of constructors for widget objects similar to the new-from-grid constructor, but instead of them taking a grid they would take an already existing widget. These would then set default values for the new widget's x and y attributes (they will still require the user to specify a width and height).

The methods I'm thinking of are

The user is free to pass in values for x and y, but these will not be interpreted as starting from the parent's origin, as they would be normally, but according to the following pattern:

Note that in those patterns, the meaning of the x value in left-of and the y value in above are flipped, so that they make more sense in context:

.left-of( $ref, x => 5, ... ); # "5 cells to the left of $ref"

By default, widgets would be positioned like the below diagram (added because it just looks too pretty, and was generated with these changes):

                ╔═════════════════╗
                ║                 ║
                ║     ABOVE       ║
                ║                 ║
                ╚═════════════════╝
       ╔═══════╗╔═════════════════╗╔═══════╗
       ║       ║║                 ║║       ║
       ║       ║║                 ║║       ║
       ║       ║║                 ║║       ║
       ║ LEFT  ║║     CENTER      ║║ RIGHT ║
       ║       ║║                 ║║       ║
       ║       ║║                 ║║       ║
       ║       ║║                 ║║       ║
       ╚═══════╝╚═════════════════╝╚═══════╝
                ╔═════════════════╗
                ║                 ║
                ║     BELOW       ║
                ║                 ║
                ╚═════════════════╝

I don't need these to exist directly in Terminal::Print::Widget. I tried to add these in a subclass, but ran into problems because I couldn't get them to set defaults for x and y in time (this might be more of a result of my own limited understanding of object construction).

jjatria commented 4 years ago

Actually, as long as these are constructors, there's no reason for these not to exist on my subclass, so I'm happy to close this.