Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

Commit

Permalink
feat: Rect.fromLTRB and Rect.fromWH
Browse files Browse the repository at this point in the history
  • Loading branch information
sheepbox8646 committed Jun 30, 2024
1 parent 3beacea commit f7514a8
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions packages/basic/src/widgets/rect.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Canvas, CanvasKit, RRect } from 'canvaskit-wasm'
import type { ConvertToProp } from '@newcar/core'
import { changed, ref } from '@newcar/core'
import { deepMerge } from '@newcar/utils'
import type { PathOptions, PathStyle } from './path.ts'
import { Path } from './path.ts'

Expand Down Expand Up @@ -41,10 +42,10 @@ export class Rect extends Path {
super.init(ck)

this.rect = new Float32Array([
0,
0,
this.width * this.progress.value,
this.height * this.progress.value,
-this.width / 2,
-this.height / 2,
this.width * this.progress.value - this.width / 2,
this.height * this.progress.value - this.height / 2,
...this.radius,
])

Expand All @@ -71,6 +72,22 @@ export class Rect extends Path {
super.draw(canvas)
}

static fromLTRB(l: number, t: number, r: number, b: number, options?: RectOptions) {
return new Rect(r - l, b - t, {
...options,
})
}

static fromWH(w: number, h: number, options?: RectOptions) {
return new Rect(w, h, deepMerge(
options,
{
x: w / 2,
y: h / 2,
},
))
}

mapRadius() {
if (typeof this.style.radius.value === 'number') {
this.radius.fill(this.style.radius.value, 0, 8)
Expand Down

0 comments on commit f7514a8

Please sign in to comment.