diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/plugins/SOURCES.app_build | 1 | ||||
-rw-r--r-- | apps/plugins/stopwatch.lua | 72 |
2 files changed, 33 insertions, 40 deletions
diff --git a/apps/plugins/SOURCES.app_build b/apps/plugins/SOURCES.app_build index a416c3b171..c4866f4ab3 100644 --- a/apps/plugins/SOURCES.app_build +++ b/apps/plugins/SOURCES.app_build | |||
@@ -13,6 +13,7 @@ theme_remove.c | |||
13 | vbrfix.c | 13 | vbrfix.c |
14 | #if PLUGIN_BUFFER_SIZE >= 0x80000 | 14 | #if PLUGIN_BUFFER_SIZE >= 0x80000 |
15 | boomshine.lua | 15 | boomshine.lua |
16 | stopwatch.lua | ||
16 | #endif | 17 | #endif |
17 | 18 | ||
18 | 19 | ||
diff --git a/apps/plugins/stopwatch.lua b/apps/plugins/stopwatch.lua index 87773e32cb..578ba7f42c 100644 --- a/apps/plugins/stopwatch.lua +++ b/apps/plugins/stopwatch.lua | |||
@@ -180,7 +180,7 @@ function Button:new(o) | |||
180 | 180 | ||
181 | if o.label then | 181 | if o.label then |
182 | local _, w, h = rb.font_getstringsize(o.label, LapsView.vp.font) | 182 | local _, w, h = rb.font_getstringsize(o.label, LapsView.vp.font) |
183 | o.width = 5 * w / 4 | 183 | o.width = math.max(5 * w / 4,o.width) |
184 | o.height = 3 * h / 2 | 184 | o.height = 3 * h / 2 |
185 | end | 185 | end |
186 | 186 | ||
@@ -244,46 +244,36 @@ end | |||
244 | 244 | ||
245 | function arrangeButtons(btns) | 245 | function arrangeButtons(btns) |
246 | local totalWidth, totalHeight, maxWidth, maxHeight, vp = 0, 0, 0, 0 | 246 | local totalWidth, totalHeight, maxWidth, maxHeight, vp = 0, 0, 0, 0 |
247 | for _, btn in pairs(btns) do | 247 | local width, row = 0, 0 |
248 | totalWidth = totalWidth + btn.width | 248 | local items, num_rows |
249 | totalHeight = totalHeight + btn.height | ||
250 | maxHeight = math.max(maxHeight, btn.height) | ||
251 | maxWidth = math.max(maxWidth, btn.width) | ||
252 | end | ||
253 | 249 | ||
254 | if totalWidth <= rb.LCD_WIDTH then | 250 | for i, btn in pairs(btns) do |
255 | local temp = 0 | 251 | maxHeight = math.max(maxHeight, btn.height) |
256 | for _, btn in pairs(btns) do | 252 | totalWidth = totalWidth + btn.width |
257 | btn.y = rb.LCD_HEIGHT - maxHeight | 253 | items = i |
258 | btn.x = temp | 254 | end |
259 | 255 | ||
260 | temp = temp + btn.width | 256 | for _, btn in pairs(btns) do |
261 | end | 257 | btn.height = maxHeight |
258 | end | ||
262 | 259 | ||
263 | vp = { | 260 | num_rows = totalWidth / rb.LCD_WIDTH |
264 | x = 0, | ||
265 | y = 0, | ||
266 | width = rb.LCD_WIDTH, | ||
267 | height = rb.LCD_HEIGHT - maxHeight | ||
268 | } | ||
269 | elseif totalHeight <= rb.LCD_HEIGHT then | ||
270 | local temp = 0 | ||
271 | for _, btn in pairs(btns) do | ||
272 | btn.x = rb.LCD_WIDTH - maxWidth | ||
273 | btn.y = temp | ||
274 | 261 | ||
275 | temp = temp + btn.height | 262 | for _, btn in pairs(btns) do |
263 | btn.x = width | ||
264 | btn.y = rb.LCD_HEIGHT - ((num_rows - row) * maxHeight) | ||
265 | width = width + btn.width | ||
266 | if (width > rb.LCD_WIDTH - 5) then -- 5 is rounding margin | ||
267 | width = 0 | ||
268 | row = row+1 | ||
276 | end | 269 | end |
277 | |||
278 | vp = { | ||
279 | x = 0, | ||
280 | y = 0, | ||
281 | width = rb.LCD_WIDTH - maxWidth, | ||
282 | height = rb.LCD_HEIGHT | ||
283 | } | ||
284 | else | ||
285 | error("Can't arrange the buttons according to your screen's resolution!") | ||
286 | end | 270 | end |
271 | vp = { | ||
272 | x = 0, | ||
273 | y = 0, | ||
274 | width = rb.LCD_WIDTH, | ||
275 | height = rb.LCD_HEIGHT - num_rows*maxHeight - 2 | ||
276 | } | ||
287 | 277 | ||
288 | for k, v in pairs(vp) do | 278 | for k, v in pairs(vp) do |
289 | LapsView.vp[k] = v | 279 | LapsView.vp[k] = v |
@@ -294,12 +284,14 @@ rb.touchscreen_set_mode(rb.TOUCHSCREEN_POINT) | |||
294 | 284 | ||
295 | LapsView:init() | 285 | LapsView:init() |
296 | 286 | ||
287 | local third = rb.LCD_WIDTH/3 | ||
288 | |||
297 | local btns = { | 289 | local btns = { |
298 | Button:new({name = "startTimer", label = "Start"}), | 290 | Button:new({name = "startTimer", label = "Start", width = third}), |
299 | Button:new({name = "stopTimer", label = "Stop"}), | 291 | Button:new({name = "stopTimer", label = "Stop", width = third}), |
300 | Button:new({name = "newLap", label = "New Lap"}), | 292 | Button:new({name = "resetTimer", label = "Reset", width = rb.LCD_WIDTH-third*2}), -- correct rounding error |
301 | Button:new({name = "resetTimer", label = "Reset"}), | 293 | Button:new({name = "newLap", label = "New Lap", width = third*2}), |
302 | Button:new({name = "exitApp", label = "Quit"}) | 294 | Button:new({name = "exitApp", label = "Quit", width = rb.LCD_WIDTH-third*2}) -- correct rounding error |
303 | } | 295 | } |
304 | 296 | ||
305 | arrangeButtons(btns) | 297 | arrangeButtons(btns) |