Skip to content

Commit 1d7fc7e

Browse files
committed
[ui] fix scaling when copying checkbox icons
When the JBCachingScalableIcon is copied for scaling, the initial scale value must be propagated from the source icon via JBScalableIcon#updateContextFrom. CheckboxIcon.WithColor did not have a constructor that accepts the source icon, so copied instances could end up with an incorrect size. This commit adds a constructor to CheckboxIcon.WithColor that takes source icon and allows to properly preserve the scale. IJPL-225566
1 parent 969e989 commit 1d7fc7e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

platform/platform-api/src/com/intellij/util/ui/CheckboxIcon.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ object CheckboxIcon {
4646
get() = if (ExperimentalUI.isNewUI()) 4 else 0
4747

4848

49-
class WithColor(private val size: Int, color: Color, arc: Int) : ColorIcon(size, size, size, size, color, false, arc) {
49+
class WithColor : ColorIcon {
5050
private var mySizedIcon: SizedIcon
5151

52-
init {
52+
constructor(size: Int, color: Color, arc: Int) : super(size, size, size, size, color, false, arc) {
5353
val icon = if (ExperimentalUI.isNewUI()) {
5454
IconUtil.resizeSquared(LafIconLookup.getIcon("checkmark", true), checkMarkSize)
5555
}
@@ -59,6 +59,10 @@ object CheckboxIcon {
5959
mySizedIcon = SizedIcon(icon, checkMarkSize, checkMarkSize)
6060
}
6161

62+
constructor(icon: WithColor) : super(icon) {
63+
mySizedIcon = icon.mySizedIcon.copy()
64+
}
65+
6266
override fun withIconPreScaled(preScaled: Boolean): WithColor {
6367
mySizedIcon = mySizedIcon.withIconPreScaled(preScaled) as SizedIcon
6468
return super.withIconPreScaled(preScaled) as WithColor
@@ -72,7 +76,7 @@ object CheckboxIcon {
7276
}
7377

7478
override fun copy(): ColorIcon {
75-
return WithColor(size, iconColor, arcSize)
79+
return WithColor(this)
7680
}
7781
}
7882
}

0 commit comments

Comments
 (0)