Skip to content

Commit 8ddb6e4

Browse files
committed
Open button_* functions to call a button callbacks directly
1 parent b982bc8 commit 8ddb6e4

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

druid/base/button.lua

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ function M:init(node_or_node_id, callback, custom_args, anim_node)
6767
self.start_scale = gui.get_scale(self.anim_node)
6868
self.start_pos = gui.get_position(self.anim_node)
6969
self.params = custom_args
70-
self.hover = self.druid:new_hover(node_or_node_id, self._on_button_hover)
71-
self.hover.on_mouse_hover:subscribe(self._on_button_mouse_hover)
70+
self.hover = self.druid:new_hover(node_or_node_id, self.button_hover)
71+
self.hover.on_mouse_hover:subscribe(self.button_mouse_hover)
7272
self.click_zone = nil
7373
self.is_repeated_started = false
7474
self.last_pressed_time = 0
@@ -184,7 +184,7 @@ function M:on_input(action_id, action)
184184
if self._is_html5_mode then
185185
self._is_html5_listener_set = true
186186
html5.set_interaction_listener(function()
187-
self:_on_button_click()
187+
self:button_click()
188188
end)
189189
end
190190
return is_consume
@@ -193,7 +193,7 @@ function M:on_input(action_id, action)
193193
-- While hold button, repeat rate pick from input.repeat_interval
194194
if action.repeated then
195195
if not self.on_repeated_click:is_empty() and self.can_action then
196-
self:_on_button_repeated_click()
196+
self:button_repeated_click()
197197
return is_consume
198198
end
199199
end
@@ -211,7 +211,7 @@ function M:on_input(action_id, action)
211211
end
212212

213213
if press_time >= self.style.LONGTAP_TIME then
214-
self:_on_button_hold(press_time)
214+
self:button_hold(press_time)
215215
return is_consume
216216
end
217217
end
@@ -326,18 +326,18 @@ end
326326

327327

328328
---@param hover_state boolean True if the hover state is active
329-
function M:_on_button_hover(hover_state)
329+
function M:button_hover(hover_state)
330330
self.style.on_hover(self, self.anim_node, hover_state)
331331
end
332332

333333

334334
---@param hover_state boolean True if the hover state is active
335-
function M:_on_button_mouse_hover(hover_state)
335+
function M:button_mouse_hover(hover_state)
336336
self.style.on_mouse_hover(self, self.anim_node, hover_state)
337337
end
338338

339339

340-
function M:_on_button_click()
340+
function M:button_click()
341341
if self._is_html5_mode then
342342
self._is_html5_listener_set = false
343343
html5.set_interaction_listener(nil)
@@ -348,7 +348,7 @@ function M:_on_button_click()
348348
end
349349

350350

351-
function M:_on_button_repeated_click()
351+
function M:button_repeated_click()
352352
if not self.is_repeated_started then
353353
self.click_in_row = 0
354354
self.is_repeated_started = true
@@ -360,23 +360,23 @@ function M:_on_button_repeated_click()
360360
end
361361

362362

363-
function M:_on_button_long_click()
363+
function M:button_long_click()
364364
self.click_in_row = 1
365365
local time = socket.gettime() - self.last_pressed_time
366366
self.on_long_click:trigger(self:get_context(), self.params, self, time)
367367
self.style.on_click(self, self.anim_node)
368368
end
369369

370370

371-
function M:_on_button_double_click()
371+
function M:button_double_click()
372372
self.click_in_row = self.click_in_row + 1
373373
self.on_double_click:trigger(self:get_context(), self.params, self, self.click_in_row)
374374
self.style.on_click(self, self.anim_node)
375375
end
376376

377377

378378
---@param press_time number Amount of time the button was held
379-
function M:_on_button_hold(press_time)
379+
function M:button_hold(press_time)
380380
self.on_hold_callback:trigger(self:get_context(), self.params, self, press_time)
381381
end
382382

@@ -413,14 +413,14 @@ function M:_on_button_release()
413413
if is_long_click then
414414
local is_hold_complete = (time - self.last_pressed_time) >= self.style.AUTOHOLD_TRIGGER
415415
if is_hold_complete then
416-
self:_on_button_long_click()
416+
self:button_long_click()
417417
else
418418
self.on_click_outside:trigger(self:get_context(), self.params, self)
419419
end
420420
elseif is_double_click then
421-
self:_on_button_double_click()
421+
self:button_double_click()
422422
else
423-
self:_on_button_click()
423+
self:button_click()
424424
end
425425

426426
self.last_released_time = time

0 commit comments

Comments
 (0)