Skip to content

Align Canvas method parameters better with JavaScript#4330

Draft
HalfWhitt wants to merge 3 commits intobeeware:mainfrom
HalfWhitt:canvas-parameter-tweaks
Draft

Align Canvas method parameters better with JavaScript#4330
HalfWhitt wants to merge 3 commits intobeeware:mainfrom
HalfWhitt:canvas-parameter-tweaks

Conversation

@HalfWhitt
Copy link
Copy Markdown
Member

@HalfWhitt HalfWhitt commented Apr 15, 2026

Part of #3994

This alters the parameters of Canvas's (new) fill and stroke methods to better match the HTML/JavaScript version. Only parameters valid in JavaScript can be provided as positional arguments; any of the extra parameters Toga accepts must be by keyword. It also renames color to fill_style/stroke_style in their respective methods. (I could also see an argument for naming them simply style.)

Because Canvas is only now gaining these methods, we don't need any new shims; the existing shims on the capitalized versions (and the methods on context managers) can do the necessary translation.

So far, I've fixed existing tests, but not yet written new ones (or done any particularly thorough double-checking yet). Wanted to go ahead and put this out there before I head to bed, in case there are questions or feedback on the general intent.

PR Checklist:

  • All new features have been tested
  • All new features have been documented
  • I have read the CONTRIBUTING.md file
  • I will abide by the code of conduct

@HalfWhitt
Copy link
Copy Markdown
Member Author

I'm not sure if this change note should be misc or removal. It's not technically changing anything that was already there, but it is changing the thing that's replacing it.

@corranwebster
Copy link
Copy Markdown
Contributor

I think the intent is good.

There may need to be some backwards compatibility about the attributes on Fill and Stroke: the docs suggest changing fill.color and redrawing in the discussion here: https://toga.beeware.org/en/stable/reference/api/widgets/canvas/#usage

However I need to catch up on the changes made in #4159 so this may have already been addressed/made moot.

@HalfWhitt
Copy link
Copy Markdown
Member Author

There may need to be some backwards compatibility about the attributes on Fill and Stroke: the docs suggest changing fill.color and redrawing in the discussion here: https://toga.beeware.org/en/stable/reference/api/widgets/canvas/#usage

Hm, that's a good point. The docs say not to ever directly create drawing actions, but they do describe editing their attributes, and that particular one by name. In any event, I do need to update the docs.

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