pmndrs / uikit

🎨 user interfaces for react-three-fiber
https://pmndrs.github.io/uikit/docs/
Other
2.68k stars 139 forks source link

show whitespaces at beginning of lines of text #92

Open flo-bit opened 4 months ago

flo-bit commented 4 months ago

I want to show some text containing multiple lines of code, with some lines being indented by whitespace at the beginning, but I can't get this to work, is this supported/a bug?

this is what I tried:

import { Canvas } from '@react-three/fiber'
import { useState } from 'react';
import { Root, Text } from '@react-three/uikit'

function App() {
  const [text, setText] = useState('Hello \n     World!');

  return (
    <div id="canvas-container">
      <pre>{text}</pre>
      <Canvas>
        <Root backgroundColor="#ccc">
          <Text wordBreak="keep-all" fontWeight="bold" multiline>{text}</Text>
        </Root>
      </Canvas>
    </div>
  )
}

export default App;
bbohlender commented 4 months ago

same issue as in #77 The default text layouting behavior ignores starting and trailing whitespace, which should be configurable instead.

flo-bit commented 4 months ago

For anyone looking for a quick workaround, this is what I'm using currently:

<Text
    paddingLeft={(text.match(/^\s*/) || [''])[0].length * 10}
>