Permalink
Browse files

notebook widget initial commit

  • Loading branch information...
1 parent ca8c749 commit 48d13b0c54989c0649958f2822395db118507932 @lljk committed Aug 20, 2011
Showing with 100 additions and 0 deletions.
  1. +34 −0 notebook_widget/README
  2. +66 −0 notebook_widget/notebook_widget_example.rb
@@ -0,0 +1,34 @@
+NoteBook Widget...
+
+ here's an example of a widget that functions something like a tabbed browser.
+
+ it's still pretty rough around the edges, but i thought i'd put it out there...
+
+ a note_book is initialized with the name of the first tab, so you create it in a Shoes::App using something like this:
+
+ nb = note_book("page 1")
+
+ this adds a button at the top of the main app with the title "page 1". it also assigns "page 1" as a key in a hash - NoteBook#pages. This hash is used when adding content to each page with the NoteBook#add method, which takes a block that will be appended to the page. adding content to "page 1" would look like this:
+
+ nb.pages["page 1"].add{para "this is page one!"}
+
+ new pages are created with NoteBook#add_page, taking the name of the tab and hash entry as an argument.
+
+ nb.add_page("page 2")
+
+ you can now add content to "page 2" in the same way you did for "page 1", using
+
+ nb.pages["page 2"].add{}
+
+ you can add more content to any page at any time - it's really just appending to the flow that is a page.
+
+
+ so here's the breakdown:
+
+note_book(page_name) - creates a new NoteBook, and a first page, referenced in the #pages hash with the key [page_name]
+
+NoteBook#pages - is a hash of all the pages
+
+NoteBook#add_page(page_name) - creates a new page in the NoteBook, referenced in the #pages hash with the key [page_name]
+
+NoteBook#pages[page_name].add{} - appends contents of the block to the page referenced
@@ -0,0 +1,66 @@
+class Page < Shoes::Widget
+ attr_accessor :name, :body
+
+ def initialize(name)
+ @name = name
+ @body = flow
+ @body.hide
+ end
+
+ def add
+ @body.append do
+ yield
+ end
+ end
+
+end
+
+
+class NoteBook < Shoes::Widget
+ attr_reader :pages
+
+ def initialize(first_page)
+ @pnum = 0
+ @pages = {}
+
+ @f = flow width: self.parent.width, height: 50, displace_top: 0
+
+ add_page(first_page)
+ @pages[first_page].body.show
+ end
+
+ def add_page(name)
+ @f.append{
+ @tab = button(name)
+ }
+
+ @pages[name] = page(name)
+
+ @tab.click{
+ @pages.each{|k, v| v.body.hide}
+ @pages[name].body.show
+ }
+
+ @pnum += 1
+ end
+
+end
+
+
+Shoes.app do
+
+ nb = note_book("tiddlywinks")
+ nb.pages["tiddlywinks"].add{
+ 10.times{para "tiddlywinks!! ", stroke: red}
+ }
+
+ nb.add_page("seamonkeys")
+ nb.pages["seamonkeys"].add{
+ 100.times{para "seamonkeys!!", stroke: blue}
+ }
+
+ nb.pages["tiddlywinks"].add{
+ 10.times{para "more tiddlywinks!! ", stroke: orange}
+ }
+
+end

0 comments on commit 48d13b0

Please sign in to comment.