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

refactor!: migrate to pango and cairo usage #98

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

refactor!: migrate to pango and cairo usage #98

wants to merge 11 commits into from

Conversation

JarKz
Copy link
Contributor

@JarKz JarKz commented Jan 2, 2025

Motivation

Last time I found that it's hard to track all low-level details of drawing and deal with widgets which are high-level together. I've spend a lot of time to write much code which can perfectly work with any case, especially ellipsization which is hard part I've had dealt. And new widgets will make more frictions to further development of notification system because of low-level details.

I wanted to save widgets logic, but delegate the drawing to libraries pango and cairo. They will be helpful to make unique widgets without any frictions. Furthermore, these libraries may have more effective and generic code than my, so I don't have any reason to avoid these libraries.

Breaking Changes

I need to mention that some config properties now works differently:

  • display.text.justification renamed to display.text.alignment and have only three values instead of four: left, right or center. To justify them I added new config property display.text.justify which accepts boolean value.
  • display.text.ellipsize_at renamed to display.text.ellipsize and now accepts only four values instead of two: start, middle, end or none. Instead of cutting words they cuts a part of text.

Except them, all available config properties should work as expected.

Changes in code

  • Removed any logic with fonts and text: crates/render/src/font.rs, crates/render/src/text.rs
  • Removed border drawing logic: crates/render/src/border.rs
  • Re-implemented Drawer struct to use cairo library
  • Updated Drawer usage in widgets
  • Re-implemented WText to use pango logic
  • Now FlexContainer will exists even if there is no children (at least render a rectangle instead of empty space)
  • Used PangoContext instead of FontCollections
  • Slightly re-implemented Image logic to store PNG instead of raw RGBA bytes
  • Re-implemented RectSize, Offset and Bgra to store generic type instead of concrete for flexibility
  • Directly handled error in crates/filetype/src/converter.rs instead of using question mark to avoid use Send + Sync auto-traits for simplicity of code
  • Added Error type for backend which allows us to handle various errors and currently possible only two errors: Vec<Notification> and Fatal. The first one allows us handle a case when some notifications not drawn because of various reasons. The second, as described by name, is unrecoverable and should stop application. Now the application drops the unrendered notifications because there's no history to which can be placed notification
  • Re-implemented the logic of computation window size, in which uses directly banner height, which will be helpful in future dynamic banner size

What about performance?

It's not surprising that library shows more effective CPU and memory usage because it's optimized by smart (I hope lol) developers. Especially the application now is not eagerly eats the available memory.

The binary size is smaller now than previously and the compilation time is faster.

@JarKz
Copy link
Contributor Author

JarKz commented Jan 2, 2025

I'm sure that for compilation requires librust-pangocairo-sys-dev library for ubuntu. But I don't know is it needed for application runtime. I want to add dependencies in README, but I don't know is it only compile-time dependencies or runtime as well.

@jsonmaf1a
Copy link
Member

jsonmaf1a commented Jan 3, 2025

Breaking Changes

I need to mention that some config properties now works differently:

  • display.text.justification renamed to display.text.alignment and have only three values instead of four: left, right or center. To justify them I added new config property display.text.justify which accepts boolean value.
  • display.text.ellipsize_at renamed to display.text.ellipsize and now accepts only four values instead of two: start, middle, end or none. Instead of cutting words they cuts a part of text.

add these to the book noti-rs/notibook#2

and to the example cfg in readme

@JarKz
Copy link
Contributor Author

JarKz commented Jan 3, 2025

Now added wrap_mode property (display.text.wrap_mode if be more correct), which gives controls to wrap text by three values:

  1. word - wrap by words
  2. word-char (word_char also acceptable for custom layouts) - wraps by words but fallback to wrapping by chars (default)
  3. char - wraps only by chars

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants