Modifying a JBInset

I have a use case where I need to zero out the left and right internal padding of a SimpleColoredComponent

In order to make it scale safe it looks like I need to make a new JBInset from the existing ipad since JBInsets looks like it needs to be treated as immutable and that new instance needs unscaled values.

The only way I found to make this work seems clunky due to JBInsets.unscale and JBInsets.unwrap (which is the same implementation as unscale) are both internal only.

Only way I found to do this is

            return SimpleColoredComponent().apply {
                setMyBorder(null)
                setIpad(JBInsets.create(JBInsets.create(ipad).unscaled.top, 0))
            }

Am I overthinking this, or is this the correct way to do it?

Would it be possible to make JBInsets.unscalepublic?

You’re doing it right, except that you use the top value for both top and bottom insets.

The only catch is that if that top (and bottom if you decide to use it as well) inset is updated due to a theme change, then your new object won’t react to that. But I don’t see any way around that in the current implementation (other than override updateUI and update the insets manually).

We’d like to avoid exposing all that unscale stuff because it’s really an implementation detail (though partially exposed already) and because of that update-on-theme-change stuff.

Ideally, we’d need withLeft, withRight etc. functions that would override some values while keeping the others scaled and synchronized with the theme. But as it’s not a very common case, nobody bothered to implement that yet.

1 Like

Thx for confirming the path is correct, I’ll keep it eye out if the withers are ever added