From 0d2d85d8d7a85ab162b724b20871c8cc5c9c3e9b Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Fri, 1 Dec 2023 20:07:20 -0800 Subject: [PATCH] activate buttons for some time The active state has 2 uses: * It gives some visual feedback that a button has been pressed. Otherwise, tapping a button gave no feedback that the tap had occurred. Particularly on a phone screen where fat-fingering is easier, hitting the 'save' button in particular gave no hint that the file had actually been saved. Which causes some anxiety. * It suppresses all mouse taps during the activation time. For example, this helps keep tapping say an overflow button from selecting text in the editor. --- 0004-on.update | 5 ++++- 0016-on.mouse_press | 2 ++ 0124-styled_button | 16 +++++++++++++--- 0147-Highlighted_button_color | 1 + 0148-Active_button | 3 +++ 5 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 0147-Highlighted_button_color create mode 100644 0148-Active_button diff --git a/0004-on.update b/0004-on.update index 386d3b7..4a7f7b3 100644 --- a/0004-on.update +++ b/0004-on.update @@ -1,5 +1,8 @@ on.update = function(dt) refresh_debug_animations() + if Active_button and Active_button.expire <= Current_time then + Active_button = nil + end if App.mouse_down(1) then update_any_sliders(App.mouse_x(), App.mouse_y()) end @@ -9,4 +12,4 @@ on.update = function(dt) adjust_scrollbar(Current_pane.output_editor_state, App.mouse_y()) end if car.update then call_protected(car.update, dt) end -end \ No newline at end of file +end diff --git a/0016-on.mouse_press b/0016-on.mouse_press index bd3d1b7..d267a80 100644 --- a/0016-on.mouse_press +++ b/0016-on.mouse_press @@ -1,4 +1,6 @@ on.mouse_press = function(x,y, mouse_button) + -- some hysteresis right after a button has been pressed + if Active_button then return end if mouse_press_consumed_by_any_button_handler(Global_state, x,y, mouse_button) then return end diff --git a/0124-styled_button b/0124-styled_button index 7b6d59e..51dd9c1 100644 --- a/0124-styled_button +++ b/0124-styled_button @@ -2,10 +2,20 @@ styled_button = function(name, x, y, onpress1) local w = App.width(name)+10 button(Global_state, name, {x=x, y=y, w=w, h=Line_height, bg={r=0.6, g=0.8, b=0.6}, icon = function(p) - App.color(Normal_color) + if Active_button and Active_button.name == name and Active_button.expire > Current_time then + App.color(Highlighted_button_color) + else + App.color(Normal_color) + end love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2) love.graphics.print(name, p.x+5,p.y+2) end, - onpress1 = onpress1, + onpress1 = function() + onpress1() + Active_button = { + name=name, + expire=Current_time+0.1, + } + end, }) -end \ No newline at end of file +end diff --git a/0147-Highlighted_button_color b/0147-Highlighted_button_color new file mode 100644 index 0000000..fa735ff --- /dev/null +++ b/0147-Highlighted_button_color @@ -0,0 +1 @@ +Highlighted_button_color = {r=1, g=1, b=1} \ No newline at end of file diff --git a/0148-Active_button b/0148-Active_button new file mode 100644 index 0000000..9d53eef --- /dev/null +++ b/0148-Active_button @@ -0,0 +1,3 @@ +Active_button = nil +-- When a button is pressed: +-- {name=..., expire=...} \ No newline at end of file