如何向fyne UI应用程序添加填充,字体大小和颜色 [英] How to add padding, font size and colours to fyne UI app

查看:332
本文介绍了如何向fyne UI应用程序添加填充,字体大小和颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面使用我要使用的fyne工具包实现了一个示例应用程序代码,无法弄清楚如何将按钮向左对齐,使顶部文本变大并添加颜色.

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.

我尝试创建一个自定义主题来实现所需的UI功能,但是我对fyne工具包的godoc缺乏了解.有没有人可以指点我来做这个工作的医生?或为我提供一些提示,因为该工具包的文档记录不充分

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

这是我的示例应用代码

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()
}

推荐答案

要以不同方式对齐按钮,您将需要使用其他布局(VBox使用Box布局).

To align the buttons differently you will need to use a different layout (VBox uses the Box layout).

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

Changing the colours and sizes of standard widgets is not possible. You can specify a different text colour or size in a custom theme but it will apply to all components. If you want elements on screen that don’t conform to the theme you could use the ‘canvas’ package as that deals with lower level elements. For example canvas.Text can be any size or colour.

这篇关于如何向fyne UI应用程序添加填充,字体大小和颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆