Skip to content

Respect CSS resize in window handling - #366

Merged
waynemwashuma merged 1 commit into
wimaengine:devfrom
waynemwashuma:fix-canvas-resizing-to-css
Sep 21, 2026
Merged

waynemwashuma merged 1 commit into
wimaengine:devfrom
waynemwashuma:fix-canvas-resizing-to-css

Conversation

@waynemwashuma

Copy link
Copy Markdown
Collaborator

Objective

Fix DOM canvas resizing so CSS controls the canvas display size and resize events are emitted when either dimension changes.

Solution

Canvas initialization now reads the computed layout size without overwriting CSS dimensions. The resize system also updates the window whenever the canvas width or height changes.

Root Cause

The canvas registration logic assigned inline width and height styles from the initial window dimensions, overriding sizes defined by external CSS.

Additionally, the resize system returned early when either dimension remained unchanged. This prevented valid single-axis resizes from being detected.

Changes Made

  • Removed inline canvas width and height assignments during window registration.
  • Continued synchronizing the canvas drawing buffer and Window dimensions with its bounding rectangle.
  • Changed the resize comparison to skip updates only when both width and height are unchanged.
  • Enabled resize events for width-only and height-only changes.

Why This Approach

This keeps layout control within CSS while allowing the engine to synchronize its window dimensions with the canvas’s rendered size. It also correctly handles responsive layouts where only one dimension changes.

Notes

  • Existing CSS rules now remain authoritative for canvas display sizing.
  • The canvas drawing buffer continues to be initialized from its rendered dimensions.
  • Resize events are dispatched whenever either dimension changes.

Showcase

Before

canvas {
  width: 100%;
  height: 100%;
}

The engine applied inline pixel dimensions during initialization, which could override the CSS layout. A change to only one dimension could also be ignored.

After

canvas {
  width: 100%;
  height: 100%;
}

The CSS dimensions remain in control, and the engine synchronizes the Window whenever the rendered width or height changes.

Migration Guide

No migration required.

Checklist

  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

@waynemwashuma waynemwashuma self-assigned this Sep 21, 2026
@waynemwashuma waynemwashuma changed the title Resspect css resize in window handling Respect css resize in window handling Sep 21, 2026
@waynemwashuma waynemwashuma changed the title Respect css resize in window handling Respect CSS resize in window handling Sep 21, 2026
@waynemwashuma
waynemwashuma merged commit 0f255dc into wimaengine:dev Sep 21, 2026
7 checks passed
@waynemwashuma
waynemwashuma deleted the fix-canvas-resizing-to-css branch September 21, 2026 10:13
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.

1 participant