Rebol 编程/布局
外观
< Rebol 编程
LAYOUT specs /size pane-size /offset where /parent new /origin pos /styles list /keep /tight
返回一个由样式描述方言构建的面板。
LAYOUT 是一个函数值。
- specs -- 样式、属性和布局的方言块 (类型:块)
- /size
- pane-size -- 面板大小 (宽和高) (类型:对)
- /offset
- where -- 面板偏移 (类型:对)
- /parent
- new -- 面板的面板样式 (类型:对象 词 块)
- /origin
- pos -- 设置布局原点 (类型:对)
- /styles
- list -- 要使用的样式块 (类型:块)
- /keep -- 保留样式相关数据
- /tight -- 零偏移和原点
layout: func [ {Return a face with a pane built from style description dialect.} specs [block!] "Dialect block of styles, attributes, and layouts" /size pane-size [pair!] "Size (wide and high) of pane face" /offset where [pair!] "Offset of pane face" /parent new [object! word! block!] "Face style for pane" /origin pos [pair!] "Set layout origin" /styles list [block!] "Block of styles to use" /keep "Keep style related data" /tight "Zero offset and origin" /local pane way space tabs var value args new-face pos-rule val facets start vid-rules max-off guide def-style rtn word ][ if tight [ if not offset [offset: true where: 0x0] if not origin [origin: true pos: 0x0] ] new-face: make any [ all [parent object? new new] all [parent word? new get-style new] vid-face ] any [all [parent block? new new] [parent: 'panel]] if not parent [ new-face/offset: any [ all [offset where] 50x50 ] ] new-face/size: pane-size: any [ all [size pane-size] new-face/size system/view/screen-face/size - (2 * new-face/offset) ] new-face/pane: pane: copy [] max-off: origin: where: either origin [pos] [20x20] space: 8x8 way: 0x1 pos: guide: none tabs: 100x100 def-style: none new-face/styles: styles: either styles [list] [copy vid-styles] parse specs [some [thru 'style val: [set word word! (if not find styles word [insert styles reduce [word none]]) | none (error "Expected a style name" val) ] ]] parse specs [some [thru 'styles val: [ set word word! ( if all [value? word value: get word block? value] [ insert styles value ] ) | none (error "Expected a style name" val) ]]] rtn: [where: (max-off * reverse way) + (way * any [guide origin])] vid-rules: [ 'return (do rtn) | 'at [set pos pair! (where: pos) | none] | 'space pos-rule (space: 1x1 * pos) | 'pad pos-rule ( value: either integer? pos [way * pos] [pos] where: where + value max-off: max-off + value ) | 'across (if way <> 1x0 [way: 1x0 do rtn]) | 'below (if way <> 0x1 [do rtn way: 0x1]) | 'origin [set pos [pair! | integer!] (origin: pos * 1x1) | none] (where: max-off: origin) | 'guide [set pos pair! (guide: pos do rtn) | none (guide: where)] (max-off: 0x0) | 'tab (where: next-tab tabs way where) | 'tabs [ set value [block! | pair!] (tabs: value) | set value integer! (tabs: value * 1x1) ] | 'indent pos-rule (where/x: either integer? pos [where/x + pos] [pos/x]) | 'style set def-style word! | 'styles set value block! | 'size set pos pair! (pane-size: new-face/size: pos size: true) | 'backcolor set value tuple! (new-face/color: value) | 'backeffect set value block! (new-face/effect: value) | 'do set value block! (do :value) ] pos-rule: [set pos [integer! | pair! | skip (error "Expected position or size:" :pos)]] if empty? vid-words [ foreach value vid-rules [if lit-word? :value [append vid-words to-word value]] ] while [not tail? specs] [ forever [ value: first specs specs: next specs if set-word? :value [var: :value break] if not word? :value [error "Misplaced item:" :value break] if find vid-words value [ either value = 'style [ facets: reduce [first specs] specs: next specs ] [ set [specs facets] do-facets start: specs [] styles ] if :var [set :var where var: none] insert facets :value if not parse facets vid-rules [error "Invalid args:" start] break ] new: select styles value if not new [error "Unknown word or style:" value break] set [specs facets] do-facets specs new/words styles new: make new either val: select facets 'with [expand-specs new val] [[]] new/style: value new/pane-size: pane-size new/styles: styles new/flags: exclude new/flags state-flags if not flag-face? new fixed [new/offset: where] grow-facets new facets track ["Style:" new/style "Offset:" new/offset "Size:" new/size] either def-style [ change next find styles def-style new def-style: none ] [ new/parent-face: none if :var [new/var: bind to-word :var :var] do bind new/init in new 'init if new/parent-face [new: new/parent-face] if :var [set :var new var: none] append pane new if not flag-face? new fixed [ max-off: maximum max-off new/size + space + where where: way * (new/size + space) + where ] if all [warn any [new/offset/x > pane-size/x new/offset/y > pane-size/y]] [ error "Face offset outside the pane:" new/style ] track ["Style:" new/style "Offset:" new/offset "Size:" new/size] if not keep [ new/init: copy [] new/words: new/styles: new/facets: none ] ] break ] ] if not size [ foreach face pane [if flag-face? face drop [face/size: 0x0]] new-face/size: size: origin + second span? pane foreach face pane [ if flag-face? face drop [face/size: size] face/pane-size: size ] ] new-face ]