d

    Daniel

    1 year ago
    Is there any way to set the width of an EditText in characters?
    Halil Ozercan

    Halil Ozercan

    1 year ago
    Wouldn't just trimming the string work?
    Text(
      text = myString.take(limit)
    )
    d

    Daniel

    1 year ago
    Sorry, by text field I meant EditText
    Halil Ozercan

    Halil Ozercan

    1 year ago
    oh sorry, my mistake 🤦‍♂️ Again similarly you have the ability to ignore anything longer than what you want
    var text by remember { mutableStateOf("") }
    TextField(
      value = text,
      onValueChange = {
        text = it.take(limit)
      }
    )
    argument names might be wrong, haven't used TextField in a while
    d

    Daniel

    1 year ago
    Yeah, but I want to set the visible width such that it wraps the amount of text in the EditText. As in if
    value = "0.000"
    I don't want a bunch of whitespace on the right, I want it to end after the last 0
    Halil Ozercan

    Halil Ozercan

    1 year ago
    Hmm, that's an interesting challenge. Your best bet might be
    onTextLayout
    and figuring out how much space your TextField should allocate.
    This might cause you to lose a frame tho
    d

    Daniel

    1 year ago
    Thanks for the suggestion. It's good to know there's no great solution. If it's numbers with sane fonts I think I can rely on the fact 1em is slightly larger than the width of a zero, so that might work