Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
twgh committed Sep 7, 2021
1 parent e17a7a6 commit 942660f
Show file tree
Hide file tree
Showing 16 changed files with 344 additions and 167 deletions.
2 changes: 1 addition & 1 deletion README-en.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ It is best to put it in the C:\Windows\System32 directory, so that there is no n

# Example

![example](https://github.com/twgh/xcgui/blob/main/example/1/1.jpg)
![example](https://github.com/twgh/xcgui/blob/main/example/simplewindow/simplewindow.jpg)

```go
package main
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ go get github.com/twgh/xcgui

# 例子

![example](https://github.com/twgh/xcgui/blob/main/example/1/1.jpg)
![example](https://github.com/twgh/xcgui/blob/main/example/simplewindow/simplewindow.jpg)

```go
package main
Expand Down
115 changes: 102 additions & 13 deletions example/1/1.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package main

import (
"fmt"
"strconv"

"github.com/twgh/xcgui/app"
"github.com/twgh/xcgui/shape"
"github.com/twgh/xcgui/widget"
Expand All @@ -9,11 +12,26 @@ import (
"github.com/twgh/xcgui/xcc"
)

var (
a *app.App
win *window.Window
cbb *widget.ComboBox
edit *widget.Edit
btn_MessageBox *widget.Button
btn_Add *widget.Button
btn_Sub *widget.Button
btn_Close *widget.Button
btn_Modal *widget.Button
bar *widget.ProgressBar
link *widget.TextLink
lbl_Title *shape.ShapeText
)

func main() {
// 1.初始化UI库
a := app.New("")
a = app.New("")
// 2.创建窗口
win := window.NewWindow(0, 0, 466, 300, "炫彩窗口", 0, xcc.Xc_Window_Style_Default)
win = window.NewWindow(0, 0, 766, 518, "炫彩窗口", 0, xcc.Xc_Window_Style_Default)

// 设置窗口边框大小
win.SetBorderSize(1, 30, 1, 1)
Expand All @@ -25,20 +43,60 @@ func main() {
win.SetTop()
// 窗口居中
win.Center()
// 设置窗口大小
//win.SetRect(&xc.RECT{Left: 0, Top: 0, Right: 1024, Bottom: 768})

// 创建标签_窗口标题
lbl_Title := shape.NewShapeText(15, 15, 56, 20, "Title", win.HWindow)
lbl_Title.SetTextColor(xc.RGB(255, 255, 255), 255)

// 创建最小化按钮
btn_Min := widget.NewButton(396, 10, 30, 30, "-", win.HWindow)
btn_Min.SetTextColor(xc.RGB(255, 255, 255), 255)
btn_Min.SetType(xcc.Button_Type_Min)
btn_Min.EnableBkTransparent(true)
lbl_Title = shape.NewShapeText(15, 15, 56, 20, "窗口标题", win.HWindow)
lbl_Title.SetTextColor(xc.RGB(255, 0, 0), 255)

// 创建结束按钮
btn_Close := widget.NewButton(426, 10, 30, 30, "X", win.HWindow)
btn_Close.SetTextColor(xc.RGB(255, 255, 255), 255)
btn_Close = widget.NewButton(681, 14, 70, 24, "close", win.HWindow)
btn_Close.SetType(xcc.Button_Type_Close)
btn_Close.EnableBkTransparent(true)

// 创建按钮_信息框
btn_MessageBox = widget.NewButton(24, 52, 70, 30, "信息框", win.HWindow)
// 注册按钮事件
btn_MessageBox.Event_BnClick1(onBtnClick)
// 创建按钮_模态窗口
btn_Modal = widget.NewButton(105, 52, 70, 30, "模态窗口", win.HWindow)
btn_Modal.Event_BnClick1(onBtnClick)
// 给按钮添加背景颜色
btn_Modal.AddBkFill(xcc.Button_Style_Default, xc.RGB(0, 162, 232), 255)
// 创建进度条
bar = widget.NewProgressBar(24, 94, 200, 10, win.HWindow)
bar.SetSpaceTwo(0, 0)
bar.SetRange(100)
bar.SetPos(0)

// 创建按钮_进度加
btn_Add = widget.NewButton(238, 84, 70, 30, "+", win.HWindow)
btn_Add.Event_BnClick1(onBtnClick)
// 创建按钮_进度减
btn_Sub = widget.NewButton(318, 84, 70, 30, "-", win.HWindow)
btn_Sub.Event_BnClick1(onBtnClick)

// 创建组合框
cbb = widget.NewComboBox(24, 126, 100, 30, win.HWindow)
cbb.CreateAdapter()
// 组合框加入项
for i := 1; i <= 5; i++ {
cbb.AddItemText("第" + strconv.Itoa(i) + "项")
}
// 组合框选中项
cbb.SetSelItem(0)
// 组合框禁止编辑项
cbb.EnableEdit(false)
// 注册组合框被选择事件
cbb.SetComboBoxSelectEnd1(onCbbSelectEnd)

// 创建编辑框
edit = widget.NewEdit(138, 126, 100, 30, win.HWindow)
edit.SetText("hello")

// 创建超链接标签
link = widget.NewTextLink(24, 184, 56, 20, "百度一下", win.HWindow)
link.RegEventC1(xcc.XE_BNCLICK, onBtnClick)

// 3.显示窗口
win.ShowWindow(xcc.SW_SHOW)
Expand All @@ -47,3 +105,34 @@ func main() {
// 5.释放UI库
a.Exit()
}

// 按钮被单击
func onBtnClick(hEle int, pbHandled *bool) int {
fmt.Println("BtnClick:", hEle)
switch hEle {
case btn_MessageBox.HEle:
win.MessageBox("This Is A MessageBox", "提示", xcc.MessageBox_Flag_Ok)
case btn_Add.HEle:
bar.SetPos(bar.GetPos() + 10)
bar.Redraw(true)
case link.HEle:
case btn_Sub.HEle:
bar.SetPos(bar.GetPos() - 10)
bar.Redraw(true)
case btn_Modal.HEle:
win_Modal := window.NewModalWindow(500, 350, "模态窗口", win.HWND, xcc.Xc_Window_Style_Modal)
widget.NewButton(50, 50, 70, 30, "close", win_Modal.HWindow).SetType(xcc.Button_Type_Close)
win_Modal.DoModal()
}
return 0
}

// 组合框被选择
func onCbbSelectEnd(hEle int, iItem int, pbHandled *bool) int {
switch hEle {
case cbb.HEle:
edit.SetText(cbb.GetItemText(iItem, 0))
edit.Redraw(true)
}
return 0
}
Binary file modified example/1/1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
138 changes: 0 additions & 138 deletions example/2/2.go

This file was deleted.

Binary file removed example/2/2.jpg
Binary file not shown.
Loading

0 comments on commit 942660f

Please sign in to comment.