ModifierField
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
Display label for the field in the inspector
Starting modifier chain configuration
See also
Functions
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.
Default UI implementation of me.tbsten.compose.preview.lab.PreviewLabField.View. Display a label and draw the content below it.
Display the label of PreviewLabField.
Create a PreviewLabField that makes the receiver's PreviewLabField nullable.
Returns a KSerializer for this field's value type, or null if serialization is not supported.
Returns a list of representative values for this field to be used in automated testing.
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.