On Jul 25, 2008, at 6:27 PM, Martin DeMello wrote:

So how do I give each flow its own click? (For that matter, am I doing
this the right way in the first place? What I need is a basic
one-column list view each of whose cells can have a different height
and background colour, and a click handler that's aware of which cell
was clicked. If there's a simpler way to achieve that than the code
below, I'm open to suggestions.)

Here's a start from a fellow fumbler.

Each slot can have its own click handler, but it's sometimes tricky getting the handler assigned to the right slot. You might put a click handler inside a flow's block, but the click handler will get assigned to the app as a whole instead of the flow unless you specifically tell it otherwise. One way to do it is to assign the slot explicitly with a variable and call "click" as a method on that variable:

@this_flow = flow
@this_flow.append { para "whatever " }
@this_flow.click { alert "clicked this flow" }

but that's kind of unpleasant.

Experimenting around I found it was easy to make sure click handlers and stuff did the right thing when I used custom widgets, like this:

( see http://hackety.org/2008/06/12/martinDemellosGooeyChallenge.html for how custom widgets are defined)

======

class ListRow < Widget
  def initialize(index, content, flow_style = {})
    flow  flow_style do
      background( index % 2 == 0 ? lightblue : white )
      para content, :size => 8
      click do
        alert "clicked flow #{index}"
      end
    end
  end
end

class ListView < Widget
  def initialize(ary, stack_style = {})
    stack stack_style do
      background white
      (0..ary.length-1).to_a.each_with_index do | e, i |
        listrow i, e
      end
    end
  end
end

Shoes.app :width => 840, :height => 700, :title => "Test" do
 background white
listview( (0..10).to_a , :width => 280, :margin_top => 20, :margin_left => 10, :height => 600 )
end



Reply via email to