libgdx/libgdx

Textbutton over-offset

harofax opened this issue · 1 comments

Sorry if this is the wrong place, but couldn't find anywhere else. Saw that there was a label for feature requests so here I go;

It would be nice (and probably not too big a hurdle maybe?) to have an offset for when a TextButton is hovered, similar to how there's one for pressed, checked, unpressed.

Looking through the source, checks using the isPressed() methods, then sets offset according to the button style. There is a isOver() method as well, so I was surprised when I didn't find a over-offset.

It was easy enough to work around but I feel like it would fit in with the other offset options.

Again if this is the wrong place, feel free to delete this, and I apologize in advance.

I think this is reasonable. It would go in Button.ButtonStyle (not TextButtonStyle). The logic in Button#draw becomes:

float offsetX = style.unpressedOffsetX, offsetY = style.unpressedOffsetY;
if (!isDisabled()) {
	if (isPressed()) {
		offsetX = style.pressedOffsetX;
		offsetY = style.pressedOffsetY;
	} else if (isChecked()) {
		offsetX = style.checkedOffsetX;
		offsetY = style.checkedOffsetY;
	} else if (isOver()) {
		offsetX = style.overOffsetX;
		offsetY = style.overOffsetY;
	}
}

This has a subtle difference: if not pressed and not checked, you get the over offset rather than the unpressed offset. That makes this a breaking change for apps that don't use 0 for unpressed offset. 0 for that is common, but the potential is there.

If everybody else is OK with that, I think it's OK.