You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package main
import (
"fmt"
"freeCaculator/Application"
"freeCaculator/framework"
"freeCaculator/global"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"github.com/flopp/go-findfont"
"log"
"os"
"strings"
"time"
)
/*
*
@author: sre
@date: 2022/8/22 0022
@desc: todo
*
*/
func init() {
//fyne原生并不支持中文所以其界面上显示和输入汉字会出错。可用init函数引用字体的方式解决。
//go get github.com/flopp/go-findfont
fontPaths := findfont.List()
for _, fontPath := range fontPaths {
fmt.Println(fontPath)
//楷体:simkai.ttf 黑体:simhei.ttf
if strings.Contains(fontPath, "simhei.ttf") {
err := os.Setenv("FYNE_FONT", fontPath)
if err != nil {
return
}
break
}
}
}
//go:generate fyne bundle -package global -o global/bundled.go assets
func main() {
// 创建程序
//_ = os.Setenv("FYNE_FONT", "./data/fonts/awesome.ttf")
a := app.NewWithID("org.yangqiao.picUploader")
a.SetIcon(global.ResourceAppPng)
//a.SetIcon(theme.FyneLogo())
logLifecycle(a)
//a.Settings().SetTheme(theme.LightTheme()) //SetTheme():设置应用的主题,默认为 DarkTheme。
w := a.NewWindow(global.APPTitle) //// 创建窗口对象、传入窗口名称
global.TopWindow = w
w.SetMainMenu(framework.MakeMenu(a, w))
w.SetMaster()
w.SetOnClosed(func() {
fmt.Println("窗口退出 打印剪切板内容")
fmt.Println(w.Clipboard().Content())
})
go func() {
time.Sleep(time.Second * 5)
}()
//主界面框架布局
Application.MainShow(w)
//demo界面框架布局
//ShowNav(w)
w.Resize(fyne.NewSize(640, 460)) //设置窗口尺寸。
//w居中显示
w.CenterOnScreen()
// 窗口的显示和运行
w.ShowAndRun()
}
func logLifecycle(a fyne.App) {
a.Lifecycle().SetOnStarted(func() {
log.Println("生存期: 开始")
})
a.Lifecycle().SetOnStopped(func() {
log.Println("生存期: 结束")
})
a.Lifecycle().SetOnEnteredForeground(func() {
log.Println("生存期: 进入前置窗口")
})
a.Lifecycle().SetOnExitedForeground(func() {
log.Println("生存期: 退出前置窗口")
})
}