golcl

module
v0.0.0-...-2c16882 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2022 License: Apache-2.0

README


大佬 ying32 库(个人觉得方便,增加和修改以下内容)

*.增加资源文件在embed.FS读取和使用
*.增加使用embed.FS内置liblcl库,运行时自动释放至用户目录 用户目录/golcl/...
*.修改所有库使用初始化,为手动调用inits.Init(libs *embed.FS, resource *embed.FS) 用于导入liblcl库和资源文件 支持embed.FS
//示例:inits.Init(emfs libs,emfs source)支持embed.FS
package main

import (
	"embed"
	"gitee.com/snxamdf/golcl/inits"
	"gitee.com/snxamdf/golcl/lcl"
	"mir-client/client"
)

//go:embed resource
var resource embed.FS

//go:embed libs
var libs embed.FS

func main() {
	inits.Init(&libs, &resource)
	lcl.Application.Initialize()
	lcl.Application.SetMainFormOnTaskBar(true)
	lcl.Application.CreateForm(&client.ClientForm, true)
	lcl.Application.Run()
}

ying32 库地址

Github | Gitee

Golcl

跨平台的Golang GUI库, 核心绑定自 Lazarus 创建的通用跨平台GUI库 liblcl

Golcl是一个原生GUI库,不是基于HTML,更不是DirectUI库,一切以实用为主。

中文全称:Go语言可视化组件库;英文全称:Go Language Visual Component Library

golcl最低要求go1.9.2。

截图查看 | 中文文档 | 更新日志 | 视频教程(非官方) | 赞助Golcl


支持的平台

Windows | Linux | macOS

如果你想要支持linux arm及linux 32bit则需要自己编译对应的liblcl二进制。


预编译GUI库二进制下载(源代码

liblcl

res2go IDE插件源代码(源代码-已改为golcl

使用方法: 安装方法

注:用Lazarus设计界面,用Golang写代码。


使用方法

步骤一:获取golcl代码

go get -u gitee.com/snxamdf/golcl

注:也可用go module方式拉取,在go.mod中配置 【 go get -v -d ./... 或 go mod tidy 】

步骤二:编写代码
  • 方法一(使用Lazarus设计界面。推荐):
package main


import (
   // 如果你使用自定义的syso文件则不要引用此包
   _ "gitee.com/snxamdf/golcl/pkgs/winappres"
   "gitee.com/snxamdf/golcl/lcl"
)

type TMainForm struct {
    *lcl.TForm
    Btn1     *lcl.TButton
}

type TAboutForm struct {
    *lcl.TForm
    Btn1    *lcl.TButton
}

var (
    mainForm *TMainForm
    aboutForm *TAboutForm
)

func main() {
    lcl.Application.Initialize()
    lcl.Application.SetMainFormOnTaskBar(true)
    lcl.Application.CreateForm(&mainForm)
    lcl.Application.CreateForm(&aboutForm)
    lcl.Application.Run()
}

// -- TMainForm

func (f *TMainForm) OnFormCreate(sender lcl.IObject) {
    
}

func (f *TMainForm) OnBtn1Click(sender lcl.IObject) {
    aboutForm.Show()
}

// -- TAboutForm

func (f *TAboutForm) OnFormCreate(sender lcl.IObject) {
 
}

func (f *TAboutForm) OnBtn1Click(sender lcl.IObject) {
    lcl.ShowMessage("Hello!")
}

方法一需要配合res2go工具使用。

  • 方法二(纯代码,仿照FreePascal类的方式):
package main


import (
   // 如果你使用自定义的syso文件则不要引用此包
   _ "gitee.com/snxamdf/golcl/pkgs/winappres"
   "gitee.com/snxamdf/golcl/lcl"
)

type TMainForm struct {
    *lcl.TForm
    Btn1     *lcl.TButton
}

type TAboutForm struct {
    *lcl.TForm
    Btn1    *lcl.TButton
}

var (
    mainForm *TMainForm
    aboutForm *TAboutForm
)

func main() {
    lcl.RunApp(&mainForm, &aboutForm)
}

// -- TMainForm

func (f *TMainForm) OnFormCreate(sender lcl.IObject) {
    f.SetCaption("MainForm")
    
    f.Btn1 = lcl.NewButton(f)
    f.Btn1.SetParent(f)
    f.Btn1.SetBounds(10, 10, 88, 28)
    f.Btn1.SetCaption("Button1")
    f.Btn1.SetOnClick(f.OnBtn1Click)  
}

func (f *TMainForm) OnBtn1Click(sender lcl.IObject) {
    aboutForm.Show()
}


// -- TAboutForm

func (f *TAboutForm) OnFormCreate(sender lcl.IObject) {
    f.SetCaption("About")
    f.Btn1 = lcl.NewButton(f)
    //f.Btn1.SetName("Btn1")
    f.Btn1.SetParent(f)
    f.Btn1.SetBounds(10, 10, 88, 28)
    f.Btn1.SetCaption("Button1")
    f.Btn1.SetOnClick(f.OnBtn1Click)  
}

func (f *TAboutForm) OnBtn1Click(sender lcl.IObject) {
    lcl.ShowMessage("Hello!")
}

步骤三:复制对应的二进制
  • Windows: 根据编译的二进制是32还是64位的,复制对应的liblcl.dll到当前可执行文件目录或系统环境路径下。

    • Go环境变量: GOARCH = amd64 386 GOOS = windows CGO_ENABLED=0
  • Linux: 复制liblcl.so当前可执行文件目录下(也可复制liblcl.so到/usr/lib/(32bit liblcl)或者/usr/lib/x86_64-linux-gnu/(64bit liblcl)目录中,作为公共库使用)。

    • Go环境变量: GOARCH = amd64 GOOS = linux CGO_ENABLED=1
  • MacOS: 复制liblcl.dylib当前可执行文件目录下(MacOS下注意:需要自行创建info.plist文件),或者参考:MacOS上应用打包

    • Go环境变量: GOARCH = amd64 GOOS = darwin CGO_ENABLED=1

注:这里的当前可执行文件目录指的是你当前编译的项目生成的可执行文件位置。


注意:

特别注意:所有UI组件都是非线程/协程安全的,当在goroutine中使用时,请使用lcl.ThreadSync来同步更新到UI上。

特别注意2:如果你使用go>=1.15编译Windows可执行文件,则必须则必须使用-buildmode=exe编译选项,不然会有错误。

API文档


jetbrains
鸣谢jetbrains

Directories

Path Synopsis
lcl
api
---------------------------------------- 加载文件或者内存中的窗口资源文件功能 需要配合窗口设计器使用 ----------------------------------------
---------------------------------------- 加载文件或者内存中的窗口资源文件功能 需要配合窗口设计器使用 ----------------------------------------
bitmap
实现一些Go的Image转lcl的
实现一些Go的Image转lcl的
rtl
win
pkgs
samples
Windows/listviewcustomdraw
由GOlcl UI设计器自动生成,不要编辑。
由GOlcl UI设计器自动生成,不要编辑。
Windows/listviewitemedit
由res2go自动生成,不要编辑。
由res2go自动生成,不要编辑。
Windows/miniblinkWebview
由GOlcl UI设计器自动生成,不要编辑 由GOlcl UI设计器自动生成,不要编辑 由GOlcl UI设计器自动生成,不要编辑
由GOlcl UI设计器自动生成,不要编辑 由GOlcl UI设计器自动生成,不要编辑 由GOlcl UI设计器自动生成,不要编辑
comboboxEx
由res2go自动生成,不要编辑。
由res2go自动生成,不要编辑。
govcl
golcl project main.go go.exe build -i -ldflags="-H windowsgui"
golcl project main.go go.exe build -i -ldflags="-H windowsgui"
macOS/nswindowTest
由res2go自动生成,不要编辑。
由res2go自动生成,不要编辑。
miniwebview
由GOlcl UI设计器自动生成,不要编辑
由GOlcl UI设计器自动生成,不要编辑
redisViewer
由res2go自动生成,不要编辑。
由res2go自动生成,不要编辑。
res2goTest/Lazarus/gocode
由res2go自动生成,不要编辑。
由res2go自动生成,不要编辑。
res2goTest/Test/gocode
由res2go自动生成,不要编辑。
由res2go自动生成,不要编辑。
simplecalc
由res2go自动生成,不要编辑。
由res2go自动生成,不要编辑。
testEmbed
Automatically generated by the res2go IDE plug-in.
Automatically generated by the res2go IDE plug-in.
videosrtgui
Automatically generated by the res2go, do not edit.
Automatically generated by the res2go, do not edit.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL