ELF 命令
大多数 ELF 命令可以创建和修改 UI 元素。在这些命令创建的元素类型后面命名创建 UI 元素的这些命令。其接受含参数的可选标志,还接受想要指定给已创建元素的名称
1 2 3 4 5 6
| window -visible true -title "Test Window" TestWindow1;
window -visible true -title "Test Window" TestWindow1;
window -edit -title "New Title" -maximizeButton false TestWindow1; window -exists TestWindow1;
|
布局
表格布局
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
| window -widthHeight 300 200 TestWindow2; string $form = `formLayout -numberOfDivisions 100`; string $b1 = `button -label "A"`; string $b2 = `button -label "B"`; string $b3 = `button -label "C"`; string $b4 = `button -label "D"`; string $b5 = `button -label "E"`; formLayout -edit -attachForm $b1 "top" 5 -attachForm $b1 "left" 5 -attachControl $b1 "bottom" 5 $b2 -attachPosition $b1 "right" 0 75 -attachNone $b2 "top" -attachForm $b2 "left" 5 -attachForm $b2 "bottom" 5 -attachForm $b2 "right" 5 -attachOppositeControl $b3 "top" 0 $b1 -attachPosition $b3 "left" 5 75 -attachNone $b3 "bottom" -attachForm $b3 "right" 5 -attachControl $b4 "top" 0 $b3 -attachOppositeControl $b4 "left" 0 $b3 -attachNone $b4 "bottom" -attachOppositeControl $b4 "right" 0 $b3 -attachControl $b5 "top" 0 $b4 -attachOppositeControl $b5 "left" 0 $b4 -attachNone $b5 "bottom" -attachOppositeControl $b5 "right" 0 $b4 $form; showWindow TestWindow2;
|
按钮 A 固定到窗口的左上角,而其底边连接到按钮 B,其右边也连接到按钮 B,以便按钮 A 的宽度占窗口宽度的 75%。通过这些连接,在调整窗口大小时,按钮 A 将相应地增大或缩小。另请注意,按钮 D 和 E 上的连接会将其左边和右边与上方的按钮对齐。
大部分 formLayout 连接标志均按预期运行。AttachOppositeForm 和 attachOppositeControl 需要额外说明。将子控件添加到表格中时,虽然没有位置,但有顺序,因此具有相对于彼此的暗含位置。就 attachControl 标志而言,第二个子控件顶部要连接到的“自然”位置为第一个子控件的底部。第二个子控件的左边要连接到的“自然”位置为第一个子控件的右边。
因此,在某种意义上,第二个子控件位于第一个子控件的右下方,第三个子控件位于第二个子控件的右下方,依此类推。
现在,假设要使第二个子控件附加到第一个子控件的旁边且必须为相对附件,以便子控件 2 在表格大小发生更改时仍保留在子控件 1 的旁边。通过常规 attachControl,可以将子控件 2 的左侧边连接到子控件 1 的右侧边,attachControl child2 “left” 0 child1; 表明要将子控件 2 的左侧边附加到子控件 1 的左右方向中距离“最近”的边,间距偏移为 0 像素。请记住,隐式顺序会直接将子控件 2 定位到子控件 1 的右边,因此“最近”边为子控件 1 的右边。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| window TestWindow3; string $form = `formLayout`; string $b1 = `button -label "AAAAAAAAA"`; string $b2 = `button -label "BBBBB"`; string $b3 = `button -label "CCCC"`; formLayout -edit -attachForm $b1 "top" 5 -attachForm $b1 "left" 5 -attachControl $b2 "top" 0 $b1 -attachControl $b2 "left" 5 $b1 -attachNone $b2 "right" -attachNone $b2 "bottom" -attachControl $b3 "top" 0 $b2 -attachControl $b3 "left" 0 $b2 -attachNone $b3 "right" -attachNone $b3 "bottom" $form; showWindow TestWindow3;
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| window TestWindow5; string $form = `formLayout`; string $b1 = `button -label "AAAAAAAAA"`; string $b2 = `button -label "BBBBB"`; string $b3 = `button -label "CCCC"`; formLayout -edit -attachForm $b1 "top" 5 -attachForm $b1 "left" 5 -attachOppositeControl $b2 "top" 0 $b1 -attachControl $b2 "left" 5 $b1 -attachNone $b2 "right" -attachNone $b2 "bottom" -attachControl $b3 "top" 0 $b2 -attachOppositeControl $b3 "left" 0 $b2 -attachNone $b3 "right" -attachNone $b3 "bottom" $form; showWindow TestWindow5;
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| window TestWindow7; string $form = `formLayout`; string $b1 = `button -label "AAAAAAAAA"`; string $b2 = `button -label "BBBBB"`; string $b3 = `button -label "CCCC"`; formLayout -edit -attachForm $b1 "top" 5 -attachForm $b1 "left" 5 -attachOppositeControl $b2 "top" 0 $b1 -attachControl $b2 "left" 5 $b1 -attachNone $b2 "right" -attachNone $b2 "bottom" -attachControl $b3 "top" 0 $b2 -attachOppositeControl $b3 "left" 0 $b1 -attachOppositeControl $b3 "right" 0 $b2 -attachNone $b3 "bottom" $form; showWindow TestWindow7;
|
父对象子对象
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| window ExampleWindow1; columnLayout; button -label "Button 1"; button -label "Button 2"; rowColumnLayout -numberOfColumns 2; text -label "Name:"; textField; text -label "City:"; textField; setParent ..; checkBox -label "Lights "; checkBox -label "Camera "; checkBox -label "Action "; showWindow ExampleWindow1;
|
text 和 textField 元素是行列布局的子对象。按照行列布局,它们排列在两列中。如果未使用 setParent .. 命令,则默认父对象将继续是行列排布,且复选框也会在两个列中进行排布
父对象菜单示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| window -menuBar true ExampleWindow3; menu -label "File" TestFileMenu; menuItem -label "Open" menuItem1; menuItem -label "Close" menuItem2; menuItem -label "Quit" menuItem3; menu -label "Edit" TestEditMenu; menuItem -label "Cut" menuItem1; menuItem -label "Copy" menuItem2; menuItem -label "Paste" menuItem3; menu -label "Options" TestOptionsMenu; menuItem -label "Color" -subMenu true menuItem1; menuItem -label "Red"; menuItem -label "Green"; menuItem -label "Blue"; setParent -menu ..; menuItem -label "Size" -subMenu true menuItem2; menuItem -label "Small"; menuItem -label "Medium"; menuItem -label "Large"; setParent -menu ..; showWindow ExampleWindow3;
|
模板菜单
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
|
if (!`uiTemplate -exists TestTemplate`) { uiTemplate TestTemplate; }
frameLayout -defineTemplate TestTemplate -borderVisible true -labelVisible true -labelAlign "center" -marginWidth 5 -marginHeight 5; button -defineTemplate TestTemplate -width 150 -label "Default Text";
window -title "Test Window" ExampleWindow4; setUITemplate -pushTemplate TestTemplate; frameLayout -label "Buttons" TestFrameLayout; columnLayout TestColumnLayout; button; button -label "Not Default Text"; button; setUITemplate -popTemplate; showWindow ExampleWindow4;
|
控件发出的命令中会作为参数需要控件的值。若要避免在控件的状态更改时对其进行查询,可将其值作为字符串“#1”象征性地嵌入到命令中。控件更改值时,“#1”将在发出命令后替换为控件的实际值。包含多个值的组会将“#2”、“#3”等用作其不同组件的值。例如,包含三个场的浮动场组可在其命令中分别使用“#1”、“#2”和“#3”表示每个场的值
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| window -title "Test Window" -widthHeight 200 100 ExampleWindow6; columnLayout; string $button = `button -label "Initial Label"`; button -edit -command ("changeButtonLabel " + $button) $button; showWindow ExampleWindow6; proc changeButtonLabel (string $whichButton) { string $labelA; string $labelB; string $currentLabel; $currentLabel = `button -query -label $whichButton`; $labelA = "New Label A"; $labelB = "New Label B"; if ($currentLabel != $labelA) { button -edit -label $labelA $whichButton; } else { button -edit -label $labelB $whichButton; } }
|
基础窗口模板
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
|
window -title "Test Window" ExampleWindow7; columnLayout ColumnLayout; frameLayout -labelVisible false -marginWidth 5 -marginHeight 5; columnLayout; text -label "Overall Intensity"; rowLayout -numberOfColumns 3; string $radioButton1, $radioButton2, $radioButton3; radioCollection; $radioButton1 = `radioButton -label "Low"`; $radioButton2 = `radioButton -label "Medium"`; $radioButton3 = `radioButton -label "High"`; setParent ..; text -label "Light Switches"; rowColumnLayout -numberOfColumns 2 -columnWidth 1 130 -columnWidth 2 130; string $checkBox1, $checkBox2, $checkBox3, $checkBox4; $checkBox1 = `checkBox -label "Front Spot"`; $checkBox2 = `checkBox -label "Center Spot"`; $checkBox3 = `checkBox -label "Near Flood"`; $checkBox4 = `checkBox -label "Sunlight"`; setParent ExampleWindow7|ColumnLayout; textField -text "Ready" -editable false -width 278 StatusLine; radioButton -edit -select $radioButton1; checkBox -edit -value on $checkBox1; checkBox -edit -value off $checkBox2; checkBox -edit -value off $checkBox3; checkBox -edit -value on $checkBox4; radioButton -edit -onCommand "showStatus \"Low Intensity\"" $radioButton1; radioButton -edit -onCommand "showStatus \"Med Intensity\"" $radioButton2; radioButton -edit -onCommand "showStatus \"High Intensity\"" $radioButton3; checkBox -edit -changeCommand "showStatus \"Front Spot: #1\"" $checkBox1; checkBox -edit -changeCommand "showStatus \"Center Spot: #1\"" $checkBox2; checkBox -edit -onCommand "showStatus \"Near Flood On\"" -offCommand "showStatus \"Near Flood Off\"" $checkBox3; checkBox -edit -onCommand "showStatus \"Sunlight On\"" -offCommand "showStatus \"Sunlight Off\"" $checkBox4; showWindow ExampleWindow7;
global proc showStatus (string $newStatus) { textField -edit -text $newStatus ExampleWindow7|ColumnLayout|StatusLine; }
|
对话框
如果按 Enter 键,-defaultButton 标志会指示要选定的按钮,如果按 Esc 键,-cancelButton 标志会指示选定的按钮。
1 2
| confirmDialog -message "Are you sure?" -button "Yes" -button "No" -defaultButton "Yes" -cancelButton "No" -dismissString "No";
|
对话框还提供了一个可编辑的滚动字段,通过该滚动字段最终用户可以回复提示的问题
1 2
| promptDialog -message "Enter name:" -button "Ok" -button "Cancel" -defaultButton "Ok" -cancelButton "Cancel" -dismissString "Cancel";
|