DpSizeField
Field for editing Compose DpSize values (width, height in Dp)
Provides separate input fields for width and height dimensions in density-independent pixels. Used for layout dimensions, component sizing, and spacing that should scale with screen density. Each dimension can be edited independently with automatic Dp conversion.
Usage
// Component size field
@Preview
@Composable
fun ButtonSizePreview() = PreviewLab {
val buttonSize: DpSize = fieldValue { DpSizeField("Button Size", DpSize(120.dp, 48.dp)) }
Button(
onClick = { },
modifier = Modifier.size(buttonSize)
) {
Text("Sized Button")
}
}
// Container dimensions
@Preview
@Composable
fun ContainerPreview() = PreviewLab {
val containerSize: DpSize = fieldValue { DpSizeField("Container", DpSize(200.dp, 100.dp)) }
Box(
modifier = Modifier
.size(containerSize)
.background(Color.LightGray)
) {
Text("Container Content")
}
}
// Image dimensions
@Preview
@Composable
fun ImageSizePreview() = PreviewLab {
val imageSize: DpSize = fieldValue { DpSizeField("Image Size", DpSize(150.dp, 150.dp)) }
Image(
painter = painterResource(R.drawable.sample),
contentDescription = null,
modifier = Modifier.size(imageSize)
)
}Parameters
Display label for the field
Starting DpSize value
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.
Helper for UI of Fields that can be input with TextField.
Transforms a MutablePreviewLabField to work with a different value type.
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.
Adds hint choices to a MutablePreviewLabField, allowing users to quickly select from predefined values.
Adds predefined color hints to a Color field for quick selection.
Wraps this field with a custom me.tbsten.compose.preview.lab.PreviewLabField.serializer implementation.
Wraps this field with a custom me.tbsten.compose.preview.lab.PreviewLabField.valueCode implementation.
Wraps this field with additional composable content.