Text
Text is a widget that can display many kinds of text (core.Text).
You can render plain text:
core.NewText(b).SetText("Hello, world!")You can render long text, which will automatically wrap by default:
core.NewText(b).SetText("This is a very long sentence that demonstrates how text content will overflow onto multiple lines when the size of the text exceeds the size of its surrounding container; text widgets are customizable widget that Cogent Core provides, allowing you to display many kinds of text")You can use HTML formatting in text:
core.NewText(b).SetText(`<b>You</b> can use <i>HTML</i> <u>formatting</u> inside of <b><i><u>Cogent Core</u></i></b> text, including <span style="color:red;background-color:yellow">custom styling</span> and <a href="https://example.com">links</a>`)Styles
You can use one of the 15 preset text types to customize the appearance of text:
core.NewText(b).SetType(core.TextHeadlineMedium).SetText("Hello, world!")You can also use a styler to further customize the appearance of text (see text styles for more details):
core.NewText(b).SetText("Hello,\n\tworld!").Styler(func(s *styles.Style) {
s.Font.Size.Dp(21)
s.Font.Weight = rich.Bold
s.Font.Slant = rich.Italic
s.Font.SetDecoration(rich.Underline, rich.LineThrough)
s.Text.WhiteSpace = text.WhiteSpacePre
s.Color = colors.Scheme.Success.Base
s.Font.Family = rich.Monospace
})The Type of text provides predefined size values according to the Material 3 standards, with the default being TextBodyLarge:
for _, typ := range core.TextTypesValues() {
s := strcase.ToSentence(typ.String())
core.NewText(b).SetType(typ).SetText(s)
}