elkowar / eww

ElKowars wacky widgets
https://elkowar.github.io/eww
MIT License
9.14k stars 379 forks source link

[FEATURE] Ability to pass throug widget arguments #1135

Open Strongleong opened 2 months ago

Strongleong commented 2 months ago

Description of the requested feature

Lets say that I want to have default arguments to box widget. I would to something like this:

(defwidget default_box []
  (box :spacing 15 :space-evenly false
    (children)
  )
)

The problem that if I want to add something to this box, it will not work:

  (centerbox
    (defbox
      ;; ...snip
    )

    (defbox :haling "center"
      ;; ...snip
    )

    (defbox :halign "end"
      ;; ...snip
    )
  )

halign argument in this excample does not apply to box inside of default_box

Proposed configuration syntax

I propose to add [...name] syntax to emphasize that widget accepts variable amount of arguments that can be refereed by name . :...name` syntax for spreading array of arguments into argument list of another component, or probably to variable as key/value JSON list

(defwidget default_box [...args]
  (box :spacing 15 :space-evenly false :...args
    (children)
  )
)

Additional context

P.S. Sorry for bad English :sweat_smile:

fabolous005 commented 2 weeks ago

You can always do something like the following:

(defwidget exmaple_widget [start]
    (box :halign {start == true ? "start" : "end"}
        (children)
    )
)

For an argument with 3 different possibilites you would have to compose a different code with a different datatype probably is a number the best performing.

Strongleong commented 2 weeks ago

For an argument with 3 different possibilites you would have to compose a different code with a different datatype probably is a number the best performing.

Sorry for unclear issue message. This three-way argument is just example. If I want to set another box argument like valign, I need to add yet another argument to my defwidget . And this goes for every addition argument I want to pass through to underline box