diff options
| author | Thomas Martitz <kugel@rockbox.org> | 2012-01-29 21:56:08 +0100 |
|---|---|---|
| committer | Thomas Martitz <kugel@rockbox.org> | 2012-01-29 22:35:49 +0100 |
| commit | a489a6be8a483aa206cfb6b7d6b1edac1be93291 (patch) | |
| tree | 8ef30bb11781e42abd7273ade50cf77fa7821da9 /apps/plugins/stopwatch.lua | |
| parent | 7728ff5912aebe2b21a3c0ca0d8624ec97dabdb6 (diff) | |
| download | rockbox-a489a6be8a483aa206cfb6b7d6b1edac1be93291.zip rockbox-a489a6be8a483aa206cfb6b7d6b1edac1be93291.tar.gz rockbox-a489a6be8a483aa206cfb6b7d6b1edac1be93291.tar.bz2 rockbox-a489a6be8a483aa206cfb6b7d6b1edac1be93291.tar.xz | |
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.lua | 72 |
1 files changed, 32 insertions, 40 deletions
diff --git a/apps/plugins/stopwatch.lua b/apps/plugins/stopwatch.lua index 87773e3..578ba7f 100644 --- a/apps/plugins/stopwatch.lua +++ b/apps/plugins/stopwatch.lua @@ -180,7 +180,7 @@ function Button:new(o) if o.label then local _, w, h = rb.font_getstringsize(o.label, LapsView.vp.font) - o.width = 5 * w / 4 + o.width = math.max(5 * w / 4,o.width) o.height = 3 * h / 2 end @@ -244,46 +244,36 @@ end function arrangeButtons(btns) local totalWidth, totalHeight, maxWidth, maxHeight, vp = 0, 0, 0, 0 - for _, btn in pairs(btns) do - totalWidth = totalWidth + btn.width - totalHeight = totalHeight + btn.height - maxHeight = math.max(maxHeight, btn.height) - maxWidth = math.max(maxWidth, btn.width) - end + local width, row = 0, 0 + local items, num_rows - if totalWidth <= rb.LCD_WIDTH then - local temp = 0 - for _, btn in pairs(btns) do - btn.y = rb.LCD_HEIGHT - maxHeight - btn.x = temp + for i, btn in pairs(btns) do + maxHeight = math.max(maxHeight, btn.height) + totalWidth = totalWidth + btn.width + items = i + end - temp = temp + btn.width - end + for _, btn in pairs(btns) do + btn.height = maxHeight + end - vp = { - x = 0, - y = 0, - width = rb.LCD_WIDTH, - height = rb.LCD_HEIGHT - maxHeight - } - elseif totalHeight <= rb.LCD_HEIGHT then - local temp = 0 - for _, btn in pairs(btns) do - btn.x = rb.LCD_WIDTH - maxWidth - btn.y = temp + num_rows = totalWidth / rb.LCD_WIDTH - temp = temp + btn.height + for _, btn in pairs(btns) do + btn.x = width + btn.y = rb.LCD_HEIGHT - ((num_rows - row) * maxHeight) + width = width + btn.width + if (width > rb.LCD_WIDTH - 5) then -- 5 is rounding margin + width = 0 + row = row+1 end - - vp = { - x = 0, - y = 0, - width = rb.LCD_WIDTH - maxWidth, - height = rb.LCD_HEIGHT - } - else - error("Can't arrange the buttons according to your screen's resolution!") end + vp = { + x = 0, + y = 0, + width = rb.LCD_WIDTH, + height = rb.LCD_HEIGHT - num_rows*maxHeight - 2 + } for k, v in pairs(vp) do LapsView.vp[k] = v @@ -294,12 +284,14 @@ rb.touchscreen_set_mode(rb.TOUCHSCREEN_POINT) LapsView:init() +local third = rb.LCD_WIDTH/3 + local btns = { - Button:new({name = "startTimer", label = "Start"}), - Button:new({name = "stopTimer", label = "Stop"}), - Button:new({name = "newLap", label = "New Lap"}), - Button:new({name = "resetTimer", label = "Reset"}), - Button:new({name = "exitApp", label = "Quit"}) + Button:new({name = "startTimer", label = "Start", width = third}), + Button:new({name = "stopTimer", label = "Stop", width = third}), + Button:new({name = "resetTimer", label = "Reset", width = rb.LCD_WIDTH-third*2}), -- correct rounding error + Button:new({name = "newLap", label = "New Lap", width = third*2}), + Button:new({name = "exitApp", label = "Quit", width = rb.LCD_WIDTH-third*2}) -- correct rounding error } arrangeButtons(btns) |