I'm trying to develop a Kivy desktop app which needs to display trees in labels.
The tree is just a string that looks something like this:
" ┌ 3 \n │\n 1 ┤ ┌ 2 \n └─────────────── 4 ┤\n └ 5 "
This works perfectly when operating inside the terminal, and the tree is aligned correctly as below.
However, when putting this string inside a Kivy label, it does not align correctly (see below).
I'm thinking there is an issue with the dimensions of the text not being the same as they are in the terminal. However, I have had no luck adjusting the properties of the label, the text size, the font or anything else. The problem always seems to persist.
The default font would not even display the tree branches. I set the font_name to "DejaVuSans.ttf", which at least renders the branches, but they are still not aligned.
How can I fix this annoying issue?
Also, is there a cleverer way to display trees in a Kivy app that would bypass this issue entirely?
If you use the FreeMono
font and adjust the label text to:
" ┌ 3 \n │\n 1 ┤ ┌ 2 \n └─────────────── 4 ┤\n └ 5 "
it seems to work.