KSP-KOS / KSLib

The standard library and examples for the Kerboscript language
MIT License
120 stars 40 forks source link

We need lib_gui_box #51

Closed abenkovskii closed 9 years ago

abenkovskii commented 9 years ago

I hate code duplication and we have the same code for printing cool-looking window in lib_number_dialog and in lib_menu

TDW89 commented 9 years ago

probably best done as an addition to lib_term as that does circles and lines already

abenkovskii commented 9 years ago

HOWTO.md:

  1. Try to break things up into smaller files. A person trying to load them onto their installation may be > trying to save space and want to only install those things they need.

What do you think?

TDW89 commented 9 years ago

humm yep fair enough boxes are probably useful more often than the rest of that lib. I was thinking of adding just a small function that used the line drawing already in lib_term but for boxes that are square to the terminal there is probably a bit of overhead with that. (would let you draw boxes at an angle tough.

abenkovskii commented 9 years ago

How I imagine it: function draw_box(top, left, w, h) function draw_wide_box(top, h) What do you think about the second function? Do we need it or only one function is fine?

TDW89 commented 9 years ago

the second one probably not so much but but one that you fed a %width and %height to might be useful. also i was thinking of a style argument so that it could be used to print different boxes (eg for indicating focus of selection) style 0 set to print " " around the edges would be a good way to remove the box without having to clear its contents too.

abenkovskii commented 9 years ago

I'd rather take 3 additional arguments (border_h, border_v, angle) than implementing a limited number of styles.

TDW89 commented 9 years ago

that works too. how would you feel about the args (list(y0,h,x0,w),list(horizontal,vertical,corner) that way it is possible to detect what is has been passed so that draw_box(list(1,5),list("#")) could be used for a full width box where all the borders were #? or is that overcomplicating it?

akrasuski1 commented 9 years ago

Maybe some function from this can be useful: https://github.com/akrasuski1/akrOS/blob/master/lib_window.ks (there are some redundant functions, but you can pick whatever you need)

In particular, draw_any_outline does almost the exact thing you need - only the corner is hardcoded as plus sign, but that's trivial to change.

abenkovskii commented 9 years ago

@TDW89 In python there are keyword arguments exactly for this purpose. I think taking lists of different size is too complicated. We can make wrapper functions instead.

akrasuski1 commented 9 years ago

Yes, I agree with @abenkovskii - wrapper functions seem to be way to go in this case.

abenkovskii commented 9 years ago

I'm going to post a PR adding this soon.