Skip to content

Commit

Permalink
Support focus font colors in VisImageTextButton (#394)
Browse files Browse the repository at this point in the history
  • Loading branch information
EtK2000 authored Jan 30, 2025
1 parent 966a285 commit 949e5f7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
1 change: 1 addition & 0 deletions ui/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#### 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

0 comments on commit 949e5f7

Please sign in to comment.