AndyObtiva / glimmer-dsl-libui

Glimmer DSL for LibUI - Prerequisite-Free Ruby Desktop Development Cross-Platform Native GUI Library - The Quickest Way From Zero To GUI - If You Liked Shoes, You'll Love Glimmer! - No need to pre-install any prerequisites. Just install the gem and have platform-independent GUI that just works on Mac, Windows, and Linux.
MIT License
474 stars 15 forks source link

API proposal: button with width and height #11

Closed rubyFeedback closed 2 years ago

rubyFeedback commented 2 years ago

Hello Andy,

I am playing around with a new glimmer-dsl-libui variant (I mean an application that uses it, actually).

While working on it and adapting your example, I have a simple button like:

button('Some button') {
    on_clicked {
      call_this_method
    }
  }

It seems as if libui automatically determines the size of a button.

The API documentation you offer says that button() accepts a String.

My question would be:

Would you consider it useful to pass two more optional arguments? E. g. width and height? Perhaps if this is not possible on a button directly, then perhaps it could mean that the button will be automatically part of some horizontal box or something.

Example:

button('Some button', 100, 25) { # or perhaps:  button('Some button', width: 100, height: 25) { to make it more explicit
    on_clicked {
      call_this_method
    }
  }

Rationale: I would kind of like to have some buttons that have a definite width and height, all the same, rather than the default which sort of seems to make the buttons quite big (probably because it takes a lot of space by default in libui or something.

Anyway, if you think it is not a good part of the API please feel to ignore it.

I'll see how far I get with this new GUI I am using - the use case will be to contain functionality that I can use on a default windows installation, e. g. batch install stuff I need and so forth. My secondary use case is to make it as pretty as possible in the long run; right now I am trying to adapt my brain to the glimmer DSL.

AndyObtiva commented 2 years ago

Would you consider it useful to pass two more optional arguments? E. g. width and height? Perhaps if this is not possible on a button directly, then perhaps it could mean that the button will be automatically part of some horizontal box or something.

The alpha C libui API for button does not currently support passing more than the button text:

_UI_EXTERN uiButton *uiNewButton(const char *text);

Furthermore, the alpha C libui API for vertical_box/horizontal_box/form/grid does not permit passing custom sizes (width & height) for controls:

_UI_EXTERN void uiBoxAppend(uiBox *b, uiControl *child, int stretchy);
_UI_EXTERN void uiFormAppend(uiForm *f, const char *label, uiControl *c, int stretchy);
_UI_EXTERN void uiGridAppend(uiGrid *g, uiControl *c, int left, int top, int xspan, int yspan, int hexpand, uiAlign halign, int vexpand, uiAlign valign);

Continue reading for some good news though...

Rationale: I would kind of like to have some buttons that have a definite width and height, all the same, rather than the default which sort of seems to make the buttons quite big (probably because it takes a lot of space by default in libui or something.

Your rationale makes sense to me and the next best thing to address it is to simply build an area-based custom control.

In fact, I just added a new example called Area Based Custom Controls that demonstrates how to build a push_button with any size (width & height) you want on top of the area control in addition to configurable font, background fill (e.g. one color or a gradient), and border stroke (e.g. one color or extra thickness/dashes). Additionally, it demonstrates how to build a custom text_label that can have the same attributes as the aforementioned push_button. (note: push_button must have a different name from button and text_label must have a different name from label to avoid clashing with the standard keywords)

Here are some screenshots to prove it (note the use of the custom text label on top as a header with big font and the push button below with everything customized):

Push Button on Windows

Push Button on Windows - Clicked

Text label on Windows

The new example is included in the just released Version 0.4.20:

https://rubygems.org/gems/glimmer-dsl-libui/versions/0.4.20

I'll see how far I get with this new GUI I am using - the use case will be to contain functionality that I can use on a default windows installation, e. g. batch install stuff I need and so forth. My secondary use case is to make it as pretty as possible in the long run; right now I am trying to adapt my brain to the glimmer DSL.

Again, I agree with your first use-case; the mentioned area-based custom control approach fully addresses it.

About your second use-case, I do not recommend deviating from standard desktop graphical user interfaces in desktop apps in general because conforming to operating system standards improves general usability of apps and decreases software engineering and development time. But, exceptions can be made perhaps in special cases like your case of accessibility for the elderly.

The example does not demonstrate every single customization possible to the push_button and text_label, so if you find yourself looking for further customizations, hit me up with more questions even if I close this issue. We can continue chatting with it closed.

Cheers!