| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- package eu.mjdev.desktop.components.text
- import androidx.compose.desktop.ui.tooling.preview.Preview
- import androidx.compose.material.LocalTextStyle
- import androidx.compose.runtime.Composable
- import androidx.compose.ui.Modifier
- import androidx.compose.ui.graphics.Color
- import androidx.compose.ui.text.TextLayoutResult
- import androidx.compose.ui.text.TextStyle
- import androidx.compose.ui.text.font.FontFamily
- import androidx.compose.ui.text.font.FontStyle
- import androidx.compose.ui.text.font.FontWeight
- import androidx.compose.ui.text.style.TextAlign
- import androidx.compose.ui.text.style.TextDecoration
- import androidx.compose.ui.text.style.TextOverflow
- import androidx.compose.ui.unit.TextUnit
- import eu.mjdev.desktop.extensions.Compose.textFrom
- @Composable
- fun AutoHideEmptyText(
- text: Any? = "test",
- modifier: Modifier = Modifier,
- color: Color = Color.Unspecified,
- fontSize: TextUnit = TextUnit.Unspecified,
- fontStyle: FontStyle? = null,
- fontWeight: FontWeight? = null,
- fontFamily: FontFamily? = null,
- letterSpacing: TextUnit = TextUnit.Unspecified,
- textDecoration: TextDecoration? = null,
- textAlign: TextAlign? = null,
- lineHeight: TextUnit = TextUnit.Unspecified,
- overflow: TextOverflow = TextOverflow.Clip,
- softWrap: Boolean = true,
- singleLine: Boolean = false,
- maxLines: Int = if (singleLine) 1 else Int.MAX_VALUE,
- minLines: Int = 1,
- onTextLayout: (TextLayoutResult) -> Unit = {},
- style: TextStyle = LocalTextStyle.current
- ) {
- val textAny = textFrom(text)
- if (textAny.isNotEmpty()) {
- TextAny(
- text = text,
- modifier = modifier,
- color = color,
- fontSize = fontSize,
- fontStyle = fontStyle,
- fontWeight = fontWeight,
- fontFamily = fontFamily,
- letterSpacing = letterSpacing,
- textDecoration = textDecoration,
- textAlign = textAlign,
- lineHeight = lineHeight,
- overflow = overflow,
- softWrap = softWrap,
- minLines = minLines,
- maxLines = maxLines,
- onTextLayout = onTextLayout,
- style = style
- )
- }
- }
- @Preview
- @Composable
- fun AutoHideEmptyTextPreview() = AutoHideEmptyText()
|