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

Commit

Permalink
update text width immediately
Browse files Browse the repository at this point in the history
  • Loading branch information
slmjkdbtl committed Sep 20, 2023
1 parent 8058185 commit 14a56b2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ loadFont("apl386", "/examples/fonts/apl386.ttf", {
- fixed `wave()` not starting at `0` when time is `0`
- kaboom now only displays error screen for kaboom's own error, instead of catching all errors in current window
- added `KaboomError` class for errors related to current kaboom instance
- setting `obj.text` with `text()` component now immediately updates `width` and `height` property
```js
const obj = add([
text("oh hi"),
pos(100, 200),
])

// before
obj.text = "bye"
console.log(obj.width) // still the width of "oh hi" until next render

// before
obj.text = "bye"
console.log(obj.width) // will be updated to the width of "bye"
```

### v3000.1.6
- fixed `loadSound` typing to accept `ArrayBuffer`
Expand Down
18 changes: 15 additions & 3 deletions src/kaboom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4474,13 +4474,20 @@ export default (gopt: KaboomOpt = {}): KaboomCtx => {

}

return {
const obj = {

id: "text",
text: t,
set text(nt) {
t = nt
// @ts-ignore
update(this)
},
get text() {
return t
},
textSize: opt.size ?? DEF_TEXT_SIZE,
font: opt.font,
width: opt.width,
width: opt.width ?? 0,
height: 0,
align: opt.align,
lineSpacing: opt.lineSpacing,
Expand All @@ -4502,6 +4509,11 @@ export default (gopt: KaboomOpt = {}): KaboomCtx => {

}

// @ts-ignore
update(obj)

return obj

}

function rect(w: number, h: number, opt: RectCompOpt = {}): RectComp {
Expand Down

0 comments on commit 14a56b2

Please sign in to comment.