diff --git a/ui/api/ui.api b/ui/api/ui.api index b1f12bd84..58dba44b9 100644 --- a/ui/api/ui.api +++ b/ui/api/ui.api @@ -309,12 +309,10 @@ public final class org/jetbrains/jewel/ui/component/GroupHeaderKt { public final class org/jetbrains/jewel/ui/component/IconActionButtonKt { public static final fun IconActionButton (Landroidx/compose/ui/graphics/painter/Painter;Ljava/lang/String;Lkotlin/jvm/functions/Function0;Landroidx/compose/ui/Modifier;ZZLorg/jetbrains/jewel/ui/component/styling/IconButtonStyle;Landroidx/compose/foundation/interaction/MutableInteractionSource;Landroidx/compose/runtime/Composer;II)V public static final fun IconActionButton (Landroidx/compose/ui/graphics/painter/Painter;Ljava/lang/String;Lkotlin/jvm/functions/Function0;Landroidx/compose/ui/Modifier;ZZLorg/jetbrains/jewel/ui/component/styling/IconButtonStyle;Lorg/jetbrains/jewel/ui/component/styling/TooltipStyle;Landroidx/compose/ui/Modifier;Landroidx/compose/foundation/TooltipPlacement;Landroidx/compose/foundation/interaction/MutableInteractionSource;Lkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;III)V - public static final fun IconActionButton (Lorg/jetbrains/jewel/ui/icon/IconKey;Ljava/lang/String;Lkotlin/jvm/functions/Function0;Landroidx/compose/ui/Modifier;ZZLorg/jetbrains/jewel/ui/component/styling/IconButtonStyle;[Lorg/jetbrains/jewel/ui/painter/PainterHint;Landroidx/compose/foundation/interaction/MutableInteractionSource;Ljava/lang/Class;Landroidx/compose/runtime/Composer;II)V - public static final fun IconActionButton (Lorg/jetbrains/jewel/ui/icon/IconKey;Ljava/lang/String;Lkotlin/jvm/functions/Function0;Landroidx/compose/ui/Modifier;ZZLorg/jetbrains/jewel/ui/component/styling/IconButtonStyle;[Lorg/jetbrains/jewel/ui/painter/PainterHint;Lorg/jetbrains/jewel/ui/component/styling/TooltipStyle;Landroidx/compose/ui/Modifier;Landroidx/compose/foundation/TooltipPlacement;Landroidx/compose/foundation/interaction/MutableInteractionSource;Ljava/lang/Class;Lkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;III)V - public static final fun SelectableIconActionButton (Lorg/jetbrains/jewel/ui/icon/IconKey;Ljava/lang/String;ZLkotlin/jvm/functions/Function0;Landroidx/compose/ui/Modifier;ZZLorg/jetbrains/jewel/ui/component/styling/IconButtonStyle;[Lorg/jetbrains/jewel/ui/painter/PainterHint;Landroidx/compose/foundation/interaction/MutableInteractionSource;Ljava/lang/Class;Landroidx/compose/runtime/Composer;III)V - public static final fun SelectableIconActionButton (Lorg/jetbrains/jewel/ui/icon/IconKey;Ljava/lang/String;ZLkotlin/jvm/functions/Function0;Landroidx/compose/ui/Modifier;ZZLorg/jetbrains/jewel/ui/component/styling/IconButtonStyle;[Lorg/jetbrains/jewel/ui/painter/PainterHint;Lorg/jetbrains/jewel/ui/component/styling/TooltipStyle;Landroidx/compose/ui/Modifier;Landroidx/compose/foundation/TooltipPlacement;Landroidx/compose/foundation/interaction/MutableInteractionSource;Ljava/lang/Class;Lkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;III)V - public static final fun ToggleableIconActionButton (Lorg/jetbrains/jewel/ui/icon/IconKey;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;Landroidx/compose/ui/Modifier;ZZLorg/jetbrains/jewel/ui/component/styling/IconButtonStyle;[Lorg/jetbrains/jewel/ui/painter/PainterHint;Landroidx/compose/foundation/interaction/MutableInteractionSource;Ljava/lang/Class;Landroidx/compose/runtime/Composer;III)V - public static final fun ToggleableIconActionButton (Lorg/jetbrains/jewel/ui/icon/IconKey;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;Landroidx/compose/ui/Modifier;ZZLorg/jetbrains/jewel/ui/component/styling/IconButtonStyle;[Lorg/jetbrains/jewel/ui/painter/PainterHint;Lorg/jetbrains/jewel/ui/component/styling/TooltipStyle;Landroidx/compose/ui/Modifier;Landroidx/compose/foundation/TooltipPlacement;Landroidx/compose/foundation/interaction/MutableInteractionSource;Ljava/lang/Class;Lkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;III)V + public static final fun IconActionButton (Lorg/jetbrains/jewel/ui/icon/IconKey;Ljava/lang/String;Lkotlin/jvm/functions/Function0;Landroidx/compose/ui/Modifier;ZZLorg/jetbrains/jewel/ui/component/styling/IconButtonStyle;Landroidx/compose/ui/graphics/ColorFilter;Lorg/jetbrains/jewel/ui/painter/PainterHint;Landroidx/compose/foundation/interaction/MutableInteractionSource;Ljava/lang/Class;Landroidx/compose/runtime/Composer;III)V + public static final fun IconActionButton (Lorg/jetbrains/jewel/ui/icon/IconKey;Ljava/lang/String;Lkotlin/jvm/functions/Function0;Landroidx/compose/ui/Modifier;ZZLorg/jetbrains/jewel/ui/component/styling/IconButtonStyle;Landroidx/compose/ui/graphics/ColorFilter;Lorg/jetbrains/jewel/ui/painter/PainterHint;Lorg/jetbrains/jewel/ui/component/styling/TooltipStyle;Landroidx/compose/ui/Modifier;Landroidx/compose/foundation/TooltipPlacement;Landroidx/compose/foundation/interaction/MutableInteractionSource;Ljava/lang/Class;Lkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;III)V + public static final fun IconActionButton (Lorg/jetbrains/jewel/ui/icon/IconKey;Ljava/lang/String;[Lorg/jetbrains/jewel/ui/painter/PainterHint;Lkotlin/jvm/functions/Function0;Landroidx/compose/ui/Modifier;ZZLorg/jetbrains/jewel/ui/component/styling/IconButtonStyle;Landroidx/compose/ui/graphics/ColorFilter;Landroidx/compose/foundation/interaction/MutableInteractionSource;Ljava/lang/Class;Landroidx/compose/runtime/Composer;III)V + public static final fun IconActionButton (Lorg/jetbrains/jewel/ui/icon/IconKey;Ljava/lang/String;[Lorg/jetbrains/jewel/ui/painter/PainterHint;Lkotlin/jvm/functions/Function0;Landroidx/compose/ui/Modifier;ZZLorg/jetbrains/jewel/ui/component/styling/IconButtonStyle;Landroidx/compose/ui/graphics/ColorFilter;Lorg/jetbrains/jewel/ui/component/styling/TooltipStyle;Landroidx/compose/ui/Modifier;Landroidx/compose/foundation/TooltipPlacement;Landroidx/compose/foundation/interaction/MutableInteractionSource;Ljava/lang/Class;Lkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;III)V } public final class org/jetbrains/jewel/ui/component/IconButtonKt { @@ -680,6 +678,13 @@ public final class org/jetbrains/jewel/ui/component/SegmentedControlState$Compan public static synthetic fun of-bhrFvog$default (Lorg/jetbrains/jewel/ui/component/SegmentedControlState$Companion;ZZZZZILjava/lang/Object;)J } +public final class org/jetbrains/jewel/ui/component/SelectableIconActionButtonKt { + public static final fun SelectableIconActionButton (Lorg/jetbrains/jewel/ui/icon/IconKey;Ljava/lang/String;ZLkotlin/jvm/functions/Function0;Landroidx/compose/ui/Modifier;ZZLorg/jetbrains/jewel/ui/component/styling/IconButtonStyle;Landroidx/compose/ui/graphics/ColorFilter;Lorg/jetbrains/jewel/ui/painter/PainterHint;Landroidx/compose/foundation/interaction/MutableInteractionSource;Ljava/lang/Class;Landroidx/compose/runtime/Composer;III)V + public static final fun SelectableIconActionButton (Lorg/jetbrains/jewel/ui/icon/IconKey;Ljava/lang/String;ZLkotlin/jvm/functions/Function0;Landroidx/compose/ui/Modifier;ZZLorg/jetbrains/jewel/ui/component/styling/IconButtonStyle;Landroidx/compose/ui/graphics/ColorFilter;Lorg/jetbrains/jewel/ui/painter/PainterHint;Lorg/jetbrains/jewel/ui/component/styling/TooltipStyle;Landroidx/compose/ui/Modifier;Landroidx/compose/foundation/TooltipPlacement;Landroidx/compose/foundation/interaction/MutableInteractionSource;Ljava/lang/Class;Lkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;III)V + public static final fun SelectableIconActionButton (Lorg/jetbrains/jewel/ui/icon/IconKey;Ljava/lang/String;Z[Lorg/jetbrains/jewel/ui/painter/PainterHint;Lkotlin/jvm/functions/Function0;Landroidx/compose/ui/Modifier;ZZLorg/jetbrains/jewel/ui/component/styling/IconButtonStyle;Landroidx/compose/ui/graphics/ColorFilter;Landroidx/compose/foundation/interaction/MutableInteractionSource;Ljava/lang/Class;Landroidx/compose/runtime/Composer;III)V + public static final fun SelectableIconActionButton (Lorg/jetbrains/jewel/ui/icon/IconKey;Ljava/lang/String;Z[Lorg/jetbrains/jewel/ui/painter/PainterHint;Lkotlin/jvm/functions/Function0;Landroidx/compose/ui/Modifier;ZZLorg/jetbrains/jewel/ui/component/styling/IconButtonStyle;Landroidx/compose/ui/graphics/ColorFilter;Lorg/jetbrains/jewel/ui/component/styling/TooltipStyle;Landroidx/compose/ui/Modifier;Landroidx/compose/foundation/TooltipPlacement;Landroidx/compose/foundation/interaction/MutableInteractionSource;Ljava/lang/Class;Lkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;III)V +} + public final class org/jetbrains/jewel/ui/component/SelectableIconButtonState : org/jetbrains/jewel/foundation/state/FocusableComponentState, org/jetbrains/jewel/foundation/state/SelectableComponentState { public static final field Companion Lorg/jetbrains/jewel/ui/component/SelectableIconButtonState$Companion; public static final synthetic fun box-impl (J)Lorg/jetbrains/jewel/ui/component/SelectableIconButtonState; @@ -911,6 +916,13 @@ public final class org/jetbrains/jewel/ui/component/TextKt { public static final fun Text-bAzTDeA (Ljava/lang/String;Landroidx/compose/ui/Modifier;JJLandroidx/compose/ui/text/font/FontStyle;Landroidx/compose/ui/text/font/FontWeight;Landroidx/compose/ui/text/font/FontFamily;JLandroidx/compose/ui/text/style/TextDecoration;IJIZILkotlin/jvm/functions/Function1;Landroidx/compose/ui/text/TextStyle;Landroidx/compose/runtime/Composer;III)V } +public final class org/jetbrains/jewel/ui/component/ToggleableIconActionButtonKt { + public static final fun ToggleableIconActionButton (Lorg/jetbrains/jewel/ui/icon/IconKey;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;Landroidx/compose/ui/Modifier;ZZLorg/jetbrains/jewel/ui/component/styling/IconButtonStyle;Landroidx/compose/ui/graphics/ColorFilter;Lorg/jetbrains/jewel/ui/painter/PainterHint;Landroidx/compose/foundation/interaction/MutableInteractionSource;Ljava/lang/Class;Landroidx/compose/runtime/Composer;III)V + public static final fun ToggleableIconActionButton (Lorg/jetbrains/jewel/ui/icon/IconKey;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;Landroidx/compose/ui/Modifier;ZZLorg/jetbrains/jewel/ui/component/styling/IconButtonStyle;Landroidx/compose/ui/graphics/ColorFilter;Lorg/jetbrains/jewel/ui/painter/PainterHint;Lorg/jetbrains/jewel/ui/component/styling/TooltipStyle;Landroidx/compose/ui/Modifier;Landroidx/compose/foundation/TooltipPlacement;Landroidx/compose/foundation/interaction/MutableInteractionSource;Ljava/lang/Class;Lkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;III)V + public static final fun ToggleableIconActionButton (Lorg/jetbrains/jewel/ui/icon/IconKey;Ljava/lang/String;Z[Lorg/jetbrains/jewel/ui/painter/PainterHint;Lkotlin/jvm/functions/Function1;Landroidx/compose/ui/Modifier;ZZLorg/jetbrains/jewel/ui/component/styling/IconButtonStyle;Landroidx/compose/ui/graphics/ColorFilter;Landroidx/compose/foundation/interaction/MutableInteractionSource;Ljava/lang/Class;Landroidx/compose/runtime/Composer;III)V + public static final fun ToggleableIconActionButton (Lorg/jetbrains/jewel/ui/icon/IconKey;Ljava/lang/String;Z[Lorg/jetbrains/jewel/ui/painter/PainterHint;Lkotlin/jvm/functions/Function1;Landroidx/compose/ui/Modifier;ZZLorg/jetbrains/jewel/ui/component/styling/IconButtonStyle;Landroidx/compose/ui/graphics/ColorFilter;Lorg/jetbrains/jewel/ui/component/styling/TooltipStyle;Landroidx/compose/ui/Modifier;Landroidx/compose/foundation/TooltipPlacement;Landroidx/compose/foundation/interaction/MutableInteractionSource;Ljava/lang/Class;Lkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;III)V +} + public final class org/jetbrains/jewel/ui/component/ToggleableIconButtonState : org/jetbrains/jewel/foundation/state/FocusableComponentState, org/jetbrains/jewel/foundation/state/ToggleableComponentState { public static final field Companion Lorg/jetbrains/jewel/ui/component/ToggleableIconButtonState$Companion; public static final synthetic fun box-impl (J)Lorg/jetbrains/jewel/ui/component/ToggleableIconButtonState; diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/IconActionButton.kt b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/IconActionButton.kt index 3ba4b27e4..fc2b02657 100644 --- a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/IconActionButton.kt +++ b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/IconActionButton.kt @@ -18,9 +18,9 @@ package org.jetbrains.jewel.ui.component import androidx.compose.foundation.TooltipPlacement import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue import androidx.compose.runtime.remember import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.ColorFilter import androidx.compose.ui.graphics.painter.Painter import androidx.compose.ui.unit.DpOffset import androidx.compose.ui.unit.dp @@ -29,7 +29,6 @@ import org.jetbrains.jewel.ui.component.styling.IconButtonStyle import org.jetbrains.jewel.ui.component.styling.TooltipStyle import org.jetbrains.jewel.ui.icon.IconKey import org.jetbrains.jewel.ui.painter.PainterHint -import org.jetbrains.jewel.ui.painter.hints.Stroke import org.jetbrains.jewel.ui.theme.iconButtonStyle import org.jetbrains.jewel.ui.theme.tooltipStyle @@ -42,21 +41,23 @@ public fun IconActionButton( enabled: Boolean = true, focusable: Boolean = true, style: IconButtonStyle = JewelTheme.iconButtonStyle, - hints: Array = emptyArray(), + colorFilter: ColorFilter? = null, + hint: PainterHint? = null, interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, iconClass: Class<*> = key::class.java, ) { - CoreIconActionButton( - key, - contentDescription, - iconClass, - enabled, - focusable, - style, - interactionSource, - modifier, - hints = hints, - onClick, + BaseIconActionButton( + key = key, + contentDescription = contentDescription, + iconClass = iconClass, + enabled = enabled, + focusable = focusable, + style = style, + interactionSource = interactionSource, + modifier = modifier, + colorFilter = colorFilter, + hint = hint, + onClick = onClick, ) } @@ -69,7 +70,8 @@ public fun IconActionButton( enabled: Boolean = true, focusable: Boolean = true, style: IconButtonStyle = JewelTheme.iconButtonStyle, - hints: Array = emptyArray(), + colorFilter: ColorFilter? = null, + hint: PainterHint? = null, tooltipStyle: TooltipStyle = JewelTheme.tooltipStyle, tooltipModifier: Modifier = Modifier, tooltipPlacement: TooltipPlacement = FixedCursorPoint(offset = DpOffset(0.dp, 16.dp)), @@ -78,79 +80,62 @@ public fun IconActionButton( tooltip: @Composable () -> Unit, ) { Tooltip(tooltip, style = tooltipStyle, modifier = tooltipModifier, tooltipPlacement = tooltipPlacement) { - CoreIconActionButton( + BaseIconActionButton( key = key, - modifier = modifier, contentDescription = contentDescription, iconClass = iconClass, enabled = enabled, focusable = focusable, style = style, interactionSource = interactionSource, - hints = hints, + modifier = modifier, + colorFilter = colorFilter, + hint = hint, onClick = onClick, ) } } @Composable -private fun CoreIconActionButton( +public fun IconActionButton( key: IconKey, contentDescription: String?, - iconClass: Class<*>, - enabled: Boolean, - focusable: Boolean, - style: IconButtonStyle, - interactionSource: MutableInteractionSource, - modifier: Modifier, hints: Array, onClick: () -> Unit, -) { - IconButton(onClick, modifier, enabled, focusable, style, interactionSource) { - Icon(key, contentDescription, iconClass = iconClass, hints = hints) - } -} - -@Composable -public fun SelectableIconActionButton( - key: IconKey, - contentDescription: String?, - selected: Boolean, - onClick: () -> Unit, modifier: Modifier = Modifier, enabled: Boolean = true, focusable: Boolean = true, style: IconButtonStyle = JewelTheme.iconButtonStyle, - extraHints: Array = emptyArray(), + colorFilter: ColorFilter? = null, interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, iconClass: Class<*> = key::class.java, ) { - CoreSelectableIconActionButton( - key, - contentDescription, - iconClass, - selected, - enabled, - focusable, - style, - interactionSource, - modifier, - extraHints, - onClick, + CoreIconActionButton( + key = key, + contentDescription = contentDescription, + iconClass = iconClass, + enabled = enabled, + focusable = focusable, + style = style, + interactionSource = interactionSource, + modifier = modifier, + colorFilter = colorFilter, + hints = hints, + onClick = onClick, ) } @Composable -public fun SelectableIconActionButton( +public fun IconActionButton( key: IconKey, contentDescription: String?, - selected: Boolean, + hints: Array, onClick: () -> Unit, modifier: Modifier = Modifier, enabled: Boolean = true, focusable: Boolean = true, style: IconButtonStyle = JewelTheme.iconButtonStyle, - extraHints: Array = emptyArray(), + colorFilter: ColorFilter? = null, tooltipStyle: TooltipStyle = JewelTheme.tooltipStyle, tooltipModifier: Modifier = Modifier, tooltipPlacement: TooltipPlacement = FixedCursorPoint(offset = DpOffset(0.dp, 16.dp)), @@ -159,123 +144,102 @@ public fun SelectableIconActionButton( tooltip: @Composable () -> Unit, ) { Tooltip(tooltip, style = tooltipStyle, modifier = tooltipModifier, tooltipPlacement = tooltipPlacement) { - CoreSelectableIconActionButton( + CoreIconActionButton( key = key, modifier = modifier, contentDescription = contentDescription, iconClass = iconClass, - selected = selected, enabled = enabled, focusable = focusable, style = style, interactionSource = interactionSource, - extraHints = extraHints, + colorFilter = colorFilter, + hints = hints, onClick = onClick, ) } } @Composable -private fun CoreSelectableIconActionButton( +private fun BaseIconActionButton( key: IconKey, contentDescription: String?, iconClass: Class<*>, - selected: Boolean, enabled: Boolean, focusable: Boolean, style: IconButtonStyle, interactionSource: MutableInteractionSource, modifier: Modifier, - extraHints: Array, + colorFilter: ColorFilter?, + hint: PainterHint?, onClick: () -> Unit, ) { - SelectableIconButton(selected, onClick, modifier, enabled, focusable, style, interactionSource) { - val strokeColor by style.colors.selectableForegroundFor(it) - Icon(key, contentDescription, iconClass = iconClass, hints = arrayOf(Stroke(strokeColor), *extraHints)) - } -} - -@Composable -public fun ToggleableIconActionButton( - key: IconKey, - contentDescription: String?, - value: Boolean, - onValueChange: (Boolean) -> Unit, - modifier: Modifier = Modifier, - enabled: Boolean = true, - focusable: Boolean = true, - style: IconButtonStyle = JewelTheme.iconButtonStyle, - extraHints: Array = emptyArray(), - interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, - iconClass: Class<*> = key::class.java, -) { - CoreToggleableIconActionButton( - key, - contentDescription, - iconClass, - value, - enabled, - focusable, - style, - interactionSource, - modifier, - extraHints, - onValueChange, - ) -} - -@Composable -public fun ToggleableIconActionButton( - key: IconKey, - contentDescription: String?, - value: Boolean, - onValueChange: (Boolean) -> Unit, - modifier: Modifier = Modifier, - enabled: Boolean = true, - focusable: Boolean = true, - style: IconButtonStyle = JewelTheme.iconButtonStyle, - extraHints: Array = emptyArray(), - tooltipStyle: TooltipStyle = JewelTheme.tooltipStyle, - tooltipModifier: Modifier = Modifier, - tooltipPlacement: TooltipPlacement = FixedCursorPoint(offset = DpOffset(0.dp, 16.dp)), - interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, - iconClass: Class<*> = key::class.java, - tooltip: @Composable () -> Unit, -) { - Tooltip(tooltip, style = tooltipStyle, modifier = tooltipModifier, tooltipPlacement = tooltipPlacement) { - CoreToggleableIconActionButton( + if (hint != null) { + CoreIconActionButton( key = key, + contentDescription = contentDescription, + iconClass = iconClass, + enabled = enabled, + focusable = focusable, + style = style, + interactionSource = interactionSource, modifier = modifier, + colorFilter = colorFilter, + hint = hint, + onClick = onClick, + ) + } else { + CoreIconActionButton( + key = key, contentDescription = contentDescription, iconClass = iconClass, - value = value, enabled = enabled, focusable = focusable, style = style, interactionSource = interactionSource, - extraHints = extraHints, - onValueChange = onValueChange, + modifier = modifier, + colorFilter = colorFilter, + hints = emptyArray(), + onClick = onClick, ) } } @Composable -private fun CoreToggleableIconActionButton( +private fun CoreIconActionButton( key: IconKey, contentDescription: String?, iconClass: Class<*>, - value: Boolean, enabled: Boolean, focusable: Boolean, style: IconButtonStyle, interactionSource: MutableInteractionSource, modifier: Modifier, - extraHints: Array, - onValueChange: (Boolean) -> Unit, + colorFilter: ColorFilter?, + hints: Array, + onClick: () -> Unit, ) { - ToggleableIconButton(value, onValueChange, modifier, enabled, focusable, style, interactionSource) { - val strokeColor by style.colors.toggleableForegroundFor(it) - Icon(key, contentDescription, iconClass = iconClass, hints = arrayOf(Stroke(strokeColor), *extraHints)) + IconButton(onClick, modifier, enabled, focusable, style, interactionSource) { + Icon(key, contentDescription, iconClass = iconClass, colorFilter = colorFilter, hints = hints) + } +} + +@Composable +private fun CoreIconActionButton( + key: IconKey, + contentDescription: String?, + iconClass: Class<*>, + enabled: Boolean, + focusable: Boolean, + style: IconButtonStyle, + interactionSource: MutableInteractionSource, + modifier: Modifier, + colorFilter: ColorFilter?, + hint: PainterHint, + onClick: () -> Unit, +) { + IconButton(onClick, modifier, enabled, focusable, style, interactionSource) { + Icon(key, contentDescription, iconClass = iconClass, hint = hint, colorFilter = colorFilter) } } diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/SelectableIconActionButton.kt b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/SelectableIconActionButton.kt new file mode 100644 index 000000000..d84f03826 --- /dev/null +++ b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/SelectableIconActionButton.kt @@ -0,0 +1,257 @@ +package org.jetbrains.jewel.ui.component + +import androidx.compose.foundation.TooltipPlacement +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.ColorFilter +import androidx.compose.ui.unit.DpOffset +import androidx.compose.ui.unit.dp +import org.jetbrains.jewel.foundation.theme.JewelTheme +import org.jetbrains.jewel.ui.component.styling.IconButtonStyle +import org.jetbrains.jewel.ui.component.styling.TooltipStyle +import org.jetbrains.jewel.ui.icon.IconKey +import org.jetbrains.jewel.ui.painter.PainterHint +import org.jetbrains.jewel.ui.painter.hints.Stroke +import org.jetbrains.jewel.ui.theme.iconButtonStyle +import org.jetbrains.jewel.ui.theme.tooltipStyle + +@Composable +public fun SelectableIconActionButton( + key: IconKey, + contentDescription: String?, + selected: Boolean, + onClick: () -> Unit, + modifier: Modifier = Modifier, + enabled: Boolean = true, + focusable: Boolean = true, + style: IconButtonStyle = JewelTheme.iconButtonStyle, + colorFilter: ColorFilter? = null, + extraHint: PainterHint? = null, + interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, + iconClass: Class<*> = key::class.java, +) { + BaseSelectableIconActionButton( + key, + contentDescription, + iconClass, + selected, + enabled, + focusable, + style, + interactionSource, + modifier, + colorFilter, + extraHint, + onClick, + ) +} + +@Composable +public fun SelectableIconActionButton( + key: IconKey, + contentDescription: String?, + selected: Boolean, + onClick: () -> Unit, + modifier: Modifier = Modifier, + enabled: Boolean = true, + focusable: Boolean = true, + style: IconButtonStyle = JewelTheme.iconButtonStyle, + colorFilter: ColorFilter? = null, + extraHint: PainterHint? = null, + tooltipStyle: TooltipStyle = JewelTheme.tooltipStyle, + tooltipModifier: Modifier = Modifier, + tooltipPlacement: TooltipPlacement = FixedCursorPoint(offset = DpOffset(0.dp, 16.dp)), + interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, + iconClass: Class<*> = key::class.java, + tooltip: @Composable () -> Unit, +) { + Tooltip(tooltip, style = tooltipStyle, modifier = tooltipModifier, tooltipPlacement = tooltipPlacement) { + BaseSelectableIconActionButton( + key = key, + modifier = modifier, + contentDescription = contentDescription, + iconClass = iconClass, + selected = selected, + enabled = enabled, + focusable = focusable, + style = style, + interactionSource = interactionSource, + colorFilter = colorFilter, + extraHint = extraHint, + onClick = onClick, + ) + } +} + +@Composable +public fun SelectableIconActionButton( + key: IconKey, + contentDescription: String?, + selected: Boolean, + extraHints: Array, + onClick: () -> Unit, + modifier: Modifier = Modifier, + enabled: Boolean = true, + focusable: Boolean = true, + style: IconButtonStyle = JewelTheme.iconButtonStyle, + colorFilter: ColorFilter? = null, + interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, + iconClass: Class<*> = key::class.java, +) { + CoreSelectableIconActionButton( + key, + contentDescription, + iconClass, + selected, + enabled, + focusable, + style, + interactionSource, + modifier, + colorFilter, + extraHints, + onClick, + ) +} + +@Composable +public fun SelectableIconActionButton( + key: IconKey, + contentDescription: String?, + selected: Boolean, + extraHints: Array, + onClick: () -> Unit, + modifier: Modifier = Modifier, + enabled: Boolean = true, + focusable: Boolean = true, + style: IconButtonStyle = JewelTheme.iconButtonStyle, + colorFilter: ColorFilter? = null, + tooltipStyle: TooltipStyle = JewelTheme.tooltipStyle, + tooltipModifier: Modifier = Modifier, + tooltipPlacement: TooltipPlacement = FixedCursorPoint(offset = DpOffset(0.dp, 16.dp)), + interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, + iconClass: Class<*> = key::class.java, + tooltip: @Composable () -> Unit, +) { + Tooltip(tooltip, style = tooltipStyle, modifier = tooltipModifier, tooltipPlacement = tooltipPlacement) { + CoreSelectableIconActionButton( + key = key, + modifier = modifier, + contentDescription = contentDescription, + iconClass = iconClass, + selected = selected, + enabled = enabled, + focusable = focusable, + style = style, + interactionSource = interactionSource, + colorFilter = colorFilter, + extraHints = extraHints, + onClick = onClick, + ) + } +} + +@Composable +private fun BaseSelectableIconActionButton( + key: IconKey, + contentDescription: String?, + iconClass: Class<*>, + selected: Boolean, + enabled: Boolean, + focusable: Boolean, + style: IconButtonStyle, + interactionSource: MutableInteractionSource, + modifier: Modifier, + colorFilter: ColorFilter?, + extraHint: PainterHint?, + onClick: () -> Unit, +) { + if (extraHint != null) { + CoreSelectableIconActionButton( + key = key, + contentDescription = contentDescription, + iconClass = iconClass, + selected = selected, + enabled = enabled, + focusable = focusable, + style = style, + interactionSource = interactionSource, + modifier = modifier, + colorFilter = colorFilter, + extraHint = extraHint, + onClick = onClick, + ) + } else { + CoreSelectableIconActionButton( + key = key, + contentDescription = contentDescription, + iconClass = iconClass, + selected = selected, + enabled = enabled, + focusable = focusable, + style = style, + interactionSource = interactionSource, + modifier = modifier, + colorFilter = colorFilter, + extraHints = emptyArray(), + onClick = onClick, + ) + } +} + +@Composable +private fun CoreSelectableIconActionButton( + key: IconKey, + contentDescription: String?, + iconClass: Class<*>, + selected: Boolean, + enabled: Boolean, + focusable: Boolean, + style: IconButtonStyle, + interactionSource: MutableInteractionSource, + modifier: Modifier, + colorFilter: ColorFilter?, + extraHint: PainterHint, + onClick: () -> Unit, +) { + SelectableIconButton(selected, onClick, modifier, enabled, focusable, style, interactionSource) { + val strokeColor by style.colors.selectableForegroundFor(it) + Icon( + key, + contentDescription, + iconClass = iconClass, + hints = arrayOf(Stroke(strokeColor), extraHint), + colorFilter = colorFilter, + ) + } +} + +@Composable +private fun CoreSelectableIconActionButton( + key: IconKey, + contentDescription: String?, + iconClass: Class<*>, + selected: Boolean, + enabled: Boolean, + focusable: Boolean, + style: IconButtonStyle, + interactionSource: MutableInteractionSource, + modifier: Modifier, + colorFilter: ColorFilter?, + extraHints: Array, + onClick: () -> Unit, +) { + SelectableIconButton(selected, onClick, modifier, enabled, focusable, style, interactionSource) { + val strokeColor by style.colors.selectableForegroundFor(it) + Icon( + key, + contentDescription, + iconClass = iconClass, + hints = arrayOf(Stroke(strokeColor), *extraHints), + colorFilter = colorFilter, + ) + } +} diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/ToggleableIconActionButton.kt b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/ToggleableIconActionButton.kt new file mode 100644 index 000000000..c3eab264d --- /dev/null +++ b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/ToggleableIconActionButton.kt @@ -0,0 +1,257 @@ +package org.jetbrains.jewel.ui.component + +import androidx.compose.foundation.TooltipPlacement +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.ColorFilter +import androidx.compose.ui.unit.DpOffset +import androidx.compose.ui.unit.dp +import org.jetbrains.jewel.foundation.theme.JewelTheme +import org.jetbrains.jewel.ui.component.styling.IconButtonStyle +import org.jetbrains.jewel.ui.component.styling.TooltipStyle +import org.jetbrains.jewel.ui.icon.IconKey +import org.jetbrains.jewel.ui.painter.PainterHint +import org.jetbrains.jewel.ui.painter.hints.Stroke +import org.jetbrains.jewel.ui.theme.iconButtonStyle +import org.jetbrains.jewel.ui.theme.tooltipStyle + +@Composable +public fun ToggleableIconActionButton( + key: IconKey, + contentDescription: String?, + value: Boolean, + onValueChange: (Boolean) -> Unit, + modifier: Modifier = Modifier, + enabled: Boolean = true, + focusable: Boolean = true, + style: IconButtonStyle = JewelTheme.iconButtonStyle, + colorFilter: ColorFilter? = null, + extraHint: PainterHint? = null, + interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, + iconClass: Class<*> = key::class.java, +) { + BaseToggleableIconActionButton( + key = key, + contentDescription = contentDescription, + iconClass = iconClass, + value = value, + enabled = enabled, + focusable = focusable, + style = style, + interactionSource = interactionSource, + modifier = modifier, + colorFilter = colorFilter, + extraHint = extraHint, + onValueChange = onValueChange, + ) +} + +@Composable +public fun ToggleableIconActionButton( + key: IconKey, + contentDescription: String?, + value: Boolean, + onValueChange: (Boolean) -> Unit, + modifier: Modifier = Modifier, + enabled: Boolean = true, + focusable: Boolean = true, + style: IconButtonStyle = JewelTheme.iconButtonStyle, + colorFilter: ColorFilter? = null, + extraHint: PainterHint? = null, + tooltipStyle: TooltipStyle = JewelTheme.tooltipStyle, + tooltipModifier: Modifier = Modifier, + tooltipPlacement: TooltipPlacement = FixedCursorPoint(offset = DpOffset(0.dp, 16.dp)), + interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, + iconClass: Class<*> = key::class.java, + tooltip: @Composable () -> Unit, +) { + Tooltip(tooltip, style = tooltipStyle, modifier = tooltipModifier, tooltipPlacement = tooltipPlacement) { + BaseToggleableIconActionButton( + key = key, + modifier = modifier, + contentDescription = contentDescription, + iconClass = iconClass, + value = value, + enabled = enabled, + focusable = focusable, + style = style, + interactionSource = interactionSource, + colorFilter = colorFilter, + extraHint = extraHint, + onValueChange = onValueChange, + ) + } +} + +@Composable +public fun ToggleableIconActionButton( + key: IconKey, + contentDescription: String?, + value: Boolean, + extraHints: Array, + onValueChange: (Boolean) -> Unit, + modifier: Modifier = Modifier, + enabled: Boolean = true, + focusable: Boolean = true, + style: IconButtonStyle = JewelTheme.iconButtonStyle, + colorFilter: ColorFilter? = null, + interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, + iconClass: Class<*> = key::class.java, +) { + CoreToggleableIconActionButton( + key = key, + contentDescription = contentDescription, + iconClass = iconClass, + value = value, + enabled = enabled, + focusable = focusable, + style = style, + interactionSource = interactionSource, + modifier = modifier, + colorFilter = colorFilter, + extraHints = extraHints, + onValueChange = onValueChange, + ) +} + +@Composable +public fun ToggleableIconActionButton( + key: IconKey, + contentDescription: String?, + value: Boolean, + extraHints: Array, + onValueChange: (Boolean) -> Unit, + modifier: Modifier = Modifier, + enabled: Boolean = true, + focusable: Boolean = true, + style: IconButtonStyle = JewelTheme.iconButtonStyle, + colorFilter: ColorFilter? = null, + tooltipStyle: TooltipStyle = JewelTheme.tooltipStyle, + tooltipModifier: Modifier = Modifier, + tooltipPlacement: TooltipPlacement = FixedCursorPoint(offset = DpOffset(0.dp, 16.dp)), + interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, + iconClass: Class<*> = key::class.java, + tooltip: @Composable () -> Unit, +) { + Tooltip(tooltip, style = tooltipStyle, modifier = tooltipModifier, tooltipPlacement = tooltipPlacement) { + CoreToggleableIconActionButton( + key = key, + modifier = modifier, + contentDescription = contentDescription, + iconClass = iconClass, + value = value, + enabled = enabled, + focusable = focusable, + style = style, + interactionSource = interactionSource, + colorFilter = colorFilter, + extraHints = extraHints, + onValueChange = onValueChange, + ) + } +} + +@Composable +private fun BaseToggleableIconActionButton( + key: IconKey, + contentDescription: String?, + iconClass: Class<*>, + value: Boolean, + enabled: Boolean, + focusable: Boolean, + style: IconButtonStyle, + interactionSource: MutableInteractionSource, + modifier: Modifier, + colorFilter: ColorFilter?, + extraHint: PainterHint?, + onValueChange: (Boolean) -> Unit, +) { + if (extraHint != null) { + CoreToggleableIconActionButton( + key = key, + contentDescription = contentDescription, + iconClass = iconClass, + value = value, + enabled = enabled, + focusable = focusable, + style = style, + interactionSource = interactionSource, + modifier = modifier, + colorFilter = colorFilter, + extraHint = extraHint, + onValueChange = onValueChange, + ) + } else { + CoreToggleableIconActionButton( + key = key, + contentDescription = contentDescription, + iconClass = iconClass, + value = value, + enabled = enabled, + focusable = focusable, + style = style, + interactionSource = interactionSource, + modifier = modifier, + colorFilter = colorFilter, + extraHints = emptyArray(), + onValueChange = onValueChange, + ) + } +} + +@Composable +private fun CoreToggleableIconActionButton( + key: IconKey, + contentDescription: String?, + iconClass: Class<*>, + value: Boolean, + enabled: Boolean, + focusable: Boolean, + style: IconButtonStyle, + interactionSource: MutableInteractionSource, + modifier: Modifier, + colorFilter: ColorFilter? = null, + extraHints: Array, + onValueChange: (Boolean) -> Unit, +) { + ToggleableIconButton(value, onValueChange, modifier, enabled, focusable, style, interactionSource) { + val strokeColor by style.colors.toggleableForegroundFor(it) + Icon( + key = key, + contentDescription = contentDescription, + iconClass = iconClass, + hints = arrayOf(Stroke(strokeColor), *extraHints), + colorFilter = colorFilter, + ) + } +} + +@Composable +private fun CoreToggleableIconActionButton( + key: IconKey, + contentDescription: String?, + iconClass: Class<*>, + value: Boolean, + enabled: Boolean, + focusable: Boolean, + style: IconButtonStyle, + interactionSource: MutableInteractionSource, + modifier: Modifier, + colorFilter: ColorFilter? = null, + extraHint: PainterHint, + onValueChange: (Boolean) -> Unit, +) { + ToggleableIconButton(value, onValueChange, modifier, enabled, focusable, style, interactionSource) { + val strokeColor by style.colors.toggleableForegroundFor(it) + Icon( + key = key, + contentDescription = contentDescription, + iconClass = iconClass, + hints = arrayOf(Stroke(strokeColor), extraHint), + colorFilter = colorFilter, + ) + } +}