-
Notifications
You must be signed in to change notification settings - Fork 1
Hover Effect
Tarushi edited this page Aug 28, 2024
·
2 revisions
The addButtonElevationEffect
method adds a visual hover effect to a specified TextButton
. When the user hovers over the button, it slightly elevates and enlarges to indicate interactivity. When the cursor moves away, the button smoothly returns to its original size and position.
- It adds brilliance to the UI scheme.
- Improves the feedback interface for the user.
-
button
(TextButton
): The button to which the hover effect will be applied.
-
Hover Initialization: The button moves up by 5 pixels and scales up by 5% when the mouse cursor enters its area.
-
Hover Exit: The button moves back down to its original position and size when the cursor leaves the button area.
private void addButtonElevationEffect(TextButton button) {
button.addListener(new ClickListener() {
@Override
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
button.addAction(Actions.parallel(
Actions.moveBy(0, 5, 0.1f),
Actions.scaleTo(1.05f, 1.05f, 0.1f)
));
//logger.info("Hover feature activated"); uncomment this if you want to check hover feature
}
@Override
public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
button.addAction(Actions.parallel(
Actions.moveBy(0, -5, 0.1f),
Actions.scaleTo(1f, 1f, 0.1f)
));
}
});
}