From e1957984e4a1c99c1f00aa30fb0eb122f717c716 Mon Sep 17 00:00:00 2001 From: MEEPofFaith <54301439+MEEPofFaith@users.noreply.github.com> Date: Tue, 9 Apr 2024 16:47:00 +0800 Subject: [PATCH] Pull button background updating and text button font color updating to separate methods Consistency with ImageButton image updating --- arc-core/src/arc/scene/ui/Button.java | 14 ++++++++++---- arc-core/src/arc/scene/ui/TextButton.java | 10 ++++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/arc-core/src/arc/scene/ui/Button.java b/arc-core/src/arc/scene/ui/Button.java index dcebdba5e..95b694cf9 100644 --- a/arc-core/src/arc/scene/ui/Button.java +++ b/arc-core/src/arc/scene/ui/Button.java @@ -206,10 +206,8 @@ public ButtonGroup getButtonGroup(){ return buttonGroup; } - @Override - public void draw(){ - validate(); - + /** Updates the background with the appropriate Drawable from the style before it is drawn. */ + public void updateBackground(){ boolean isDisabled = isDisabled(); boolean isPressed = isPressed(); boolean isChecked = isChecked(); @@ -228,6 +226,14 @@ else if(isOver && style.over != null){ background = style.up; setBackground(background); + } + + @Override + public void draw(){ + validate(); + + boolean isPressed = isPressed(); + updateBackground(); float offsetX, offsetY; if(isPressed && !isDisabled){ diff --git a/arc-core/src/arc/scene/ui/TextButton.java b/arc-core/src/arc/scene/ui/TextButton.java index 9a14012b2..278657aca 100644 --- a/arc-core/src/arc/scene/ui/TextButton.java +++ b/arc-core/src/arc/scene/ui/TextButton.java @@ -51,8 +51,9 @@ public void setStyle(ButtonStyle style){ } } - @Override - public void draw(){ + + /** Updates the font color with the appropriate font color from the style before it is drawn. */ + protected void updateFontColor(){ Color fontColor; if(isDisabled() && style.disabledFontColor != null) fontColor = style.disabledFontColor; @@ -65,6 +66,11 @@ else if(isOver() && style.overFontColor != null) else fontColor = style.fontColor; if(fontColor != null) label.getStyle().fontColor = fontColor; + } + + @Override + public void draw(){ + updateFontColor(); super.draw(); }