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 Bold and Underline to TextGrid widget #4244

Merged

Conversation

mgazza
Copy link
Contributor

@mgazza mgazza commented Sep 13, 2023

Description:

Enable the text style to be passed in as part of the TextGridStyle. this will allow font options to be passed down

Checklist:

  • Tests included.
  • Lint and formatter run with no errors.
  • Tests all pass.

Where applicable:

  • Public APIs match existing style and have Since: line.
  • Any breaking changes have a deprecation path or have been discussed.
  • Check for binary size increases when importing new modules.

@mgazza mgazza force-pushed the feature/text-grid-highlighting branch 2 times, most recently from 9d2680a to cf930d3 Compare September 13, 2023 17:06
@coveralls
Copy link

coveralls commented Sep 13, 2023

Coverage Status

coverage: 65.566% (-0.004%) from 65.57%
when pulling 123747e on codelaboratoryltd:feature/text-grid-highlighting
into 389162b on fyne-io:develop.

Copy link
Member

@andydotxyz andydotxyz left a comment

Choose a reason for hiding this comment

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

Looks good. A few comments inline about since notes and naming.

Would it be possible to add a test?

Also I think you might find that although the APIs are added they do not take effect on output...
You'll need to extend the code in internal/painter/font.go I think (line 35 onwards). It will likely be necessary to pass the style in to the actual theme Font call instead of using the helper methods which are limited to monospace vs all other styles...

widget/textgrid.go Outdated Show resolved Hide resolved
widget/textgrid.go Outdated Show resolved Hide resolved
widget/textgrid.go Outdated Show resolved Hide resolved
@mgazza
Copy link
Contributor Author

mgazza commented Sep 14, 2023

quick demo
image

widget/textgrid.go Outdated Show resolved Hide resolved
widget/textgrid.go Show resolved Hide resolved
widget/textgrid.go Outdated Show resolved Hide resolved
@andydotxyz
Copy link
Member

You'll need to extend the code in internal/painter/font.go I think (line 35 onwards). It will likely be necessary to pass the style in to the actual theme Font call instead of using the helper methods which are limited to monospace vs all other styles...

I'm curious about how you got the demo working with that font cache not patched - did you find that it wasn't a problem for some reason? How was the bold monospace font looked up in that demo?

@mgazza
Copy link
Contributor Author

mgazza commented Sep 18, 2023

You'll need to extend the code in internal/painter/font.go I think (line 35 onwards). It will likely be necessary to pass the style in to the actual theme Font call instead of using the helper methods which are limited to monospace vs all other styles...

I'm curious about how you got the demo working with that font cache not patched - did you find that it wasn't a problem for some reason? How was the bold monospace font looked up in that demo?

overriding the theme was all that was needed
image

@andydotxyz
Copy link
Member

Yup I appreciate that the API was designed to make this possible - but I'm pretty sure you'll get cache collisions inside the toolkit as it does not understand bold monospace.

Happy to be proved wrong on this of course, but it's a concern.

@mgazza
Copy link
Contributor Author

mgazza commented Sep 19, 2023

Yup I appreciate that the API was designed to make this possible - but I'm pretty sure you'll get cache collisions inside the toolkit as it does not understand bold monospace.

Happy to be proved wrong on this of course, but it's a concern.

I haven't seen any, it sounds like an ideal unit test candidate, however. Is there a table test which I can add a test case to?

@andydotxyz
Copy link
Member

I haven't seen any, it sounds like an ideal unit test candidate, however. Is there a table test which I can add a test case to?

The problem will be in CachedFontFace of internal/painter/font.go and there is a font_internal_test.go used to test caching and other non-public API.

@mgazza
Copy link
Contributor Author

mgazza commented Sep 27, 2023

When running the tests locally, I get quite a few failures. I have checked to ensure no more/other tests are failing due to this work. I can't see how CachedFontFace is affected, it appears to call the theme font in every case from what I can see. I may be missing something however.

@andydotxyz
Copy link
Member

When running the tests locally, I get quite a few failures. I have checked to ensure no more/other tests are failing due to this work. I can't see how CachedFontFace is affected, it appears to call the theme font in every case from what I can see. I may be missing something however.

I can't figure out how! The OpenGL driver text rendering uses the cached face to draw. it is created in internall/painter/gl/texture.go:155, and the text style passed in uses only the Monospace field in the case of mono, ignoring the others. I cannot find any other routes to get to DrawString which is the entry point for rendering text...

@andydotxyz
Copy link
Member

I just realised that TextGridTextStyle does not handle Italics... so would that be another new interface in the future? It's looking more and more like a duplication of the TextStyle struct!

@andydotxyz
Copy link
Member

When running the tests locally, I get quite a few failures.

There should not be - there is an intermittent issue due to window sizing and OS not always allowing it during the test IIRC. If the CI does not see failures then it's probably OK but worth opening a bug to report that it's not all working at your end.

@andydotxyz
Copy link
Member

When running the tests locally, I get quite a few failures.

Latest develop should have all the test failures resolved.
Shall we try and get something based on this in to 2.5? Would be good to have the TextStyle used on more widgets.

@mgazza
Copy link
Contributor Author

mgazza commented Jun 4, 2024

Sorry for the delay, yeah it would be good to have this into 2.5

@andydotxyz
Copy link
Member

That might be tough, yesterday was feature freeze. I remain concerned that adding "TextGridTextStyle" in addition to "TextGridStyle" and "TextStyle" is confusing and the discussion about bold/bolded underline/underlined would be avoided by using the existing APIs

@mgazza
Copy link
Contributor Author

mgazza commented Jun 11, 2024

I hope the last commit aligns more with your thinking?

text.go Outdated Show resolved Hide resolved
@andydotxyz
Copy link
Member

I hope the last commit aligns more with your thinking?

This seems much more consistent thanks.
There is a conflict stopping CI from running unfortunately. Either way I added some small thoughts inline.

@mgazza
Copy link
Contributor Author

mgazza commented Jun 12, 2024

I hope the last commit aligns more with your thinking?

This seems much more consistent thanks. There is a conflict stopping CI from running unfortunately. Either way I added some small thoughts inline.

Thanks, I'll add the comments and tidy up the branch so its much more atomic :D

Fix TextGrid tests
And underline to text style
Add underline support to TextGrid widget
@mgazza mgazza changed the title Add TextGridTextStyle Add Bold and Underline to TextGrid widget Jun 14, 2024
Copy link
Member

@andydotxyz andydotxyz left a comment

Choose a reason for hiding this comment

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

Thanks so much, this is great to have in.

@andydotxyz
Copy link
Member

I guess the apps would need a bold monospace font in the theme to see the difference on that right? Perhaps we should consider with the new system font lookup to find local defaults that are more flexible? A later PR works for that.

Also, I am curious - is italic being included for the TextGrid lots of extra work or would it follow the same model?

Thanks again for sticking through the process here.

@mgazza
Copy link
Contributor Author

mgazza commented Jun 17, 2024

The same model will work for italics. yes you have to return a different font for bold and italics in the font lookup

@andydotxyz andydotxyz merged commit 5a97251 into fyne-io:develop Jun 17, 2024
12 checks passed
@mgazza mgazza deleted the feature/text-grid-highlighting branch June 17, 2024 09:40
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.

4 participants