Fix ColorMarkupLabel prefSize (#9077)

This commit is contained in:
SomeTroglodyte 2023-03-31 13:48:30 +02:00 committed by GitHub
parent 2d184655c7
commit ce495d4ff2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,6 +3,7 @@
package com.unciv.ui.components package com.unciv.ui.components
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.GlyphLayout
import com.badlogic.gdx.scenes.scene2d.ui.Label import com.badlogic.gdx.scenes.scene2d.ui.Label
import com.unciv.Constants import com.unciv.Constants
import com.unciv.models.translations.tr import com.unciv.models.translations.tr
@ -33,8 +34,6 @@ class ColorMarkupLabel private constructor(
fontSize: Int = Constants.defaultFontSize) fontSize: Int = Constants.defaultFontSize)
: this (fontSize, prepareText(text, textColor, symbolColor)) : this (fontSize, prepareText(text, textColor, symbolColor))
private val originalMarkupEnabled: Boolean
init { init {
if (fontSize != Constants.defaultFontSize) { if (fontSize != Constants.defaultFontSize) {
val labelStyle = LabelStyle(style) // clone otherwise all default-styled Labels affected val labelStyle = LabelStyle(style) // clone otherwise all default-styled Labels affected
@ -42,15 +41,22 @@ class ColorMarkupLabel private constructor(
style.font = Fonts.font style.font = Fonts.font
setFontScale(fontSize / Fonts.ORIGINAL_FONT_SIZE) setFontScale(fontSize / Fonts.ORIGINAL_FONT_SIZE)
} }
originalMarkupEnabled = style.font.data.markupEnabled
} }
override fun layout() { override fun layout() {
val originalMarkupEnabled = style.font.data.markupEnabled
style.font.data.markupEnabled = true style.font.data.markupEnabled = true
super.layout() super.layout()
style.font.data.markupEnabled = originalMarkupEnabled style.font.data.markupEnabled = originalMarkupEnabled
} }
override fun computePrefSize(layout: GlyphLayout?) {
val originalMarkupEnabled = style.font.data.markupEnabled
style.font.data.markupEnabled = true
super.computePrefSize(layout)
style.font.data.markupEnabled = originalMarkupEnabled
}
companion object { companion object {
private fun mapMarkup(text: String): String { private fun mapMarkup(text: String): String {
val translated = text.tr() val translated = text.tr()