UITheme可用來安排UI畫面Layout,不過網路上的範例及說明文件很少,官方的資料只提到下列幾個範例,可以打開SystemBrowser閱讀相關程式碼
UITheme exampleBasicControls.
UITheme exampleColorControls.
UITheme exampleDialogs.
UITheme exampleGroups.
UITheme exampleOtherControls.
UITheme exampleWindowWithToolbars.
以下是Pharo轉出的Smalltalk程式碼,是Jimmy's papa整理過的簡單範例程式,看起來很多,其實在Pharo的環境下寫沒幾行,在加上Smalltalkm語法規則超簡單,蠻容易上手的
Object subclass: #HelloButton
instanceVariableNames: 'builder content'
classVariableNames: ''
poolDictionaries: ''
category: 'JimmyScratchLab'!
!HelloButton methodsFor: 'main' stamp: 'JimmyScratchLab 10/2/2011 23:35'!
aboutButtonClick
SmalltalkImage current aboutThisSystem.! !
!HelloButton methodsFor: 'main' stamp: 'JimmyScratchLab 10/2/2011 10:22'!
builder
^ builder
! !
!HelloButton methodsFor: 'main' stamp: 'JimmyScratchLab 10/2/2011 10:24'!
builder: anObject
builder := anObject
! !
!HelloButton methodsFor: 'main' stamp: 'JimmyScratchLab 10/2/2011 23:40'!
helloButtonClick
Transcript show: 'hello,JimmyScratchLab'; cr.
! !
!HelloButton methodsFor: 'main' stamp: 'JimmyScratchLab 10/2/2011 10:24'!
initialize
self builder: UITheme builder.
! !
!HelloButton methodsFor: 'main' stamp: 'JimmyScratchLab 10/2/2011 23:37'!
open
content := builder newColumn: {
builder newButtonFor: self
action: #helloButtonClick
label: 'Hello'
help: 'Say hello!!!!!!'.
builder newButtonFor: self
action: #aboutButtonClick
label: 'About'
help: 'Show About!!!!!!'.
}.
(content openInWindowLabeled: 'HelloBouton') extent: 300@50.
! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
HelloButton class
instanceVariableNames: 'content'!
!HelloButton class methodsFor: 'main' stamp: 'JimmyScratchLab 10/2/2011 10:20'!
open
^ self new open.
! !
在WorkSpace寫入HelloButton open後執行DoIt,便會在畫面出現HelloButton視窗
寄件者 scratchlab |
沒有留言:
張貼留言