picotui icon indicating copy to clipboard operation
picotui copied to clipboard

Geometry management questions

Open peterjschroeder opened this issue 6 years ago • 4 comments

When assigning coordinates to widgets, picotui does not consider that some consoles will be different sizes. So when the application is executed on a different size terminal than it was written for, the widgets may be off-screen, wrap, or there may be extra padding.

Here is my current idea on how to fix this.

Define some functions like this

def ax(x):
    return int(x / 191 * Screen.screen_size()[0])
          
def ay(y):
    return int(y / 52 * Screen.screen_size()[1])

191x52 is the console size on my main desktop. By wrapping each coordinate with these functions it should adjust the placement of the widgets depending on the screen size.

Something like this would be beneficial in the library.

I am thinking it could work like this.

Create a variable in Screen which hold a virtual screen, vscreen_size? The user than sets vscreen_size when writing their code and uses those coordinates to place widgets.

Now in the widgets, when x, y, height, weight, etc. is set, it wraps the given coordinates in these new functions (could probably be a single function, as a tuple?) in each widget.

This would remove the need for constant dividing in a user's application to place the widgets in the same proportional location when screen size is different than what is being developed on.

peterjschroeder avatar Dec 29 '17 21:12 peterjschroeder

When assigning coordinates to widgets, picotui does not consider that some consoles will be different sizes.

Of course it considers that, in a very specific and obvious way, from the README:

it lacks geometry managers, so calculating coordinates is up to you

pfalcon avatar Dec 29 '17 21:12 pfalcon

Yes, the README considers that, but that actual code does not. Is this something you would accept if I can get it working?

peterjschroeder avatar Dec 29 '17 21:12 peterjschroeder

README explicitly states that it's outside of picotui's scope. Geometry management can be implemented on top of picotui using separate libraries. Feel free to keep this issue open and discuss the matter with other interested picotui users. (I personally won't be interested in it until I find a usecase for it. In the meantime, there're much more mundane issues to resolve like https://github.com/pfalcon/picotui/issues/13 or https://github.com/pfalcon/picotui/issues/23).

pfalcon avatar Dec 29 '17 21:12 pfalcon

The functions above work almost perfectly for this. Some additional math is required when text and frames are involved tho. When using ax for a widget width, it would be something like ax(30)-2. Same goes if you have text on the side of the widget, but the minus would be the length of the label. The way I got it to work, was to set the dialog to 80x24. Than I set all the widget coordinates within that range and wrapped them in these new functions. Now all the widgets will expand to their right positions on different size screens and when resizing. The only thing it doesn't handle is if the screen goes below 80x24. It will have overlaps.

peterjschroeder avatar Dec 31 '17 02:12 peterjschroeder