summaryrefslogtreecommitdiff
path: root/apps/plugins/stopwatch.lua
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2012-01-29 21:56:08 +0100
committerThomas Martitz <kugel@rockbox.org>2012-01-29 22:35:49 +0100
commita489a6be8a483aa206cfb6b7d6b1edac1be93291 (patch)
tree8ef30bb11781e42abd7273ade50cf77fa7821da9 /apps/plugins/stopwatch.lua
parent7728ff5912aebe2b21a3c0ca0d8624ec97dabdb6 (diff)
downloadrockbox-a489a6be8a483aa206cfb6b7d6b1edac1be93291.tar.gz
rockbox-a489a6be8a483aa206cfb6b7d6b1edac1be93291.zip
stopwatch.lua: Improve button layout. Enable on touchscreen RaaA.
Change-Id: Iae3b9e80cbec60856689b1c12aabfd26c85e3d96
Diffstat (limited to 'apps/plugins/stopwatch.lua')
-rw-r--r--apps/plugins/stopwatch.lua72
1 files changed, 32 insertions, 40 deletions
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
245function arrangeButtons(btns) 245function 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
295LapsView:init() 285LapsView:init()
296 286
287local third = rb.LCD_WIDTH/3
288
297local btns = { 289local 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
305arrangeButtons(btns) 297arrangeButtons(btns)