Skip to content

Commit

Permalink
Add simple FocusOutline API (#410)
Browse files Browse the repository at this point in the history
Add an overload for Modifier.focusOutline that takes a simple Boolean
instead of a FocusableComponentState, allowing users to use the modifier
even for components that don't have a FocusableComponentState.
  • Loading branch information
rock3r authored Jun 14, 2024
1 parent bf5969b commit fdbcc05
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions ui/api/ui.api
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ 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 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
10 changes: 9 additions & 1 deletion ui/src/main/kotlin/org/jetbrains/jewel/ui/Outline.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,18 @@ public fun Modifier.focusOutline(
outlineShape: Shape,
alignment: Stroke.Alignment = Stroke.Alignment.Outside,
outlineWidth: Dp = JewelTheme.globalMetrics.outlineWidth,
): Modifier = focusOutline(state.isFocused, outlineShape, alignment, outlineWidth)

@Composable
public fun Modifier.focusOutline(
showOutline: Boolean,
outlineShape: Shape,
alignment: Stroke.Alignment = Stroke.Alignment.Outside,
outlineWidth: Dp = JewelTheme.globalMetrics.outlineWidth,
): Modifier {
val outlineColors = JewelTheme.globalColors.outlines

return thenIf(state.isFocused) {
return thenIf(showOutline) {
val outlineColor = outlineColors.focused
border(alignment, outlineWidth, outlineColor, outlineShape)
}
Expand Down

0 comments on commit fdbcc05

Please sign in to comment.