Sfoglia il codice sorgente

text any improvement

milan jurkulák 2 anni fa
parent
commit
5c11c47cef
1 ha cambiato i file con 32 aggiunte e 22 eliminazioni
  1. 32 22
      src/main/kotlin/eu/mjdev/desktop/components/text/TextAny.kt

+ 32 - 22
src/main/kotlin/eu/mjdev/desktop/components/text/TextAny.kt

@@ -37,31 +37,41 @@ fun TextAny(
     minLines: Int = 1,
     maxLines: Int = Int.MAX_VALUE,
     onTextLayout: (TextLayoutResult) -> Unit = {},
-    style: TextStyle = LocalTextStyle.current
-) = SelectionContainer(
-    modifier = modifier
+    style: TextStyle = LocalTextStyle.current,
+    textSelectionEnabled: Boolean = false
 ) {
-    Text(
-        text = textFrom(text),
-        modifier = modifier,
-        color = color,
-        minLines = minLines,
-        fontSize = fontSize,
-        fontStyle = fontStyle,
-        fontWeight = fontWeight,
-        fontFamily = fontFamily,
-        letterSpacing = letterSpacing,
-        textDecoration = textDecoration,
-        textAlign = textAlign,
-        lineHeight = lineHeight,
-        overflow = overflow,
-        softWrap = softWrap,
-        maxLines = maxLines,
-        onTextLayout = onTextLayout,
-        style = style
-    )
+    val content: @Composable () -> Unit = {
+        Text(
+            text = textFrom(text),
+            modifier = modifier,
+            color = color,
+            minLines = minLines,
+            fontSize = fontSize,
+            fontStyle = fontStyle,
+            fontWeight = fontWeight,
+            fontFamily = fontFamily,
+            letterSpacing = letterSpacing,
+            textDecoration = textDecoration,
+            textAlign = textAlign,
+            lineHeight = lineHeight,
+            overflow = overflow,
+            softWrap = softWrap,
+            maxLines = maxLines,
+            onTextLayout = onTextLayout,
+            style = style
+        )
+    }
+    if (textSelectionEnabled) {
+        SelectionContainer(
+            modifier = modifier,
+            content = content
+        )
+    } else {
+        content()
+    }
 }
 
+
 @Preview
 @Composable
 fun TextAnyPreview() = TextAny()