Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic word wrapping #1819

Merged
merged 18 commits into from May 12, 2022
Merged

Add basic word wrapping #1819

merged 18 commits into from May 12, 2022

Conversation

ffreyer
Copy link
Collaborator

@ffreyer ffreyer commented Apr 14, 2022

Description

This adds word_wrap_width as an attribute for text, which sets a limit for the size of a line. If a word (currently anything between two spaces with no newline in between) overflows this limit, a newline is inserted before it to wrap it to the next line.

Example (which is also the test I added):
Screenshot from 2022-04-14 18-08-51

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist

  • Added an entry in NEWS.md (for new features and breaking changes)
  • Added or changed relevant sections in the documentation
  • Added reference image tests for new plotting functions, recipes, visual options, etc.

@ffreyer
Copy link
Collaborator Author

ffreyer commented Apr 14, 2022

I think this could be nice with Label. Instead of having it resize to "fit" long text, the text could be wrapped to a region fitting the Label instead. Could also be helpful for Axis titles, x and y labels, etc. Related: #757

@ffreyer
Copy link
Collaborator Author

ffreyer commented Apr 14, 2022

Tests only failed because there is no refimage for new test

@ffreyer
Copy link
Collaborator Author

ffreyer commented Apr 15, 2022

I added word_wrap::Bool to Label now. Setting it to false (default) gives the old behavior. With word_wrap = true the Label uses the suggested width as its width and wraps text to fit (height is derived). The refimage test looks like this:

Screenshot from 2022-04-15 12-15-13

@ffreyer
Copy link
Collaborator Author

ffreyer commented Apr 15, 2022

Moved some stuff around to avoid creating a second GlyphCollection and got this to work for latex strings. (At least strings with mostly text.) New first refimage:
Screenshot from 2022-04-15 16-23-39

@fatteneder
Copy link
Contributor

Hi,

I have implemented the same feature here (although in a hacky way) https://github.com/fatteneder/MakieSlides.jl
This is just a proof-of-principle implementation to see whether we can use Makie.jl and its layouting functionality as the building blocks for a new presentation/slideshow engine with Markdown syntax (a la reveal.js and Marpit etc, but without the html/css madness :) The initial idea was mentioned on Zulip.
In case you wanna take a look please check the test folder for examples, the ones in examples are broken right now.

The reference image you added already goes into the same direction with what I want to do. So I very much support this PR for Makie native line wrapping support. Please let me know if I can be of any help here.

@ffreyer
Copy link
Collaborator Author

ffreyer commented Apr 27, 2022

Funnily enough I also worked on this for presentations. Though I didn't end up using it myself.

This is my attempt: https://github.com/ffreyer/MakiePresentation.jl It requires #1818

@fatteneder
Copy link
Contributor

That's funny. If you want we can join forces :)

@ffreyer
Copy link
Collaborator Author

ffreyer commented Apr 28, 2022

For the next 2 weeks I want to keep my package (more or less) as is because I have a presentarion planned with it and I don't want to break it. After that I'd be happy to merge them.

@ffreyer
Copy link
Collaborator Author

ffreyer commented May 9, 2022

All test errors are because of the missing refimg for the new test, so this is ready to be merged again

@SimonDanisch SimonDanisch merged commit c418a13 into master May 12, 2022
@SimonDanisch SimonDanisch deleted the ff/word_wraping branch May 12, 2022 15:20
kunzaatko pushed a commit to kunzaatko/Makie.jl that referenced this pull request May 16, 2022
* add basic word wrapping

* add refimg test

* dd NEWS entry

* update docs

* add word_wrap to Label

* test Label with word wrapping

* update word_wrap NEWS entry

* fix test

* move word wrapping to glyph collection constructors

* fix wrap position and update test

* only wrap with positive wrap width

* fix dropped space

* fix wrapping at string end

* fix number of arguments

* tighten test settings

Co-authored-by: Simon <sdanisch@protonmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants