Skip to content

Commit

Permalink
Fix Scrollbars [part 12/n]
Browse files Browse the repository at this point in the history
* Remove debug bg from Scrollbars sample
* Fix thumb appearing/disappearing animation
* Fix colour animations
* Keep AlwaysVisible thumb "hovered" while dragging
* Fix styling in the bridge
  • Loading branch information
rock3r committed Aug 22, 2024
1 parent b2b782b commit b5c5341
Show file tree
Hide file tree
Showing 8 changed files with 397 additions and 463 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,19 @@ public fun retrieveColor(
default: Color,
): Color = retrieveColorOrNull(key) ?: default

public fun retrieveColor(
key: String,
isDark: Boolean,
default: Color,
defaultDark: Color,
): Color = retrieveColorOrNull(key) ?: if (isDark) defaultDark else default

public fun retrieveColorOrNull(key: String): Color? = JBColor.namedColorOrNull(key)?.toComposeColor()

public fun retrieveColorOrUnspecified(key: String): Color {
val color = retrieveColorOrNull(key)
if (color == null) {
logger.warn("Color with key \"$key\" not found, fallback to 'Color.Unspecified'")
logger.debug("Color with key \"$key\" not found, fallback to 'Color.Unspecified'")
}
return color ?: Color.Unspecified
}
Expand Down Expand Up @@ -98,9 +105,8 @@ public fun retrieveInsetsAsPaddingValues(
): PaddingValues = UIManager.getInsets(key)?.toPaddingValues() ?: default ?: keyNotFound(key, "Insets")

/**
* Converts a [Insets] to [PaddingValues]. If the receiver is a [JBInsets]
* instance, this function delegates to the specific [toPaddingValues] for
* it, which is scaling-aware.
* Converts a [Insets] to [PaddingValues]. If the receiver is a [JBInsets] instance, this function delegates to the
* specific [toPaddingValues] for it, which is scaling-aware.
*/
public fun Insets.toPaddingValues(): PaddingValues =
if (this is JBInsets) {
Expand All @@ -110,26 +116,22 @@ public fun Insets.toPaddingValues(): PaddingValues =
}

/**
* Converts a [JBInsets] to [PaddingValues], in a scaling-aware way. This
* means that the resulting [PaddingValues] will be constructed from the
* [JBInsets.getUnscaled] values, treated as [Dp]. This avoids double
* scaling.
* Converts a [JBInsets] to [PaddingValues], in a scaling-aware way. This means that the resulting [PaddingValues] will
* be constructed from the [JBInsets.getUnscaled] values, treated as [Dp]. This avoids double scaling.
*/
@Suppress("ktlint:standard:function-signature") // False positive
public fun JBInsets.toPaddingValues(): PaddingValues =
PaddingValues(unscaled.left.dp, unscaled.top.dp, unscaled.right.dp, unscaled.bottom.dp)

/**
* Converts a [Dimension] to [DpSize]. If the receiver is a [JBDimension]
* instance, this function delegates to the specific [toDpSize] for it,
* which is scaling-aware.
* Converts a [Dimension] to [DpSize]. If the receiver is a [JBDimension] instance, this function delegates to the
* specific [toDpSize] for it, which is scaling-aware.
*/
public fun Dimension.toDpSize(): DpSize = if (this is JBDimension) toDpSize() else DpSize(width.dp, height.dp)

/**
* Converts a [JBDimension] to [DpSize], in a scaling-aware way. This means
* that the resulting [DpSize] will be constructed by first obtaining the
* unscaled values. This avoids double scaling.
* Converts a [JBDimension] to [DpSize], in a scaling-aware way. This means that the resulting [DpSize] will be
* constructed by first obtaining the unscaled values. This avoids double scaling.
*/
public fun JBDimension.toDpSize(): DpSize {
val scaleFactor = scale(1f)
Expand Down Expand Up @@ -182,7 +184,8 @@ public fun retrieveTextStyle(
val jbFont = JBFont.create(lafFont, false)

val derivedFont =
jbFont.let { if (bold) it.asBold() else it.asPlain() }
jbFont
.let { if (bold) it.asBold() else it.asPlain() }
.let { if (fontStyle == FontStyle.Italic) it.asItalic() else it }

return TextStyle(
Expand Down
Loading

0 comments on commit b5c5341

Please sign in to comment.