Skip to content

[RFC] Responsive fill mode #7645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
marklundin opened this issue May 6, 2025 · 6 comments
Open

[RFC] Responsive fill mode #7645

marklundin opened this issue May 6, 2025 · 6 comments
Assignees

Comments

@marklundin
Copy link
Member

marklundin commented May 6, 2025

Problem

PlayCanvas currently supports:
FILLMODE_KEEP_ASPECT and FILLMODE_FILL_WINDOW: tied to the window size
FILLMODE_NONE: allows manual control over the canvas dimensions

However, a common use case - embedding a responsive canvas that fills its container (width: 100%; height: 100%) - requires manually tracking container size and managing updates with FILLMODE_NONE. This is unintuitive and boilerplate-heavy for something that should be simple.

related - playcanvas/react#123

Proposal

Introduce a new fill mode:
FILLMODE_RESPONSIVE - automatically sizes the canvas to fill its parent element using standard CSS dimensions.

This would greatly simplify responsive layouts, especially for apps with embedded or resizable UIs.

Implementation

This could be implemented with a minimal change here, adding a clause to handle the new mode using:

canvas.style.width = '100%';
canvas.style.height = '100%';

The Graphics Device would naturally get the correct dimensions during update via

if (this._resolutionMode === RESOLUTION_AUTO) {
// Check if the canvas DOM has changed size
const canvas = this.graphicsDevice.canvas;
this.graphicsDevice.resizeCanvas(canvas.clientWidth, canvas.clientHeight);

/cc @willeastcott @mvaligursky @Maksims

@marklundin marklundin self-assigned this May 6, 2025
@mvaligursky
Copy link
Contributor

Sounds great!

@mvaligursky
Copy link
Contributor

But isn't it the same as FILLMODE_FILL_WINDOW ?

@marklundin
Copy link
Member Author

marklundin commented May 6, 2025

Not quite, FILLMODE_WINDOW specifically targets the window size. This is just if you want a responsive canvas that fills a specific container.

@Maksims
Copy link
Collaborator

Maksims commented May 6, 2025

In CSS terms, this is called "relative", so could be called "FILLMODE_RELATIVE". For width and height being 100%, does it require a parent element's style to have at least position: relative so it has positioning layout context?

@marklundin
Copy link
Member Author

marklundin commented May 6, 2025

If I understand correctly no, the container would not need position: relative, nor would the canvas need position: absolute. This is just about sizing, not positioning.

An example is having a container sized according to various breakpoints. Ideally the canvas does not need to know those dimensions, it just fills the container regardless. RESOLUTION_AUTO takes care of ensuring the context matches.

I feel 'responsive' is a familiar enough terminology in the flex box and grid layout models for users to understand although it's not official

@Maksims
Copy link
Collaborator

Maksims commented May 6, 2025

Responsive in web world - associated with reaction of a style to a different resolutions and aspect ratios: mobile/tablet/desktop.

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

No branches or pull requests

3 participants