public
Description: a tiny graphical app kit for ruby
Homepage: http://code.whytheluckystiff.net/shoes
Clone URL: git://github.com/why/shoes.git
shoes / samples / simple-accordion.rb
100644 77 lines (71 sloc) 1.817 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
module Accordion
  def open_page stack
    active = app.contents.map { |x| x.contents[1] }.
      detect { |x| x.height > 0 }
    return if active == stack
    a = animate 60 do
      stack.height += 20
      active.height = 240 - stack.height if active
      a.stop if stack.height == 240
    end
  end
  def page title, text
    @pages ||= []
    @pages <<
      stack do
        page_text = nil
        stack :width => "100%" do
          background "#fff".."#eed"
          hi = background "#ddd".."#ba9", :hidden => true
          para link(title).
            click { open_page page_text }, :size => 26
          hover { hi.show }
          leave { hi.hide }
          click { open_page page_text }
        end
        page_text =
          stack :width => "100%", :height => (@pages.empty? ? 240 : 0) do
            stack :margin => 10 do
              text.split(/\n{2,}/).each do |pg|
                para pg
              end
            end
          end
      end
  end
end
 
Shoes.app do
  extend Accordion
  style(Link, :stroke => black, :underline => nil, :weight => "strong")
  style(LinkHover, :stroke => black, :fill => nil, :underline => nil)
 
  page "0.0", <<-'END'
There is a thought
I have just had
Which I don’t care to pass to
Anyone at all at this time.
 
I have even forgotten it now,
But kept only the pleasures
Of my property
And of my controlled mental slippage.
END
  page "0.1", <<-'END'
My eyes have blinked again
And I have just realized
This upright world
I have been in.
 
My eyelids wipe
My eyes hundreds of times
Reseting and renovating
The scenery.
END
  page "0.2", <<-'END'
Sister, without you,
The universe would
Have such a hole through it,
Where infinity has been shot.
 
This cannot be, though.
There will always be room
For you—all of us are
Holding the way open.
END
end