Skip to content

canvas: Add background field to canvas context for background-aware drawing#823

Merged
johannes-wolf merged 1 commit intocetz-package:cetz-0.3.3from
hooyuser:ctx_background
Feb 26, 2025
Merged

canvas: Add background field to canvas context for background-aware drawing#823
johannes-wolf merged 1 commit intocetz-package:cetz-0.3.3from
hooyuser:ctx_background

Conversation

@hooyuser
Copy link
Copy Markdown
Contributor

When drawing inside a canvas, having access to the background color is crucial for background-aware drawing. By adding background field to the canvasctx, we can retrieve the current background color using the get-ctx function.

This improves visual consistency, especially in dynamic themes like dark mode. The following example demonstrates the impact (Typst App Link)

  • The upper diagram utilizes the background color for adaptive drawing.
  • The lower diagram lacks background color infomation, resulting in a much poorer appearance in dark theme.

cetz_canvas_background

Add background to canvas context
@hooyuser hooyuser changed the title Add background field to canvas context for background-aware drawing canvas: Add background field to canvas context for background-aware drawing Feb 26, 2025
@johannes-wolf johannes-wolf added this to the 0.3.3 milestone Feb 26, 2025
@johannes-wolf johannes-wolf self-requested a review February 26, 2025 09:36
@johannes-wolf johannes-wolf changed the base branch from master to cetz-0.3.3 February 26, 2025 09:40
@johannes-wolf johannes-wolf merged commit dc25e2d into cetz-package:cetz-0.3.3 Feb 26, 2025
1 check passed
johannes-wolf added a commit that referenced this pull request Mar 2, 2025
* treewide: Bump version to 0.3.3

* canvas: Add background field to canvas context for background-aware drawing (#823)

Add background to canvas context

Add background to canvas context

* background: Update changelog & add documentation

* mark: Fix mark styling issues with incomplete dict (#825)

* matrix: Add a diag function (#824)

* matrix: Add a diag function

* matrix: Improve ident

* mark: Add missing test case

* bezier: Possible fix for div by zero bug

---------

Co-authored-by: Derived Cat <hooyuser@outlook.com>
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.

2 participants