Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix default button focus outline & chip colors #420

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,11 @@ import androidx.compose.ui.unit.dp
import com.intellij.ide.ui.laf.darcula.DarculaUIUtil
import com.intellij.ui.scale.JBUIScale
import com.intellij.util.ui.JBUI
import com.intellij.util.ui.UIUtil
import org.jetbrains.jewel.foundation.GlobalMetrics

public fun GlobalMetrics.Companion.readFromLaF(): GlobalMetrics {
// Copied from DarculaUIUtil.doPaint(java.awt.Graphics2D, int, int, float, float, boolean)
// except that scaling is all moved into the .dp operation below
val f = if (UIUtil.isRetina()) 0.5f else 1.0f
val lw = if (UIUtil.isUnderDefaultMacTheme()) f else DarculaUIUtil.LW.unscaled

return GlobalMetrics(
outlineWidth = (DarculaUIUtil.BW.unscaled + lw).dp,
public fun GlobalMetrics.Companion.readFromLaF(): GlobalMetrics =
GlobalMetrics(
outlineWidth = DarculaUIUtil.BW.unscaled.dp,
// The rowHeight() function returns a scaled value, but we need the base value
rowHeight = (JBUI.CurrentTheme.List.rowHeight() / JBUIScale.scale(1f)).dp,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import org.jetbrains.jewel.bridge.toDpSize
import org.jetbrains.jewel.bridge.toPaddingValues
import org.jetbrains.jewel.foundation.GlobalColors
import org.jetbrains.jewel.foundation.GlobalMetrics
import org.jetbrains.jewel.foundation.Stroke
import org.jetbrains.jewel.foundation.theme.ThemeColorPalette
import org.jetbrains.jewel.foundation.theme.ThemeDefinition
import org.jetbrains.jewel.foundation.theme.ThemeIconData
Expand Down Expand Up @@ -282,8 +283,10 @@ private fun readDefaultButtonStyle(): ButtonStyle {
cornerSize = retrieveArcAsCornerSizeWithFallbacks("Button.default.arc", "Button.arc"),
padding = PaddingValues(horizontal = 14.dp), // see DarculaButtonUI.HORIZONTAL_PADDING
minSize = DpSize(minimumSize.width, minimumSize.height),
borderWidth = DarculaUIUtil.LW.dp,
borderWidth = 1.dp,
focusOutlineExpand = 1.5.dp, // From DarculaButtonPainter.getBorderInsets
),
focusOutlineAlignment = Stroke.Alignment.Center,
)
}

Expand Down Expand Up @@ -330,7 +333,9 @@ private fun readOutlinedButtonStyle(): ButtonStyle {
padding = PaddingValues(horizontal = 14.dp), // see DarculaButtonUI.HORIZONTAL_PADDING
minSize = DpSize(minimumSize.width, minimumSize.height),
borderWidth = DarculaUIUtil.LW.dp,
focusOutlineExpand = Dp.Unspecified,
),
focusOutlineAlignment = Stroke.Alignment.Center,
)
}

Expand Down
16 changes: 8 additions & 8 deletions int-ui/int-ui-standalone/api/int-ui-standalone.api
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ public final class org/jetbrains/jewel/intui/standalone/StandalonePainterHintsPr
}

public final class org/jetbrains/jewel/intui/standalone/styling/IntUiButtonStylingKt {
public static final fun default-H1KY9o8 (Lorg/jetbrains/jewel/ui/component/styling/ButtonMetrics$Companion;Landroidx/compose/foundation/shape/CornerSize;Landroidx/compose/foundation/layout/PaddingValues;JF)Lorg/jetbrains/jewel/ui/component/styling/ButtonMetrics;
public static synthetic fun default-H1KY9o8$default (Lorg/jetbrains/jewel/ui/component/styling/ButtonMetrics$Companion;Landroidx/compose/foundation/shape/CornerSize;Landroidx/compose/foundation/layout/PaddingValues;JFILjava/lang/Object;)Lorg/jetbrains/jewel/ui/component/styling/ButtonMetrics;
public static final fun default-Kzyhx1A (Lorg/jetbrains/jewel/ui/component/styling/ButtonMetrics$Companion;Landroidx/compose/foundation/shape/CornerSize;Landroidx/compose/foundation/layout/PaddingValues;JFF)Lorg/jetbrains/jewel/ui/component/styling/ButtonMetrics;
public static synthetic fun default-Kzyhx1A$default (Lorg/jetbrains/jewel/ui/component/styling/ButtonMetrics$Companion;Landroidx/compose/foundation/shape/CornerSize;Landroidx/compose/foundation/layout/PaddingValues;JFFILjava/lang/Object;)Lorg/jetbrains/jewel/ui/component/styling/ButtonMetrics;
public static final fun getDefault (Lorg/jetbrains/jewel/ui/component/styling/ButtonColors$Companion;)Lorg/jetbrains/jewel/intui/standalone/styling/IntUiDefaultButtonColorFactory;
public static final fun getDefault (Lorg/jetbrains/jewel/ui/component/styling/ButtonStyle$Companion;)Lorg/jetbrains/jewel/intui/standalone/styling/IntUiDefaultButtonStyleFactory;
public static final fun getOutlined (Lorg/jetbrains/jewel/ui/component/styling/ButtonColors$Companion;)Lorg/jetbrains/jewel/intui/standalone/styling/IntUiOutlinedButtonColorFactory;
public static final fun getOutlined (Lorg/jetbrains/jewel/ui/component/styling/ButtonStyle$Companion;)Lorg/jetbrains/jewel/intui/standalone/styling/IntUiOutlinedButtonStyleFactory;
public static final fun outlined-H1KY9o8 (Lorg/jetbrains/jewel/ui/component/styling/ButtonMetrics$Companion;Landroidx/compose/foundation/shape/CornerSize;Landroidx/compose/foundation/layout/PaddingValues;JF)Lorg/jetbrains/jewel/ui/component/styling/ButtonMetrics;
public static synthetic fun outlined-H1KY9o8$default (Lorg/jetbrains/jewel/ui/component/styling/ButtonMetrics$Companion;Landroidx/compose/foundation/shape/CornerSize;Landroidx/compose/foundation/layout/PaddingValues;JFILjava/lang/Object;)Lorg/jetbrains/jewel/ui/component/styling/ButtonMetrics;
public static final fun outlined-Kzyhx1A (Lorg/jetbrains/jewel/ui/component/styling/ButtonMetrics$Companion;Landroidx/compose/foundation/shape/CornerSize;Landroidx/compose/foundation/layout/PaddingValues;JFF)Lorg/jetbrains/jewel/ui/component/styling/ButtonMetrics;
public static synthetic fun outlined-Kzyhx1A$default (Lorg/jetbrains/jewel/ui/component/styling/ButtonMetrics$Companion;Landroidx/compose/foundation/shape/CornerSize;Landroidx/compose/foundation/layout/PaddingValues;JFFILjava/lang/Object;)Lorg/jetbrains/jewel/ui/component/styling/ButtonMetrics;
}

public final class org/jetbrains/jewel/intui/standalone/styling/IntUiCheckboxStylingKt {
Expand Down Expand Up @@ -86,8 +86,8 @@ public final class org/jetbrains/jewel/intui/standalone/styling/IntUiDefaultButt
public final class org/jetbrains/jewel/intui/standalone/styling/IntUiDefaultButtonStyleFactory {
public static final field $stable I
public static final field INSTANCE Lorg/jetbrains/jewel/intui/standalone/styling/IntUiDefaultButtonStyleFactory;
public final fun dark (Lorg/jetbrains/jewel/ui/component/styling/ButtonColors;Lorg/jetbrains/jewel/ui/component/styling/ButtonMetrics;Landroidx/compose/runtime/Composer;II)Lorg/jetbrains/jewel/ui/component/styling/ButtonStyle;
public final fun light (Lorg/jetbrains/jewel/ui/component/styling/ButtonColors;Lorg/jetbrains/jewel/ui/component/styling/ButtonMetrics;Landroidx/compose/runtime/Composer;II)Lorg/jetbrains/jewel/ui/component/styling/ButtonStyle;
public final fun dark (Lorg/jetbrains/jewel/ui/component/styling/ButtonColors;Lorg/jetbrains/jewel/ui/component/styling/ButtonMetrics;Lorg/jetbrains/jewel/foundation/Stroke$Alignment;Landroidx/compose/runtime/Composer;II)Lorg/jetbrains/jewel/ui/component/styling/ButtonStyle;
public final fun light (Lorg/jetbrains/jewel/ui/component/styling/ButtonColors;Lorg/jetbrains/jewel/ui/component/styling/ButtonMetrics;Lorg/jetbrains/jewel/foundation/Stroke$Alignment;Landroidx/compose/runtime/Composer;II)Lorg/jetbrains/jewel/ui/component/styling/ButtonStyle;
}

public final class org/jetbrains/jewel/intui/standalone/styling/IntUiDefaultDropdownColorsFactory {
Expand Down Expand Up @@ -232,8 +232,8 @@ public final class org/jetbrains/jewel/intui/standalone/styling/IntUiOutlinedBut
public final class org/jetbrains/jewel/intui/standalone/styling/IntUiOutlinedButtonStyleFactory {
public static final field $stable I
public static final field INSTANCE Lorg/jetbrains/jewel/intui/standalone/styling/IntUiOutlinedButtonStyleFactory;
public final fun dark (Lorg/jetbrains/jewel/ui/component/styling/ButtonColors;Lorg/jetbrains/jewel/ui/component/styling/ButtonMetrics;Landroidx/compose/runtime/Composer;II)Lorg/jetbrains/jewel/ui/component/styling/ButtonStyle;
public final fun light (Lorg/jetbrains/jewel/ui/component/styling/ButtonColors;Lorg/jetbrains/jewel/ui/component/styling/ButtonMetrics;Landroidx/compose/runtime/Composer;II)Lorg/jetbrains/jewel/ui/component/styling/ButtonStyle;
public final fun dark (Lorg/jetbrains/jewel/ui/component/styling/ButtonColors;Lorg/jetbrains/jewel/ui/component/styling/ButtonMetrics;Lorg/jetbrains/jewel/foundation/Stroke$Alignment;Landroidx/compose/runtime/Composer;II)Lorg/jetbrains/jewel/ui/component/styling/ButtonStyle;
public final fun light (Lorg/jetbrains/jewel/ui/component/styling/ButtonColors;Lorg/jetbrains/jewel/ui/component/styling/ButtonMetrics;Lorg/jetbrains/jewel/foundation/Stroke$Alignment;Landroidx/compose/runtime/Composer;II)Lorg/jetbrains/jewel/ui/component/styling/ButtonStyle;
}

public final class org/jetbrains/jewel/intui/standalone/styling/IntUiRadioButtonStylingKt {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import org.jetbrains.jewel.foundation.Stroke
import org.jetbrains.jewel.intui.core.theme.IntUiDarkTheme
import org.jetbrains.jewel.intui.core.theme.IntUiLightTheme
import org.jetbrains.jewel.ui.component.styling.ButtonColors
Expand All @@ -23,13 +24,15 @@ public object IntUiDefaultButtonStyleFactory {
public fun light(
colors: ButtonColors = ButtonColors.Default.light(),
metrics: ButtonMetrics = ButtonMetrics.default(),
): ButtonStyle = ButtonStyle(colors, metrics)
focusOutlineAlignment: Stroke.Alignment = Stroke.Alignment.Center,
): ButtonStyle = ButtonStyle(colors, metrics, focusOutlineAlignment)

@Composable
public fun dark(
colors: ButtonColors = ButtonColors.Default.dark(),
metrics: ButtonMetrics = ButtonMetrics.default(),
): ButtonStyle = ButtonStyle(colors, metrics)
focusOutlineAlignment: Stroke.Alignment = Stroke.Alignment.Center,
): ButtonStyle = ButtonStyle(colors, metrics, focusOutlineAlignment)
}

public val ButtonStyle.Companion.Outlined: IntUiOutlinedButtonStyleFactory
Expand All @@ -40,13 +43,15 @@ public object IntUiOutlinedButtonStyleFactory {
public fun light(
colors: ButtonColors = ButtonColors.Outlined.light(),
metrics: ButtonMetrics = ButtonMetrics.outlined(),
): ButtonStyle = ButtonStyle(colors, metrics)
focusOutlineAlignment: Stroke.Alignment = Stroke.Alignment.Center,
): ButtonStyle = ButtonStyle(colors, metrics, focusOutlineAlignment)

@Composable
public fun dark(
colors: ButtonColors = ButtonColors.Outlined.dark(),
metrics: ButtonMetrics = ButtonMetrics.outlined(),
): ButtonStyle = ButtonStyle(colors, metrics)
focusOutlineAlignment: Stroke.Alignment = Stroke.Alignment.Center,
): ButtonStyle = ButtonStyle(colors, metrics, focusOutlineAlignment)
}

public val ButtonColors.Companion.Default: IntUiDefaultButtonColorFactory
Expand All @@ -67,8 +72,8 @@ public object IntUiDefaultButtonColorFactory {
contentHovered: Color = IntUiLightTheme.colors.grey(14),
border: Brush = SolidColor(IntUiLightTheme.colors.blue(4)),
borderDisabled: Brush = SolidColor(IntUiLightTheme.colors.grey(12)),
borderFocused: Brush = SolidColor(IntUiLightTheme.colors.blue(4)),
borderPressed: Brush = border,
borderFocused: Brush = SolidColor(IntUiLightTheme.colors.grey(14)),
borderPressed: Brush = borderFocused,
borderHovered: Brush = border,
): ButtonColors =
ButtonColors(
Expand Down Expand Up @@ -104,7 +109,7 @@ public object IntUiDefaultButtonColorFactory {
border: Brush = SolidColor(IntUiDarkTheme.colors.blue(6)),
borderDisabled: Brush = SolidColor(IntUiDarkTheme.colors.grey(5)),
borderFocused: Brush = SolidColor(IntUiDarkTheme.colors.grey(1)),
borderPressed: Brush = border,
borderPressed: Brush = borderFocused,
borderHovered: Brush = border,
): ButtonColors =
ButtonColors(
Expand Down Expand Up @@ -207,12 +212,14 @@ public fun ButtonMetrics.Companion.default(
cornerSize: CornerSize = CornerSize(4.dp),
padding: PaddingValues = PaddingValues(horizontal = 12.dp, vertical = 6.dp),
minSize: DpSize = DpSize(72.dp, 28.dp),
borderWidth: Dp = 0.dp,
): ButtonMetrics = ButtonMetrics(cornerSize, padding, minSize, borderWidth)
borderWidth: Dp = 1.dp,
focusOutlineExpand: Dp = 1.5.dp,
): ButtonMetrics = ButtonMetrics(cornerSize, padding, minSize, borderWidth, focusOutlineExpand)

public fun ButtonMetrics.Companion.outlined(
cornerSize: CornerSize = CornerSize(4.dp),
padding: PaddingValues = PaddingValues(horizontal = 12.dp, vertical = 6.dp),
minSize: DpSize = DpSize(72.dp, 28.dp),
borderWidth: Dp = 1.dp,
): ButtonMetrics = ButtonMetrics(cornerSize, padding, minSize, borderWidth)
focusOutlineExpand: Dp = Dp.Unspecified,
): ButtonMetrics = ButtonMetrics(cornerSize, padding, minSize, borderWidth, focusOutlineExpand)
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ public fun ChipColors.Companion.light(
background: Brush = SolidColor(IntUiLightTheme.colors.grey(14)),
backgroundDisabled: Brush = SolidColor(IntUiLightTheme.colors.grey(12)),
backgroundFocused: Brush = background,
backgroundPressed: Brush = SolidColor(IntUiLightTheme.colors.grey(13)),
backgroundPressed: Brush = SolidColor(IntUiLightTheme.colors.grey(11)),
backgroundHovered: Brush = background,
backgroundSelected: Brush = background,
backgroundSelected: Brush = SolidColor(IntUiLightTheme.colors.grey(13)),
backgroundSelectedDisabled: Brush = backgroundDisabled,
backgroundSelectedFocused: Brush = background,
backgroundSelectedPressed: Brush = background,
backgroundSelectedHovered: Brush = background,
backgroundSelectedFocused: Brush = backgroundSelected,
backgroundSelectedPressed: Brush = backgroundPressed,
backgroundSelectedHovered: Brush = backgroundSelected,
content: Color = IntUiLightTheme.colors.grey(1),
contentDisabled: Color = IntUiLightTheme.colors.grey(8),
contentFocused: Color = content,
Expand All @@ -49,12 +49,12 @@ public fun ChipColors.Companion.light(
contentSelectedPressed: Color = content,
contentSelectedHovered: Color = content,
border: Color = IntUiLightTheme.colors.grey(9),
borderDisabled: Color = IntUiLightTheme.colors.grey(6),
borderDisabled: Color = IntUiLightTheme.colors.grey(11),
borderFocused: Color = IntUiLightTheme.colors.blue(4),
borderPressed: Color = IntUiLightTheme.colors.grey(7),
borderHovered: Color = IntUiLightTheme.colors.grey(8),
borderSelected: Color = IntUiLightTheme.colors.blue(4),
borderSelectedDisabled: Color = borderSelected,
borderSelectedDisabled: Color = borderDisabled,
borderSelectedFocused: Color = borderSelected,
borderSelectedPressed: Color = borderSelected,
borderSelectedHovered: Color = borderSelected,
Expand Down Expand Up @@ -95,15 +95,15 @@ public fun ChipColors.Companion.light(
@Composable
public fun ChipColors.Companion.dark(
background: Brush = SolidColor(IntUiDarkTheme.colors.grey(2)),
backgroundDisabled: Brush = SolidColor(IntUiDarkTheme.colors.grey(5)),
backgroundDisabled: Brush = SolidColor(IntUiDarkTheme.colors.grey(4)),
backgroundFocused: Brush = background,
backgroundPressed: Brush = background,
backgroundPressed: Brush = SolidColor(IntUiDarkTheme.colors.grey(5)),
backgroundHovered: Brush = background,
backgroundSelected: Brush = background,
backgroundSelected: Brush = SolidColor(IntUiDarkTheme.colors.grey(3)),
backgroundSelectedDisabled: Brush = backgroundDisabled,
backgroundSelectedFocused: Brush = background,
backgroundSelectedPressed: Brush = background,
backgroundSelectedHovered: Brush = background,
backgroundSelectedFocused: Brush = backgroundSelected,
backgroundSelectedPressed: Brush = backgroundPressed,
backgroundSelectedHovered: Brush = backgroundSelected,
content: Color = IntUiDarkTheme.colors.grey(12),
contentDisabled: Color = IntUiDarkTheme.colors.grey(8),
contentFocused: Color = content,
Expand All @@ -120,7 +120,7 @@ public fun ChipColors.Companion.dark(
borderPressed: Color = IntUiDarkTheme.colors.grey(7),
borderHovered: Color = borderPressed,
borderSelected: Color = IntUiDarkTheme.colors.blue(6),
borderSelectedDisabled: Color = borderSelected,
borderSelectedDisabled: Color = borderDisabled,
borderSelectedFocused: Color = borderSelected,
borderSelectedPressed: Color = borderSelected,
borderSelectedHovered: Color = borderSelected,
Expand Down
10 changes: 6 additions & 4 deletions ui/api/ui.api
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ public final class org/jetbrains/jewel/ui/Outline$Companion {
}

public final class org/jetbrains/jewel/ui/OutlineKt {
public static final fun focusOutline-FJfuzF0 (Landroidx/compose/ui/Modifier;Lorg/jetbrains/jewel/foundation/state/FocusableComponentState;Landroidx/compose/ui/graphics/Shape;Lorg/jetbrains/jewel/foundation/Stroke$Alignment;FLandroidx/compose/runtime/Composer;II)Landroidx/compose/ui/Modifier;
public static final fun focusOutline-FJfuzF0 (Landroidx/compose/ui/Modifier;ZLandroidx/compose/ui/graphics/Shape;Lorg/jetbrains/jewel/foundation/Stroke$Alignment;FLandroidx/compose/runtime/Composer;II)Landroidx/compose/ui/Modifier;
public static final fun focusOutline-AGcomas (Landroidx/compose/ui/Modifier;Lorg/jetbrains/jewel/foundation/state/FocusableComponentState;Landroidx/compose/ui/graphics/Shape;Lorg/jetbrains/jewel/foundation/Stroke$Alignment;FFLandroidx/compose/runtime/Composer;II)Landroidx/compose/ui/Modifier;
public static final fun focusOutline-AGcomas (Landroidx/compose/ui/Modifier;ZLandroidx/compose/ui/graphics/Shape;Lorg/jetbrains/jewel/foundation/Stroke$Alignment;FFLandroidx/compose/runtime/Composer;II)Landroidx/compose/ui/Modifier;
public static final fun outline-HYR8e34 (Landroidx/compose/ui/Modifier;Lorg/jetbrains/jewel/foundation/state/FocusableComponentState;Lorg/jetbrains/jewel/ui/Outline;Landroidx/compose/ui/graphics/Shape;Lorg/jetbrains/jewel/foundation/Stroke$Alignment;FLandroidx/compose/runtime/Composer;II)Landroidx/compose/ui/Modifier;
}

Expand Down Expand Up @@ -796,10 +796,11 @@ public final class org/jetbrains/jewel/ui/component/styling/ButtonColors$Compani
public final class org/jetbrains/jewel/ui/component/styling/ButtonMetrics {
public static final field $stable I
public static final field Companion Lorg/jetbrains/jewel/ui/component/styling/ButtonMetrics$Companion;
public synthetic fun <init> (Landroidx/compose/foundation/shape/CornerSize;Landroidx/compose/foundation/layout/PaddingValues;JFLkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (Landroidx/compose/foundation/shape/CornerSize;Landroidx/compose/foundation/layout/PaddingValues;JFFLkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun equals (Ljava/lang/Object;)Z
public final fun getBorderWidth-D9Ej5fM ()F
public final fun getCornerSize ()Landroidx/compose/foundation/shape/CornerSize;
public final fun getFocusOutlineExpand-D9Ej5fM ()F
public final fun getMinSize-MYxV2XQ ()J
public final fun getPadding ()Landroidx/compose/foundation/layout/PaddingValues;
public fun hashCode ()I
Expand All @@ -812,9 +813,10 @@ public final class org/jetbrains/jewel/ui/component/styling/ButtonMetrics$Compan
public final class org/jetbrains/jewel/ui/component/styling/ButtonStyle {
public static final field $stable I
public static final field Companion Lorg/jetbrains/jewel/ui/component/styling/ButtonStyle$Companion;
public fun <init> (Lorg/jetbrains/jewel/ui/component/styling/ButtonColors;Lorg/jetbrains/jewel/ui/component/styling/ButtonMetrics;)V
public fun <init> (Lorg/jetbrains/jewel/ui/component/styling/ButtonColors;Lorg/jetbrains/jewel/ui/component/styling/ButtonMetrics;Lorg/jetbrains/jewel/foundation/Stroke$Alignment;)V
public fun equals (Ljava/lang/Object;)Z
public final fun getColors ()Lorg/jetbrains/jewel/ui/component/styling/ButtonColors;
public final fun getFocusOutlineAlignment ()Lorg/jetbrains/jewel/foundation/Stroke$Alignment;
public final fun getMetrics ()Lorg/jetbrains/jewel/ui/component/styling/ButtonMetrics;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
Expand Down
Loading