GithubHelp home page GithubHelp logo

matrix14159 / govcl Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ying32/govcl

0.0 1.0 0.0 34.08 MB

Cross-platform Golang GUI library, Binding with Lazarus LCL.

Home Page: https://z-kit.cc

License: Apache License 2.0

Pascal 0.01% Go 99.96% Batchfile 0.01% Shell 0.01% C 0.03%

govcl's Introduction


GoVCL

跨平台的Golang GUI库,底层绑定自Lazarus LCL。

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

当前版本已不再支持Delphi/VCL了。最后一个支持vcl版本的分支:last-vcl-support

govcl最低要求go1.9。

截图查看 | 中文文档 | 更新日志 | 加入QQ群 | GoVCL视频教程(第三方) | 赞助GoVCL


支持的平台

Windows | Linux | macOS

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


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

liblcl

res2go工具下载(文档、源代码

需要自己编译: 编译方法

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


使用方法

步骤一:获取govcl代码

go get -u github.com/ying32/govcl

步骤二:编写代码

  • 方法一(使用Lazarus设计界面。推荐):
package main


import (
   // 如果你使用自定义的syso文件则不要引用此包
   _ "github.com/ying32/govcl/pkgs/winappres"
   "github.com/ying32/govcl/vcl"
)

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

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

var (
    mainForm *TMainForm
    aboutForm *TAboutForm
)

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

// -- TMainForm

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

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

// -- TAboutForm

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

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

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

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


import (
   // 如果你使用自定义的syso文件则不要引用此包
   _ "github.com/ying32/govcl/pkgs/winappres"
   "github.com/ying32/govcl/vcl"
)

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

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

var (
    mainForm *TMainForm
    aboutForm *TAboutForm
)

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

// -- TMainForm

func (f *TMainForm) OnFormCreate(sender vcl.IObject) {
    f.SetCaption("MainForm")
    
    f.Btn1 = vcl.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 vcl.IObject) {
    vcl.ShowMessage("Hello!")
}


// -- TAboutForm

func (f *TAboutForm) OnFormCreate(sender vcl.IObject) {
    f.SetCaption("About")
    f.Btn1 = vcl.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 vcl.IObject) {
    vcl.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中使用时,请使用vcl.ThreadSync来同步更新到UI上。

API文档

govcl's People

Contributors

ying32 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.