diff options
| author | s-ol <s+removethis@s-ol.nu> | 2025-09-27 15:51:07 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2025-09-27 15:51:07 +0000 |
| commit | 42508d4e25148e8951d67ee8806eb5cef65aa2b7 (patch) | |
| tree | 55de2aada60938a285b55ea0cc2d1d5c9d45389d | |
| parent | lib/link-time: add fade (diff) | |
| download | alive-42508d4e25148e8951d67ee8806eb5cef65aa2b7.tar.gz alive-42508d4e25148e8951d67ee8806eb5cef65aa2b7.zip | |
lib/love: add text-wrap
| -rw-r--r-- | alv-lib/love.moon | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/alv-lib/love.moon b/alv-lib/love.moon index 9d3c64c..e18ea3f 100644 --- a/alv-lib/love.moon +++ b/alv-lib/love.moon @@ -227,6 +227,38 @@ Create a shape that draws the text `str` with font `font` (or the default font). height = fnt\getHeight! love.graphics.print str, fnt, math.floor(width*wm), math.floor(-height/2) +text_wrap = Constant.meta + meta: + name: 'text' + summary: "create a text shape, wrapping beyond a certain width." + examples: { '(love/text-wrap str width [align] [font])' } + description: " +Create a shape that draws the text `str` with font `font` (or the default font). +`align` should be on of the following strings: +- `center` (the default) +- `left` +- `right`" + + value: class extends PureOp + pattern: any.str + any.num + -any.str + -any['love/font'] + type: T['love/shape'] + + tick: => + { str, width, align, fnt } = @unwrap_all! + + wm = switch align or 'center' + when 'left' then 0 + when 'center' then -0.5 + when 'right' then -1 + else + error Error 'argument', "unknown text alignment '#{align}'" + + @out\set -> + fnt or= love.graphics.getFont! + _, lines = fnt\getWrap str, width + height = #lines * fnt\getHeight! + love.graphics.printf str, fnt, math.floor(width*wm), math.floor(-height/2), width, align + color = Constant.meta meta: name: 'color' @@ -631,7 +663,8 @@ macro [->>][]: 'no-shape': no_shape :font - :circle, :ellipse, :line, :rectangle, :text + :circle, :ellipse, :line, :rectangle + :text, 'text-wrap': text_wrap :translate, :rotate, :scale, :shear :color, 'line-width': line_width |
