Debian Codegraph @

Nasal/canvas/PFD/TextElement.nas

raw
1 # PFD UI Element - Text UI Element. Can have values set and retrieved
2 var TextElement =
3 {
4 new : func (pagename, svg, name, value="", style=nil)
5 {
6 var obj = {
7 parents : [ TextElement, PFD.UIElement ],
8 _name : pagename ~ name,
9 _edit : 0,
10 _style : style,
11 };
12
13 if (style == nil) obj._style = PFD.DefaultStyle;
14
15 obj._symbol = svg.getElementById(obj._name);
16 if (obj._symbol == nil) die("Unable to find element " ~ obj._name);
17 obj.setValue(value);
18
19 # State and timer for flashing highlighting of elements
20 obj._highlighted = 0;
21 obj._flash = 0;
22
23 # Text to assign at the end of the highlight period.
24 # Used for annunicators that should flash and then change value.
25 obj._endText = nil;
26
27 return obj;
28 },
29
30 getName : func() { return me._name; },
31 getValue : func() {
32 if (me._symbol.getText() == nil) return ""; # Special case - canvas text elements return nil instead of empty string
33 return me._symbol.getText();
34 },
35 setValue : func(value) { me._symbol.setText(value); },
36 setVisible : func(vis) { me._symbol.setVisible(vis); },
37 _flashElement : func() {
38 if (me._flash == 0) {
39 me._symbol.setDrawMode(canvas.Text.TEXT + canvas.Text.FILLEDBOUNDINGBOX);
40 me._symbol.setColorFill(me._style.HIGHLIGHT_COLOR);
41 me._symbol.setColor(me._style.HIGHLIGHT_TEXT_COLOR);
42 me._flash = 1;
43 } else {
44 me._symbol.setDrawMode(canvas.Text.TEXT);
45 me._symbol.setColor(me._style.NORMAL_TEXT_COLOR);
46 me._flash = 0;
47 }
48 },
49 highlightElement : func(highlighttime=-1, endText=nil) {
50 me._endText = endText;
51 me._highlighted = 1;
52 me._flash == 0;
53 PFD.HighlightTimer.startHighlight(me, highlighttime);
54 },
55 unhighlightElement : func() {
56 if (me._endText != nil) me.setValue(me._endText);
57 me._endText = nil;
58 me._highlighted = 0;
59 me._symbol.setDrawMode(canvas.Text.TEXT);
60 me._symbol.setColor(me._style.NORMAL_TEXT_COLOR);
61 PFD.HighlightTimer.stopHighlight(me);
62 },
63 setColor : func(color) { me._symbol.setColor(color); },
64 isEditable : func () { return 0; },
65 isInEdit : func() { return 0; },
66 isHighlighted : func() { return me._highlighted; },
67 enterElement : func() { return me.getValue(); },
68 clearElement : func() { },
69 editElement : func() { },
70 incrSmall : func(value) { },
71 incrLarge : func(value) { },
72 };