libui-node icon indicating copy to clipboard operation
libui-node copied to clipboard

Text wrap

Open RangerMauve opened this issue 7 years ago β€’ 13 comments

Hi, what's the appropriate way to handle wrapping text?

Preferably with text that's been created with the AttributedString API.

RangerMauve avatar Oct 04 '18 18:10 RangerMauve

Sorry, let me clarify a little.

I understand that you can use the DrawTextLayout API in order to draw text with wrapping within an area, but that only works if the area takes up all the space in a container.

My use case is rendering a markdown document using libui. This requires me to have a vertical layout that combines paragraphs of text along with other elements like images.

My ideal would be that an Area filled with text would automatically set it's height so that I could stack them on top of each other with other content in between.

Does this seem possible with the library in it's current state?

Right now I'm trying how to figure out how to build something that attempts to draw the text in an area and resizes the area to just fit the text.

RangerMauve avatar Oct 04 '18 18:10 RangerMauve

Oh dang, just noticed that UIImage isn't supported yet. πŸ˜… I guess I'll focus on plain text rendering for now, then.

RangerMauve avatar Oct 04 '18 19:10 RangerMauve

My ideal would be that an Area filled with text would automatically set it's height so that I could stack them on top of each other with other content in between.

Area controls are always stretchy (I think). You would be better off with using a single area and rendering everything inside. You should be able to get the actual width and height the DrawTextLayout takes up and do the layout yourself with this information.

(This works fine in normal areas, but not so much in scrolling areas: https://github.com/andlabs/libui/issues/401)

mischnic avatar Oct 04 '18 20:10 mischnic

Any ideas on how I should handle mixed content in the future? Or is that even realistic?

I'm definately going to need to rely on scrolling since the markdown documents could be quite long.

Maybe libui isn't the right approach for doing something like this. πŸ˜…

RangerMauve avatar Oct 04 '18 20:10 RangerMauve

Also, this might not be the point of the issue, but how would I set multiple attributes at once?

Can I use appendAttributed to make something both italic and underlined?

It doesn't look like it's possible, but I might be missing something. πŸ˜…

RangerMauve avatar Oct 04 '18 20:10 RangerMauve

Any ideas on how I should handle mixed content in the future? Or is that even realistic?

I think you should be able to pull this off. (My bad, the issue I linked exists because I created a textlayout with width=0. - They should work fine.)

Do you want to create something like this?

ohne titel

Maybe libui isn't the right approach for doing something like this. πŸ˜…

Yet.... πŸ˜„ ?

mischnic avatar Oct 04 '18 20:10 mischnic

Also, this might not be the point of the issue, but how would I set multiple attributes at once? Can I use appendAttributed to make something both italic and underlined? It doesn't look like it's possible, but I might be missing something. πŸ˜…

That is possible: you can pass as many attributes to appendAttributed as you want: https://github.com/parro-it/libui-node/blob/8e3bc5800f9a111e3f95ec345db81ba42b2d5f32/examples/text.js#L48-L50

Also described (not as clear) here: https://github.com/parro-it/libui-node/blob/master/docs/attributedstring.md#appendattributed

mischnic avatar Oct 04 '18 21:10 mischnic

Do you want to create something like this?

Yeah, sort of like that, but it'd look like similar to how Github renders markdown content with Images and stuff spaced between the sections of text.

So far my biggest blockers are:

  • No support for images in the node binding
  • No support for hyperlinks in the text rendering

I think that combined this makes libui a bad target for rendering markdown content. I'll probably park that idea or concede with supporting a subset for now.

you can pass as many attributes to appendAttributed as you want

Dang! I totally missed that.

Thank you for the help! I'll see what I can do with this. 😁

RangerMauve avatar Oct 04 '18 21:10 RangerMauve

A webview might come in the near future (there an issue in andlabs/libui), so you could create a html file from markdown and show that.

mischnic avatar Oct 04 '18 21:10 mischnic

Yeah, part of why I'm going this route is to experiment with UIs that don't use the web.

My long-term goal is to create something like Firefox's reader view where instead of using the DOM and CSS, I'll extract the semantic content from the page and use native UI elements to render it.

I got this idea after being frusterated with browsers taking up hundreds of megabytes of ram to show just a little content. The goal is to use less system resources, though, I'm not sure how realistic that will be. πŸ˜…

The content I want to render in the end will look kind of like markdown, so that's why I'm starting with getting that to render with libui.

RangerMauve avatar Oct 04 '18 21:10 RangerMauve

Hyperlinks in attributed string: https://github.com/andlabs/libui/issues/303 Drawing images (not in tables): https://github.com/andlabs/libui/issues/318 (The uiImage that is used by the table API is rather an icon that can have multiple resolutions, e.g. for High-DPI and normal displays. So not really "image".)

mischnic avatar Oct 05 '18 05:10 mischnic

Thanks! I've subscribed to both of those so I can see when they're ready. :D

RangerMauve avatar Oct 05 '18 14:10 RangerMauve

@RangerMauve Were you able to achieve this? I need gui to display rendered markdown too...

VarLad avatar Feb 10 '21 11:02 VarLad