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 Oct 1, 2024
1 parent 94b7273 commit 705eb4c
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 `merge(attr1, attr2)` modifying nested attributes in `attr1` [#4416](https://github.com/MakieOrg/Makie.jl/pull/4416)
- Fixed issue with CairoMakie rendering scene backgrounds at the wrong position [#4425](https://github.com/MakieOrg/Makie.jl/pull/4425)
- Fix incorrect inverse transformation in `position_on_plot` for lines, causing incorrect tooltip placement in DataInspector [#4402](https://github.com/MakieOrg/Makie.jl/pull/4402)
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]
elseif points[1][1] < 0
points[1][1]
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]
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
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
end
tbox.displayed_string[] = join(newchars)
textplot.converted[1][] = [Point3f(oldval[1]-offset, oldval[2:3]...)]
end

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

0 comments on commit 705eb4c

Please sign in to comment.