PolyMeilex / sctk-adwaita

Adwaita-like SCTK Frame
MIT License
28 stars 20 forks source link

Add `ab_glyph` feature for drawing title text #8

Closed alexheretic closed 2 years ago

alexheretic commented 2 years ago

This pr provides an alternative to crossfont/"title" feature using crate _abglyph to render title text.

This is helpful in some cases since the latter is pure rust requiring no extra dynamically linked dependencies or cmake freetype builds etc. (Related https://github.com/rust-windowing/winit/issues/2373#issuecomment-1214189515).

_abglyph titles use an embedded Cantarell-Regular.ttf font & hardcoded size selected to best match the current crossfont title size. I'm not sure how hard it would be to find the system default font file & size, but this seems a decent starting point.

cargo run --example simple --features crossfont

cargo run --example simple (new default feature ab_glyph)

Update: Made ab_glyph feature default. This is a breaking change.

alexheretic commented 2 years ago

Yeah defaults are up to you, I went with non-default to be minimally breaking. I can change that. Maybe we can just lose the title feature and default to ab_glyph optional dependency?

I think _abglyph should have good compatibility thanks to the work in ttf-parser. The current pr just uses a single embedded font & size. If we knew where the desired/system font ttf/otf file was and the desired size that should work fine too, we just need to look it up somehow.

I considered looking into that, but even if we had that it's probably worth having a reasonable fallback too.

alexheretic commented 2 years ago

I've switched the new renderer to be default & updated the readme with how to use crossfont.

PolyMeilex commented 2 years ago

Maybe we can just lose the title feature and default to ab_glyph optional dependency?

Sure, sounds good to me.

I considered looking into that, but even if we had that it's probably worth having a reasonable fallback too.

If we want to replace fontconfig we would most likely have to do something similar to https://github.com/fschutt/rust-fontconfig (or just use it if possible) but that's a whole another issue that should be done separately. For now I'm fine with embedded font, still better that people disabling title rendering all together just to get it to build without cmake.

And once again, thank you for working on this ❤️

alexheretic commented 2 years ago

I agree, in which case this is ready to merge :+1: