mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-28 02:02:08 +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:
@@ -6,7 +6,7 @@ import { clamp } from "@/litegraph"
|
||||
import { CanvasMouseEvent } from "@/types/events"
|
||||
import { getWidgetStep } from "@/utils/widget"
|
||||
|
||||
import { BaseWidget } from "./BaseWidget"
|
||||
import { BaseWidget, type DrawWidgetOptions } from "./BaseWidget"
|
||||
|
||||
export class KnobWidget extends BaseWidget implements IKnobWidget {
|
||||
declare type: "knob"
|
||||
@@ -45,30 +45,28 @@ export class KnobWidget extends BaseWidget implements IKnobWidget {
|
||||
|
||||
drawWidget(
|
||||
ctx: CanvasRenderingContext2D,
|
||||
options: {
|
||||
y: number
|
||||
width: number
|
||||
show_text?: boolean
|
||||
margin?: number
|
||||
gradient_stops?: string
|
||||
},
|
||||
{
|
||||
y,
|
||||
width,
|
||||
show_text = true,
|
||||
margin = 15,
|
||||
}: DrawWidgetOptions,
|
||||
): void {
|
||||
// Store original context attributes
|
||||
const originalTextAlign = ctx.textAlign
|
||||
const originalStrokeStyle = ctx.strokeStyle
|
||||
const originalFillStyle = ctx.fillStyle
|
||||
|
||||
const { y, width: widget_width, show_text = true, margin = 15 } = options
|
||||
const { gradient_stops = "rgb(14, 182, 201); rgb(0, 216, 72)" } = this.options
|
||||
const effective_height = this.computedHeight || this.height
|
||||
// Draw background
|
||||
const size_modifier =
|
||||
Math.min(this.computedHeight || this.height, this.width || 20) / 20 // TODO: replace magic numbers
|
||||
const arc_center = { x: widget_width / 2, y: effective_height / 2 + y }
|
||||
const arc_center = { x: width / 2, y: effective_height / 2 + y }
|
||||
ctx.lineWidth =
|
||||
(Math.min(widget_width, effective_height) - margin * size_modifier) / 6
|
||||
(Math.min(width, effective_height) - margin * size_modifier) / 6
|
||||
const arc_size =
|
||||
(Math.min(widget_width, effective_height) -
|
||||
(Math.min(width, effective_height) -
|
||||
margin * size_modifier -
|
||||
ctx.lineWidth) / 2
|
||||
{
|
||||
@@ -188,7 +186,7 @@ export class KnobWidget extends BaseWidget implements IKnobWidget {
|
||||
const fixedValue = Number(this.value).toFixed(this.options.precision ?? 3)
|
||||
ctx.fillText(
|
||||
`${this.label || this.name}\n${fixedValue}`,
|
||||
widget_width * 0.5,
|
||||
width * 0.5,
|
||||
y + effective_height * 0.5,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user