Skip to content

Commit

Permalink
scroll text if width of Textbox is exceeded
Browse files Browse the repository at this point in the history
  • Loading branch information
bjarthur committed Aug 30, 2024
1 parent 02ccec3 commit ce7b505
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [Unreleased]

- For `Textbox`es in which a fixed width is specified, the text is now scrolled
if the width is exceeded [#4293](https://github.com/MakieOrg/Makie.jl/pull/4293)
- Fix attribute updates for SpecApi and SpecPlots (e.g. ecdfplot) [#4265](https://github.com/MakieOrg/Makie.jl/pull/4265).
- Bring back `poly` convert arguments for matrix with points as row [#4266](https://github.com/MakieOrg/Makie.jl/pull/4258).
- Fix gl_ClipDistance related segfault on WSL with GLMakie [#4270](https://github.com/MakieOrg/Makie.jl/pull/4270)
Expand Down
29 changes: 28 additions & 1 deletion src/makielayout/blocks/textbox.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,28 @@ function initialize_block!(tbox::Textbox)
return
end

if 0 < ci < length(bbs)
points = if 0 < ci < length(bbs)
[leftline(bbs[ci+1])...]
elseif ci == 0
[leftline(bbs[1])...]
else
[leftline(bbs[ci])...] .+ Point2f(hadvances[ci], 0)
end

textpos = textplot.converted[1][][1]
offset = if points[1][1] > tbox.layoutobservables.computedbbox[].widths[1]
points[1][1] - tbox.layoutobservables.computedbbox[].widths[1]

Check warning on line 103 in src/makielayout/blocks/textbox.jl

View check run for this annotation

Codecov / codecov/patch

src/makielayout/blocks/textbox.jl#L103

Added line #L103 was not covered by tests
elseif points[1][1] < 0
points[1][1]

Check warning on line 105 in src/makielayout/blocks/textbox.jl

View check run for this annotation

Codecov / codecov/patch

src/makielayout/blocks/textbox.jl#L105

Added line #L105 was not covered by tests
else
0
end
if offset != 0
textplot.converted[1][] = [Point3f(textpos[1]-offset, textpos[2:3]...)]
points = [Point2f(p[1]-offset, p[2]) for p in points]

Check warning on line 111 in src/makielayout/blocks/textbox.jl

View check run for this annotation

Codecov / codecov/patch

src/makielayout/blocks/textbox.jl#L110-L111

Added lines #L110 - L111 were not covered by tests
end

points
end

cursor = linesegments!(scene, cursorpoints, color = tbox.cursorcolor, linewidth = 1, inspectable = false)
Expand Down Expand Up @@ -161,8 +176,12 @@ function initialize_block!(tbox::Textbox)
empty!(displayed_chars[])
index = 1
end
textplot = t.blockscene.plots[1]
oldval = textplot.converted[1][][1]
newchars = [displayed_chars[][1:index-1]; c; displayed_chars[][index:end]]
tbox.displayed_string[] = join(newchars)
offset = displayed_charbbs[][index].widths[1] / 2
textplot.converted[1][] = [Point3f(oldval[1]+offset, oldval[2:3]...)]
cursorindex[] = index
end

Expand All @@ -171,6 +190,7 @@ function initialize_block!(tbox::Textbox)
end

function removechar!(index)
index==0 && return

Check warning on line 193 in src/makielayout/blocks/textbox.jl

View check run for this annotation

Codecov / codecov/patch

src/makielayout/blocks/textbox.jl#L193

Added line #L193 was not covered by tests
newchars = [displayed_chars[][1:index-1]; displayed_chars[][index+1:end]]

if isempty(newchars)
Expand All @@ -181,7 +201,14 @@ function initialize_block!(tbox::Textbox)
cursorindex[] = max(0, cursorindex[] - 1)
end

textplot = t.blockscene.plots[1]
oldval = textplot.converted[1][][1]
offset = displayed_charbbs[][index].widths[1] / 2
if displayed_charbbs[][1].origin[1] < 0
offset *= -1

Check warning on line 208 in src/makielayout/blocks/textbox.jl

View check run for this annotation

Codecov / codecov/patch

src/makielayout/blocks/textbox.jl#L204-L208

Added lines #L204 - L208 were not covered by tests
end
tbox.displayed_string[] = join(newchars)
textplot.converted[1][] = [Point3f(oldval[1]-offset, oldval[2:3]...)]

Check warning on line 211 in src/makielayout/blocks/textbox.jl

View check run for this annotation

Codecov / codecov/patch

src/makielayout/blocks/textbox.jl#L211

Added line #L211 was not covered by tests
end

on(topscene, events(scene).unicode_input; priority=60) do char
Expand Down

0 comments on commit ce7b505

Please sign in to comment.