Created
January 6, 2011 05:23
-
-
Save deguchi/767545 to your computer and use it in GitHub Desktop.
CoffeeScriptのクラスを使ったTitaniumのサンプルコード
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# debug function | |
log = (obj) -> Titanium.API.log obj | |
Titanium.UI.setBackgroundColor '#000' | |
class TabGroup | |
constructor: () -> | |
@tabGroup = Titanium.UI.createTabGroup() | |
return @tabGroup | |
class Window | |
constructor: (@title) -> | |
return Titanium.UI.createWindow | |
title:@title | |
backgroundColor:'#fff' | |
class Tab | |
constructor: (@title, @icon) -> | |
@window = new Window @title | |
@tab = Titanium.UI.createTab | |
icon:@icon | |
title:@title | |
window:@window | |
@createContents() | |
createContents: -> | |
label = Titanium.UI.createLabel | |
color:'#999' | |
text:'I am Window on '+@title | |
font: | |
fontSize:20 | |
fontFamily:'Helvetica Neue' | |
textAlign:'center' | |
width:'auto' | |
label.addEventListener 'click', -> | |
alert 'OK' | |
log 'OK' | |
@window.add label | |
tabGroup = new TabGroup() | |
tab1 = new Tab 'Tab1', 'KS_nav_ui.png' | |
tabGroup.addTab tab1.tab | |
tab2 = new Tab 'Tab2', 'KS_nav_views.png' | |
tabGroup.addTab tab2.tab | |
#継承してみる | |
class ImageTab extends Tab | |
createContents: -> | |
images = | |
0: | |
name: 'appcelerator' | |
image: 'http://gyazo.com/64ee108bc98ab4e6632c2ee183eb0288.png' | |
1: | |
name: 'Titanium' | |
image: 'http://gyazo.com/d2d78ef02588f6c69a53147e06547a38.png' | |
2: | |
name: 'CoffeeScript' | |
image: 'http://gyazo.com/a6cb876b91bcfa8f6580e7c7fd461868.png' | |
3: | |
name: 'Gyazo' | |
image: 'http://gyazo.com/c86f9566d5fd2904b2929ad4b67347c7.png' | |
imgs = [] | |
for own key, value of images | |
imgs.push value.image | |
@view = Titanium.UI.createCoverFlowView | |
images: imgs | |
backgroundColor: '#000' | |
# 画像選択時のイベント | |
#Function binding | |
@view.addEventListener 'click', (e) => # => と書くと this を渡せる | |
log "image clicked: #{e.index}, selected is #{@view.selected}" | |
@window.title = images[e.index].name | |
# フリックなどで選択中の画像が変わったときのイベント | |
#Function binding | |
@view.addEventListener 'change', (e) => | |
log "image changed: #{e.index}, selected is #{@view.selected}" | |
@window.add @view | |
tab3 = new ImageTab 'CoverFlow', 'KS_nav_views.png' | |
tabGroup.addTab tab3.tab | |
tabGroup.open() | |
# 参照可能 | |
log tab3.view | |
log tab3.window.title |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment