androidx.compose.foundation.style

Interfaces

AlphaScope

An interface that introduces the alpha property to a Style receiver scope.

Cmn
AnimateStyleScope

An interface that introduces animate functions to a Style receiver scope.

Cmn
BackgroundScope

An interface that introduces the background property to a Style receiver scope.

Cmn
BaselineShiftScope

An interface that introduces the baselineShift property to a Style receiver scope.

Cmn
BorderScope

An interface that introduces border properties to a Style receiver scope interface.

Cmn
ClipScope

An interface that introduces the clip property to a Style receiver scope.

Cmn
ColorFilterScope

An interface the introduces the colorFilter property to a Style receiver scope.

Cmn
ContentColorScope

An interface that introduces the contentColor property to a Style receiver scope.

Cmn
ContentPaddingScope

An interface that introduces the contentPadding property to a Style receiver scope interface.

Cmn
CustomStyle

A base type for custom styles including Style itself.

Cmn
CustomStyleScope

An interface that is the base interface for all styles scopes.

Cmn
DrawStyleScope

An interface that introduces the drawing property to a Style receiver scope.

Cmn
ExternalPaddingScope

An interface that introduces the externalPadding properties to a Style receiver scope interface.

Cmn
FontFamilyScope

An interface that introduces the fontFamily property to a Style receiver scope.

Cmn
FontSizeScope

An interface that introduces the fontSize property to a Style receiver scope.

Cmn
FontStyleScope

An interface that introduces the fontStyle property to a Style receiver scope.

Cmn
FontSynthesisScope

An interface that introduces the fontSynthesis property to a Style receiver scope.

Cmn
FontWeightScope

An interface that introduces the fontWeight property to a Style receiver scope.

Cmn
ForegroundScope

An interface that introduces the foreground property to a Style receiver scope.

Cmn
HyphensScope

An interface that introduces the hyphens property to a Style receiver scope.

Cmn
LayerStyleScope

An interface that introduces the graphics layer property to a Style receiver scope.

Cmn
LayoutStyleScope

An interface that introduces the layout properties to a Style receiver scope.

Cmn
LetterSpacingScope

An interface that introduces the letterSpacing property to a Style receiver scope.

Cmn
LineBreakScope

An interface that introduces the lineBreak property to a Style receiver scope.

Cmn
LineHeightScope

An interface that introduces the lineHeight property to a Style receiver scope.

Cmn
MaxSizeScope

An interface that introduces maxWidth and maxHeight properties to a Style receiver scope.

Cmn
MinSizeScope

An interface that introduces min size properties to a Style receiver scope interface.

Cmn
PositionScope

An interface that introduces position properties to a Style receiver scope interface.

Cmn
RotationScope

An interface that introduces the rotation properties to a Style receiver scope.

Cmn
ScaleScope

An interface that introduces the scaleX and scaleY properties to a Style receiver scope.

Cmn
ShadowScope

An interface that introduces the shadow properties to a Style receiver scope.

Cmn
ShapeScope

An interface that introduces the shape property to a Style receiver scope.

Cmn
SizeScope

An interface that introduces size properties to a Style receiver scope interface.

Cmn
Style

Style represents an opaque type which encodes a description of how to style a node in compose.

Cmn
StyleScope

A StyleScope is the receiver scope of a Style lambda.

Cmn
StyleStateScope

An interface that introduces the state property to a Style receiver scope.

Cmn
TextAlignScope

An interface that introduces the textAlign property to a Style receiver scope.

Cmn
TextDecorationScope

An interface that introduces the textDecoration property to a Style receiver scope.

Cmn
TextDirectionScope

An interface that introduces the textDirection property to a Style receiver scope.

Cmn
TextIndentScope

An interface that introduces the textIndent property to a Style receiver scope.

Cmn
TextMotionScope

An interface that introduces the textMotion property to a Style receiver scope.

Cmn
TextStyleScope

An interface that introduces the textStyle property to a Style receiver scope.

Cmn
TextStyleStyleScope

An interface that introduces the text property to a Style receiver scope.

Cmn
TransformOriginScope

An interface that introduces the transform origin properties to a Style receiver scope.

Cmn
TranslationScope

An interface that introduces the translation properties to a Style receiver scope.

Cmn
ZIndexScope

An interface that introduces the zIndex property to a Style receiver scope.

Cmn

Classes

MutableStyleState

The state a style that can be updated to reflect the current state of a component.

Cmn
StyleState

The state a style can use to select property values depending on the state of the component is a style for.

Cmn
StyleStateKey

The key to a StyleState value.

Cmn

Objects

Annotations

Composables

rememberUpdatedStyleState

Create, remember and update a StyleState for use as a parameter of a androidx.compose.ui.Modifier.styleable modifier.

Cmn

Modifiers

styleable

Modifier that creates a region that is styled by the given Style object for the component this Modifier is attached to.

Cmn

Top-level functions summary

Style

Combine multiple Style objects together.

Cmn
Style

Combine multiple Style objects together.

Cmn
Style
@ExperimentalFoundationStyleApi
Style(style1: Style, style2: Style, style3: Style)

Combine multiple Style objects together.

Cmn

Extension functions summary

Unit

Specifies a Style whose properties will be animated to when they change.

Cmn
Unit

Specifies a Style whose properties will be animated to when they change, using the provided AnimationSpec.

Cmn
Unit
@ExperimentalFoundationStyleApi
<ScopeT : CustomStyleScope, StyleT : CustomStyle<ScopeT>> ScopeT.apply(
    style: StyleT
)

Apply style to the current StyleScope.

Cmn
Unit

Sets a border for the component with the specified width and brush.

Cmn
Unit

Sets a solid border for the component with the specified width and color.

Cmn
Unit

Defines a Style to be applied when the component is StyleState.isChecked is true.

Cmn
Unit

Sets the padding for the component's content.

Cmn
Unit

Sets the padding for all four edges (top, end, bottom, start) edges of the component's content.

Cmn
Unit

Sets the padding for the vertical (top and bottom) and horizontal (start and end) edges of the component's content.

Cmn
Unit

Sets the padding for all four edges (top, end, bottom, start) edges of the component's content.

Cmn
Unit

Sets the padding for the horizontal (start and end) edges of the component's content.

Cmn
Unit

Sets the padding for the vertical (start and end) edges of the component's content.

Cmn
Unit

Defines a Style to be applied when the component is disabled.

Cmn
Unit

Sets the external padding for the component.

Cmn
Unit

Sets the external padding for all four edges (top, end, bottom, start) of the component.

Cmn
Unit

Sets the external padding for the vertical (top and bottom) and horizontal (start and end) edges of the component.

Cmn
Unit
@ExperimentalFoundationStyleApi
ExternalPaddingScope.externalPadding(
    start: Dp,
    top: Dp,
    end: Dp,
    bottom: Dp
)

Sets the external padding for all four edges (top, end, bottom, start) of the component.

Cmn
Unit

Sets the external padding for the horizontal (start and end) edges of the component.

Cmn
Unit

Sets the external padding for the vertical (start and end) edges of the component.

Cmn
Unit

Sets the height of the component to fill the parent's available height (equivalent to height(1.0f)).

Cmn
Unit

Sets the width and height of the component to fill the parent's available space (equivalent to width(1.0f) and height(1.0f)).

Cmn
Unit

Sets the width of the component to fill the parent's available width (equivalent to width(1.0f)).

Cmn
Unit

Defines a Style to be applied when the component is focused.

Cmn
Unit

Defines a Style to be applied when the component is hovered.

Cmn
Unit

Constrains the maximum size (width and height) of the component.

Cmn
Unit

Constrains the maximum width and height of the component.

Cmn
Unit

Constrains the minimum size (width and height) of the component.

Cmn
Unit

Constrains the minimum width and height of the component.

Cmn
Unit

Defines a Style to be applied when the component is pressed.

Cmn
Unit

Rotates the component around the X-axis, Y-axis and Z-axis (perpendicular to the screen) through its center.

Cmn
Unit

Scales the component uniformly (both horizontally and vertically) around its center pivot point.

Cmn
Unit
@ExperimentalFoundationStyleApi
ScaleScope.scale(
    x: @FloatRange(from = 0.0) Float,
    y: @FloatRange(from = 0.0) Float
)

Scales the component uniformly (both horizontally and vertically) around its center pivot point.

Cmn
Unit

Defines a Style to be applied when the component is StyleState.isSelected is true.

Cmn
Unit

Sets the preferred width and height of the component to the same value.

Cmn
Unit

Sets the preferred width and height of the component using a DpSize object.

Cmn
Unit

Sets the preferred width and height of the component.

Cmn
Unit

A helper function to implement state reading extension functions such as StyleScope.pressed for use with Boolean states.

Cmn
infix Style

Merges this styles with another.

Cmn
Unit

Offset percentage along the x and y-axis for which contents are rotated and scaled.

Cmn
Unit

Translates (moves) the component by the given Offset.

Cmn
Unit
@ExperimentalFoundationStyleApi
TranslationScope.translation(
    x: @FloatRange(from = 0.0) Float,
    y: @FloatRange(from = 0.0) Float
)

Translates (moves) the component horizontally and vertically.

Cmn
Unit

Defines a Style to be applied when the component is StyleState.triStateToggle is ToggleableState.Indeterminate.

Cmn
Unit

Defines a Style to be applied when the component is StyleState.triStateToggle is ToggleableState.Off.

Cmn
Unit

Defines a Style to be applied when the component is StyleState.triStateToggle is ToggleableState.On.

Cmn

Top-level functions

@ExperimentalFoundationStyleApi
fun Style(vararg styles: Style): Style

Combine multiple Style objects together. Styles whose argument positions are further "to the right" will override styles to the left of them, on a per-property basis.

@ExperimentalFoundationStyleApi
fun Style(style1: Style, style2: Style): Style

Combine multiple Style objects together. Styles whose argument positions are further "to the right" will override styles to the left of them, on a per-property basis.

@ExperimentalFoundationStyleApi
fun Style(style1: Style, style2: Style, style3: Style): Style

Combine multiple Style objects together. Styles whose argument positions are further "to the right" will override styles to the left of them, on a per-property basis.

Extension functions

AnimateStyleScope.animate

@ExperimentalFoundationStyleApi
fun AnimateStyleScope.animate(block: () -> Unit): Unit

Specifies a Style whose properties will be animated to when they change. This uses a default animation specification. This allows for smooth transitions between style states without manual animation setup. A androidx.compose.animation.core.spring will be used for the animation for both animating to and from the style.

Parameters
block: () -> Unit

The target Style whose properties should be animated.

See also
Style

AnimateStyleScope.animate

@ExperimentalFoundationStyleApi
fun AnimateStyleScope.animate(spec: AnimationSpec<Float>, block: () -> Unit): Unit

Specifies a Style whose properties will be animated to when they change, using the provided AnimationSpec. This allows for smooth transitions between style states with custom animation curves. The same animation spec will be used for animating both to and from the style.

Parameters
spec: AnimationSpec<Float>

The AnimationSpec to use for the animation.

block: () -> Unit

The target Style whose properties should be animated.

See also
Style
AnimationSpec
@ExperimentalFoundationStyleApi
fun <ScopeT : CustomStyleScope, StyleT : CustomStyle<ScopeT>> ScopeT.apply(
    style: StyleT
): Unit

Apply style to the current StyleScope. Applying the scope calls the scope applies any properties set in the scope directly.

Parameters
style: StyleT

the style to apply.

BorderScope.border

@ExperimentalFoundationStyleApi
fun BorderScope.border(width: Dp, brush: Brush): Unit

Sets a border for the component with the specified width and brush. The border is drawn on top of the background and the padded content. The border itself does not contribute to the component's layout size (width/height).

Specifying a Dp.Unspecified width will remove the border.

Specifying a Dp.Hairline or 0.dp width will create 1 pixel border regardless of density.

This property is not inherited

Parameters
width: Dp

The width of the border.

brush: Brush

The brush to paint the border (e.g., for gradients).

BorderScope.border

@ExperimentalFoundationStyleApi
fun BorderScope.border(width: Dp, color: Color): Unit

Sets a solid border for the component with the specified width and color. The border is drawn on top of the background and the padded content. The border itself does not contribute to the component's layout size (width/height).

Specifying a Dp.Unspecified width will remove the border.

Specifying a Dp.Hairline or 0.dp width will create 1 pixel border regardless of density.

This property is not inherited

Parameters
width: Dp

The width of the border.

color: Color

The color of the border.

StyleStateScope.checked

@ExperimentalFoundationStyleApi
fun StyleStateScope.checked(block: () -> Unit): Unit

Defines a Style to be applied when the component is StyleState.isChecked is true. The properties within the provided block will override or merge with the base style of the component when a toggle interaction is detected.

T.contentPadding

@ExperimentalFoundationStyleApi
fun <T : ContentPaddingScope & CompositionLocalAccessorScope> T.contentPadding(
    paddingValues: PaddingValues
): Unit

Sets the padding for the component's content. Content padding is the space between the component's border (if any) and its content. The width/height of the component includes content padding.

This property is not inherited

Parameters
paddingValues: PaddingValues

The PaddingValues to apply to the content.

ContentPaddingScope.contentPadding

@ExperimentalFoundationStyleApi
fun ContentPaddingScope.contentPadding(value: Dp): Unit

Sets the padding for all four edges (top, end, bottom, start) edges of the component's content. Content padding is the space between the component's border (if any) and its content. The width/height of the component includes content padding.

This property is not inherited

Parameters
value: Dp

The amount of padding to apply to all four edges.

ContentPaddingScope.contentPadding

@ExperimentalFoundationStyleApi
fun ContentPaddingScope.contentPadding(horizontal: Dp, vertical: Dp): Unit

Sets the padding for the vertical (top and bottom) and horizontal (start and end) edges of the component's content. Content padding is the space between the component's border (if any) and its content. The width/height of the component includes content padding.

This property is not inherited

Parameters
horizontal: Dp

The padding for the start and end edges.

vertical: Dp

The padding for the top and bottom edges.

ContentPaddingScope.contentPadding

@ExperimentalFoundationStyleApi
fun ContentPaddingScope.contentPadding(start: Dp, top: Dp, end: Dp, bottom: Dp): Unit

Sets the padding for all four edges (top, end, bottom, start) edges of the component's content. Content padding is the space between the component's border (if any) and its content. The width/height of the component includes content padding.

This property is not inherited

Parameters
start: Dp

The padding for the start edge.

top: Dp

The padding for the top edge.

end: Dp

The padding for the end edge.

bottom: Dp

The padding for the bottom edge.

ContentPaddingScope.contentPaddingHorizontal

@ExperimentalFoundationStyleApi
fun ContentPaddingScope.contentPaddingHorizontal(value: Dp): Unit

Sets the padding for the horizontal (start and end) edges of the component's content. Content padding is the space between the component's border (if any) and its content. The width/height of the component includes content padding.

This property is not inherited

Parameters
value: Dp

The amount of padding to apply to both start and end edges.

ContentPaddingScope.contentPaddingVertical

@ExperimentalFoundationStyleApi
fun ContentPaddingScope.contentPaddingVertical(value: Dp): Unit

Sets the padding for the vertical (start and end) edges of the component's content. Content padding is the space between the component's border (if any) and its content. The width/height of the component includes content padding.

This property is not inherited

Parameters
value: Dp

The amount of padding to apply to both top and bottom edges.

StyleStateScope.disabled

@ExperimentalFoundationStyleApi
fun StyleStateScope.disabled(block: () -> Unit): Unit

Defines a Style to be applied when the component is disabled. The properties within the provided value Style will override or merge with the base style of the component when the style state for the component is disabled.

Parameters
block: () -> Unit

The Style to apply on hover.

See also
isEnabled

T.externalPadding

@ExperimentalFoundationStyleApi
fun <T : ExternalPaddingScope & CompositionLocalAccessorScope> T.externalPadding(
    paddingValues: PaddingValues
): Unit

Sets the external padding for the component. The external padding is the space between the edge of the component and its border (if any). The width/height of the component includes external padding.

This property is not inherited

Parameters
paddingValues: PaddingValues

The PaddingValues to apply to the external padding.

ExternalPaddingScope.externalPadding

@ExperimentalFoundationStyleApi
fun ExternalPaddingScope.externalPadding(value: Dp): Unit

Sets the external padding for all four edges (top, end, bottom, start) of the component. The external padding is the space between the edge of the component and its border (if any). The width/height of the component includes external padding.

This property is not inherited

Parameters
value: Dp

The amount of padding to apply to all four edges.

ExternalPaddingScope.externalPadding

@ExperimentalFoundationStyleApi
fun ExternalPaddingScope.externalPadding(horizontal: Dp, vertical: Dp): Unit

Sets the external padding for the vertical (top and bottom) and horizontal (start and end) edges of the component. The external padding is the space between the edge of the component and its border (if any). The width/height of the component includes external padding.

This property is not inherited

Parameters
horizontal: Dp

The padding for the start and end edges.

vertical: Dp

The padding for the top and bottom edges.

ExternalPaddingScope.externalPadding

@ExperimentalFoundationStyleApi
fun ExternalPaddingScope.externalPadding(
    start: Dp,
    top: Dp,
    end: Dp,
    bottom: Dp
): Unit

Sets the external padding for all four edges (top, end, bottom, start) of the component. The external padding is the space between the edge of the component and its border (if any). The width/height of the component includes external padding.

This property is not inherited

Parameters
start: Dp

The padding for the start edge.

top: Dp

The padding for the top edge.

end: Dp

The padding for the end edge.

bottom: Dp

The padding for the bottom edge.

ExternalPaddingScope.externalPaddingHorizontal

@ExperimentalFoundationStyleApi
fun ExternalPaddingScope.externalPaddingHorizontal(value: Dp): Unit

Sets the external padding for the horizontal (start and end) edges of the component. The external padding is the space between the edge of the component and its border (if any). The width/height of the component includes external padding.

This property is not inherited

Parameters
value: Dp

The amount of padding to apply to both start and end edges.

ExternalPaddingScope.externalPaddingVertical

@ExperimentalFoundationStyleApi
fun ExternalPaddingScope.externalPaddingVertical(value: Dp): Unit

Sets the external padding for the vertical (start and end) edges of the component. The external padding is the space between the edge of the component and its border (if any). The width/height of the component includes external padding.

This property is not inherited

Parameters
value: Dp

The amount of padding to apply to both top and bottom edges.

SizeScope.fillHeight

@ExperimentalFoundationStyleApi
fun SizeScope.fillHeight(): Unit

Sets the height of the component to fill the parent's available height (equivalent to height(1.0f)). The specified height includes any padding.

This property is not inherited

SizeScope.fillSize

@ExperimentalFoundationStyleApi
fun SizeScope.fillSize(): Unit

Sets the width and height of the component to fill the parent's available space (equivalent to width(1.0f) and height(1.0f)). The specified size includes any padding.

This property is not inherited

SizeScope.fillWidth

@ExperimentalFoundationStyleApi
fun SizeScope.fillWidth(): Unit

Sets the width of the component to fill the parent's available width (equivalent to width(1.0f)). The specified width includes any padding.

This property is not inherited

StyleStateScope.focused

@ExperimentalFoundationStyleApi
fun StyleStateScope.focused(block: () -> Unit): Unit

Defines a Style to be applied when the component is focused. The properties within the provided value Style will override or merge with the base style of the component when a focus interaction is detected.

Parameters
block: () -> Unit

The Style to apply on focus.

StyleStateScope.hovered

@ExperimentalFoundationStyleApi
fun StyleStateScope.hovered(block: () -> Unit): Unit

Defines a Style to be applied when the component is hovered. The properties within the provided value Style will override or merge with the base style of the component when a hover interaction is detected.

Parameters
block: () -> Unit

The Style to apply on hover.

MaxSizeScope.maxSize

@ExperimentalFoundationStyleApi
fun MaxSizeScope.maxSize(size: DpSize): Unit

Constrains the maximum size (width and height) of the component. The component's dimensions, including padding, will be at most these values.

This property is not inherited

Parameters
size: DpSize

The maximum size (DpSize).

MaxSizeScope.maxSize

@ExperimentalFoundationStyleApi
fun MaxSizeScope.maxSize(width: Dp, height: Dp): Unit

Constrains the maximum width and height of the component. The component's dimensions, including padding, will be at most these values.

This property is not inherited

Parameters
width: Dp

The maximum width.

height: Dp

The maximum height.

MinSizeScope.minSize

@ExperimentalFoundationStyleApi
fun MinSizeScope.minSize(size: DpSize): Unit

Constrains the minimum size (width and height) of the component. The component's dimensions, including padding, will be at least these values.

This property is not inherited

Parameters
size: DpSize

The minimum size (DpSize).

MinSizeScope.minSize

@ExperimentalFoundationStyleApi
fun MinSizeScope.minSize(width: Dp, height: Dp): Unit

Constrains the minimum width and height of the component. The component's dimensions, including padding, will be at least these values.

This property is not inherited

Parameters
width: Dp

The minimum width.

height: Dp

The minimum height.

StyleStateScope.pressed

@ExperimentalFoundationStyleApi
fun StyleStateScope.pressed(block: () -> Unit): Unit

Defines a Style to be applied when the component is pressed. The properties within the provided value Style will override or merge with the base style of the component when a press interaction is detected.

Parameters
block: () -> Unit

The Style to apply on press.

RotationScope.rotation

@ExperimentalFoundationStyleApi
fun RotationScope.rotation(x: Float, y: Float, z: Float): Unit

Rotates the component around the X-axis, Y-axis and Z-axis (perpendicular to the screen) through its center.

This property is not inherited

Parameters
x: Float

The x-axis rotation angle in degrees.

y: Float

The x-axis rotation angle in degrees.

z: Float

The x-axis rotation angle in degrees.

ScaleScope.scale

@ExperimentalFoundationStyleApi
fun ScaleScope.scale(value: @FloatRange(from = 0.0) Float): Unit

Scales the component uniformly (both horizontally and vertically) around its center pivot point.

Setting scale will override the horizontal scaling set by a previous call to ScaleScope.scaleX and the previous vertical scaling set by calling ScaleScope.scaleY.

This property is not inherited

Parameters
value: @FloatRange(from = 0.0) Float

The scaling factor for both X and Y axes. 1.0f is no scale.

ScaleScope.scale

@ExperimentalFoundationStyleApi
fun ScaleScope.scale(
    x: @FloatRange(from = 0.0) Float,
    y: @FloatRange(from = 0.0) Float
): Unit

Scales the component uniformly (both horizontally and vertically) around its center pivot point.

Setting scale will override the horizontal scaling set by a previous call to ScaleScope.scaleX and the previous vertical scaling set by calling ScaleScope.scaleY.

This property is not inherited

Parameters
x: @FloatRange(from = 0.0) Float

The scaling factor for X axes. 1.0f is no scale.

y: @FloatRange(from = 0.0) Float

The scaling factor for Y axes. 1.0f is no scale.

StyleStateScope.selected

@ExperimentalFoundationStyleApi
fun StyleStateScope.selected(block: () -> Unit): Unit

Defines a Style to be applied when the component is StyleState.isSelected is true. The properties within the provided block Style will override or merge with the base style of the component when a toggle interaction is detected.

Parameters
block: () -> Unit

The Style to apply on press.

See also
isSelected

SizeScope.size

@ExperimentalFoundationStyleApi
fun SizeScope.size(value: Dp): Unit

Sets the preferred width and height of the component to the same value. The actual size will also depend on the parent's constraints and other modifiers. The specified size includes any padding.

This property is not inherited

Parameters
value: Dp

The preferred width and height in Dp.

See also
size

SizeScope.size

@ExperimentalFoundationStyleApi
fun SizeScope.size(value: DpSize): Unit

Sets the preferred width and height of the component using a DpSize object. The actual size will also depend on the parent's constraints and other modifiers. The specified size includes any padding.

This property is not inherited

Parameters
value: DpSize

The preferred size.

See also
size

SizeScope.size

@ExperimentalFoundationStyleApi
fun SizeScope.size(width: Dp, height: Dp): Unit

Sets the preferred width and height of the component. The actual size will also depend on the parent's constraints and other modifiers. The specified dimensions includes both contentPadding and externalPadding.

This property is not inherited

Parameters
width: Dp

The preferred width in Dp.

height: Dp

The preferred height in Dp.

See also
size

StyleStateScope.state

@ExperimentalFoundationStyleApi
fun StyleStateScope.state(key: StyleStateKey<Boolean>, block: () -> Unit): Unit

A helper function to implement state reading extension functions such as StyleScope.pressed for use with Boolean states.

Custom style states can use this function to implement start reading functions to be consistent with the predefined state reading functions.

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.style.CustomStyle
import androidx.compose.foundation.style.Style
import androidx.compose.foundation.style.StyleScope
import androidx.compose.foundation.style.StyleStateKey
import androidx.compose.foundation.style.rememberUpdatedStyleState
import androidx.compose.foundation.style.state
import androidx.compose.foundation.style.styleable
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color

// Create a new StyleStateKey
val playingStateKey = StyleStateKey(false)

// In the module scope are the following declarations:
//
//    // A custom style scope which has all the properties of StyleScope
//    interface MediaPlayerStyleScope : StyleScope
//
//    // A custom style type
//    fun interface MediaPlayerStyle : CustomStyle<MediaPlayerStyleScope> {
//        companion object : MediaPlayerStyle {
//            override fun MediaPlayerStyleScope.applyStyle() { }
//        }
//    }

// Introduce a function to convert the custom style to a Style
fun MediaPlayerStyle.toStyle(): Style = Style {
    val scope = object : StyleScope by this, MediaPlayerStyleScope {}
    with(scope) { applyStyle() }
}

// Introduce an extension function to read the style state. This will only be
// available in a MediaPlayerStyle.
fun MediaPlayerStyleScope.playerPlaying(block: () -> Unit) {
    state(playingStateKey, block)
}

// The MediaPlayer composable
@Suppress("UNUSED_PARAMETER")
@Composable
fun MediaPlayer(
    url: String,
    modifier: Modifier = Modifier,
    style: MediaPlayerStyle = MediaPlayerStyle,
    playing: Boolean = true,
) {
    val styleState =
        rememberUpdatedStyleState(null) { state -> state[playingStateKey] = playing }
    Box(modifier = modifier.styleable(styleState, style.toStyle())) {
        // Implementation of the media player
    }
}

// Using the style in a composable that sets the state.
MediaPlayer(
    url = "https://example.com/media/video",
    style = {
        borderColor(Color.Gray)

        // This only sets the border color to green when the media player is playing
        playerPlaying { borderColor(Color.Green) }
    },
)
Parameters
key: StyleStateKey<Boolean>

the StyleStateKey for the custom state.

block: () -> Unit

the block to execute when the style state is true.

Style.then

@ExperimentalFoundationStyleApi
infix fun Style.then(other: Style): Style

Merges this styles with another. The style to the right on the then will overwrite the properties set by the style to the left.

Parameters
other: Style

the style to merge into the receiver.

TransformOriginScope.transformOrigin

@ExperimentalFoundationStyleApi
fun TransformOriginScope.transformOrigin(value: TransformOrigin): Unit

Offset percentage along the x and y-axis for which contents are rotated and scaled. The default value of 0.5f, 0.5f indicates the pivot point will be at the midpoint of the left and right as well as the top and bottom bounds of the layer. Default value is TransformOrigin.Center.

Parameters
value: TransformOrigin

The origin of the transform

TranslationScope.translation

@ExperimentalFoundationStyleApi
fun TranslationScope.translation(offset: Offset): Unit

Translates (moves) the component by the given Offset.

This property is not inherited

Parameters
offset: Offset

The translation offset in pixels.

TranslationScope.translation

@ExperimentalFoundationStyleApi
fun TranslationScope.translation(
    x: @FloatRange(from = 0.0) Float,
    y: @FloatRange(from = 0.0) Float
): Unit

Translates (moves) the component horizontally and vertically.

This property is not inherited

Parameters
x: @FloatRange(from = 0.0) Float

The translation amount on the X-axis in pixels.

y: @FloatRange(from = 0.0) Float

The translation amount on the Y-axis in pixels.

StyleStateScope.triStateToggleIndeterminate

@ExperimentalFoundationStyleApi
fun StyleStateScope.triStateToggleIndeterminate(block: () -> Unit): Unit

Defines a Style to be applied when the component is StyleState.triStateToggle is ToggleableState.Indeterminate. The properties within the provided block Style will override or merge with the base style of the component when a toggle interaction is detected.

Parameters
block: () -> Unit

The Style to apply on press.

StyleStateScope.triStateToggleOff

@ExperimentalFoundationStyleApi
fun StyleStateScope.triStateToggleOff(block: () -> Unit): Unit

Defines a Style to be applied when the component is StyleState.triStateToggle is ToggleableState.Off. The properties within the provided block Style will override or merge with the base style of the component when a toggle interaction is detected.

Parameters
block: () -> Unit

The Style to apply on press.

StyleStateScope.triStateToggleOn

@ExperimentalFoundationStyleApi
fun StyleStateScope.triStateToggleOn(block: () -> Unit): Unit

Defines a Style to be applied when the component is StyleState.triStateToggle is ToggleableState.On. The properties within the provided block Style will override or merge with the base style of the component when a toggle interaction is detected.

Parameters
block: () -> Unit

The Style to apply on press.