Skip to content

fix(ui): start Ink from the colours shown under a legend, colorbar, table or chart - #3136

Merged
jgregoriorincon merged 2 commits into
opengeos:mainfrom
jgregoriorincon:fix/2953-ink-under
Nov 27, 2026
Merged

jgregoriorincon merged 2 commits into
opengeos:mainfrom
jgregoriorincon:fix/2953-ink-under

Conversation

@jgregoriorincon

@jgregoriorincon jgregoriorincon commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Turning on Ink for a legend, colorbar, table or chart picked its starting colour from the element's own background and the page only, so over another element it could be unreadable: white text over a white rectangle on a dark page, or dark grey over a dark rectangle on a white one.

The starting colour now reads what is shown at the centre of the element's box, in drawing order:

  1. the page's colour;
  2. the fills of the visible elements under it that cover that point: any element's background (padding included, rounded corners counted as square, a turned text's box turned), and a rectangle's or an ellipse's own fill, each with its opacity;
  3. the element's own background.

Maps, pictures, text and lines have no single fill to read and are skipped, as before. One point is read, not the whole box. A table's own white cells and a north arrow's shapes aren't read either: text over them runs into their content whatever its ink. Only the first colour is affected: the swatch changes it, and a command giving color is unchanged.

Reach: the Ink checkbox of the Format pane, so the desktop and browser apps. The command line, Python, the Assistant and MCP give color themselves; the phone interface (ui-touch) doesn't show the Format pane.

Testing

  • New tests in layoutview/tests.rs: fills under, hidden or over the element, one short of the centre, opacity and order, an ellipse's shape, a background's padding, a turned text, a map and a picture. The two that expect a new result failed with the previous rule.
  • Full local run before the last commit (a comment, a variable name and the guide's wrapping): cargo fmt --check, clippy, cargo nextest (10089 passed, 29 skipped), doctests, cargo xtask layers and schema --check. On the last commit: cargo nextest run -p rustgis-ui-egui -E 'test(ink_)', clippy of rustgis-ui-egui with warnings as errors, cargo fmt --check.
  • Headless ui_shot before and after: a legend over a white rectangle on a dark page, then Ink turned on.

UI evidence

Before (left) and after (right), with Ink just turned on:

Related issue

Closes #2953.

Summary by CodeRabbit

  • Improvements
    • Automatic text ink now adapts to the visible colors at the center of an element, including underlying backgrounds and shapes, to improve contrast.
  • Documentation
    • Clarified how automatic ink selection works and that maps and pictures are not included in its color calculation.

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Ink now starts with a color selected from the composite color at the element’s center. The calculation considers the page, visible fills beneath the element, and its own background. Maps and pictures do not contribute a single fill.

Changes: Ink color sampling

Layer / File(s) Summary
Center-point color selection
crates/ui-egui/src/layoutview/format.rs, crates/ui-egui/src/layoutview/tests.rs, docs/user-guide/layouts.md
Ink initialization samples the element’s center and chooses white or INK based on contrast. The calculation includes applicable backgrounds and rectangle or ellipse fills beneath the element, plus its own background. Tests cover drawing order, visibility, shape coverage, background padding, rotation, maps, and pictures. The guide describes the updated rule.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Low

Possibly related PRs

Suggested reviewers: m-hollis-1, giswqs

Merge Risk: Minimal · up to a5104

This changes only the starting Ink color in the Format pane, and users can still change it with the swatch. No concrete merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the change: Ink's starting colour now comes from the colours shown under a legend, colorbar, table or chart. The raw summary and objectives confirm the change samples the page, visible…
Description check Passed The description follows the template sections: Summary, Testing, UI evidence, and Related issue. The Summary explains the problem and the new rule, and it states the reach and exclusions. Testing list…
Linked Issues check Passed Requirement from #2953: the starting Ink colour must read what shows under the element's text, including visible elements under it in drawing order (fill and opacity), then the page. The reviewed head…
Out of Scope Changes check Passed The whole-PR diff against the merge base touches three areas: format.rs (the first_ink rewrite, its helper fills_at, the import change from Background to Element, and the call site), `layout…
Full details: Title check

Explanation

The title names the change: Ink's starting colour now comes from the colours shown under a legend, colorbar, table or chart. The raw summary and objectives confirm the change samples the page, visible fills beneath the element, and its own background at the element centre. The title is specific, uses the fix prefix, and is about 82 characters, which is slightly long but readable.

Full details: Description check

Explanation

The description follows the template sections: Summary, Testing, UI evidence, and Related issue. The Summary explains the problem and the new rule, and it states the reach and exclusions. Testing lists new tests and commands run. UI evidence includes a before and after comparison with a compare-page placeholder, but the template asks for screenshots by drag-and-drop, so the placeholder may not hold a real image. The Related issue section names #2953. The template's 'No visible UI change' line was correctly replaced, since the change is visible. The main gap is that the UI evidence may need real images attached.

Resolution

Confirm the before and after screenshots were uploaded. The current text contains only a '<!-- compare-page -->' placeholder with no image.

Full details: Linked Issues check

Explanation

Requirement from #2953: the starting Ink colour must read what shows under the element's text, including visible elements under it in drawing order (fill and opacity), then the page. The reviewed head implements this in first_ink(layout, &amp;e) (crates/ui-egui/src/layoutview/format.rs). It starts from the page colour (layout.paper, default white), folds in fills_at for each visible element before e in layout.elements order, then folds in e.background. Each fill composites with its own alpha. fills_at covers backgrounds (padding included, via background_box), rectangle fills, and ellipse fills (tested with from_centre &lt;= 1.0), and it un-rotates the sample point with e.unturned. The sample point is the centre of the element box. The Ink checkbox calls first_ink(layout, &amp;e), so the starting colour uses this rule. The swatch and color command paths are unchanged. The PR summary reports tests for fills under, hidden, or over the element, opacity and order, ellipse shape, padding, rotation, maps, and pictures. I did not run those tests. The code diff matches the claimed behaviour.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff against the merge base touches three areas: format.rs (the first_ink rewrite, its helper fills_at, the import change from Background to Element, and the call site), layoutview/tests.rs (tests for the new rule), and docs/user-guide/layouts.md (the Ink description). The tests and docs support the same objective. The Background import change is required by the new signature. No unrelated behaviour change is visible in the reviewed diff.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks the colors below,
Where page and painted shapes all show.
It finds the center, tests the hue,
And picks an ink with contrast true.
Maps and pictures pass it by,
While clearer letters greet the eye.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 10988102-eae3-4277-a446-c12fa5c944c5
Commits

Reviewing files that changed from the base of the PR and between 1be4009 and a510472.

Files selected for processing: 3

  • crates/ui-egui/src/layoutview/format.rs
  • crates/ui-egui/src/layoutview/tests.rs
  • docs/user-guide/layouts.md

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review.

Comment thread crates/ui-egui/src/layoutview/format.rs Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Code review

Bugs

  • Medium confidence: Fills under an opaque map frame or picture still count toward the starting ink. first_ink in format.rs skips maps and pictures only as sources, so a dark rectangle under a map frame still turns the ink white even though the map covers it. This is posted inline at crates/ui-egui/src/layoutview/format.rs:389. The new test ink_reads_no_map_or_picture doesn't cover a fill under a map, so it misses this.

Security

  • None found.

Performance

  • None found. first_ink runs only when the Ink checkbox changes, not every frame, and each call is a single pass over the layout's elements.

Quality

  • None raised. The removed Background import is correct, and the new Element import line fits the 140-column rustfmt.toml limit.

AGENTS.md

  • None found. The changes add no unwrap, expect or indexing outside tests, and the Ink documentation is updated in docs/user-guide/layouts.md.

Checked for twins: first_ink has no other callers. The Ink colour is chosen only in the Format pane, so no #[cfg(target_arch = "wasm32")] twin needs the same change. The layout.update color path is untouched.

Other notes

  • The PR body's "UI evidence" section contains only a <!-- compare-page --> marker and no screenshots, which AGENTS.md requires for visible changes. I couldn't tell whether a bot fills it in later.
  • Prior reviews: no existing threads, so no concerns were left alone.

Change size

Compared with the base branch (merge base 0f4d10e, PR head a510472), the whole PR.

Metric Value
Files changed 3 (0 added, 3 modified, 0 removed, 0 renamed)
Size before 214.4 KB
Size after 220.3 KB
Total size change +6.0 KB
Path Before After Change
crates/ui-egui/src/layoutview/tests.rs 115.2 KB 119.9 KB +4.6 KB
crates/ui-egui/src/layoutview/format.rs 19.8 KB 20.9 KB +1.2 KB
docs/user-guide/layouts.md 79.4 KB 79.6 KB +185 B

@github-actions

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-3136/
Web app https://preview.rustgis.app/pr-3136/app/
Commit a510472

GitHub Pages takes a minute or two to publish a new commit. Newer commits from the fork aren't published until a maintainer adds the preview label (once per commit).

@jgregoriorincon
jgregoriorincon added this pull request to the merge queue Nov 27, 2026
Merged via the queue into opengeos:main with commit 05bed2f Nov 27, 2026
28 checks passed
@jgregoriorincon
jgregoriorincon deleted the fix/2953-ink-under branch November 27, 2026 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Ink's starting colour ignores the elements under a legend, colorbar, table or chart

1 participant