-
Notifications
You must be signed in to change notification settings - Fork 1
/
stack.js
80 lines (73 loc) · 3.76 KB
/
stack.js
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Stackpanel page
//
exports.View =
{
title: "StackPanel",
elements:
[
{ control: "stackpanel", orientation: "Horizontal", contents: [
{ control: "text", value: "Padding", fontsize: 10, width: 140, verticalAlignment: "Center" },
{ control: "slider", minimum: 0, maximum: 20, binding: "padding", width: 300, verticalAlignment: "Center" },
] },
{ control: "stackpanel", orientation: "Horizontal", contents: [
{ control: "text", value: "Margin", fontsize: 10, width: 140, verticalAlignment: "Center" },
{ control: "slider", minimum: 0, maximum: 20, binding: "margin", width: 300, verticalAlignment: "Center" },
] },
{ control: "stackpanel", orientation: "Horizontal", contents: [
{ control: "text", value: "Orientation", fontsize: 10, verticalAlignment: "Center" },
{ control: "picker", margin: { bottom: 10 }, verticalAlignment: "Center",
binding: { items: "orientations", selection: "orientation", onSelectionChange: { command: "setOrientation", orientation: "{$data}" } }
},
] },
{ control: "stackpanel", orientation: "Horizontal", visibility: "{isHorizontal}", contents: [
{ control: "button", width: 135, caption: "Top", binding: { command: "setVAlign", align: "Top" } },
{ control: "button", width: 135, caption: "Center", binding: { command: "setVAlign", align: "Center" } },
{ control: "button", width: 135, caption: "Bottom", binding: { command: "setVAlign", align: "Bottom" } },
] },
{ control: "stackpanel", orientation: "Horizontal", visibility: "{!isHorizontal}", contents: [
{ control: "button", width: 135, caption: "Left", binding: { command: "setHAlign", align: "Left" } },
{ control: "button", width: 135, caption: "Center", binding: { command: "setHAlign", align: "Center" } },
{ control: "button", width: 135, caption: "Right", binding: { command: "setHAlign", align: "Right" } },
] },
{ control: "border", border: "Gray", borderThickness: "5", contents: [
{ control: "stackpanel", background: "Red", padding: "{padding}", orientation: "{orientation}", contents: [
{ control: "border", border: "Blue", borderThickness: "2", background: "LightBlue", height: 50, width: 125, margin: "{margin}", horizontalAlignment: "{alignContentH}", verticalAlignment: "{alignContentV}", contents: [
{ control: "text", value: "Small", foreground: "Black", fontsize: 10, horizontalAlignment: "Center", verticalAlignment: "Center" },
] },
{ control: "border", border: "Blue", borderThickness: "2", background: "LightBlue", height: 150, width: 250, margin: 0, contents: [
{ control: "text", value: "Tall and Fat", foreground: "Black", fontsize: 10, horizontalAlignment: "Center", verticalAlignment: "Center" },
] },
] },
] },
]
}
exports.InitializeViewModel = function(context, session)
{
var viewModel =
{
padding: 0,
margin: 0,
orientation: "Horizontal",
isHorizontal: true,
alignContentH: "Left",
alignContentV: "Top",
orientations: ["Horizontal", "Vertical"]
}
return viewModel;
}
exports.Commands =
{
setOrientation: function(context, session, viewModel, params)
{
viewModel.orientation = params.orientation;
viewModel.isHorizontal = params.orientation == "Horizontal";
},
setVAlign: function(context, session, viewModel, params)
{
viewModel.alignContentV = params.align;
},
setHAlign: function(context, session, viewModel, params)
{
viewModel.alignContentH = params.align;
},
}