TextAny.kt 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package eu.mjdev.desktop.components.text
  2. import androidx.compose.desktop.ui.tooling.preview.Preview
  3. import androidx.compose.foundation.text.selection.SelectionContainer
  4. import androidx.compose.material.LocalTextStyle
  5. import androidx.compose.material.Text
  6. import androidx.compose.runtime.Composable
  7. import androidx.compose.ui.Modifier
  8. import androidx.compose.ui.graphics.Color
  9. import androidx.compose.ui.text.TextLayoutResult
  10. import androidx.compose.ui.text.TextStyle
  11. import androidx.compose.ui.text.font.FontFamily
  12. import androidx.compose.ui.text.font.FontStyle
  13. import androidx.compose.ui.text.font.FontWeight
  14. import androidx.compose.ui.text.style.TextAlign
  15. import androidx.compose.ui.text.style.TextDecoration
  16. import androidx.compose.ui.text.style.TextOverflow
  17. import androidx.compose.ui.unit.TextUnit
  18. import eu.mjdev.desktop.extensions.Compose.textFrom
  19. @Suppress("FunctionName")
  20. @Composable
  21. fun TextAny(
  22. text: Any? = "test",
  23. modifier: Modifier = Modifier,
  24. color: Color = Color.Unspecified,
  25. fontSize: TextUnit = TextUnit.Unspecified,
  26. fontStyle: FontStyle? = null,
  27. fontWeight: FontWeight? = null,
  28. fontFamily: FontFamily? = null,
  29. letterSpacing: TextUnit = TextUnit.Unspecified,
  30. textDecoration: TextDecoration? = null,
  31. textAlign: TextAlign? = null,
  32. lineHeight: TextUnit = TextUnit.Unspecified,
  33. overflow: TextOverflow = TextOverflow.Clip,
  34. softWrap: Boolean = true,
  35. minLines: Int = 1,
  36. maxLines: Int = Int.MAX_VALUE,
  37. onTextLayout: (TextLayoutResult) -> Unit = {},
  38. style: TextStyle = LocalTextStyle.current
  39. ) = SelectionContainer(
  40. modifier = modifier
  41. ) {
  42. Text(
  43. text = textFrom(text),
  44. modifier = modifier,
  45. color = color,
  46. minLines = minLines,
  47. fontSize = fontSize,
  48. fontStyle = fontStyle,
  49. fontWeight = fontWeight,
  50. fontFamily = fontFamily,
  51. letterSpacing = letterSpacing,
  52. textDecoration = textDecoration,
  53. textAlign = textAlign,
  54. lineHeight = lineHeight,
  55. overflow = overflow,
  56. softWrap = softWrap,
  57. maxLines = maxLines,
  58. onTextLayout = onTextLayout,
  59. style = style
  60. )
  61. }
  62. @Preview
  63. @Composable
  64. fun TextAnyPreview() = TextAny()