Text Cursor #82
-
I've been looking for some example code on how to render a text editing cursor, does glyphon have a way to have an (ideally) blinking cursor and I'm just missing it? It seems through a roundabout way i can get the position to render it, by passing a cursor to buffer.layout_cursor, then calling line_layout on buffer, going to the glyph in the returned layout line and eventually get its position. This feels super unintuitive and wrong, cosmic text has an editor struct with a cursor, but it's not exposed through glyphon. Any guidance in the right direction would be greatly appreciated. Thank you ^^ |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
👋 Hi @CoralynnMay! I haven't had a need to render a cursor yet so I haven't spent much time working with cosmic-text's editing functionality. I'd probably take a look at what iced does to start, because I think their editor contains a cursor buitl it's still built on top of glyphon. glyphon re-exposes all of cosmic-text, so you should be able to access the editor struct the same way as usual just with Happy to help if you're stuck on this, but hopefully that should give you a starting point! |
Beta Was this translation helpful? Give feedback.
-
I've successfully created a single-line text input element in my GUI library complete with a blinking cursor and selection-highlights. In particular the code to calculate the position of the cursor/highlight region is here: https://github.com/MeadowlarkDAW/Yarrow/blob/ca85bdeb9d98b4d310eed2214012638ff1c544e7/src/elements/text_input.rs#L425 |
Beta Was this translation helpful? Give feedback.
👋 Hi @CoralynnMay! I haven't had a need to render a cursor yet so I haven't spent much time working with cosmic-text's editing functionality. I'd probably take a look at what iced does to start, because I think their editor contains a cursor buitl it's still built on top of glyphon.
glyphon re-exposes all of cosmic-text, so you should be able to access the editor struct the same way as usual just with
glyphon::
as a prefix, likeuse glyphon::cosmic_text
. If it's more convenient, you could also depend oncosmic_text
directly (matching versions between cosmic-text and the version used by glyphon).Happy to help if you're stuck on this, but hopefully that should give you a starting point!