Skip to content

Commit

Permalink
model presets wizard: first version
Browse files Browse the repository at this point in the history
  • Loading branch information
oshmuely authored and oshmuely committed Oct 5, 2023
1 parent 5960243 commit 3a16626
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 65 deletions.
62 changes: 4 additions & 58 deletions sdcard/c480x272/SCRIPTS/PRESETS/engine/lib_utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions sdcard/c480x272/SCRIPTS/PRESETS/engine/libgui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion sdcard/c480x272/SCRIPTS/PRESETS/engine/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 3a16626

Please sign in to comment.