-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace IconButtonMetrics with IconButtonStyle for effective theming
The existing metric defining approach, IconButtonMetrics, was restricting the theming of the IconButton component effectively. Thus, the 'IconButtonMetrics' was replaced by 'IconButtonStyle' and the necessary changes for the field change were implemented. This would assist in providing the same theme across different platforms. The 'IconButton' has been made theme-aware by allowing access to theme and style via properties. Changes were made in implementations concerning IntelliJTheme, BaseIntUiTheme, and ComponentShowcaseTab. File names were also appropriately renamed.
- Loading branch information
Showing
12 changed files
with
242 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package org.jetbrains.jewel | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.interaction.FocusInteraction | ||
import androidx.compose.foundation.interaction.HoverInteraction | ||
import androidx.compose.foundation.interaction.MutableInteractionSource | ||
import androidx.compose.foundation.interaction.PressInteraction | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.BoxScope | ||
import androidx.compose.foundation.layout.defaultMinSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.clip | ||
import androidx.compose.ui.semantics.Role | ||
import org.jetbrains.jewel.styling.IconButtonStyle | ||
|
||
@Composable | ||
fun IconButton( | ||
onClick: () -> Unit, | ||
modifier: Modifier = Modifier, | ||
enabled: Boolean = true, | ||
style: IconButtonStyle = IntelliJTheme.iconButtonStyle, | ||
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, | ||
content: @Composable (BoxScope.(ButtonState) -> Unit), | ||
) { | ||
var buttonState by remember(interactionSource) { | ||
mutableStateOf(ButtonState.of(enabled = enabled)) | ||
} | ||
|
||
remember(enabled) { | ||
buttonState = buttonState.copy(enabled = enabled) | ||
} | ||
|
||
LaunchedEffect(interactionSource) { | ||
interactionSource.interactions.collect { interaction -> | ||
when (interaction) { | ||
is PressInteraction.Press -> buttonState = buttonState.copy(pressed = true) | ||
is PressInteraction.Cancel, is PressInteraction.Release -> | ||
buttonState = | ||
buttonState.copy(pressed = false) | ||
|
||
is HoverInteraction.Enter -> buttonState = buttonState.copy(hovered = true) | ||
is HoverInteraction.Exit -> buttonState = buttonState.copy(hovered = false) | ||
is FocusInteraction.Focus -> buttonState = buttonState.copy(focused = true) | ||
is FocusInteraction.Unfocus -> buttonState = buttonState.copy(focused = false) | ||
} | ||
} | ||
} | ||
val shape = RoundedCornerShape(style.metrics.cornerSize) | ||
val background by style.colors.backgroundFor(buttonState) | ||
Box( | ||
modifier = modifier | ||
.defaultMinSize(style.metrics.minSize.width, style.metrics.minSize.height) | ||
.clickable( | ||
onClick = onClick, | ||
enabled = enabled, | ||
role = Role.Button, | ||
interactionSource = interactionSource, | ||
indication = NoIndication, | ||
) | ||
.clip(shape) | ||
.padding(style.metrics.padding) | ||
.background(background), | ||
propagateMinConstraints = true, | ||
contentAlignment = Alignment.Center, | ||
content = { | ||
content(buttonState) | ||
}, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.