From a489a6be8a483aa206cfb6b7d6b1edac1be93291 Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Sun, 29 Jan 2012 21:56:08 +0100 Subject: stopwatch.lua: Improve button layout. Enable on touchscreen RaaA. Change-Id: Iae3b9e80cbec60856689b1c12aabfd26c85e3d96 --- apps/plugins/SOURCES.app_build | 1 + apps/plugins/stopwatch.lua | 72 +++++++++++++++++++----------------------- 2 files changed, 33 insertions(+), 40 deletions(-) (limited to 'apps/plugins') 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 vbrfix.c #if PLUGIN_BUFFER_SIZE >= 0x80000 boomshine.lua +stopwatch.lua #endif 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) 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) -- cgit v1.2.3