Showing 1 changed files with 54 additions and 23 deletions
+54 -23
Nasal/menu.nas
... ...
@@ -69,11 +69,22 @@ var pageClass = {
69 69
             .setColor(0,1,1);
70 70
     },
71 71
 
72
-    fill : func (id) {
72
+    fill : func (id, scroll = nil) {
73 73
         var state = me.state[id];
74
-        forindex (var line; state.lines) {
75
-            if (find('separator', state.lines[line].type) > -1) {
76
-                me.window[id ~ '-' ~ line] = me.page.createChild('path')
74
+        state.scroll = {
75
+            offset : 0,           # offset between canvas element and state element
76
+            last : 9999,          # last scrollgroup
77
+            begin: -9999,         # first canvas element of the scrolling area
78
+            end: 9999,            # last canvas element of the scrolling area
79
+            upper: -9999,         # group printed on the top of the scrolling area
80
+            lower: 9999,          # group printed at the bottom of the scrolling area
81
+            lines : scroll.lines, # number of lines for the scrolling area
82
+            columns : scroll.columns, # number of objects on each scrolling lines
83
+        };
84
+        var scrollgroup = {};
85
+        forindex (var line; state.objects) {
86
+            if (find('separator', state.objects[line].type) > -1) {
87
+                me.window[id ~ '-' ~ (line - state.scroll.offset)] = me.page.createChild('path')
77 88
                     .setStrokeLineWidth(1)
78 89
                     .moveTo(state.x_base, state.geometry.y - 12)
79 90
                     .horiz(state.geometry.w - 20)
... ...
@@ -82,51 +93,71 @@ var pageClass = {
82 93
                 state.geometry.y += 8;
83 94
             }
84 95
             else {
85
-                me.window[id ~ '-' ~ line] = me.page.createChild('text');
86
-                if (find('normal', state.lines[line].type) > -1)
96
+                if (contains(state.objects[line], 'scrollgroup')) {
97
+                    state.scroll.last = state.objects[line].scrollgroup;
98
+                    scrollgroup[state.objects[line].scrollgroup] = 1;
99
+                    if (state.scroll.begin == -9999) {
100
+                        state.scroll.begin = line;
101
+                        state.scroll.upper = state.objects[line].scrollgroup;
102
+                    }
103
+                    if (size(keys(scrollgroup)) > state.scroll.lines) {
104
+                        if (state.scroll.end == 9999) {
105
+                            state.scroll.end = line - 1;
106
+                            state.scroll.lower = state.objects[line - 1].scrollgroup;
107
+                        }
108
+                        else
109
+                            state.scroll.last = state.objects[line].scrollgroup;
110
+                        state.scroll.offset += 1;
111
+                        continue;
112
+                    }
113
+                }
114
+                me.window[id ~ '-' ~ (line - state.scroll.offset)] = me.page.createChild('text');
115
+                if (find('normal', state.objects[line].type) > -1)
87 116
                     me._normal_text(
88
-                            id ~ '-' ~ line,
89
-                            state.lines[line].text,
117
+                            id ~ '-' ~ (line - state.scroll.offset),
118
+                            state.objects[line].text,
90 119
                             state.geometry.x,
91 120
                             state.geometry.y,
92 121
                             );
93 122
 
94
-                elsif (find('selected', state.lines[line].type) > -1)
123
+                elsif (find('selected', state.objects[line].type) > -1)
95 124
                     me._selected_text(
96
-                            id ~ '-' ~ line,
97
-                            state.lines[line].text,
125
+                            id ~ '-' ~ (line - state.scroll.offset),
126
+                            state.objects[line].text,
98 127
                             state.geometry.x,
99 128
                             state.geometry.y,
100 129
                             );
101 130
 
102
-                elsif (find('editable', state.lines[line].type) > -1)
131
+                elsif (find('editable', state.objects[line].type) > -1)
103 132
                     me._editable_text(
104
-                            id ~ '-' ~ line,
105
-                            state.lines[line].text,
133
+                            id ~ '-' ~ (line - state.scroll.offset),
134
+                            state.objects[line].text,
106 135
                             state.geometry.x,
107 136
                             state.geometry.y,
108 137
                             );
109 138
 
110
-                elsif (find('title', state.lines[line].type) > -1)
139
+                elsif (find('title', state.objects[line].type) > -1)
111 140
                     me._title_text(
112
-                            id ~ '-' ~ line,
113
-                            state.lines[line].text,
141
+                            id ~ '-' ~ (line - state.scroll.offset),
142
+                            state.objects[line].text,
114 143
                             state.x_base - 10 + state.geometry.w / 2,
115 144
                             state.geometry.y
116 145
                         );
117 146
 
118
-                if (find('end-of-line', state.lines[line].type) > -1
119
-                or  find('title', state.lines[line].type) > -1) {
147
+                if (find('end-of-line', state.objects[line].type) > -1
148
+                or  find('title', state.objects[line].type) > -1) {
120 149
                     state.geometry.x = state.x_base;
121 150
                     state.geometry.y += 24;
122 151
                 }
123 152
                 else
124
-                    state.geometry.x += size(state.lines[line].text) * 10 + 8;
153
+                    state.geometry.x += size(state.objects[line].text) * 10 + 8;
125 154
             }
126 155
         }
156
+        # reset the scrolling offset before the first move
157
+        state.scroll.offset = 0;
127 158
     },
128 159
     
129
-    draw : func (id, geometry, lines) {
160
+    draw : func (id, geometry, objects, scroll = nil) {
130 161
         if (contains(me.window, id ~ '-bg')) {
131 162
             printlog('debug', 'objet ' ~ id ~ ' already exists');
132 163
             return;
... ...
@@ -136,7 +167,7 @@ var pageClass = {
136 167
             return;
137 168
         }
138 169
         me.state[id] = {
139
-            lines: lines, 
170
+            objects: objects,
140 171
             geometry: geometry,
141 172
             x_base : geometry.x + 10,
142 173
             h_max : contains(geometry, 'h') ? h : geometry.l * 24 + 8 + geometry.sep * 16,
... ...
@@ -150,6 +181,6 @@ var pageClass = {
150 181
             .setColorFill(0,0,0);
151 182
         me.state[id].geometry.x += 10;
152 183
         me.state[id].geometry.y += 16;
153
-        me.fill(id);
184
+        me.fill(id, scroll);
154 185
     },
155 186
 };