z0w0/helm

Giving a maximum area for a Text

Raveline opened this issue · 0 comments

Though text rendering is done through Pango, the current version of Helm doesn't allow us to leverage Pango line-wrapping abilities. Considering that linewrapping is typically not something one want to do manually, it looks like a good feature to add.

The ideal feature would be to set width and height, but current Pango bindings to not provide us with the setHeight function (I've just added an issue to the Gtk2hs repo that maintain Pango about this).

In the meantime, a possible fix is to:

  • Add an optional line width field (as a Maybe Double) to the Text datatype;
  • Add two calls on the SDL rendering engine for Text:
Pango.layoutSetWidth layout lineWidth
Pango.layoutSetWrap layout Pango.WrapWholeWords
  • This could be further improved by adding Pango alignment and justification features.

The beauty of it is that a call to setWidth with Nothing does... nothing, and wrapWholeWords has no effect without a set lineWidth.

I have a small proof of concept and would be happy to push a PR, but I'm troubled by two things:

  • I'm not sure how to mix the current available TextAlignment with this new system;
  • Other backends might now benefit from Pango and this would increase the workload of writing new backends.