mirror of
https://github.com/yairm210/Unciv.git
synced 2025-03-15 04:14:44 +07:00
Fix images not being able to have their size set (#6887)
* Fix images not being able to have their size set * Small corrections `> 0f` to include `-0f`
This commit is contained in:
parent
3e95e3f152
commit
a128ea0d59
@ -162,11 +162,11 @@ object ImageGetter {
|
||||
// loading screen and Tutorial.WorldScreen quite a bit. More anisotropy barely helps.
|
||||
val texture = Texture("ExtraImages/$fileName")
|
||||
texture.setFilter(TextureFilter.Linear, TextureFilter.Linear)
|
||||
return Image(TextureRegion(texture))
|
||||
return ImageWithCustomSize(TextureRegion(texture))
|
||||
}
|
||||
|
||||
fun getImage(fileName: String?): Image {
|
||||
return Image(getDrawable(fileName))
|
||||
return ImageWithCustomSize(getDrawable(fileName))
|
||||
}
|
||||
|
||||
fun getDrawable(fileName: String?): TextureRegionDrawable {
|
||||
|
38
core/src/com/unciv/ui/images/ImageWithCustomSize.kt
Normal file
38
core/src/com/unciv/ui/images/ImageWithCustomSize.kt
Normal file
@ -0,0 +1,38 @@
|
||||
package com.unciv.ui.images
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Image
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.Drawable
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable
|
||||
|
||||
/**
|
||||
* Either [Image] or [com.badlogic.gdx.scenes.scene2d.utils.Drawable] is badly written, as the [Image.drawable] always has its texture width/height
|
||||
* as min width/height, and [Image.getPrefWidth]/Height is always equal to its [Image.drawable]'s minWidth/Height.
|
||||
*
|
||||
* This results in an [Image.getPrefWidth]/Height call to completely ignore the width/height that was set by [setSize]. To fix this, this class provides a
|
||||
* custom implementation of [getPrefWidth] and [getPrefHeight].
|
||||
*/
|
||||
class ImageWithCustomSize(drawable: Drawable) : Image(drawable) {
|
||||
|
||||
constructor(region: TextureRegion) : this(TextureRegionDrawable(region))
|
||||
|
||||
override fun getPrefWidth(): Float {
|
||||
return if (width > 0f) {
|
||||
width
|
||||
} else if (drawable != null) {
|
||||
drawable.minWidth
|
||||
} else {
|
||||
0f
|
||||
}
|
||||
}
|
||||
|
||||
override fun getPrefHeight(): Float {
|
||||
return if (height > 0f) {
|
||||
height
|
||||
} else if (drawable != null) {
|
||||
drawable.minHeight
|
||||
} else {
|
||||
0f
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user