zkv1000 / Nasal / menu.nas /
Newer Older
255 lines | 10.377kb
add window management
Sébastien MARQUE authored on 2017-03-28
1
var pageClass = {
2
    new : func (d) {
3
        var m = { parents : [pageClass] };
fix issue #2
Sébastien MARQUE authored on 2017-04-23
4
        m.page = d.display.display.createGroup().set('z-index', 100);
add window management
Sébastien MARQUE authored on 2017-03-28
5
        m.window = {};
6
        m.state = {};
7
        m.selected = '';
8
        return m;
9
    },
10

            
11
    del : func (id = nil) {
fixes some bugs in windows
Sébastien MARQUE authored on 2017-04-12
12
        if (id != nil and typeof(id) == 'scalar') {
add window management
Sébastien MARQUE authored on 2017-03-28
13
            delete(me.state, id);
fix deletion of specific win...
Sébastien MARQUE authored on 2017-04-24
14
            var _id = id ~ '-';
15
            id = [];
16
            foreach (var w; keys(me.window))
17
                if (find(_id, w) == 0)
18
                    append(id, w);
add window management
Sébastien MARQUE authored on 2017-03-28
19
        }
20
        else {
21
            foreach (var s; keys(me.state))
22
                delete(me.state, s);
23
            id = keys(me.window);
24
        }
25
        foreach (var w; id) {
26
            me.window[w]
27
                .hide()
28
                .del();
29
            delete(me.window, w);
30
        }
31
    },
32

            
33
    _selected_text : func (id, text, x, y) {
34
        me.selected = id;
35
        me.window[id]
36
            .setFontSize(16)
37
            .setFont('LiberationFonts/LiberationMono-Regular.ttf')
38
            .setTranslation(x, y)
39
            .setDrawMode(0x01 + 0x04)
40
            .setText(text)
withrawal of highlight selec...
Sébastien MARQUE authored on 2020-05-02
41
            .setColorFill(0,0,0)
42
            .setColor(1,0,0);
add window management
Sébastien MARQUE authored on 2017-03-28
43
    },
44

            
45
    _editable_text : func (id, text, x, y) {
46
        me.window[id]
47
            .setFontSize(16)
48
            .setFont('LiberationFonts/LiberationMono-Regular.ttf')
49
            .setTranslation(x, y)
50
            .setText(text)
51
            .setColorFill(0,0,0)
52
            .setColor(0,1,1);
53
    },
54

            
55
    _normal_text : func (id, text, x, y) {
56
        me.window[id]
57
            .setFontSize(16)
58
            .setFont('LiberationFonts/LiberationMono-Regular.ttf')
59
            .setTranslation(x, y)
60
            .setText(text)
61
            .setColorFill(0,0,0)
62
            .setColor(1,1,1);
63
    },
64

            
65
    _title_text : func (id, text, x, y) {
66
        me.window[id]
67
            .setFontSize(16)
68
            .setFont('LiberationFonts/LiberationMono-Regular.ttf')
69
            .setTranslation(x, y)
70
            .setAlignment('center-center')
71
            .setText(text)
72
            .setColorFill(0,0,0)
73
            .setColor(0,1,1);
74
    },
75

            
changes about how to fill wi...
Sébastien MARQUE authored on 2017-04-02
76
    fill : func (id, scroll = nil) {
add window management
Sébastien MARQUE authored on 2017-03-28
77
        var state = me.state[id];
changes about how to fill wi...
Sébastien MARQUE authored on 2017-04-02
78
        state.scroll = {
79
            offset : 0,           # offset between canvas element and state element
80
            last : 9999,          # last scrollgroup
81
            begin: -9999,         # first canvas element of the scrolling area
82
            end: 9999,            # last canvas element of the scrolling area
83
            upper: -9999,         # group printed on the top of the scrolling area
84
            lower: 9999,          # group printed at the bottom of the scrolling area
fixes some bugs in windows
Sébastien MARQUE authored on 2017-04-12
85
            lines : scroll != nil ? scroll.lines : 0, # number of lines for the scrolling area
86
            columns : scroll != nil ? scroll.columns : 0, # number of objects on each scrolling lines
changes about how to fill wi...
Sébastien MARQUE authored on 2017-04-02
87
        };
88
        var scrollgroup = {};
89
        forindex (var line; state.objects) {
90
            if (find('separator', state.objects[line].type) > -1) {
91
                me.window[id ~ '-' ~ (line - state.scroll.offset)] = me.page.createChild('path')
add window management
Sébastien MARQUE authored on 2017-03-28
92
                    .setStrokeLineWidth(1)
93
                    .moveTo(state.x_base, state.geometry.y - 12)
94
                    .horiz(state.geometry.w - 20)
95
                    .setColor(1,1,1);
96
                state.geometry.x = state.x_base;
97
                state.geometry.y += 8;
98
            }
99
            else {
changes about how to fill wi...
Sébastien MARQUE authored on 2017-04-02
100
                if (contains(state.objects[line], 'scrollgroup')) {
101
                    state.scroll.last = state.objects[line].scrollgroup;
102
                    scrollgroup[state.objects[line].scrollgroup] = 1;
103
                    if (state.scroll.begin == -9999) {
104
                        state.scroll.begin = line;
105
                        state.scroll.upper = state.objects[line].scrollgroup;
106
                    }
107
                    if (size(keys(scrollgroup)) > state.scroll.lines) {
108
                        if (state.scroll.end == 9999) {
109
                            state.scroll.end = line - 1;
110
                            state.scroll.lower = state.objects[line - 1].scrollgroup;
111
                        }
112
                        else
113
                            state.scroll.last = state.objects[line].scrollgroup;
114
                        state.scroll.offset += 1;
115
                        continue;
116
                    }
117
                }
118
                me.window[id ~ '-' ~ (line - state.scroll.offset)] = me.page.createChild('text');
type normal for text is defa...
Sébastien MARQUE authored on 2017-04-12
119
                if (find('selected', state.objects[line].type) > -1)
add window management
Sébastien MARQUE authored on 2017-03-28
120
                    me._selected_text(
changes about how to fill wi...
Sébastien MARQUE authored on 2017-04-02
121
                            id ~ '-' ~ (line - state.scroll.offset),
122
                            state.objects[line].text,
add window management
Sébastien MARQUE authored on 2017-03-28
123
                            state.geometry.x,
124
                            state.geometry.y,
125
                            );
126

            
adds type highlighted
Sébastien MARQUE authored on 2017-04-12
127
                elsif (find('editable', state.objects[line].type) > -1
128
                   or  find('highlighted', state.objects[line].type) > -1)
add window management
Sébastien MARQUE authored on 2017-03-28
129
                    me._editable_text(
changes about how to fill wi...
Sébastien MARQUE authored on 2017-04-02
130
                            id ~ '-' ~ (line - state.scroll.offset),
131
                            state.objects[line].text,
add window management
Sébastien MARQUE authored on 2017-03-28
132
                            state.geometry.x,
133
                            state.geometry.y,
134
                            );
135

            
changes about how to fill wi...
Sébastien MARQUE authored on 2017-04-02
136
                elsif (find('title', state.objects[line].type) > -1)
add window management
Sébastien MARQUE authored on 2017-03-28
137
                    me._title_text(
changes about how to fill wi...
Sébastien MARQUE authored on 2017-04-02
138
                            id ~ '-' ~ (line - state.scroll.offset),
139
                            state.objects[line].text,
add window management
Sébastien MARQUE authored on 2017-03-28
140
                            state.x_base - 10 + state.geometry.w / 2,
141
                            state.geometry.y
142
                        );
143

            
type normal for text is defa...
Sébastien MARQUE authored on 2017-04-12
144
                else
145
                    me._normal_text(
146
                            id ~ '-' ~ (line - state.scroll.offset),
147
                            state.objects[line].text,
148
                            state.geometry.x,
149
                            state.geometry.y,
150
                            );
151

            
152

            
changes about how to fill wi...
Sébastien MARQUE authored on 2017-04-02
153
                if (find('end-of-line', state.objects[line].type) > -1
154
                or  find('title', state.objects[line].type) > -1) {
add window management
Sébastien MARQUE authored on 2017-03-28
155
                    state.geometry.x = state.x_base;
156
                    state.geometry.y += 24;
157
                }
158
                else
changes about how to fill wi...
Sébastien MARQUE authored on 2017-04-02
159
                    state.geometry.x += size(state.objects[line].text) * 10 + 8;
add window management
Sébastien MARQUE authored on 2017-03-28
160
            }
161
        }
changes about how to fill wi...
Sébastien MARQUE authored on 2017-04-02
162
        # reset the scrolling offset before the first move
163
        state.scroll.offset = 0;
add window management
Sébastien MARQUE authored on 2017-03-28
164
    },
165
    
changes about how to fill wi...
Sébastien MARQUE authored on 2017-04-02
166
    draw : func (id, geometry, objects, scroll = nil) {
add window management
Sébastien MARQUE authored on 2017-03-28
167
        if (contains(me.window, id ~ '-bg')) {
printlog deprecated + consta...
Sébastien MARQUE authored on 2020-04-24
168
            logprint(LOG_DEBUG, 'objet ' ~ id ~ ' already exists');
add window management
Sébastien MARQUE authored on 2017-03-28
169
            return;
170
        }
add auto config geometry for...
Sébastien MARQUE authored on 2020-04-30
171
        if (!contains(geometry, 'sep'))
172
            geometry.sep = 0;
173
        if (contains(geometry, 'autogeom') and geometry.autogeom) {
174
            # 1024x768 display
175
            # - let 10 from the border
176
            # - plus other 10 from the window border and the text
177
            # - font size tends to be 10x24
178
            # - let 8+8 around the separator
fix count of lines
Sébastien MARQUE authored on 2020-05-03
179
            var textWidth = 0;
add auto config geometry for...
Sébastien MARQUE authored on 2020-04-30
180
            var lines = 0;
fix count of lines
Sébastien MARQUE authored on 2020-05-03
181
            var _textWidth = 0;
add auto config geometry for...
Sébastien MARQUE authored on 2020-04-30
182
            forindex (var o; objects) {
fix count of lines
Sébastien MARQUE authored on 2020-05-03
183
                if (find('end-of-line', objects[o].type) > -1) {
improve autogeom
Sébastien MARQUE authored on 2020-05-02
184
                    if (scroll != nil and contains(scroll, 'lines')) {
fix count of lines
Sébastien MARQUE authored on 2020-05-03
185
                        if (contains(objects[o], 'scrollgroup')) {
improve autogeom
Sébastien MARQUE authored on 2020-05-02
186
                            if (objects[o].scrollgroup < scroll.lines)
187
                                lines += 1;
fix count of lines
Sébastien MARQUE authored on 2020-05-03
188
                            _textWidth += size(objects[o].text) * 10;
189
                            if (_textWidth > textWidth) textWidth = _textWidth;
190
                            _textWidth = 0;
191
                        }
192
                        else {
193
                            lines += 1;
194
                            _textWidth += size(objects[o].text) * 10;
195
                            if (_textWidth > textWidth) textWidth = _textWidth;
196
                            _textWidth = 0;
197
                        }
improve autogeom
Sébastien MARQUE authored on 2020-05-02
198
                    }
fix count of lines
Sébastien MARQUE authored on 2020-05-03
199
                    else {
improve autogeom
Sébastien MARQUE authored on 2020-05-02
200
                        lines += 1;
fix count of lines
Sébastien MARQUE authored on 2020-05-03
201
                        _textWidth += size(objects[o].text) * 10;
202
                        if (_textWidth > textWidth) textWidth = _textWidth;
203
                        _textWidth = 0;
204
                    }
add auto config geometry for...
Sébastien MARQUE authored on 2020-04-30
205
                }
fix count of lines
Sébastien MARQUE authored on 2020-05-03
206
                elsif (objects[o].type == 'title') {
207
                    lines += 1;
208
                    _textWidth = size(objects[o].text) * 10;
209
                    if (_textWidth > textWidth) textWidth = _textWidth;
210
                    _textWidth = 0;
211
                }
212
                elsif (objects[o].type != 'separator') {
213
                    _textWidth += size(objects[o].text) * 10;
214
                }
215

            
add auto config geometry for...
Sébastien MARQUE authored on 2020-04-30
216
                if (contains(objects[o], 'type') and objects[o].type == 'separator')
217
                    geometry.sep += 1;
218
            }
fix count of lines
Sébastien MARQUE authored on 2020-05-03
219
            if (!contains(geometry, 'l')) geometry.l = lines;
220
            if (!contains(geometry, 'x')) geometry.x = 1014 - textWidth;
221
            if (!contains(geometry, 'y')) geometry.y = 758 - (lines * 24) - 72; # 72 = offset from bottom to let softkeys display and margin
add auto config geometry for...
Sébastien MARQUE authored on 2020-04-30
222
            if (!contains(geometry, 'w')) geometry.w = textWidth;
223
        }
add window management
Sébastien MARQUE authored on 2017-03-28
224
        if (!contains(geometry, 'h') and !contains(geometry, 'l')) {
printlog deprecated + consta...
Sébastien MARQUE authored on 2020-04-24
225
            logprint(LOG_DEBUG, 'missing parameter l or h');
add window management
Sébastien MARQUE authored on 2017-03-28
226
            return;
227
        }
add auto config geometry for...
Sébastien MARQUE authored on 2020-04-30
228

            
fixes some bugs in windows
Sébastien MARQUE authored on 2017-04-12
229
        var save_x = geometry.x;
230
        var save_y = geometry.y;
add auto config geometry for...
Sébastien MARQUE authored on 2020-04-30
231
        if (!geometry.sep)
232
            geometry.sep = 1;
add window management
Sébastien MARQUE authored on 2017-03-28
233
        me.state[id] = {
changes about how to fill wi...
Sébastien MARQUE authored on 2017-04-02
234
            objects: objects,
add window management
Sébastien MARQUE authored on 2017-03-28
235
            geometry: geometry,
236
            x_base : geometry.x + 10,
237
            h_max : contains(geometry, 'h') ? h : geometry.l * 24 + 8 + geometry.sep * 16,
238
        };
add auto config geometry for...
Sébastien MARQUE authored on 2020-04-30
239

            
240
        logprint(LOG_DEBUG, sprintf('geom id: %s, x: %d, y: %d, w: %d, h: %d, l: %d, sep: %d',
241
                 id, geometry.x, geometry.y, geometry.w, me.state[id].h_max, geometry.l, geometry.sep));
add window management
Sébastien MARQUE authored on 2017-03-28
242
        me.state[id].y_max = me.state[id].h_max + me.state[id].geometry.y;
243
        me.window[id ~ '-bg'] = me.page.createChild('path');
244
        me.window[id ~ '-bg']
245
            .rect(geometry.x, geometry.y,
246
                  geometry.w, me.state[id].h_max)
247
            .setColor(1,1,1)
248
            .setColorFill(0,0,0);
249
        me.state[id].geometry.x += 10;
250
        me.state[id].geometry.y += 16;
changes about how to fill wi...
Sébastien MARQUE authored on 2017-04-02
251
        me.fill(id, scroll);
fixes some bugs in windows
Sébastien MARQUE authored on 2017-04-12
252
        geometry.x = save_x;
253
        geometry.y = save_y;
add window management
Sébastien MARQUE authored on 2017-03-28
254
    },
255
};