From f5c703a8b352d2eb7bb7f8d53a862dd54861033a Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Thu, 28 Jul 2022 11:42:22 -0400 Subject: [PATCH] fixed push button touch redraw --- graphics/elements/controls/push_button.lua | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/graphics/elements/controls/push_button.lua b/graphics/elements/controls/push_button.lua index 5e2bf4d..227b8e0 100644 --- a/graphics/elements/controls/push_button.lua +++ b/graphics/elements/controls/push_button.lua @@ -37,9 +37,14 @@ local function push_button(args) local h_pad = math.floor((e.frame.w - text_width) / 2) + 1 local v_pad = math.floor(e.frame.h / 2) + 1 - -- write the button text - e.window.setCursorPos(h_pad, v_pad) - e.window.write(args.text) + -- draw the button + local function draw() + e.window.clear() + + -- write the button text + e.window.setCursorPos(h_pad, v_pad) + e.window.write(args.text) + end -- handle touch ---@param event monitor_touch monitor touch event @@ -49,13 +54,13 @@ local function push_button(args) -- show as pressed e.window.setTextColor(args.active_fg_bg.fgd) e.window.setBackgroundColor(args.active_fg_bg.bkg) - e.window.redraw() + draw() - -- show as unpressed in 0.5 seconds - tcd.dispatch(0.5, function () + -- show as unpressed in 0.25 seconds + tcd.dispatch(0.25, function () e.window.setTextColor(e.fg_bg.fgd) e.window.setBackgroundColor(e.fg_bg.bkg) - e.window.redraw() + draw() end) end @@ -63,6 +68,9 @@ local function push_button(args) args.callback() end + -- initial draw + draw() + return e.get() end