Re: [shoes] list box in shoes??
- From:
- J. Kaiden
- Date:
- 2011-06-16 @ 21:05
hi hex,
check out the question i asked about creating a playlist -
http://librelist.com/browser//shoes/2011/6/8/creating-a-playlist/ -
i was looking for something similar, and Steve and ashbb helped me come up
with some "funky new ways to do ui stuff" ;) ... one uses the observer
pattern to notify the main app of a selection made in the list box, and the
other pops up a menu when an item is selected. take a look if either of
these is something like what you're thinking of...
with observer:
###
require 'observer'
class ListCell < Shoes::Widget
def initialize(entry)
fill black
r = rect()
r.width= 600
r.height= 27
para entry, :stroke => white
r.hover{r.style(:fill => blue)}
r.leave{r.style(:fill => black)}
r.click{yield entry}
end
end
class ListManager < Shoes::Widget
include Observable
def initialize(array)
array.each{|item|
list_cell(item) do |entry|
changed
notify_observers(entry)
end
}
end
end
Shoes.app :title => "main" do
@app = self
@list = %W[aparagus cucumbers leafygreens]
def update(message)
para "observed: #{message} ", :stroke => red
end
def manager(parent, list)
app = self
window{
@manager = list_manager(list)
@manager.add_observer(parent)
}
end
button ("playlist"){self.manager(@app, @list)}
end
####
with a pop-up menu - in this example only the "play" option of the menu is
actually implemented, but you'll get the idea...:
#####
class ListCell < Shoes::Widget
def initialize(entry)
fill black
r = rect()
r.width= 595
r.height= 27
para entry, :stroke => white
r.hover{r.style(:fill => blue)}
r.leave{r.style(:fill => black)}
r.click{yield(entry)}
end
end
class PlayList < Shoes::Widget
def initialize(array)
window :title => "playlist" do
array.each{|item|
list_cell(item){|entry|
win = window :title => "playlist", :width => 340, :height => 30 do
button("play"){cmd = "play:#{entry}"; yield(cmd); win.close}
button("insert"){cmd = "insert:#{entry}"; yield(cmd); win.close}
button("delete"){cmd = "delete:#{entry}"; yield(cmd); win.close}
button("clear list"){cmd = "clear"; yield(cmd); win.close}
end
}
}
end
end
end
Shoes.app do
@lineup = %W[asparagus cucumbers leafygreens]
def playlist
stack{
plist = play_list(@lineup){|cmd|
command = cmd.split(":")[0]
selected = cmd.split(":")[-1]
case command
when "play"
self.pl_play(selected)
end
}
}
end
def pl_play(selected)
para "pl says play #{selected}", :stroke => yellow
end
button("playlist"){self.playlist}
end
######
cheers,
- j