zkv1000 / Nasal / menu.nas /
Newer Older
233 lines | 9.342kb
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
179
            var textWidth = 200;
180
            var lines = 0;
181
            forindex (var o; objects) {
182
                if (contains(objects[o], 'text')) {
improve autogeom
Sébastien MARQUE authored on 2020-05-02
183
                    if (scroll != nil and contains(scroll, 'lines')) {
184
                        if (contains(objects[o], 'scrollgroup'))
185
                            if (objects[o].scrollgroup < scroll.lines)
186
                                lines += 1;
187
                    }
188
                    else
189
                        lines += 1;
add auto config geometry for...
Sébastien MARQUE authored on 2020-04-30
190
                    var l = size(objects[o].text) * 10;
191
                    if (l > textWidth)
192
                        textWidth = l;
193
                }
194
                if (contains(objects[o], 'type') and objects[o].type == 'separator')
195
                    geometry.sep += 1;
196
            }
improve autogeom
Sébastien MARQUE authored on 2020-05-02
197
            if (!contains(geometry, 'l')) geometry.l  = lines;
198
            if (!contains(geometry, 'x')) geometry.x  = 1014 - textWidth;
199
            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
200
            if (!contains(geometry, 'w')) geometry.w = textWidth;
201
        }
add window management
Sébastien MARQUE authored on 2017-03-28
202
        if (!contains(geometry, 'h') and !contains(geometry, 'l')) {
printlog deprecated + consta...
Sébastien MARQUE authored on 2020-04-24
203
            logprint(LOG_DEBUG, 'missing parameter l or h');
add window management
Sébastien MARQUE authored on 2017-03-28
204
            return;
205
        }
add auto config geometry for...
Sébastien MARQUE authored on 2020-04-30
206

            
fixes some bugs in windows
Sébastien MARQUE authored on 2017-04-12
207
        var save_x = geometry.x;
208
        var save_y = geometry.y;
add auto config geometry for...
Sébastien MARQUE authored on 2020-04-30
209
        if (!geometry.sep)
210
            geometry.sep = 1;
add window management
Sébastien MARQUE authored on 2017-03-28
211
        me.state[id] = {
changes about how to fill wi...
Sébastien MARQUE authored on 2017-04-02
212
            objects: objects,
add window management
Sébastien MARQUE authored on 2017-03-28
213
            geometry: geometry,
214
            x_base : geometry.x + 10,
215
            h_max : contains(geometry, 'h') ? h : geometry.l * 24 + 8 + geometry.sep * 16,
216
        };
add auto config geometry for...
Sébastien MARQUE authored on 2020-04-30
217

            
218
        logprint(LOG_DEBUG, sprintf('geom id: %s, x: %d, y: %d, w: %d, h: %d, l: %d, sep: %d',
219
                 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
220
        me.state[id].y_max = me.state[id].h_max + me.state[id].geometry.y;
221
        me.window[id ~ '-bg'] = me.page.createChild('path');
222
        me.window[id ~ '-bg']
223
            .rect(geometry.x, geometry.y,
224
                  geometry.w, me.state[id].h_max)
225
            .setColor(1,1,1)
226
            .setColorFill(0,0,0);
227
        me.state[id].geometry.x += 10;
228
        me.state[id].geometry.y += 16;
changes about how to fill wi...
Sébastien MARQUE authored on 2017-04-02
229
        me.fill(id, scroll);
fixes some bugs in windows
Sébastien MARQUE authored on 2017-04-12
230
        geometry.x = save_x;
231
        geometry.y = save_y;
add window management
Sébastien MARQUE authored on 2017-03-28
232
    },
233
};