fyne-io / fyne

Cross platform GUI toolkit in Go inspired by Material Design
https://fyne.io/
Other
24.95k stars 1.38k forks source link

Support loading TrueType fonts for use in Canvas objects #808

Closed ajstarks closed 9 months ago

ajstarks commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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

andydotxyz commented 3 years ago

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 commented 3 years ago

Seems good to me

dosgo commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

andydotxyz commented 3 years ago

This should be covered by the Rich Text proposal at https://github.com/fyne-io/proposals/pull/3/files#diff-eb10bfb4b3ec7c6895fe11638107950db8201a985453fa98eac3c5c0eb6fc674R90

dweymouth commented 9 months ago

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

andydotxyz commented 3 months ago

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