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

Support loading TrueType fonts for use in Canvas objects #808

Closed
ajstarks opened this issue Apr 3, 2020 · 11 comments
Closed

Support loading TrueType fonts for use in Canvas objects #808

ajstarks opened this issue Apr 3, 2020 · 11 comments

Comments

@ajstarks
Copy link

ajstarks commented Apr 3, 2020

Is your feature request related to a problem? Please describe:

it would be useful to apply an arbitrary font to Text objects rendered on the fyne Canvas

Is it possible to construct a solution with the existing API?

No.

Describe the solution you'd like to see:

Add a field to the fyne/canvas.Text object that points to font resource. The default value can be the sans-serif font used by the current theme.

type Text struct {
    Alignment fyne.TextAlign // The alignment of the text content

    Color     color.Color    // The main text draw colour
    Text      string         // The string content of this Text
    TextSize  int            // Size of the text - if the Canvas scale is 1.0 this will be equivalent to point size
    TextStyle fyne.TextStyle // The style of the text content
    TextFont string          // font name -- points to TTF file in a magic place?
}
@andydotxyz
Copy link
Member

I don't think we can rely on magic places, or even filesystem in general if this should work on mobile.
I would propose instead a TextFont fyne.Resource field which means it could be loaded from various different places and passed, already loaded, into the app? That way it could be (recommended?) bundled into the app binary.

It doesn't, however, have the usual font caching or fallback to the latin characters if a lookup fails... I guess that is OK for this purpose though, as the developer has full control over the font they load?

@ajstarks
Copy link
Author

ajstarks commented Apr 4, 2020

Yes, I agree the fyne.Resource is a better choice.

@andydotxyz
Copy link
Member

I don't know exactly how this should be done - but as we review text handling in 2.0 it's a good time to discuss

@ajstarks
Copy link
Author

Seems good to me

@dosgo
Copy link

dosgo commented Mar 29, 2021

Does it now support custom font size for widgets? Generally important information in the design may be different in font size and color. If the widget does not support separate font definition, then it cannot be used.

@andydotxyz
Copy link
Member

Does it now support custom font size for widgets?

Widgets use the standard size and colours set by the theme. The canvas package provides complete flexibility over what you do as there is no semantic meaning to them.

Generally important information in the design may be different in font size and color.

I agree, but this is controlled by widget APIs, not customisation. For example the Title of a Card or Button.Importance = HighImportance allow this differentiation without breaking the concept of a semantic API styled by the current theme.

@andydotxyz
Copy link
Member

Remember, if the standard widgets don't do what you want you can insert your own code or just canvas.Text element - you are not limited to the standard widgets, that is just an easy to use happy-path.

@dosgo
Copy link

dosgo commented Mar 29, 2021

Thank you very much. Canvas.NewText is really easy to use.

@andydotxyz
Copy link
Member

@dweymouth
Copy link
Contributor

I think we can close this issue as the original request seems to have been resolved.

@andydotxyz
Copy link
Member

In addition to this Text.FontSource now allows you to load font faces outside of the theme definition.

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

No branches or pull requests

4 participants