Skip to content
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

Add set canvas element #534

Merged
merged 7 commits into from
May 30, 2024
Merged

Add set canvas element #534

merged 7 commits into from
May 30, 2024

Conversation

dovicsin
Copy link
Contributor

No description provided.

@dovicsin dovicsin requested a review from simzer May 28, 2024 12:19
CHANGELOG.md Outdated
@@ -7,6 +7,10 @@
- Do not calculate disabled markers to the color normalization.
- More precise TS type for transform matrix in event handlers.

### Added

- The canvas cahange options to the htmlcanvas plugin.
Copy link
Member

Choose a reason for hiding this comment

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

typo: cahange -> change

@@ -20,6 +20,7 @@ export interface HtmlCanvasApi extends PluginApi {
get element(): HTMLCanvasElement
/** Returns the actual canvas context */
get context(): CanvasRenderingContext2D
set element(element: HTMLCanvasElement)
Copy link
Member

Choose a reason for hiding this comment

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

Please add comment (needed for generated reference documentation)
Also better place would be right after get element().

src/apps/weblib/ts-api/plugins/htmlcanvas.ts Show resolved Hide resolved
@@ -128,6 +140,11 @@ export class HtmlCanvas implements Plugin, HtmlCanvasAlternative {
return this._mainCanvas
}

set element(element: HTMLCanvasElement) {
this.unregister()
Copy link
Member

Choose a reason for hiding this comment

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

We shouldn't call unregister here, since it also unregisters the window resize event listener, which we need further on.

@@ -44,6 +45,7 @@ export class HtmlCanvas implements Plugin, HtmlCanvasAlternative {
return {
element: this.element,
context: this.context,
setElement: this._setElement.bind(this),
Copy link
Member

Choose a reason for hiding this comment

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

It would be better to have getter setter for element here:

return {
  get element() { ... }
  set element() { ... }
}

Also calling _setElement() here is faulty, since it does not register the handlers to the canvas, just stores the element to the class.

window.addEventListener('resize', this._resizeHandler)
}

private _setElement(element: HTMLCanvasElement): void {
Copy link
Member

Choose a reason for hiding this comment

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

This method is not necessary, we should cann _setCanvas() for the API object.

simzer
simzer previously approved these changes May 30, 2024
@simzer simzer merged commit 4baccf9 into main May 30, 2024
1 check passed
@simzer simzer deleted the set-canvas-element branch May 30, 2024 13:03
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