forked from google/create-framework
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathviews.dart
183 lines (141 loc) · 5.48 KB
/
views.dart
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// Copyright 2016 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import '../../elements.dart';
import 'point.dart';
import 'styles.dart';
/// An interface for the view of a given model.
abstract class View<ModelType> {
ReadRef<ModelType> get model;
ReadRef<Style> get style;
}
/// An interface for the editor of a given model.
abstract class Editor<ModelType> extends View<ModelType> {
Ref<ModelType> get model;
}
/// A base class for the view of a given model.
class BaseView<ModelType> implements View<ModelType> {
final ReadRef<ModelType> _model;
final ReadRef<Style> style;
// Fields for internal use by the toolkit implementation
Lifespan cachedSubSpan;
ReadRef<ModelType> get model => _model;
BaseView(this._model, this.style);
}
/// A base class for the view of a given model.
class BaseEditor<ModelType> extends BaseView<ModelType> implements Editor<ModelType> {
Ref<ModelType> get model => _model as Ref<ModelType>;
BaseEditor(Ref<ModelType> model, ReadRef<Style> style) : super(model, style);
}
/// A text view of a String model
class LabelView extends BaseView<String> {
LabelView(ReadRef<String> labelText, ReadRef<Style> style) : super(labelText, style);
}
/// A transparent glue (empty view).
class GlueView extends BaseView<double> {
GlueView(ReadRef<double> glueWidth, [ReadRef<Style> style]) : super(glueWidth, style);
}
/// An editable text view
class TextInput extends BaseEditor<String> {
TextInput(Ref<String> text, ReadRef<Style> style) : super(text, style);
}
/// A boolean input, a checkbox or a switch depending on style
class BooleanInput extends BaseEditor<bool> {
BooleanInput(Ref<bool> state, [ReadRef<Style> style]) : super(state, style);
}
/// A slider, with values from 0.0 to 1.0
class SliderInput extends BaseEditor<double> {
SliderInput(Ref<double> state, [ReadRef<Style> style]) : super(state, style);
}
/// A link (underlined text) view
class LinkView extends BaseView<String> {
final ReadRef<Operation> action;
LinkView(ReadRef<String> buttonText, this.action, [ReadRef<Style> style])
: super(buttonText, style);
}
/// A button view
class ButtonView extends BaseView<String> {
final ReadRef<Operation> action;
ButtonView(ReadRef<String> buttonText, ReadRef<Style> style, this.action)
: super(buttonText, style);
}
/// An icon button view
class IconButtonView extends BaseView<IconId> {
final ReadRef<Operation> action;
IconButtonView(ReadRef<IconId> icon, ReadRef<Style> style, this.action) : super(icon, style);
}
typedef String SelectDisplayFunction<T>(T value);
/// A selection view (a.k.a. dropdown buttons)
class SelectionInput<T> extends BaseEditor<T> {
final ReadList<T> options;
final SelectDisplayFunction<T> display;
final bool sort;
SelectionInput(Ref<T> current, this.options, this.display, this.sort, [ReadRef<Style> style])
: super(current, style);
}
/// A flex container view that has subviews
abstract class FlexView extends BaseView<ReadList<View>> {
FlexView(ReadList<View> subviews, [ReadRef<Style> style])
: super(new Constant<ReadList<View>>(subviews), style);
}
/// A row view
class RowView extends FlexView {
RowView(ReadList<View> columns, [ReadRef<Style> style]) : super(columns, style);
}
/// A column view
class ColumnView extends FlexView {
ColumnView(ReadList<View> rows, [ReadRef<Style> style]) : super(rows, style);
}
/// A container wrapper
class ContainerView extends BaseView<View> {
ContainerView(ReadRef<View> child, ReadRef<Style> style) : super(child, style);
}
/// An action view (rendered using InkWell)
class ActionView extends BaseView<View> {
final ReadRef<Operation> action;
ActionView(ReadRef<View> child, this.action, [ReadRef<Style> style]) : super(child, style);
}
enum GestureActionType { dragStart, dragUpdate, dragEnd }
typedef GestureActionCallback = void Function(GestureActionType type, Point point);
/// A gesture detector/action view (rendered using GestureDetector)
class GestureActionView extends BaseView<View> {
final GestureActionCallback action;
GestureActionView(ReadRef<View> child, this.action, [ReadRef<Style> style]) : super(child, style);
}
/// A canvas with lines drawn on it
class CanvasView extends BaseView<ReadList<Point>> {
CanvasView(ReadRef<ReadList<Point>> points, [ReadRef<Style> style]) : super(points, style);
}
/// A header item (which can be rendered as a DrawerHeader)
class HeaderView extends BaseView<String> {
HeaderView(ReadRef<String> headerText) : super(headerText, null);
}
/// An item (which can be rendered as a DrawerItem)
class ItemView extends BaseView<String> {
final ReadRef<IconId> icon;
final ReadRef<bool> selected;
final ReadRef<Operation> action;
// Do not specify the style here.
ItemView(ReadRef<String> itemText, this.icon, this.selected, this.action) : super(itemText, null);
}
/// A divider
class DividerView extends BaseView<void> {
// TODO: move to style
double height;
DividerView([this.height]) : super(null, null);
}
/// A drawer
class DrawerView extends FlexView {
DrawerView(ReadList<View> items) : super(items);
}
/// Application view
class ApplicationView extends BaseView<View> {
ReadRef<String> appTitle;
ReadRef<String> appVersion;
ReadRef<DrawerView> drawer;
ReadRef<IconId> buttonIcon;
ReadRef<Operation> buttonOperation;
ApplicationView(ReadRef<View> mainView, this.appTitle,
{this.appVersion, this.drawer, this.buttonIcon, this.buttonOperation})
: super(mainView, null);
}