mirror of
https://gitee.com/energye/energy.git
synced 2024-12-02 11:47:37 +08:00
v2.3.55 add new sys tray
This commit is contained in:
parent
baa61ac9a9
commit
71e0865ba9
32
cef/cef-sys-menu.go
Normal file
32
cef/cef-sys-menu.go
Normal file
@ -0,0 +1,32 @@
|
||||
package cef
|
||||
|
||||
type SysMenu struct {
|
||||
Label string
|
||||
Items []*SysMenuItem
|
||||
}
|
||||
|
||||
type SysMenuItem struct {
|
||||
ChildMenu *SysMenu
|
||||
IsSeparator bool
|
||||
Label string
|
||||
Action func()
|
||||
Disabled bool
|
||||
Checked bool
|
||||
Icon []byte
|
||||
Shortcut string
|
||||
}
|
||||
|
||||
// NewMenu 创建一个新菜单,给定指定的标签和要显示的项目列表
|
||||
func NewMenu(label string, items ...*SysMenuItem) *SysMenu {
|
||||
return &SysMenu{Label: label, Items: items}
|
||||
}
|
||||
|
||||
// NewMenuItem 根据传递的标签和操作参数创建一个新菜单项
|
||||
func NewMenuItem(label string, action func()) *SysMenuItem {
|
||||
return &SysMenuItem{Label: label, Action: action}
|
||||
}
|
||||
|
||||
// NewMenuItemSeparator 创建将用作分隔符的菜单项
|
||||
func NewMenuItemSeparator() *SysMenuItem {
|
||||
return &SysMenuItem{IsSeparator: true}
|
||||
}
|
@ -13,41 +13,44 @@ import (
|
||||
"github.com/energye/golcl/lcl/types"
|
||||
)
|
||||
|
||||
//TMouseEvent 鼠标事件
|
||||
type TMouseEvent func(sender lcl.IObject, button types.TMouseButton, shift types.TShiftState, x, y int32) bool
|
||||
|
||||
//TrayICONClick 托盘图标鼠标事件
|
||||
type TrayICONClick func()
|
||||
|
||||
//ITray 托盘接口
|
||||
type ITray interface {
|
||||
SetTitle(title string) //设置标题
|
||||
SetVisible(v bool) //显示和隐藏托盘图标
|
||||
Visible() bool //
|
||||
Show() //显示托盘菜单窗口 windows有效
|
||||
Hide() //隐藏托盘菜单窗口 windows有效
|
||||
close() //关闭托盘菜单窗口 windows有效
|
||||
SetOnDblClick(fn TrayICONClick) //双击事件 linux 和 macos 可能不启作用
|
||||
SetOnClick(fn TrayICONClick) //单击事件
|
||||
SetOnMouseUp(fn TMouseEvent) //up事件 linux 和 macos 可能不启作用
|
||||
SetOnMouseDown(fn lcl.TMouseEvent) //down事件 linux 和 macos 可能不启作用
|
||||
SetOnMouseMove(fn lcl.TMouseMoveEvent) //move事件 linux 和 macos 可能不启作用
|
||||
SetIconFS(iconResourcePath string) //设置托盘图标
|
||||
SetIcon(iconResourcePath string) //设置托盘图标
|
||||
SetHint(value string) //设置托盘hint(鼠标移动到托盘图标显示的文字)
|
||||
ShowBalloon() //显示托盘气泡
|
||||
SetBalloon(title, content string, timeout int32) ITray //设置托盘气泡内容
|
||||
Tray() ITray //获得 LCLTray, ( CefTray 返回 nil )
|
||||
AsViewsFrameTray() *ViewsFrameTray //
|
||||
AsCEFTray() *CEFTray //
|
||||
AsLCLTray() *LCLTray //
|
||||
SetTitle(title string) //SetTitle 设置标题
|
||||
SetVisible(v bool) //SetVisible 设置显示和隐藏托盘图标
|
||||
Visible() bool //Visible 托盘的显示和隐藏状态
|
||||
Show() //Show 显示托盘菜单窗口 windows有效
|
||||
Hide() //Hide 隐藏托盘菜单窗口 windows有效
|
||||
close() //close 关闭托盘菜单窗口 windows有效
|
||||
SetOnDblClick(fn TrayICONClick) //SetOnDblClick 双击事件 linux 和 macos 可能不启作用
|
||||
SetOnClick(fn TrayICONClick) //SetOnClick 单击事件
|
||||
SetOnMouseUp(fn TMouseEvent) //SetOnMouseUp up事件 linux 和 macos 可能不启作用
|
||||
SetOnMouseDown(fn lcl.TMouseEvent) //SetOnMouseDown down事件 linux 和 macos 可能不启作用
|
||||
SetOnMouseMove(fn lcl.TMouseMoveEvent) //SetOnMouseMove move事件 linux 和 macos 可能不启作用
|
||||
SetIconFS(iconResourcePath string) //SetIconFS 设置托盘图标
|
||||
SetIcon(iconResourcePath string) //SetIcon 设置托盘图标
|
||||
SetHint(value string) //SetHint 设置托盘hint(鼠标移动到托盘图标显示的文字)
|
||||
ShowBalloon() //ShowBalloon 显示托盘气泡
|
||||
SetBalloon(title, content string, timeout int32) ITray //SetBalloon 设置托盘气泡内容
|
||||
Tray() ITray //Tray 返回ITray接口
|
||||
AsViewsFrameTray() *ViewsFrameTray //AsViewsFrameTray 尝试转换为 views framework 组件托盘, 如果当前创建的是其它类型托盘返回nil
|
||||
AsCEFTray() *CEFTray //AsCEFTray 尝试转换为 LCL+CEF 组件托盘, 如果当前创建的是其它类型托盘返回nil
|
||||
AsLCLTray() *LCLTray //AsLCLTray 尝试转换为 LCL 组件托盘, 如果当前创建的是其它类型托盘返回nil
|
||||
}
|
||||
|
||||
//LCL 系统托盘
|
||||
//LCLTray LCL 托盘
|
||||
type LCLTray struct {
|
||||
owner lcl.IComponent
|
||||
trayIcon *lcl.TTrayIcon
|
||||
popupMenu *lcl.TPopupMenu
|
||||
}
|
||||
|
||||
//CEF views framework 系统托盘
|
||||
//ViewsFrameTray CEF views framework 托盘
|
||||
type ViewsFrameTray struct {
|
||||
trayWindow *ViewsFrameworkBrowserWindow
|
||||
trayIcon *lcl.TTrayIcon
|
||||
@ -56,7 +59,7 @@ type ViewsFrameTray struct {
|
||||
isClosing bool
|
||||
}
|
||||
|
||||
//CEF + LCL 托盘
|
||||
//CEFTray CEF + LCL 托盘
|
||||
type CEFTray struct {
|
||||
*lcl.TForm
|
||||
owner lcl.IComponent
|
||||
@ -68,3 +71,8 @@ type CEFTray struct {
|
||||
isClosing bool
|
||||
url string
|
||||
}
|
||||
|
||||
//SysTray 系统原生托盘
|
||||
type SysTray struct {
|
||||
trayStart, trayStop func()
|
||||
}
|
||||
|
@ -69,14 +69,17 @@ func (m *LCLTray) SetOnClick(fn TrayICONClick) {
|
||||
fn()
|
||||
})
|
||||
}
|
||||
|
||||
func (m *LCLTray) SetOnMouseUp(fn TMouseEvent) {
|
||||
m.trayIcon.SetOnMouseUp(func(sender lcl.IObject, button types.TMouseButton, shift types.TShiftState, x, y int32) {
|
||||
fn(sender, button, shift, x, y)
|
||||
})
|
||||
}
|
||||
|
||||
func (m *LCLTray) SetOnMouseDown(fn lcl.TMouseEvent) {
|
||||
m.trayIcon.SetOnMouseDown(fn)
|
||||
}
|
||||
|
||||
func (m *LCLTray) SetOnMouseMove(fn lcl.TMouseMoveEvent) {
|
||||
m.trayIcon.SetOnMouseMove(fn)
|
||||
}
|
||||
@ -104,6 +107,7 @@ func (m *LCLTray) SetHint(value string) {
|
||||
m.trayIcon.SetHint(value)
|
||||
}
|
||||
|
||||
//SetTitle 设置标题
|
||||
func (m *LCLTray) SetTitle(title string) {
|
||||
m.trayIcon.SetHint(title)
|
||||
}
|
||||
|
@ -7,7 +7,3 @@
|
||||
//----------------------------------------
|
||||
|
||||
package cef
|
||||
|
||||
//Sys 系统托盘
|
||||
type SysTray struct {
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ func onReady() {
|
||||
fmt.Println("systray.onReady")
|
||||
systray.SetTemplateIcon(icon.Data, icon.Data)
|
||||
systray.SetTitle("Energy Sys Tray")
|
||||
systray.SetTooltip("Energy tooltip")
|
||||
systray.SetTooltip("这里是文字\nEnergy tooltip")
|
||||
systray.SetOnClick(func() {
|
||||
fmt.Println("SetOnClick")
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user