如何更改 GUI 组件的颜色
How to change color of GUI components
我正在尝试遵循 fyne
的演示代码:
package main
import (
"fyne.io/fyne/app"
"fyne.io/fyne/widget"
)
func main() {
a := app.New()
w := a.NewWindow("Hello")
w.SetContent(
widget.NewVBox(
widget.NewLabel("Hello Fyne!"),
widget.NewButton("Quit", func(){a.Quit()} ),
),
)
w.ShowAndRun()
}
它运行正常,但我想将标签的颜色更改为蓝色,将按钮的颜色更改为绿色。我看到有 theme
但这似乎是针对整个应用程序而不是针对单个元素的。
如何将不同的颜色应用于不同的 GUI 组件?感谢您的帮助。
中提出
I propose individual styles assignable to widgets:
但是:
Part of our design is to promote application consistency - a user experience that cannot be trivially compromised by "this label is larger" or "this dropdown is transparent".
Fyne's approach to this is that widgets have a set style (that can be themed) but the canvas remains fully available to do whatever specific designs a developer chooses to code.
因此本机不支持更改单个按钮的颜色。
Andy Williams, author/main contributor of fyne-io/fyne, adds :
This is quite correct.
The only way to have a widget that is is styled differently to the standard colours is to implement a custom widget and add that functionality yourself.
There are, however, some semantic styles, a button can be “primary, for example, in which case it will use the theme highlight color
由于 Fyne 中的标准小部件不支持自定义,因此没有简短的答案(除非我们不建议这样做)。
如果出于用户要求的某些正当理由,您必须这样做,那么您应该查看我们的开发人员文档,其中简要介绍了编写 custom widgets。然而,我们的目标是在今年晚些时候的 1.2 版中简化此过程。
只是重申一下 Fyne 工具包上面的评论,旨在创建一种简单、快速编程的一致用户体验。每次您创建自定义小部件以便拥有自定义颜色或样式时,您可能会让用户感到困惑,并且会使维护代码变得更加困难。
我正在尝试遵循 fyne
的演示代码:
package main
import (
"fyne.io/fyne/app"
"fyne.io/fyne/widget"
)
func main() {
a := app.New()
w := a.NewWindow("Hello")
w.SetContent(
widget.NewVBox(
widget.NewLabel("Hello Fyne!"),
widget.NewButton("Quit", func(){a.Quit()} ),
),
)
w.ShowAndRun()
}
它运行正常,但我想将标签的颜色更改为蓝色,将按钮的颜色更改为绿色。我看到有 theme
但这似乎是针对整个应用程序而不是针对单个元素的。
如何将不同的颜色应用于不同的 GUI 组件?感谢您的帮助。
I propose individual styles assignable to widgets:
但是:
Part of our design is to promote application consistency - a user experience that cannot be trivially compromised by "this label is larger" or "this dropdown is transparent".
Fyne's approach to this is that widgets have a set style (that can be themed) but the canvas remains fully available to do whatever specific designs a developer chooses to code.
因此本机不支持更改单个按钮的颜色。
Andy Williams, author/main contributor of fyne-io/fyne, adds
This is quite correct.
The only way to have a widget that is is styled differently to the standard colours is to implement a custom widget and add that functionality yourself.There are, however, some semantic styles, a button can be “primary, for example, in which case it will use the theme highlight color
由于 Fyne 中的标准小部件不支持自定义,因此没有简短的答案(除非我们不建议这样做)。
如果出于用户要求的某些正当理由,您必须这样做,那么您应该查看我们的开发人员文档,其中简要介绍了编写 custom widgets。然而,我们的目标是在今年晚些时候的 1.2 版中简化此过程。
只是重申一下 Fyne 工具包上面的评论,旨在创建一种简单、快速编程的一致用户体验。每次您创建自定义小部件以便拥有自定义颜色或样式时,您可能会让用户感到困惑,并且会使维护代码变得更加困难。