Skip to content

Commit

Permalink
add textWidth
Browse files Browse the repository at this point in the history
  • Loading branch information
Acepie committed May 1, 2024
1 parent 087b6e1 commit 7cd892e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gleam.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "p5js_gleam"
version = "2.1.0"
version = "2.1.2"
target = "javascript"

description = "A simple game library providing p5.js bindings for Gleam in a functional style to make basic games and animations. Heavily inspired by the Racket library 2htdp/universe"
Expand Down
3 changes: 2 additions & 1 deletion scripts/generate_p5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const elements: Record<string, Binding> = {
textFont: { arguments: ["font: P5Font"] },
textFontFromString: { arguments: ["font: String"], bindingName: "textFont" },
textSize: { arguments: ["size: Int"] },
textWidth: { arguments: ["text: String"], returnType: "Float" },
background: { arguments: ["color: String"] },
ellipse: {
arguments: [
Expand Down Expand Up @@ -181,7 +182,7 @@ for (const [elementName, elementBinding] of Object.entries(elements)) {
outJs += js(
elementName,
elementBinding.bindingName ?? elementName,
Boolean(elementBinding.returnType),
Boolean(elementBinding.returnType)
);
}

Expand Down
4 changes: 4 additions & 0 deletions src/p5js_ffi.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ export function textSize(p, ...args) {
return p;
}

export function textWidth(p, ...args) {
return p.textWidth(...args);
}

export function background(p, ...args) {
p.background(...args);
return p;
Expand Down
4 changes: 4 additions & 0 deletions src/p5js_gleam/bindings.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ pub fn text_font_from_string(p: P5, font: String) -> P5
@external(javascript, "../p5js_ffi.mjs", "textSize")
pub fn text_size(p: P5, size: Int) -> P5

/// A binding to the p5.js [`textWidth`](https://p5js.org/reference/#/p5/textWidth) function. Takes a p5 instance and the function's arguments and returns the p5 instance.
@external(javascript, "../p5js_ffi.mjs", "textWidth")
pub fn text_width(p: P5, text: String) -> Float

/// A binding to the p5.js [`background`](https://p5js.org/reference/#/p5/background) function. Takes a p5 instance and the function's arguments and returns the p5 instance.
@external(javascript, "../p5js_ffi.mjs", "background")
pub fn background(p: P5, color: String) -> P5
Expand Down

0 comments on commit 7cd892e

Please sign in to comment.