Skip to content

Commit

Permalink
Merge pull request #571 from Shallowmallow/Button-repeater-action
Browse files Browse the repository at this point in the history
Button repeater action
  • Loading branch information
ianharrigan authored Jan 22, 2024
2 parents 8aa4673 + 755203a commit cac69ee
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
7 changes: 6 additions & 1 deletion haxe/ui/actions/ActionManager.hx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ class ActionManager {
if (actionEvent.canceled == false) {
dispatch(new ActionEvent(ActionEvent.ACTION_START, action, false, Type.getClassName(Type.getClass(source))));
}
if (actionEvent.repeater == true && _repeatActions.exists(action) == false) {
if (actionEvent.repeater == true) {
if (_repeatActions.exists(action)) {
var info = _repeatActions.get(action);
info.timer.stop();
_repeatActions.remove(action);
}
_repeatActions.set(action, {
type: action,
timer: new Timer(c.actionRepeatInterval, function() { // TODO: 100ms should probably be configurable
Expand Down
14 changes: 14 additions & 0 deletions haxe/ui/components/Button.hx
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,20 @@ class ButtonEvents extends haxe.ui.events.Events {
private function onActionStart(event:ActionEvent) {
switch (event.action) {
case ActionType.PRESS | ActionType.CONFIRM:
if (_button.repeater == true) {
if (_repeatInterval == 0) {
_repeatInterval = (_button.easeInRepeater) ? _button.repeatInterval * 2 : _button.repeatInterval;
}
_button.actionRepeatInterval = _repeatInterval;
event.repeater = true;
}
press();
if (_button.repeater == true) {
_button.dispatch(new MouseEvent(MouseEvent.CLICK));
if ( _repeatInterval > _button.repeatInterval) {
_repeatInterval = Std.int(_repeatInterval - (_repeatInterval - _button.repeatInterval) / 2);
}
}
case _:
}
}
Expand All @@ -671,6 +684,7 @@ class ButtonEvents extends haxe.ui.events.Events {
switch (event.action) {
case ActionType.PRESS | ActionType.CONFIRM:
release();
_repeatInterval = 0;
case _:
}
}
Expand Down

0 comments on commit cac69ee

Please sign in to comment.