3

I have this sample app code below for a UI I'm implementing using the fyne toolkit, and cant figure out how to align the buttons to the left, makes top text bigger, and add colours.

I've tried trying to create a custom theme to implement the UI features I need, but my understanding of the godoc for the fyne toolkit is lacking. Is there a doc someone can point me to to make this work? or provide me with some pointers, as the toolkit is poorly documented

this is my sample app code

package main

import (
    "fyne.io/fyne"
    "fyne.io/fyne/app"
    "fyne.io/fyne/layout"
    "fyne.io/fyne/theme"
    "fyne.io/fyne/widget"
)

func main() {
    a := app.New()
    a.Settings().SetTheme(theme.LightTheme())
    w := a.NewWindow("myapp")
    w.Resize(fyne.NewSize(340, 600))
    w.SetContent(widget.NewVBox(
        widget.NewLabelWithStyle("myApp version1", fyne.TextAlignLeading, fyne.TextStyle{Bold: true}),
        widget.NewLabelWithStyle("Welcome to \n myAPp", fyne.TextAlignLeading, fyne.TextStyle{Bold: true}),
        layout.NewSpacer(),
        widget.NewButton("Register", func() {
            a.Quit()
        }),
        widget.NewButton("Login", func() {
            a.Quit()
        }),
    ))
    w.ShowAndRun()
}
4

2 回答 2

5

你不能开箱即用,但你可以使用Fyne 的画布。例子:

带颜色的标签:

label := canvas.NewText("Hello world", color.White)

不同字体大小的标签:

label := canvas.NewText("Hello world", color.White)
label.TextSize = 50

与 VBox 右对齐:

layout := fyne.NewContainerWithLayout(
    layout.NewVBoxLayout(),
    layout.NewSpacer(),
    widget.NewLabel("Hello world"),
)
于 2020-10-18T18:36:11.860 回答
3

要以不同方式对齐按钮,您需要使用不同的布局(VBox 使用 Box 布局)。

无法更改标准小部件的颜色和大小。您可以在自定义主题中指定不同的文本颜色或大小,但它将应用于所有组件。如果您希望屏幕上的元素不符合主题,您可以使用“canvas”包,因为它处理较低级别的元素。例如 canvas.Text 可以是任何大小或颜色。

于 2019-12-13T00:17:13.253 回答