ModifierField

class ModifierField(label: String, initialValue: ModifierFieldValueList = ModifierFieldValue.mark()) : ImmutablePreviewLabField<Modifier>

Interactive field for building and editing Compose Modifier chains

Provides a visual interface for constructing complex Modifier chains through a builder pattern. Users can add, remove, and configure individual modifier values like padding, background, size constraints, etc. The field displays a real-time preview of the constructed modifier and allows fine-tuning of parameters through dedicated UI controls.

Usage

// Basic modifier field with default marking
@Preview
@Composable
fun ButtonPreview() = PreviewLab {
Button(
onClick = { },
modifier = fieldValue { ModifierField("Button modifier") },
) {
Text("Styled Button")
}
}

// Custom initial modifier chain
@Preview
@Composable
fun CardPreview() = PreviewLab {
val customModifier: Modifier = fieldValue {
ModifierField(
label = "Card Modifier",
initialValue = ModifierFieldValue.mark()
.padding(16.dp)
.background(Color.Blue)
)
}

Card(modifier = customModifier) {
Text("Custom Card")
}
}

// Pre-configured with multiple modifiers
@Preview
@Composable
fun BoxPreview() = PreviewLab {
val containerModifier: Modifier = fieldValue {
ModifierField(
label = "Container",
initialValue = ModifierFieldValue.mark()
.padding(all = 8.dp)
.background(Color.Gray.copy(alpha = 0.3f))
.border(width = 2.dp, color = Color.Black)
)
}

Box(modifier = containerModifier) {
Text("Container Content")
}
}

Parameters

label

Display label for the field in the inspector

initialValue

Starting modifier chain configuration

See also

Constructors

Link copied to clipboard
constructor(label: String, initialValue: ModifierFieldValueList = ModifierFieldValue.mark())

Properties

Link copied to clipboard
open override val coroutineScope: CoroutineScope
Link copied to clipboard
open override val initialValue: Modifier

Default value for this field.

Link copied to clipboard
open override val label: String

The label for this field. This is not used in any of the program logic, but only for display purposes, so it is best to set it in a language that is easy for your team members to read.

Link copied to clipboard
open override var value: Modifier

Current value of this PreviewLabField.

Link copied to clipboard
open override val valueFlow: Flow<Modifier>

Functions

Link copied to clipboard
open override fun Content()

Composable, which displays the main UI for this Field. If you want to customize the UI, you can override this method in your PreviewLabField to customize the UI.

Link copied to clipboard
fun <Value> PreviewLabField<Value>.DefaultFieldView(modifier: Modifier = Modifier, menuItems: List<PreviewLabField.ViewMenuItem<Value>> = ViewMenuItem.defaults<Value>(this), content: @Composable () -> Unit = { Content() })

Default UI implementation of me.tbsten.compose.preview.lab.PreviewLabField.View. Display a label and draw the content below it.

Link copied to clipboard
fun <Value> PreviewLabField<Value>.FieldLabelHeader(menuItems: List<PreviewLabField.ViewMenuItem<Value>> = ViewMenuItem.defaults<Value>(this))

Display the label of PreviewLabField.

Link copied to clipboard
fun <Value : Any> PreviewLabField<Value>.nullable(initialValue: Value? = this.initialValue): NullableField<Value>

Create a PreviewLabField that makes the receiver's PreviewLabField nullable.

Link copied to clipboard
open fun onCleared()
Link copied to clipboard
open fun serializer(): KSerializer<Modifier>?

Returns a KSerializer for this field's value type, or null if serialization is not supported.

Link copied to clipboard
open fun testValues(): List<Modifier>

Returns a list of representative values for this field to be used in automated testing.

Link copied to clipboard
open fun valueCode(): String

Returns a Kotlin code string representing the current value of this field.

Link copied to clipboard

Composable, which displays the entire UI for this Field. If you want to customize the UI, you can override this method in your PreviewLabField to customize the UI. However, in many cases where the UI is customized, overriding the content method is more appropriate.

Link copied to clipboard