mirror of
https://gitee.com/energye/energy.git
synced 2024-12-02 11:47:37 +08:00
v2.5.2 demos: add zoom
This commit is contained in:
parent
48f772dcfd
commit
a6af6ac04f
@ -15,10 +15,9 @@ func main() {
|
||||
//指定一个URL地址,或本地html文件目录
|
||||
cef.BrowserWindow.Config.Url = "https://www.csdn.net"
|
||||
//chromium 配置
|
||||
config := cef.NewChromiumConfig()
|
||||
config := cef.BrowserWindow.Config.ChromiumConfig()
|
||||
config.SetEnableMenu(true) //启用右键菜单
|
||||
config.SetEnableDevTools(true) //启用开发者工具
|
||||
cef.BrowserWindow.Config.SetChromiumConfig(config)
|
||||
//运行应用
|
||||
cef.Run(cefApp)
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>cookie</title>
|
||||
<title>browser-print-pdf</title>
|
||||
<style>
|
||||
button {
|
||||
height: 80px;
|
||||
|
@ -2,7 +2,7 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>cookie</title>
|
||||
<title>browser-search-text</title>
|
||||
<style>
|
||||
button {
|
||||
height: 80px;
|
||||
|
@ -0,0 +1,3 @@
|
||||
提取Energy压缩包动态链接库liblcl.dll到该目录下
|
||||
|
||||
libs目录下的文件会被编译到执行文件中
|
BIN
example/browser-view-source/resources/icon.ico
Normal file
BIN
example/browser-view-source/resources/icon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 66 KiB |
44
example/browser-view-source/resources/index.html
Normal file
44
example/browser-view-source/resources/index.html
Normal file
@ -0,0 +1,44 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>browser-view-source</title>
|
||||
<style>
|
||||
</style>
|
||||
<script type="application/javascript">
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body style="overflow: hidden;margin: 0px;padding: 0px;width: 100%;text-align: center;">
|
||||
<h3>
|
||||
查看网页源码通过<br>
|
||||
config := cef.BrowserWindow.Config.ChromiumConfig()<br>
|
||||
config.SetEnableViewSource(true)<br>
|
||||
配置开启或关闭 默认true
|
||||
</h3>
|
||||
<div>
|
||||
文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容
|
||||
</div>
|
||||
<div>
|
||||
文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容
|
||||
</div>
|
||||
<div>
|
||||
文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容
|
||||
</div>
|
||||
<div>
|
||||
文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容
|
||||
</div>
|
||||
<div>
|
||||
文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容
|
||||
</div>
|
||||
<div>
|
||||
文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容
|
||||
</div>
|
||||
<div>
|
||||
文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容
|
||||
</div>
|
||||
<div>
|
||||
文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
18
example/browser-view-source/resources/资源存放目录-可内置到执行程序中.md
Normal file
18
example/browser-view-source/resources/资源存放目录-可内置到执行程序中.md
Normal file
@ -0,0 +1,18 @@
|
||||
可将html css javascript image等静态资源放入该目录,编译后将内置到执行程序中
|
||||
|
||||
通过内置http server 读取该目录文件,展示到页面中
|
||||
```go
|
||||
//内置http服务链接安全配置
|
||||
assetserve.AssetsServerHeaderKeyName = "energy"
|
||||
assetserve.AssetsServerHeaderKeyValue = "energy"
|
||||
//内置http服务链接安全配置
|
||||
cef.SetBrowserProcessStartAfterCallback(func(b bool) {
|
||||
fmt.Println("主进程启动 创建一个内置http服务")
|
||||
//通过内置http服务加载资源
|
||||
server := assetserve.NewAssetsHttpServer()
|
||||
server.PORT = 22022
|
||||
server.AssetsFSName = "resources" //必须设置目录名
|
||||
server.Assets = &resources
|
||||
go server.StartHttpServer()
|
||||
})
|
||||
```
|
35
example/browser-view-source/view-source.go
Normal file
35
example/browser-view-source/view-source.go
Normal file
@ -0,0 +1,35 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"github.com/energye/energy/cef"
|
||||
"github.com/energye/energy/common/assetserve"
|
||||
)
|
||||
|
||||
//go:embed resources
|
||||
var resources embed.FS
|
||||
|
||||
func main() {
|
||||
//全局初始化 每个应用都必须调用的
|
||||
cef.GlobalInit(nil, &resources)
|
||||
//创建应用
|
||||
cefApp := cef.NewApplication(nil)
|
||||
//指定一个URL地址,或本地html文件目录
|
||||
cef.BrowserWindow.Config.Url = "http://localhost:22022/index.html"
|
||||
cef.BrowserWindow.Config.IconFS = "resources/icon.ico"
|
||||
cef.BrowserWindow.Config.Title = "Energy 查看网页源码"
|
||||
config := cef.BrowserWindow.Config.ChromiumConfig()
|
||||
config.SetEnableViewSource(true)
|
||||
cef.SetBrowserProcessStartAfterCallback(func(b bool) {
|
||||
fmt.Println("主进程启动 创建一个内置http服务")
|
||||
//通过内置http服务加载资源
|
||||
server := assetserve.NewAssetsHttpServer()
|
||||
server.PORT = 22022
|
||||
server.AssetsFSName = "resources" //必须设置目录名
|
||||
server.Assets = &resources
|
||||
go server.StartHttpServer()
|
||||
})
|
||||
//运行应用
|
||||
cef.Run(cefApp)
|
||||
}
|
BIN
example/browser-zoom/resources/icon.ico
Normal file
BIN
example/browser-zoom/resources/icon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 66 KiB |
42
example/browser-zoom/resources/index.html
Normal file
42
example/browser-zoom/resources/index.html
Normal file
@ -0,0 +1,42 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>browser-zoom</title>
|
||||
<style>
|
||||
button {
|
||||
height: 50px;
|
||||
width: 100px;
|
||||
margin: 10px;
|
||||
}
|
||||
</style>
|
||||
<script type="application/javascript">
|
||||
function reset() {
|
||||
ipc.emit("zoom-reset");
|
||||
}
|
||||
function dec() {
|
||||
ipc.emit("zoom-dec");
|
||||
}
|
||||
function inc() {
|
||||
ipc.emit("zoom-inc");
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body style="overflow: hidden;margin: 0px;padding: 0px;width: 100%;text-align: center;">
|
||||
<button onclick="inc()">放大</button>
|
||||
<button onclick="dec()">缩小</button>
|
||||
<button onclick="reset()">重置</button>
|
||||
<div>
|
||||
文字文字文字文字文字文字文字文字文字文字文字
|
||||
</div>
|
||||
<div>
|
||||
文字文字文字文字文字文字文字文字文字文字文字
|
||||
</div>
|
||||
<div>
|
||||
文字文字文字文字文字文字文字文字文字文字文字
|
||||
</div>
|
||||
<div>
|
||||
文字文字文字文字文字文字文字文字文字文字文字
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
18
example/browser-zoom/resources/资源存放目录-可内置到执行程序中.md
Normal file
18
example/browser-zoom/resources/资源存放目录-可内置到执行程序中.md
Normal file
@ -0,0 +1,18 @@
|
||||
可将html css javascript image等静态资源放入该目录,编译后将内置到执行程序中
|
||||
|
||||
通过内置http server 读取该目录文件,展示到页面中
|
||||
```go
|
||||
//内置http服务链接安全配置
|
||||
assetserve.AssetsServerHeaderKeyName = "energy"
|
||||
assetserve.AssetsServerHeaderKeyValue = "energy"
|
||||
//内置http服务链接安全配置
|
||||
cef.SetBrowserProcessStartAfterCallback(func(b bool) {
|
||||
fmt.Println("主进程启动 创建一个内置http服务")
|
||||
//通过内置http服务加载资源
|
||||
server := assetserve.NewAssetsHttpServer()
|
||||
server.PORT = 22022
|
||||
server.AssetsFSName = "resources" //必须设置目录名
|
||||
server.Assets = &resources
|
||||
go server.StartHttpServer()
|
||||
})
|
||||
```
|
@ -1,17 +1,52 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"github.com/energye/energy/cef"
|
||||
"github.com/energye/energy/common/assetserve"
|
||||
"github.com/energye/energy/consts"
|
||||
"github.com/energye/energy/ipc"
|
||||
)
|
||||
|
||||
//go:embed resources
|
||||
var resources embed.FS
|
||||
|
||||
func main() {
|
||||
//全局初始化 每个应用都必须调用的
|
||||
cef.GlobalInit(nil, nil)
|
||||
cef.GlobalInit(nil, &resources)
|
||||
//创建应用
|
||||
cefApp := cef.NewApplication(nil)
|
||||
//主窗口的配置
|
||||
//指定一个URL地址,或本地html文件目录
|
||||
cef.BrowserWindow.Config.Url = "https://energy.yanghy.cn"
|
||||
cef.BrowserWindow.Config.Url = "http://localhost:22022/index.html"
|
||||
cef.BrowserWindow.Config.IconFS = "resources/icon.ico"
|
||||
cef.SetBrowserProcessStartAfterCallback(func(b bool) {
|
||||
fmt.Println("主进程启动 创建一个内置http服务")
|
||||
//通过内置http服务加载资源
|
||||
server := assetserve.NewAssetsHttpServer()
|
||||
server.PORT = 22022
|
||||
server.AssetsFSName = "resources" //必须设置目录名
|
||||
server.Assets = &resources
|
||||
go server.StartHttpServer()
|
||||
})
|
||||
ipc.IPC.Browser().SetOnEvent(func(event ipc.IEventOn) {
|
||||
event.On("zoom-inc", func(context ipc.IIPCContext) {
|
||||
bw := cef.BrowserWindow.GetWindowInfo(context.BrowserId())
|
||||
bw.Chromium().BrowserZoom(consts.ZOOM_INC)
|
||||
fmt.Println("zoom-inc")
|
||||
})
|
||||
event.On("zoom-dec", func(context ipc.IIPCContext) {
|
||||
bw := cef.BrowserWindow.GetWindowInfo(context.BrowserId())
|
||||
bw.Chromium().BrowserZoom(consts.ZOOM_DEC)
|
||||
fmt.Println("zoom-dec")
|
||||
})
|
||||
event.On("zoom-reset", func(context ipc.IIPCContext) {
|
||||
bw := cef.BrowserWindow.GetWindowInfo(context.BrowserId())
|
||||
bw.Chromium().BrowserZoom(consts.ZOOM_RESET)
|
||||
fmt.Println("zoom-reset")
|
||||
})
|
||||
})
|
||||
//运行应用
|
||||
cef.Run(cefApp)
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>cookie</title>
|
||||
<title>simple</title>
|
||||
<style>
|
||||
</style>
|
||||
<script type="application/javascript">
|
||||
|
Loading…
Reference in New Issue
Block a user