mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-05-03 20:51:58 +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:
@@ -5,7 +5,7 @@ import type { INumericWidget, IWidgetOptions } from "@/types/widgets"
|
||||
|
||||
import { getWidgetStep } from "@/utils/widget"
|
||||
|
||||
import { BaseWidget } from "./BaseWidget"
|
||||
import { BaseWidget, type DrawWidgetOptions } from "./BaseWidget"
|
||||
|
||||
export class NumberWidget extends BaseWidget implements INumericWidget {
|
||||
// INumberWidget properties
|
||||
@@ -24,20 +24,18 @@ export class NumberWidget extends BaseWidget implements INumericWidget {
|
||||
* @param ctx The canvas context
|
||||
* @param options The options for drawing the widget
|
||||
*/
|
||||
override drawWidget(ctx: CanvasRenderingContext2D, options: {
|
||||
y: number
|
||||
width: number
|
||||
show_text?: boolean
|
||||
margin?: number
|
||||
}) {
|
||||
override drawWidget(ctx: CanvasRenderingContext2D, {
|
||||
y,
|
||||
width,
|
||||
show_text = true,
|
||||
margin = 15,
|
||||
}: DrawWidgetOptions) {
|
||||
// Store original context attributes
|
||||
const originalTextAlign = ctx.textAlign
|
||||
const originalStrokeStyle = ctx.strokeStyle
|
||||
const originalFillStyle = ctx.fillStyle
|
||||
|
||||
const { y, width, show_text = true, margin = 15 } = options
|
||||
const widget_width = width
|
||||
const H = this.height
|
||||
const { height } = this
|
||||
|
||||
ctx.textAlign = "left"
|
||||
ctx.strokeStyle = this.outline_color
|
||||
@@ -45,9 +43,9 @@ export class NumberWidget extends BaseWidget implements INumericWidget {
|
||||
ctx.beginPath()
|
||||
|
||||
if (show_text)
|
||||
ctx.roundRect(margin, y, widget_width - margin * 2, H, [H * 0.5])
|
||||
ctx.roundRect(margin, y, width - margin * 2, height, [height * 0.5])
|
||||
else
|
||||
ctx.rect(margin, y, widget_width - margin * 2, H)
|
||||
ctx.rect(margin, y, width - margin * 2, height)
|
||||
ctx.fill()
|
||||
|
||||
if (show_text) {
|
||||
@@ -57,14 +55,14 @@ export class NumberWidget extends BaseWidget implements INumericWidget {
|
||||
ctx.fillStyle = this.text_color
|
||||
ctx.beginPath()
|
||||
ctx.moveTo(margin + 16, y + 5)
|
||||
ctx.lineTo(margin + 6, y + H * 0.5)
|
||||
ctx.lineTo(margin + 16, y + H - 5)
|
||||
ctx.lineTo(margin + 6, y + height * 0.5)
|
||||
ctx.lineTo(margin + 16, y + height - 5)
|
||||
ctx.fill()
|
||||
// Draw right arrow
|
||||
ctx.beginPath()
|
||||
ctx.moveTo(widget_width - margin - 16, y + 5)
|
||||
ctx.lineTo(widget_width - margin - 6, y + H * 0.5)
|
||||
ctx.lineTo(widget_width - margin - 16, y + H - 5)
|
||||
ctx.moveTo(width - margin - 16, y + 5)
|
||||
ctx.lineTo(width - margin - 6, y + height * 0.5)
|
||||
ctx.lineTo(width - margin - 16, y + height - 5)
|
||||
ctx.fill()
|
||||
}
|
||||
|
||||
@@ -72,7 +70,7 @@ export class NumberWidget extends BaseWidget implements INumericWidget {
|
||||
ctx.fillStyle = this.secondary_text_color
|
||||
const label = this.label || this.name
|
||||
if (label != null) {
|
||||
ctx.fillText(label, margin * 2 + 5, y + H * 0.7)
|
||||
ctx.fillText(label, margin * 2 + 5, y + height * 0.7)
|
||||
}
|
||||
|
||||
// Draw value
|
||||
@@ -84,8 +82,8 @@ export class NumberWidget extends BaseWidget implements INumericWidget {
|
||||
? this.options.precision
|
||||
: 3,
|
||||
),
|
||||
widget_width - margin * 2 - 20,
|
||||
y + H * 0.7,
|
||||
width - margin * 2 - 20,
|
||||
y + height * 0.7,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user