Skip to content

Comments

feat(canvas): add scale factor to canvas options#122

Open
Wybxc wants to merge 3 commits intoratatui:mainfrom
Wybxc:scale
Open

feat(canvas): add scale factor to canvas options#122
Wybxc wants to merge 3 commits intoratatui:mainfrom
Wybxc:scale

Conversation

@Wybxc
Copy link
Contributor

@Wybxc Wybxc commented Aug 19, 2025

This Pull Request introduces a scale option to the canvas options. Setting the scale to a value greater than 1 enables rendering graphics at a higher internal resolution, producing sharper output.

scale=1.0:

Scheenshot 2025-08-19 08 50 46

scale=2.0:

Scheenshot 2025-08-19 08 50 54

Copy link
Member

@junkdog junkdog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neat trick for nicer-looking rendering :)

Copy link
Member

@orhun orhun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking good to me, would be nice to address Adrian's points :)

///
/// Panics if `scale` is not positive.
pub fn scale(mut self, scale: f64) -> Self {
if scale <= 0.0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it be scale < 0.0? i guess 0 is not a valid scale.

i think it would be good to set a restriction the upper bounds too, maybe 4.0 - it's already at x16 memory consumption. i haven't tried it locally, but i guess setting really high values would cause the canvas to fail somehow.

otherwise i think it LGTM 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it be scale < 0.0? i guess 0 is not a valid scale.

When the scale is set to 0, the graphic will not be displayed, so it is reasonable to throw an error when scale=0.

i think it would be good to set a restriction the upper bounds too, maybe 4.0 - it's already at x16 memory consumption.

Excessively high scaling requires substantial hardware resources, but it is not impossible to run. In such cases, I believe a hard error should not be issued - after all, with sufficient computational resources, it remains feasible to execute. A warning, or even just a note in the documentation to caution users, would suffice.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so it is reasonable to throw an error when scale=0.

i can't read if statements 😅 yeah, i agree - scale=0 should throw.

Excessively high scaling

do values above 3-4 have any visual impact?

what happens to the canvas/tab/browser/system if it allocates more memory than the user has available? (i can take a look after work too)

Copy link
Contributor Author

@Wybxc Wybxc Sep 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do values above 3-4 have any visual impact?

In fact, 3x resolution has reached the limit of what is discernible. Perhaps I should make this point clearer in the documentation.

what happens to the canvas/tab/browser/system if it allocates more memory than the user has available? (i can take a look after work too)

First, the running speed will slow down. If increased further, the entire webpage (Firefox) or the <canvas> element (Safari/Chrome) will stop functioning. However, in any case, the browser's security measures are well-implemented and will not allow a webpage to consume all system resources.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there's no discernible difference except resource consumption past 3x, i think we can restrict the range to <= 3 (or 4). or is there ever a reason for higher scale values?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be also nice to document the side effects of slightly high values

@junkdog junkdog added the canvas Canvas backend related label Feb 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

canvas Canvas backend related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants