core: let a font ask for tracking - #1
Open
Colin-Hayes wants to merge 3 commits into
Open
Conversation
Cosmic Text has carried letter spacing all along; nothing above it could ask for it. A design that specifies tracking on its labels had no way to say so, and uppercasing a label is not the same thing. Font gains a Tracking, expressed as a fraction of the type size so a heading and a caption asking for the same tracking stay proportionate. Cosmic Text takes em as well, so the value passes through unscaled, and it is left unset when it would change nothing -- a font asking for no tracking keeps whatever the face itself specifies. Font is a hash key throughout the text pipeline, so Tracking compares and hashes by bits, canonicalizing the two values that would otherwise break the Eq/Hash agreement: NaN, which is never equal to itself, and negative zero, which is equal to zero while their bits differ. That is the same treatment Cosmic Text gives its own wrapper. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
Adding a new public field to Font is a breaking public API change and needs an explicit API/semver decision (or an alternative approach) before approval.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR extends the text/font pipeline so a Font can request glyph tracking (letter spacing) and have it propagated into the cosmic_text::Attrs used by the graphics text backend.
Changes:
- Introduces a new
Tracking(f32)type and adds it tocore::Font, includingEq/Hashbehavior that remains consistent forNaNand-0.0. - Adds a
Font::tracking(...)setter and defaults tracking to “unset/no-op” so existing constructors keep prior behavior. - Updates the graphics text attribute conversion to set
cosmic_textletter spacing only when tracking is non-zero, and re-exportsTrackingfromiced_core.
File summaries
| File | Description |
|---|---|
| core/src/font.rs | Adds Tracking, integrates it into Font, and adds unit tests for equality/hashing/default semantics. |
| core/src/lib.rs | Re-exports Tracking alongside Font for public API access. |
| graphics/src/text.rs | Applies Font::tracking to cosmic_text::Attrs via letter_spacing when non-zero. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
62
to
66
| /// The [`Style`] of the [`Font`]. | ||
| pub style: Style, | ||
| /// The [`Tracking`] of the [`Font`]. | ||
| pub tracking: Tracking, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cosmic Text has carried letter spacing all along; nothing above it could ask for it. A design that specifies tracking on its labels had no way to say so, and uppercasing a label is not the same thing.
Fontgains aTracking, expressed as a fraction of the type size so a heading and a caption asking for the same tracking stay proportionate to one another. Cosmic Text takes em as well, so the value passes through unscaled, and it is left unset when it would change nothing — a font asking for no tracking keeps whatever the face itself specifies.Fontis a hash key throughout the text pipeline, soTrackingcompares and hashes by bits, canonicalizing the two values that would otherwise break theEq/Hashagreement: NaN, which is never equal to itself, and negative zero, which is equal to zero while their bits differ. That is the same treatment Cosmic Text gives its own wrapper.Additive:
Font::DEFAULTand every existing constructor leave tracking unset, so nothing that does not ask for it changes.iced_core,iced_graphics,iced_widget,iced_runtimeandiced_winitall build unchanged.Four tests cover the default, that tracking takes part in equality and hashing, that the awkward float values keep
EqandHashin agreement, and that only a real tracking counts as set.Consumed by MicroPerceptron/vkore#18 and MicroPerceptron/axiom#84.