From fbe4cb10ee0c3141137ebb8d62e5545e1659cf76 Mon Sep 17 00:00:00 2001 From: sulai <6741822+sulai@users.noreply.github.com> Date: Tue, 7 Jan 2025 21:48:36 +0100 Subject: [PATCH] correct alignment of text to icons (#12756) * correct alignment of text to icons * Add documentation to padTopDescent() --------- Co-authored-by: mrimvo <6030346+mrimvo@users.noreply.github.com> --- .../unciv/ui/components/tilegroups/CityButton.kt | 3 ++- core/src/com/unciv/ui/images/IconTextButton.kt | 13 ++++++++++--- .../screens/cityscreen/CityScreenCityPickerTable.kt | 5 +++-- .../ui/screens/mainmenuscreen/MainMenuScreen.kt | 2 ++ .../ui/screens/worldscreen/status/NextTurnButton.kt | 2 +- .../unciv/ui/screens/worldscreen/unit/UnitTable.kt | 3 ++- .../worldscreen/unit/actions/UnitActionsTable.kt | 1 + 7 files changed, 21 insertions(+), 8 deletions(-) diff --git a/core/src/com/unciv/ui/components/tilegroups/CityButton.kt b/core/src/com/unciv/ui/components/tilegroups/CityButton.kt index 9b27813286..89d95b648d 100644 --- a/core/src/com/unciv/ui/components/tilegroups/CityButton.kt +++ b/core/src/com/unciv/ui/components/tilegroups/CityButton.kt @@ -28,6 +28,7 @@ import com.unciv.ui.components.input.onClick import com.unciv.ui.components.input.onRightClick import com.unciv.ui.components.widgets.BorderedTable import com.unciv.ui.images.ImageGetter +import com.unciv.ui.images.padTopDescent import com.unciv.ui.popups.Popup import com.unciv.ui.screens.basescreen.BaseScreen import com.unciv.ui.screens.cityscreen.CityReligionInfoTable @@ -314,7 +315,7 @@ private class CityTable(city: City, forPopup: Boolean = false) : BorderedTable( } val cityName = city.name.toLabel(fontColor = textColor, alignment = Align.center, hideIcons = true) - table.add(cityName).growY().center() + table.add(cityName).growY().center().padTopDescent() if (!forPopup) { val cityReligion = city.religion.getMajorityReligion() diff --git a/core/src/com/unciv/ui/images/IconTextButton.kt b/core/src/com/unciv/ui/images/IconTextButton.kt index 9068f77a42..ba0f8e0ed6 100644 --- a/core/src/com/unciv/ui/images/IconTextButton.kt +++ b/core/src/com/unciv/ui/images/IconTextButton.kt @@ -10,8 +10,6 @@ import com.unciv.Constants import com.unciv.ui.components.fonts.Fonts import com.unciv.ui.components.extensions.toLabel import com.unciv.ui.screens.basescreen.BaseScreen -import kotlin.math.floor -import kotlin.math.ceil /** * Translate a [String] and make a [Button] widget from it, with control over font size, font colour, an optional icon, and custom formatting. @@ -44,6 +42,15 @@ open class IconTextButton( init { pad(10f) - labelCell.padTop(10f - Fonts.getDescenderHeight(fontSize)); + // aligned with icon + labelCell.padTopDescent() } } + +/** + * Intended for labels in tables that also contain icons, to ensure + * the label vertically aligns correctly to the icon, respecting the baseline of the text. + */ +fun Cell