Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The character on cursor is hidden by it. #67

Closed
niuez opened this issue May 30, 2023 · 9 comments
Closed

The character on cursor is hidden by it. #67

niuez opened this issue May 30, 2023 · 9 comments
Labels
bug Something isn't working Sugarloaf

Comments

@niuez
Copy link
Contributor

niuez commented May 30, 2023

Hi, I want to use rio with beam cursor, but the cursor hide the character. Other kind cursors also do.
Because the cursor is rendered to replace the character to cursor character.
It should be like this.

image
my opinion I think rendering the cursor by Sugarloaf's Rect is one of the solutions. The image above was created by this code. Cursors are considered to be associated with characters, so I defined new SugarStyle `on_cursor`.

https://github.com/niuez/rio/blob/0ea71b80d30af2038fa0a361b4d73b4d92be6b24/sugarloaf/src/sugarloaf.rs#L299-L307

But there are some problems.

  • Sugarloaf is rendering engine. It should not be contain cursor shape information. The cursor shapes should be defined in rio.
  • The color of cursor should be able to change by rio.
  • How to render more complex cursors. For example, unfilled rectangle.
@raphamorim raphamorim added the bug Something isn't working label May 30, 2023
@raphamorim
Copy link
Owner

Yea, that's for bring this up. Unfortunately the way sugarloaf is built now, consider cursor as a sugar so it would replace a text block, it would work for Block cursors but not for other cases. For fix this issue I was thinking in few possibilities:

  • add a new type called SugarPileLayer that would be used by SugarPile to contain multiple layers (that would be useful for rects that are rendered in background, so after the refactor will be 3 layers: rect, text, text[cursor or special]).
  • add a new type called SugarLayer that would be used by Sugar. Kinda same approach as SugarPileLayer but for sugar blocks only.
  • render it like we do with pile method (in the sugarloaf examples), would be an external method that we say we want a sugar in a specific position in the screen.

@raphamorim
Copy link
Owner

raphamorim commented May 30, 2023

I kinda of like SugarLayer cause it simplify stuff (the way we consider Rects for example).

Maybe something like this:

pub struct SugarLayer {
    pub layers: Vec<char>
}

#[derive(Debug)]
pub struct Sugar {
    pub content: SugarLayer,
    pub foreground_color: [f32; 4],
    pub background_color: [f32; 4],
    pub style: Option<SugarStyle>,
}

Then in the renderer it would check layers length and iterate Text on it.

@niuez
Copy link
Contributor Author

niuez commented May 30, 2023

Using SugarLayer becomes block and underline cursor OK, but Beam will be like this I think.
image

@raphamorim
Copy link
Owner

hmmm I think is due to the alignment configuration, we do centralize characters in the Sugar. Maybe we can add a property alignment that reflects in the OwnedText alignment: https://docs.rs/wgpu_glyph/latest/wgpu_glyph/enum.HorizontalAlign.html

@niuez
Copy link
Contributor Author

niuez commented May 30, 2023

How about thinking of the cursor as decoration on the glyph box of the character by Rect?
gray is beam, blue is underline.

image

Here is example implementation.

https://github.com/niuez/rio/blob/fc0c9c5dc5b1d2acddb1496c95a9c629307de0d7/rio/src/screen/state.rs#L207-L226

@raphamorim
Copy link
Owner

Hmm, SugarDecoration would be a representation of Rect to a specific Sugar right?
That's also a good idea.

One concern I have with that is when comes to create the underline style that doesn't exist yet, so cursor and underline style doesn't conflict, but underline doesn't necessarily need to use same solution.

@niuez
Copy link
Contributor Author

niuez commented May 31, 2023

SugarDecoration would be a representation of Rect to a specific Sugar right?

Yes. Rendering cursor by Rect does not depend on fonts, and We can know position of cursor by rendering cursor and the character at the same time. It is also possible to think of decoration as a layer whose origin is the top-left position of the letter.

But as you say, it is not clear whether this method should be used in rendering underlines. It may be necessary to consider whether it should be a special parameter for the cursor or a generic one.

@raphamorim
Copy link
Owner

Have been thinking about it, I actually am sold to cursor being rendered by sugarloaf, because when you change fonts, you don't want the cursor dimensions to change or rely on that. I think underline can coexist with the "underline cursor" as well.

Let me know you want to add the implementation for that in the sugarloaf , would be great @niuez

@raphamorim
Copy link
Owner

Closing after #74 merge.
Thanks for the contribution! 🎖️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Sugarloaf
Projects
None yet
Development

No branches or pull requests

2 participants