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
left-of
right-of
above
below
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:
left-ofx: cells to the left of the referent origin
y: cells below referent origin
right-ofx: cells to the right of referent origin + width
y: cells below referent orgin
abovex: cells to the right of referent origin
y: cells above referent origin - height
belowx: cells to the right of referent origin
y: cells below referent origin
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):
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).
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'sx
andy
attributes (they will still require the user to specify a width and height).The methods I'm thinking of are
left-of
right-of
above
below
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:
left-of
x
: cells to the left of the referent originy
: cells below referent originright-of
x
: cells to the right of referent origin + widthy
: cells below referent orginabove
x
: cells to the right of referent originy
: cells above referent origin - heightbelow
x
: cells to the right of referent originy
: cells below referent originNote that in those patterns, the meaning of the
x
value inleft-of
and they
value inabove
are flipped, so that they make more sense in context:By default, widgets would be positioned like the below diagram (added because it just looks too pretty, and was generated with these changes):
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
andy
in time (this might be more of a result of my own limited understanding of object construction).