Skip to content

Commit

Permalink
Update button styling in IntUiDarkTheme
Browse files Browse the repository at this point in the history
The IntUiDarkTheme now uses different colors for the "pressed" and "hovered" states of a button. Additionally, the background color selection logic has been refactored in IconButtonMetrics.kt to use a simpler and more readable 'when' construct.
  • Loading branch information
fscarponi committed Oct 11, 2023
1 parent 4e71f81 commit 46fc1bf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions core/src/main/kotlin/org/jetbrains/jewel/IconButton.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fun IconButton(
}
}
val shape = RoundedCornerShape(style.metrics.cornerSize)
val background = style.colors.backgroundFor(buttonState)
val backgroundColor by style.colors.backgroundFor(buttonState)
Box(
modifier = modifier
.defaultMinSize(style.metrics.minSize.width, style.metrics.minSize.height)
Expand All @@ -70,7 +70,7 @@ fun IconButton(
)
.clip(shape)
.padding(style.metrics.padding)
.background(background.value),
.background(backgroundColor),
propagateMinConstraints = true,
contentAlignment = Alignment.Center,
content = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@ interface IconButtonColors {

@Composable
fun backgroundFor(state: ButtonState) = rememberUpdatedState(
state.chooseValue(
normal = background,
disabled = backgroundDisabled,
focused = backgroundFocused,
pressed = backgroundPressed,
hovered = backgroundHovered,
active = background,
),
when {
!state.isEnabled -> backgroundDisabled
state.isPressed -> backgroundPressed
state.isHovered -> backgroundHovered
state.isFocused -> backgroundFocused
else -> background
}
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.compose.runtime.Stable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import org.jetbrains.jewel.intui.core.theme.IntUiDarkTheme
import org.jetbrains.jewel.intui.core.theme.IntUiLightTheme
import org.jetbrains.jewel.styling.IconButtonColors
import org.jetbrains.jewel.styling.IconButtonMetrics
Expand Down Expand Up @@ -61,8 +62,8 @@ data class IntUiIconButtonColors(
background: Color = Color.Unspecified,
backgroundDisabled: Color = Color.Unspecified,
backgroundFocused: Color = background,
backgroundPressed: Color = IntUiLightTheme.colors.grey(12),
backgroundHovered: Color = IntUiLightTheme.colors.grey(11),
backgroundPressed: Color = IntUiDarkTheme.colors.grey(5),
backgroundHovered: Color = IntUiDarkTheme.colors.grey(3),
) =
IntUiIconButtonColors(
background,
Expand Down

0 comments on commit 46fc1bf

Please sign in to comment.