From 3a166263f92b0cffd8feba436aedb210122a2f5e Mon Sep 17 00:00:00 2001 From: oshmuely Date: Thu, 5 Oct 2023 12:02:47 +0300 Subject: [PATCH] model presets wizard: first version --- .../SCRIPTS/PRESETS/engine/lib_utils.lua | 62 ++----------------- .../SCRIPTS/PRESETS/engine/libgui.lua | 12 ++-- .../c480x272/SCRIPTS/PRESETS/engine/main.lua | 2 +- 3 files changed, 11 insertions(+), 65 deletions(-) diff --git a/sdcard/c480x272/SCRIPTS/PRESETS/engine/lib_utils.lua b/sdcard/c480x272/SCRIPTS/PRESETS/engine/lib_utils.lua index db07c20f..596af0ee 100644 --- a/sdcard/c480x272/SCRIPTS/PRESETS/engine/lib_utils.lua +++ b/sdcard/c480x272/SCRIPTS/PRESETS/engine/lib_utils.lua @@ -57,13 +57,13 @@ local function lcdSizeTextFixed(txt, font_size) elseif font_size == M.FONT_6 then v_offset = 0 end - return ts_w, ts_h, v_offset + return ts_w, ts_h +2*v_offset, v_offset end function M.drawBadgedText(txt, field, font_size, is_selected, is_edit) local ts_w, ts_h, v_offset = lcdSizeTextFixed(txt, font_size) - ts_h = 10 + ts_h + v_offset * 2 - local r = ts_h / 2 + local bdg_h = 5 + ts_h + 5 + local r = bdg_h / 2 if (field.w > 0) then ts_w = field.w @@ -78,7 +78,7 @@ function M.drawBadgedText(txt, field, font_size, is_selected, is_edit) end lcd.drawFilledCircle(field.x, field.y + r, r, bg_color) lcd.drawFilledCircle(field.x + ts_w, field.y + r, r, bg_color) - lcd.drawFilledRectangle(field.x, field.y, ts_w, ts_h, bg_color) + lcd.drawFilledRectangle(field.x, field.y, ts_w, bdg_h, bg_color) local attr = 0 if (is_selected and is_edit) then attr = attr + BLINK @@ -151,60 +151,6 @@ function M.readMeta(filename) return properties end ------------------------------------------------------------------ --- better font names -local FONT_38 = XXLSIZE -- 38px -local FONT_16 = DBLSIZE -- 16px -local FONT_12 = MIDSIZE -- 12px -local FONT_8 = 0 -- Default 8px -local FONT_6 = SMLSIZE -- 6px - -local function lcdSizeTextFixed(txt, font_size) - local ts_w, ts_h = lcd.sizeText(txt, font_size) - - local v_offset = 0 - if font_size == FONT_38 then - v_offset = -11 - elseif font_size == FONT_16 then - v_offset = -5 - elseif font_size == FONT_12 then - v_offset = -4 - elseif font_size == FONT_8 then - v_offset = -3 - elseif font_size == FONT_6 then - v_offset = 0 - end - return ts_w, ts_h, v_offset -end - - -local function drawBadgedText(txt, field, font_size, is_selected, is_edit) - local ts_w, ts_h, v_offset = lcdSizeTextFixed(txt, font_size) - ts_h = 10 + ts_h + v_offset * 2 - local r = ts_h / 2 - - if (field.w > 0) then - ts_w = field.w - else - if (ts_w < 30) then - ts_w = 30 - end - end - local bg_color = WHITE - if (is_selected) then - bg_color = GREEN - end - lcd.drawFilledCircle(field.x, field.y + r, r, bg_color) - lcd.drawFilledCircle(field.x + ts_w, field.y + r, r, bg_color) - lcd.drawFilledRectangle(field.x, field.y, ts_w, ts_h, bg_color) - local attr = 0 - if (is_selected and is_edit) then - attr = attr + BLINK - end - - lcd.drawText(field.x, field.y + v_offset + 5, txt, font_size + BLACK + attr) -end - -------------------------------------------------------------------- function M.input_search_by_name(neededInputName) diff --git a/sdcard/c480x272/SCRIPTS/PRESETS/engine/libgui.lua b/sdcard/c480x272/SCRIPTS/PRESETS/engine/libgui.lua index ff897c94..fff6d79e 100644 --- a/sdcard/c480x272/SCRIPTS/PRESETS/engine/libgui.lua +++ b/sdcard/c480x272/SCRIPTS/PRESETS/engine/libgui.lua @@ -127,17 +127,17 @@ function M.newGUI() local v_offset = 0 if font_size == M.FONT_SIZES.FONT_38 then - v_offset = -11 + v_offset = -15 elseif font_size == M.FONT_SIZES.FONT_16 then - v_offset = -5 + v_offset = -8 elseif font_size == M.FONT_SIZES.FONT_12 then - v_offset = -4 + v_offset = -6 elseif font_size == M.FONT_SIZES.FONT_8 then - v_offset = -3 + v_offset = -4 elseif font_size == M.FONT_SIZES.FONT_6 then - v_offset = 0 + v_offset = -3 end - return ts_w, ts_h, v_offset + return ts_w, ts_h +2*v_offset, v_offset end function gui.drawText(x, y, text, flags, inversColor) diff --git a/sdcard/c480x272/SCRIPTS/PRESETS/engine/main.lua b/sdcard/c480x272/SCRIPTS/PRESETS/engine/main.lua index 467d5ddb..36ec7c4c 100644 --- a/sdcard/c480x272/SCRIPTS/PRESETS/engine/main.lua +++ b/sdcard/c480x272/SCRIPTS/PRESETS/engine/main.lua @@ -251,7 +251,7 @@ local function state_PRESET_OPTIONS_INIT() end local function state_PRESET_OPTIONS(event, touchState) - log("state_PRESET_OPTIONS()") + --log("state_PRESET_OPTIONS()") if event == EVT_TOUCH_FIRST and (touchState.x <= 40 and touchState.y >= 100 and touchState.y <= 160) then print(string.format("(%s) %s - %s", page, touchState.x, touchState.y))