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

Text clipping #277

Closed
captchaKing opened this issue Feb 3, 2022 · 6 comments · Fixed by #336
Closed

Text clipping #277

captchaKing opened this issue Feb 3, 2022 · 6 comments · Fixed by #336
Labels
appearance Concerns visuals internal API Design of core feature

Comments

@captchaKing
Copy link
Contributor

Is it possible for Text to cut instead of word-wrapping? I'm trying to build Labels-holding Separator for header of listview, but when i collapse headers text always overlaps.
I must say i modified Separator, so its handles could collapse to some smaller size. And changed Label's TextClass to Button, so it wont word-wrap.

@dhardy
Copy link
Collaborator

dhardy commented Feb 3, 2022

Good question. Yes, if you have direct access to the Text object: text.env_mut().flags.remove(kas::text::EnvFlags::WRAP). You should be able to do this with a custom widget.

Or, yes, using TextClass::Button is a good solution. Maybe we need a standard widget for single-line label, or allow configuration of Label?

As for row/column labels, I'd like to get support for those built into MatrixView, but not done yet. A stupid little app I wrote today:
Screenshot_20220203_203340

@captchaKing
Copy link
Contributor Author

captchaKing commented Feb 4, 2022

But text wont cut, it overlaps instead. Maybe i'm doing something wrong and there should be borders or something.

Don't want to create another issue for a simple problem i ask - do you happen to know why it is all Italics font on my system (Ubuntu -> PopOS) in Kas applications? Except for EditBox'es

Thanks!

@dhardy
Copy link
Collaborator

dhardy commented Feb 4, 2022

You're right, text should be cropped/clipped instead of overlap. I think that won't be hard to fix. Currently I use scissor-rects to clip the inside of a scroll region, but text drawing is essentially just copying a sprite so modifying the coordinates should be enough.


Use export RUST_LOG=kas_text=trace then run the app and paste the output. For reference, I get:

[2022-02-04T16:47:10Z INFO  kas_text::fonts::selector] Found 371 fonts
[2022-02-04T16:47:10Z INFO  kas_text::fonts::selector] Default serif font: DejaVu Serif
[2022-02-04T16:47:10Z INFO  kas_text::fonts::selector] Default sans-serif font: Noto Sans
[2022-02-04T16:47:10Z INFO  kas_text::fonts::selector] Default monospace font: Noto Sans Mono
[2022-02-04T16:47:10Z DEBUG kas_text::fonts::library] Loaded: FaceId(0) = /usr/share/fonts/google-noto/NotoSans-Regular.ttf,0
[2022-02-04T16:47:10Z DEBUG kas_text::fonts::library] Loaded: FaceId(1) = /usr/share/fonts/dejavu-sans-fonts/DejaVuSans.ttf,0
[2022-02-04T16:47:10Z DEBUG kas_text::fonts::library] Loaded: FaceId(2) = /usr/share/fonts/google-droid-sans-fonts/DroidSans.ttf,0
[2022-02-04T16:47:10Z DEBUG kas_text::fonts::library] Loaded: FaceId(3) = /usr/share/fonts/liberation-sans/LiberationSans-Regular.ttf,0
[2022-02-04T16:47:10Z DEBUG kas_text::fonts::library] Loaded: FaceId(4) = /usr/share/fonts/dejavu-serif-fonts/DejaVuSerif.ttf,0
[2022-02-04T16:47:10Z DEBUG kas_text::fonts::library] Loaded: FaceId(5) = /usr/share/fonts/liberation-serif/LiberationSerif-Regular.ttf,0

You can try modifying https://github.com/kas-gui/kas-text/blob/master/src/fonts/families.rs to fix it — this file is basically a quick hack (see kas-gui/kas-text#53). I think it may be a while since a proper solution for font discovery is available in the Rust ecosystem, so tweaking this file to work well on more systems would be useful.

You can also modify font selection through config files (see config-examples/theme.yaml).

@captchaKing
Copy link
Contributor Author

captchaKing commented Feb 4, 2022

Thank you, i'll try that.


[2022-02-04T19:17:07Z INFO  kas_text::fonts::selector] Found 676 fonts
[2022-02-04T19:17:07Z INFO  kas_text::fonts::selector] Default serif font: Georgia
[2022-02-04T19:17:07Z INFO  kas_text::fonts::selector] Default sans-serif font: Noto Sans
[2022-02-04T19:17:07Z INFO  kas_text::fonts::selector] Default monospace font: Noto Mono
[2022-02-04T19:17:07Z INFO  kas_text::fonts::selector] Default cursive font: Comic Sans MS
[2022-02-04T19:17:07Z INFO  kas_text::fonts::selector] Default fantasy font: Impact
[2022-02-04T19:17:07Z DEBUG kas_text::fonts::library] Loaded: FaceId(0) = /usr/share/fonts/truetype/noto/NotoSans-BoldItalic.ttf,0
[2022-02-04T19:17:07Z DEBUG kas_text::fonts::library] Loaded: FaceId(1) = /usr/share/fonts/truetype/dejavu/DejaVuSans-Oblique.ttf,0
[2022-02-04T19:17:07Z DEBUG kas_text::fonts::library] Loaded: FaceId(2) = /usr/share/fonts/truetype/open-sans/OpenSans-Italic.ttf,0
[2022-02-04T19:17:07Z DEBUG kas_text::fonts::library] Loaded: FaceId(3) = /usr/share/fonts/truetype/msttcorefonts/Arial_Bold.ttf,0
[2022-02-04T19:17:07Z DEBUG kas_text::fonts::library] Loaded: FaceId(4) = /usr/share/fonts/truetype/msttcorefonts/verdanab.ttf,0
[2022-02-04T19:17:07Z DEBUG kas_text::fonts::library] Loaded: FaceId(5) = /usr/share/fonts/truetype/liberation/LiberationSans-Bold.ttf,0
[2022-02-04T19:17:07Z DEBUG kas_text::fonts::library] Loaded: FaceId(6) = /usr/share/fonts/truetype/msttcorefonts/Georgia.ttf,0
[2022-02-04T19:17:07Z DEBUG kas_text::fonts::library] Loaded: FaceId(7) = /usr/share/fonts/truetype/msttcorefonts/Times_New_Roman.ttf,0
[2022-02-04T19:17:07Z DEBUG kas_text::fonts::library] Loaded: FaceId(8) = /usr/share/fonts/truetype/dejavu/DejaVuSerif-Italic.ttf,0
[2022-02-04T19:17:07Z DEBUG kas_text::fonts::library] Loaded: FaceId(9) = /usr/share/fonts/truetype/liberation/LiberationSerif-BoldItalic.ttf,0

I have all of them, but still get italics

@dhardy
Copy link
Collaborator

dhardy commented Feb 6, 2022

Reopening because text-clipping isn't done yet.

@dhardy dhardy reopened this Feb 6, 2022
@dhardy
Copy link
Collaborator

dhardy commented Feb 6, 2022

I'll postpone implementation of text-clipping for now to reduce API changes. Plan:

  1. Consider Font configuration and size #279: the Environment struct contains various text formatting parameters, most of which should be part of the Text object (the exception being dpp, probably). Currently, these are part of the Text object but not TextDisplay, which is what gets passed into text-drawing methods. Moving parameters in means that the bounds parameter (size) will be available when drawing text.
  2. The methods in text_pipe.rs on Window draw sprites. Given bounds, we can reject/clip sprites here.

@dhardy dhardy changed the title Text cutting Text clipping Feb 23, 2022
@dhardy dhardy added appearance Concerns visuals internal API Design of core feature labels Feb 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
appearance Concerns visuals internal API Design of core feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants