jrubyfx icon indicating copy to clipboard operation
jrubyfx copied to clipboard

HBox "add" should accept an array

Open vpereira opened this issue 11 years ago • 2 comments

Hi, I have the following snippet:

require 'jrubyfx'

class AddSubtract < JRubyFX::Application 
    attr_accessor :count
    def initialize
        @count = 0
    end

    def start(stage)
        lbl = label("Count: 0")
        btn_add = button("Add")
        btn_sub = button("Sub")
        btn_add.set_on_action  { |e| @count+=1; lbl.text = "Count: #{@count}" }
        btn_sub.set_on_action  { |e| @count-=1; lbl.text = "Count: #{@count}" }
        pane = hbox 10
        pane.add lbl
        pane.add btn_add
        pane.add btn_sub
        stage.scene = scene(pane,200,75)
        stage.title = "Add/Sub"
        stage.show   
    end
end

AddSubtract.launch

I'm not using the DSL, because I feel that I can better manage my variables contexts. However I think the lines:

 pane = hbox 10
 pane.add lbl
 pane.add btn_add
 pane.add btn_sub

should accept as well the pane.add [lbl,btn_add,btn_sub]. Does it make sense? if yes, can you guide me, how could I update jrubyfx to support it (in long term, i would like to contribute to the project, so it would be a baby step in this direction)

vpereira avatar Nov 07 '14 09:11 vpereira

I would be more in favor or pane.add(lbl,btn_add,btn_sub) as *args instead of array args.

There are several options, such as https://github.com/jruby/jrubyfx/blob/master/lib/jrubyfx/core_ext/exts.yml and https://github.com/jruby/jrubyfx/blob/master/lib/jrubyfx/dsl.rb#L192 or adding it manually to each class. I'm currently thinking all classes that do the add thing should support multi-arguments, which would be a +1 for the exts.yaml way

byteit101 avatar Nov 07 '14 17:11 byteit101

ok, i will try to work on the exts.yaml way, thanks!

vpereira avatar Nov 08 '14 11:11 vpereira