Skip to content

Commit

Permalink
Support glow for text (fixes for #3858) (#3866)
Browse files Browse the repository at this point in the history
* Support glow for text

* Add reference test

* Update examples3d.jl

* forward glowwidth + glowcolor in Text for WGLMakie

---------

Co-authored-by: Kipton Barros <kbarros@gmail.com>
  • Loading branch information
SimonDanisch and kbarros authored May 14, 2024
1 parent 4b048df commit f89efc3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions MakieCore/src/basic_plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,10 @@ Plots one or multiple texts passed via the `text` keyword.
markerspace = :pixel
"Controls whether the model matrix (without translation) applies to the glyph itself, rather than just the positions. (If this is true, `scale!` and `rotate!` will affect the text glyphs.)"
transform_marker = false
"Sets the color of the glow effect around the text."
glowcolor = (:black, 0.0)
"Sets the size of a glow effect around the text."
glowwidth = 0.0
"The offset of the text from the given position in `markerspace` units."
offset = (0.0, 0.0)
"Specifies a linewidth limit for text. If a word overflows this limit, a newline is inserted before it. Negative numbers disable word wrapping."
Expand Down
9 changes: 9 additions & 0 deletions ReferenceTests/src/tests/examples3d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,15 @@ end
meshscatter(positions, color=RGBAf(0.9, 0.2, 0.4, 1), markersize=0.05)
end

@reference_test "Text glow and overdraw" begin
p1 = Point3f(0,0,0)
p2 = Point3f(1,0,0)
f, ax, pl = meshscatter([p1, p2]; markersize=0.3, color=[:purple, :yellow])
text!(ax, p1; text="A", align=(:center, :center), glowwidth=10.0, glowcolor=:white, color=:black, fontsize=40, overdraw=true)
text!(ax, p2; text="B", align=(:center, :center), glowwidth=20.0, glowcolor=(:black, 0.6), color=:white, fontsize=40, overdraw=true)
f
end

@reference_test "Animated surface and wireframe" begin
function xy_data(x, y)
r = sqrt(x^2 + y^2)
Expand Down
4 changes: 3 additions & 1 deletion WGLMakie/src/particles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,9 @@ function create_shader(scene::Scene, plot::Makie.Text{<:Tuple{<:Union{<:Makie.Gl
:uv_offset_width => uv_offset_width,
:transform_marker => get(plot.attributes, :transform_marker, Observable(true)),
:billboard => Observable(false),
:depth_shift => get(plot, :depth_shift, Observable(0f0))
:depth_shift => get(plot, :depth_shift, Observable(0f0)),
:glowwidth => plot.glowwidth,
:glowcolor => plot.glowcolor,
)

return scatter_shader(scene, uniforms, plot_attributes)
Expand Down

0 comments on commit f89efc3

Please sign in to comment.