mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-05-04 13:12:10 +00:00
[Refactor] Prefer param destructuring over manual (#756)
- Replaces manual runtime destructuring with built-in param destructuring - Standardises naming - Reorders deprecated code
This commit is contained in:
@@ -3,7 +3,7 @@ import type { LGraphNode } from "@/LGraphNode"
|
||||
import type { CanvasMouseEvent } from "@/types/events"
|
||||
import type { IBooleanWidget } from "@/types/widgets"
|
||||
|
||||
import { BaseWidget } from "./BaseWidget"
|
||||
import { BaseWidget, type DrawWidgetOptions } from "./BaseWidget"
|
||||
|
||||
export class BooleanWidget extends BaseWidget implements IBooleanWidget {
|
||||
// IBooleanWidget properties
|
||||
@@ -16,15 +16,13 @@ export class BooleanWidget extends BaseWidget implements IBooleanWidget {
|
||||
this.value = widget.value
|
||||
}
|
||||
|
||||
override drawWidget(ctx: CanvasRenderingContext2D, options: {
|
||||
y: number
|
||||
width: number
|
||||
show_text?: boolean
|
||||
margin?: number
|
||||
}) {
|
||||
const { y, width, show_text = true, margin = 15 } = options
|
||||
const widget_width = width
|
||||
const H = this.height
|
||||
override drawWidget(ctx: CanvasRenderingContext2D, {
|
||||
y,
|
||||
width,
|
||||
show_text = true,
|
||||
margin = 15,
|
||||
}: DrawWidgetOptions) {
|
||||
const { height } = this
|
||||
|
||||
ctx.textAlign = "left"
|
||||
ctx.strokeStyle = this.outline_color
|
||||
@@ -32,16 +30,16 @@ export class BooleanWidget extends BaseWidget implements IBooleanWidget {
|
||||
ctx.beginPath()
|
||||
|
||||
if (show_text)
|
||||
ctx.roundRect(margin, y, widget_width - margin * 2, H, [H * 0.5])
|
||||
else ctx.rect(margin, y, widget_width - margin * 2, H)
|
||||
ctx.roundRect(margin, y, width - margin * 2, height, [height * 0.5])
|
||||
else ctx.rect(margin, y, width - margin * 2, height)
|
||||
ctx.fill()
|
||||
if (show_text && !this.disabled) ctx.stroke()
|
||||
ctx.fillStyle = this.value ? "#89A" : "#333"
|
||||
ctx.beginPath()
|
||||
ctx.arc(
|
||||
widget_width - margin * 2,
|
||||
y + H * 0.5,
|
||||
H * 0.36,
|
||||
width - margin * 2,
|
||||
y + height * 0.5,
|
||||
height * 0.36,
|
||||
0,
|
||||
Math.PI * 2,
|
||||
)
|
||||
@@ -50,14 +48,14 @@ export class BooleanWidget extends BaseWidget implements IBooleanWidget {
|
||||
ctx.fillStyle = this.secondary_text_color
|
||||
const label = this.label || this.name
|
||||
if (label != null) {
|
||||
ctx.fillText(label, margin * 2, y + H * 0.7)
|
||||
ctx.fillText(label, margin * 2, y + height * 0.7)
|
||||
}
|
||||
ctx.fillStyle = this.value ? this.text_color : this.secondary_text_color
|
||||
ctx.textAlign = "right"
|
||||
ctx.fillText(
|
||||
this.value ? this.options.on || "true" : this.options.off || "false",
|
||||
widget_width - 40,
|
||||
y + H * 0.7,
|
||||
width - 40,
|
||||
y + height * 0.7,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user