Skip to content

Commit 285fd92

Browse files
committed
doc: Clarify usage about clear(fill)
1 parent fdc926e commit 285fd92

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/blendend/canvas.ex

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,17 @@ defmodule Blendend.Canvas do
141141
default (transparent black).
142142
143143
With options, the call behaves like a full–canvas fill using the given
144-
style (for example a solid background color):
144+
style (for example a solid background color).
145+
146+
Note: `fill:` goes through the normal Blend2D compositing pipeline (default
147+
`comp_op: :src_over`). This means `fill: Color.rgb!(..., 0)` (fully
148+
transparent) will not necessarily overwrite existing pixels. If you want a
149+
deterministic "wipe" with a specific color (including alpha 0), either call
150+
`clear/1` with no options or use `comp_op: :src_copy`:
145151
146152
iex> c = Blendend.Canvas.new!(100, 100)
147153
iex> :ok = Blendend.Canvas.clear(c, fill: Blendend.Style.Color.rgb!(255, 255, 255))
154+
iex> :ok = Blendend.Canvas.clear(c, fill: Blendend.Style.Color.rgb!(0, 0, 0, 0), comp_op: :src_copy)
148155
149156
The exact shape of the options is the same as the shape–drawing functions in
150157
`Blendend.Canvas.Fill.path/3`.

test/image_pixel_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ defmodule Blendend.ImagePixelTest do
77

88
test "pixel_at!/3 reads RGBA from a decoded PNG image" do
99
{:ok, canvas} = Canvas.new(2, 2)
10-
:ok = Canvas.clear(canvas, fill: Color.rgb!(0, 0, 0, 0))
10+
:ok = Canvas.clear(canvas)
1111

1212
:ok = Canvas.Fill.rect(canvas, 0, 0, 1, 1, fill: Color.rgb!(255, 0, 0, 128))
1313
:ok = Canvas.Fill.rect(canvas, 1, 1, 1, 1, fill: Color.rgb!(0, 255, 0, 255))

0 commit comments

Comments
 (0)