Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support focus font colors in VisImageTextButton #394

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ui/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#### Version: 1.5.4-SNAPSHOT (libGDX 1.12.1)
- **Changed**: [#393](https://github.com/kotcrab/vis-ui/pull/393) - Removed use of Apple Java extensions in `FileUtils`
- **Added**: `VisImageTextButton` now supports focus font colors

#### Version: 1.5.3 (libGDX 1.12.1)
- Updated to libGDX 1.12.1
Expand Down
41 changes: 30 additions & 11 deletions ui/src/main/java/com/kotcrab/vis/ui/widget/VisImageTextButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.Null;
import com.badlogic.gdx.utils.Scaling;
import com.kotcrab.vis.ui.FocusManager;
import com.kotcrab.vis.ui.Focusable;
Expand Down Expand Up @@ -178,20 +179,38 @@ else if (style.imageUp != null)
}
}

/**
* Returns the appropriate label font color from the style based on the current button state.
* <p>
* Taken from LibGDX 1.13.0's {@link TextButton#getFontColor()}
**/
protected @Null Color getFontColor () {
if (isDisabled() && style.disabledFontColor != null) return style.disabledFontColor;
if (isPressed()) {
if (isChecked() && style.checkedDownFontColor != null) return style.checkedDownFontColor;
if (style.downFontColor != null) return style.downFontColor;
}
if (isOver()) {
if (isChecked()) {
if (style.checkedOverFontColor != null) return style.checkedOverFontColor;
} else {
if (style.overFontColor != null) return style.overFontColor;
}
}
boolean focused = hasKeyboardFocus();
if (isChecked()) {
if (focused && style.checkedFocusedFontColor != null) return style.checkedFocusedFontColor;
if (style.checkedFontColor != null) return style.checkedFontColor;
if (isOver() && style.overFontColor != null) return style.overFontColor;
}
if (focused && style.focusedFontColor != null) return style.focusedFontColor;
return style.fontColor;
}

@Override
public void draw (Batch batch, float parentAlpha) {
updateImage();
Color fontColor;
if (isDisabled() && style.disabledFontColor != null)
fontColor = style.disabledFontColor;
else if (isPressed() && style.downFontColor != null)
fontColor = style.downFontColor;
else if (isChecked() && style.checkedFontColor != null)
fontColor = (isOver() && style.checkedOverFontColor != null) ? style.checkedOverFontColor : style.checkedFontColor;
else if (isOver() && style.overFontColor != null)
fontColor = style.overFontColor;
else
fontColor = style.fontColor;
Color fontColor = getFontColor();
if (fontColor != null) label.getStyle().fontColor = fontColor;
super.draw(batch, parentAlpha);
if (focusBorderEnabled && drawBorder && style.focusBorder != null)
Expand Down