Typography 排版
提供统一的文本、标题、段落和链接排版层级。
何时使用
- 页面标题使用
Title,正文使用Paragraph或Text。 - 需要可点击的文字操作时使用
Link,不要用普通文本模拟链接。 - 复杂富文本或代码编辑使用专用组件。
在线体验
基本用法
import "github.com/tangoui/tango/ui"
func page(c *ui.Context) {
ui.Title(c, "项目概览", 1)
ui.Paragraph(c, "这里是一段用于说明页面内容的正文。")
ui.Link(c, "查看详情")
}常见用法
层级标题
func headings(c *ui.Context) {
ui.Title(c, "一级标题", 1)
ui.Title(c, "二级标题", 2)
ui.Title(c, "三级标题", 3)
}文本装饰
func decoration(c *ui.Context) {
ui.Text(c, "重点").Mark()
ui.Text(c, "代码").Code()
ui.Text(c, "已删除").Delete().Underline()
}链接交互
func action(c *ui.Context, open *bool) {
if ui.Link(c, "打开详情").Clicked() { *open = true }
}主题与样式
Typography 令牌控制字号、字重、行高、标题颜色和链接状态;三套主题只改变令牌配方,标题层级仍为 1–5。Layout 可为文本应用布局选项。
注意事项
标题层级应按页面结构递进;动态文本不要拼接未转义的用户输入。链接提供清晰的动作名,并确保可用 Tab 聚焦、Enter 激活;RTL 下文本方向和对齐跟随作用域。
示例代码
以下是上方在线演示运行的 Go 源码(来自官方 gallery),点击标题展开。函数接收的 c *ui.Context 由窗口的 UI 循环每帧传入,接入方式见 Go GUI 入门。
API
签名与说明由 site/tools/compdoc 从 Go 源码和文档注释提取;点击名称跳到 Go API 参考 的对应条目。
入口函数
ui.Text
func Text(c *Context, s string) *LabelText adds a single paragraph of text that wraps to its width.
返回 *Label,可链式调用的方法见 Label 方法。
ui.Title
func Title(c *Context, s string, level int) *LabelTitle adds a heading; level 1..5 like Typography.Title.
返回 *Label,可链式调用的方法见 Label 方法。
ui.Paragraph
func Paragraph(c *Context, s string) *LabelParagraph is Text intended for long-form content.
返回 *Label,可链式调用的方法见 Label 方法。
ui.Link
func Link(c *Context, s string) *LinkWLink adds a hyperlink-styled text button.
ConfigProvider.Defaults("Link", ...) keys: "underline" ("always" | "hover" | "never"; Element underline).
返回 *LinkW,可链式调用的方法见 LinkW 方法。
Label 方法
ui.Label:Label is a run of text (Typography.Text).
| 方法 | 说明 | 签名 |
|---|---|---|
Align | Align aligns the text in its box. | Align(a TextAlign) *Label |
Code | Code() *Label | |
Color | Color sets the text color. | Color(col theme.Color) *Label |
Copied | Copied reports whether the copy icon was clicked within the last 3s. | Copied() bool |
CopyText | CopyText is Copyable with a different clipboard payload. | CopyText(payload string) *Label |
Copyable | Copyable adds a copy icon after the text; clicking it writes the text to the clipboard and shows a check mark for three seconds. | Copyable() *Label |
Delete | Delete() *Label | |
Disabled | Disabled greys the text out. | Disabled() *Label |
Editable | Editable adds an edit icon; clicking it swaps the text for an input. | Editable(val *string) *Label |
Editing | Editing reports whether the label is being edited. | Editing() bool |
Ellipsis | Ellipsis keeps one line and truncates with "…". | Ellipsis() *Label |
Expandable | Expandable adds an "展开" link when the text is cut by Lines(n); open is toggled by the link ("收起" collapses when open). | Expandable(open *bool) *Label |
ID | ID returns the node ID. | ID() ID |
Italic | Italic slants the text (synthetic oblique). | Italic() *Label |
Layout | Layout applies layout options to the text node. | Layout(opts ...layout.Option) *Label |
LineHeight | LineHeight overrides the line height in px. | LineHeight(px float32) *Label |
Lines | Lines limits wrapping to n lines with an ellipsis. | Lines(n int) *Label |
Mark | Mark() *Label | |
NoWrap | NoWrap keeps the text on one line. | NoWrap() *Label |
Secondary | Secondary uses the secondary text color. | Secondary() *Label |
Size | Size sets the font size (line height follows the theme). | Size(px float32) *Label |
Strong | Strong uses the theme's strong weight. | Strong() *Label |
Tertiary | Tertiary uses the tertiary text color (descriptions, hints). | Tertiary() *Label |
TextDir | TextDir sets the paragraph base direction explicitly. | TextDir(d text.Direction) *Label |
Type | Type colors the text by status: "success", "warning", "danger"/"error". | Type(status string) *Label |
Underline | Underline / Delete / Code / Mark decorations. | Underline() *Label |
Weight | Weight sets the font weight. | Weight(w text.Weight) *Label |
LinkW 方法
ui.LinkW:LinkW is a clickable text link.
| 字段 | 说明 | 类型 |
|---|---|---|
Label | *Label(嵌入) |
LinkW 的方法:
| 方法 | 说明 | 签名 |
|---|---|---|
Align | Align aligns the text in its box. (来自嵌入的 Label) | Align(a TextAlign) *Label |
Clicked | Clicked reports activation. | Clicked() bool |
Code | (来自嵌入的 Label) | Code() *Label |
Color | Color draws the link in col in every state (disabled still greys out). | Color(col theme.Color) *LinkW |
Copied | Copied reports whether the copy icon was clicked within the last 3s. (来自嵌入的 Label) | Copied() bool |
CopyText | CopyText is Copyable with a different clipboard payload. (来自嵌入的 Label) | CopyText(payload string) *Label |
Copyable | Copyable adds a copy icon after the text; clicking it writes the text to the clipboard and shows a check mark for three seconds. (来自嵌入的 Label) | Copyable() *Label |
Delete | (来自嵌入的 Label) | Delete() *Label |
Disabled | Disabled greys the text out. (来自嵌入的 Label) | Disabled() *Label |
Editable | Editable adds an edit icon; clicking it swaps the text for an input. (来自嵌入的 Label) | Editable(val *string) *Label |
Editing | Editing reports whether the label is being edited. (来自嵌入的 Label) | Editing() bool |
Ellipsis | Ellipsis keeps one line and truncates with "…". (来自嵌入的 Label) | Ellipsis() *Label |
Expandable | Expandable adds an "展开" link when the text is cut by Lines(n); open is toggled by the link ("收起" collapses when open). (来自嵌入的 Label) | Expandable(open *bool) *Label |
Hovered | Hovered reports hover. | Hovered() bool |
ID | ID returns the node ID. (来自嵌入的 Label) | ID() ID |
Icon | Icon puts an icon before the text in the link color (Element el-link icon). | Icon(ic *icon.Icon) *LinkW |
Italic | Italic slants the text (synthetic oblique). (来自嵌入的 Label) | Italic() *Label |
Layout | Layout applies layout options to the text node. (来自嵌入的 Label) | Layout(opts ...layout.Option) *Label |
LineHeight | LineHeight overrides the line height in px. (来自嵌入的 Label) | LineHeight(px float32) *Label |
Lines | Lines limits wrapping to n lines with an ellipsis. (来自嵌入的 Label) | Lines(n int) *Label |
Mark | (来自嵌入的 Label) | Mark() *Label |
NoWrap | NoWrap keeps the text on one line. (来自嵌入的 Label) | NoWrap() *Label |
Secondary | Secondary is Type("secondary"). | Secondary() *LinkW |
Size | Size sets the font size (line height follows the theme). (来自嵌入的 Label) | Size(px float32) *Label |
Strong | Strong uses the theme's strong weight. (来自嵌入的 Label) | Strong() *Label |
Tertiary | Tertiary uses the tertiary text color (descriptions, hints). (来自嵌入的 Label) | Tertiary() *Label |
TextDir | TextDir sets the paragraph base direction explicitly. (来自嵌入的 Label) | TextDir(d text.Direction) *Label |
Type | Type colors the link by status: "success", "warning", "danger" / "error", "info" use that palette (hover and pressed shades follow); "secondary" (or Element's "default") starts in the secondary text color and turns link-colored on hover; "primary" is the primary palette. | Type(status string) *LinkW |
Underline | Underline / Delete / Code / Mark decorations. (来自嵌入的 Label) | Underline() *Label |
UnderlineMode | UnderlineMode sets when the link is underlined: "always", "hover" or "never" (Element underline; the default follows the theme: never for Ant, on hover for Element, always for shadcn). | UnderlineMode(mode string) *LinkW |
Weight | Weight sets the font weight. (来自嵌入的 Label) | Weight(w text.Weight) *Label |