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
497 stars 15 forks source link

API suggestion: vbox and hbox #12

Closed rubyFeedback closed 2 years ago

rubyFeedback commented 2 years ago

Hey there Andy,

Right now there is:

vertical_box {
}

Would it be possible/useful to add "vbox" as top-level alias to vertical_box as well and "hbox" for horizontal_box?

I am kind of used to use shortcuts. If you think this is not good for glimmer-dsl-libui by default, would it be possible to show on the main README how to do such an alias action? Do I have to alias under a specific Glimmer submodule? (Very noobie-ish question ...)

AndyObtiva commented 2 years ago

This can be addressed in one of two ways:

  1. Control Keyword Aliases
  2. Method-Based Custom Keywords

To configure a control keyword alias, there is already a mechanism in place. For the time being, simply add the following code right after the require 'glimmer-dsl-libui' statement:

Glimmer::LibUI::ControlProxy::KEYWORD_ALIASES['vertical_box'] = 'vbox'
Glimmer::LibUI::ControlProxy::KEYWORD_ALIASES['horizontal_box'] = 'hbox'

Otherwise, you could always just define any keyword you want with method-based custom keywords.

For example:

# ensure Glimmer is included

def vbox(*args, &block)
  vertical_box(*args, &block)
end

def hbox(*args, &block)
  horizontal_box(*args, &block)
end

As for your last question, I intentionally did not add hbox and vbox as built-in (default) aliases because I did not want to encourage usage of cryptic keywords when it is not that hard to type in a few more characters to enter the full keyword. The goal is to keep Glimmer DSL for LibUI codebases understandable and approachable by brand new software engineers without wondering what hbox and vbox are when in fact they are not defined as such in the official LibUI headers and documentation.

That said, if I find out in the future that my concerns are overblown, perhaps I'll add them as default aliases to Glimmer DSL for LibUI.

Thank you for your request.