PreviewLabField

Field class specified in PreviewLabScope.field/fieldValue. In reality, it may be better to use the value property, getValue method, and setValue method to implement MutableState.

In many cases, it is sufficient to use StringField, SelectableField, etc., and it is unlikely that this class will be set directly. You would use this Composable if you want to create a Field of a custom type (set the value type parameter to your custom type) or if you want to create a UI for a custom Field (override the View method).

Inheritors

Types

Link copied to clipboard
abstract class ViewMenuItem<Value>(val field: PreviewLabField<Value>)

Properties

Link copied to clipboard
abstract val coroutineScope: CoroutineScope
Link copied to clipboard
abstract val initialValue: Value

Default value for this field.

Link copied to clipboard
abstract 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
abstract val value: Value

Current value of this PreviewLabField.

Link copied to clipboard
abstract val valueFlow: Flow<Value>

Functions

Link copied to clipboard
abstract 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<Value>?

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

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

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
open fun View(menuItems: List<PreviewLabField.ViewMenuItem<Value>> = ViewMenuItem.defaults(this))

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