Textarea in salt

0 votes
asked Oct 15, 2021 in Wanted features by pihentagy (180 points)

Hi!

In salt, it is cumbersome to mimic textarea.

My current attempt is something like:

{+
   This is a long
   text in a textarea
   .
   "                         "
}


Note the dot to fill up vertical space. And also the last line of space to make the area wider.

Is there an easier way to achieve this?

1 Answer

0 votes
answered Oct 19, 2021 by Martin (9,120 points)

If you're happy to always have at least one blank line, you could define some spacer variables to use.  Note that using a monospaced font lets you control the width much better:

@startsalt
!$pad40="<font:monospaced>                                        </font>"

{+
   This is a long
   text in a textarea
   $pad40
}
@endsalt

If you have lots of different widths, you could use a macro to generate a specific width spacing line on demand:

@startsalt
!function $pad($width)
  !$spaces=""
  !while %strlen($spaces) <= $width
    !$spaces=$spaces+" "
  !endwhile
  !return "<font:monospaced>"+$spaces+"</font>"
!endfunction

{+
   This is a long
   text in a textarea
   $pad(40)
}
@endsalt

Before I came up with that, I experimented with a macro to pad out strings to a set length, so I'll include that too.  The advantage is that there's no need for a blank line.  The disadvantage is that you either use monospaced font throughout or you use lose precise control over the width.

(click diagram for source)

...