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

Expose word wrap in TextLayout and Label #1195

Merged
merged 1 commit into from
Sep 11, 2020
Merged

Expose word wrap in TextLayout and Label #1195

merged 1 commit into from
Sep 11, 2020

Conversation

cmyr
Copy link
Member

@cmyr cmyr commented Sep 8, 2020

With this patch, the TextLayout object can now be given a width
for wrapping words. This is exposed in the Label via a new
LineBreaking enum, with three options. With LineBreaking::WordWrap,
the TextLayout's wrap-width is set to the maximum width of the label's
BoxConstraints, and lines are broken appropriately. The other two
options (LineBreaking::Overflow and LineBreaking::Clip) both disable
line-breaking; in the former case if text exceeds the width of
the label it is painted outside of the label's bounds, and in the
latter case the text is clipped to the bounds of the label.

It would be nice if, in the clipping case, we could use a gradient
mask or something to fade the edges of the clipped text, but I don't
believe this is currently possible in piet. A simple alternative
of drawing a gradient from (transparent -> label background color)
doesn't work, because label's do not have an explicit background color,
which I think is also correct.

progress on #1192
Screen Shot 2020-09-10 at 12 08 45 PM
Screen Shot 2020-09-10 at 12 08 50 PM
Screen Shot 2020-09-10 at 12 10 17 PM
Screen Shot 2020-09-10 at 12 10 23 PM

@cmyr cmyr force-pushed the text-layout-width branch from d598323 to a3d1b41 Compare September 8, 2020 22:37
@rjwittams
Copy link
Collaborator

rjwittams commented Sep 8, 2020

This looks really good! (Looking at the pics not code! )

@cmyr cmyr force-pushed the text-layout-width branch from a3d1b41 to ca40deb Compare September 9, 2020 13:26
Base automatically changed from new-text-integration to master September 9, 2020 13:31
@cmyr cmyr force-pushed the text-layout-width branch from ca40deb to 832b17e Compare September 9, 2020 18:16
Copy link
Contributor

@raphlinus raphlinus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See inline, I think this PR sets off a much deeper discussion than was planned...

CHANGELOG.md Outdated Show resolved Hide resolved
druid/examples/custom_widget.rs Outdated Show resolved Hide resolved
druid/examples/styled_text.rs Outdated Show resolved Hide resolved
druid/examples/text.rs Outdated Show resolved Hide resolved
druid/examples/text.rs Outdated Show resolved Hide resolved
druid/src/widget/label.rs Outdated Show resolved Hide resolved
@cmyr cmyr mentioned this pull request Sep 9, 2020
7 tasks
@luleyleo luleyleo added the S-waiting-on-author waits for changes from the submitter label Sep 10, 2020
@luleyleo
Copy link
Collaborator

This should get a changlog entry.

@cmyr cmyr marked this pull request as draft September 10, 2020 13:55
@cmyr
Copy link
Member Author

cmyr commented Sep 10, 2020

I'm going to rework this to have a different API.

@cmyr cmyr force-pushed the text-layout-width branch 3 times, most recently from 9a3a716 to ce1cbd8 Compare September 10, 2020 16:08
@cmyr
Copy link
Member Author

cmyr commented Sep 10, 2020

Okay, I've reworked this significantly so that instead of exposing an explicit wrap-width in label, we expose a LineBreaking enum that manages the wrap-width of the internal TextLayout object as appropriate. The PR description and screenshots have been updated appropriately.

@cmyr cmyr marked this pull request as ready for review September 10, 2020 16:12
@ForLoveOfCats
Copy link
Collaborator

That looks glorious

@cmyr cmyr added S-needs-review waits for review and removed S-waiting-on-author waits for changes from the submitter labels Sep 10, 2020
Copy link
Contributor

@raphlinus raphlinus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, thanks!

With this patch, the TextLayout object can now be given a width
for wrapping words. This is exposed in the Label via a new
LineBreaking enum, with three options. With LineBreaking::WordWrap,
the TextLayout's wrap-width is set to the maximum width of the label's
BoxConstraints, and lines are broken appropriately. The other two
options (LineBreaking::Overflow and LineBreaking::Clip) both disable
line-breaking; in the former case if text exceeds the width of
the label it is painted outside of the label's bounds, and in the
latter case the text is clipped to the bounds of the label.

It would be nice if, in the clipping case, we could use a gradient
mask or something to fade the edges of the clipped text, but I don't
believe this is currently possible in piet. A simple alternative
of drawing a gradient from (transparent -> label background color)
doesn't work, because label's do not have an explicit background color,
which I think is also correct.

progress on #1192
@cmyr cmyr force-pushed the text-layout-width branch from ce1cbd8 to 7261854 Compare September 11, 2020 14:41
@cmyr cmyr merged commit bfe33a9 into master Sep 11, 2020
@cmyr cmyr deleted the text-layout-width branch September 11, 2020 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-needs-review waits for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants