faiface / gui Goto Github PK
View Code? Open in Web Editor NEWSuper minimal, rock-solid foundation for concurrent GUI in Go.
License: MIT License
Super minimal, rock-solid foundation for concurrent GUI in Go.
License: MIT License
Do keyboard events allow the capture of key combinations, such as "CTRL+R"?
Simultaneously pressing this combination generates a "kb/down/ctrl" followed by a kb/up/ctrl when the CTRL key is released. However, no kb/down/ nor kb/up/ events are produced while pressing "R" until after the CTRL key is released.
BTW, thank you for a wonderfully minimal, concurrent GUI framework! My graphical requirements matched its minimalism allowing me to encode a prototype in just a couple hours avoiding the time sink of just understanding a qt implementation written in go.
Noticed your roadmap and was wondering if the distributed nature of concurrency requires disseminating the "intelligence" of drawing widgets and their interaction among the cooperating goroutines, as opposed to the notion of a "controller" in a hierarchical GUI where the "smarts" are concentrated in it, such that it dictates the rendering/behavior of its subordinate widgets?
Are there are any text input fields/form examples?
I would like to have a go at developing graphical programs in your GUI framework, and to begin, I have downloaded your Pexeso example and have installed the required libraries as per the "Installation" section in the README and the GLFW setup instructions. That is, I have installed both your GUI library, your mainthread library, and the GLFW library (all through go get -u
), and the Linux-specific X11 and mesa packages (from my Linux distro's package manager, which is Alpine Linux, if that helps).
In the same folder as the Pexeso main.go
, I have created a go.mod
file with go mod init github.com/faiface/gui
, and ran go mod tidy
. Upon this, I receive success for the mainthread library but not the gui/win library:
go: finding module for package github.com/faiface/mainthread
go: finding module for package github.com/faiface/gui/win
go: found github.com/faiface/mainthread in github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3
go: finding module for package github.com/faiface/gui/win
github.com/faiface/gui imports
github.com/faiface/gui/win: no matching versions for query "latest"
I have tried to find relevant information and similar issues on the Web to fix the issue. Unfortunately I have not found anything useful so far.
This is the version of Go I have, if that helps:
go version go1.16.8 linux/amd64
I'm thinking something along these lines:
type Event interface {
Name() string
Args() interface{}
}
This would look like this when in use:
package main
import (
"image"
"image/draw"
"github.com/peterhellberg/gfx"
"github.com/peterhellberg/gui"
)
func main() {
gui.Run(loop)
}
func loop() {
win, err := gui.New(gui.Title("gui-xor"), gui.Size(512, 512))
if err != nil {
return
}
win.Draw() <- func(dst draw.Image) image.Rectangle {
r := dst.Bounds()
gfx.EachPixel(r, func(x, y int) {
c := uint8(x ^ y)
dst.Set(x, y, gfx.ColorNRGBA(c, c%192, c, 255))
})
return r
}
for event := range win.Events() {
switch event.Name() {
case gui.EventClose, gui.EventKeyboardUp:
close(win.Draw())
default:
gfx.Log("Event: %+v", event)
}
}
}
I will experiment a bit more, but so far I've reduced the code in this project to a single file (in order to help with the experimentation)
Hi @faiface, thank you so much for writing this inspiring and awesome package.
I read your README and got a few questions:
glfw
. I have huge interests in how that could be possibly done. As I partially read your code, the glfw is for cross-platform window, kb/mo events managements, and gl
is for rendering. To get rid of those C dependencies, on macOS, one must use cocoa and metal for those purposes, and on Linux, X11 and OpenGL seems to be the only way for those purposes. It seems to me that no matter what we do, there must be some C dependencies. Could you maybe share a few of your thoughts on how to get rid of C in Go for doing GUI stuff?Thank you very much for your reading and happy new year :)
package main
import (
"github.com/faiface/gui/win"
"github.com/faiface/mainthread"
"github.com/vova616/screenshot"
"image"
"image/draw"
"time"
)
func run() {
w, err := win.New(win.Title("faiface/gui"), win.Size(800, 600))
if err != nil {
panic(err)
}
redraw := func(drw draw.Image) image.Rectangle {
r := image.Rect(0, 0, 2560, 1440)
img2, _ := screenshot.CaptureScreen()
myImg := image.Image(img2)
draw.Draw(drw, r, myImg, image.ZP, draw.Src)
return r
}
for event := range w.Events() {
switch event.(type) {
case win.WiClose:
close(w.Draw())
default:
time.Sleep(17 * time.Millisecond)
w.Draw() <- redraw
}
}
}
func main() {
mainthread.Run(run)
}
I have coded this example. It grabs a screenshot of my screen and displays it just fine at around 60Hz. It runs for a coupe of seconds until it crashes with the message attached below. I assume im running out of somthing.
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x4e00a0]
goroutine 18 [running, locked to thread]:
image.(*RGBA).Bounds(0x54d8de)
/snap/go/9360/src/image/image.go:98
image/draw.clip({0x60e608, 0xc000356000}, 0xc00497be08, {0x60db08, 0x0}, 0xc00497bdc8, {0x0, 0x0}, 0xc00497bde8)
/snap/go/9360/src/image/draw/draw.go:86 +0xd3
image/draw.DrawMask({0x60e608, 0xc000356000}, {{0x0, 0x0}, {0x320, 0x258}}, {0x60db08, 0x0}, {0x0, 0x0}, ...)
/snap/go/9360/src/image/draw/draw.go:117 +0xa5
image/draw.Draw(...)
/snap/go/9360/src/image/draw/draw.go:111
main.run.func1({0x60e608, 0xc000356000})
Hi, I want to get a gg version use in arm.
How to get the version?
thank you.
The DrawText
function in examples/imageviewer/util.go
creates a new image with the given text, it does not draw it on an image like the other Draw*
functions.
gui/examples/imageviewer/util.go
Lines 66 to 82 in 4324b48
$ go run ./imageviewer/
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7fff2df567b4]
runtime stack:
runtime.throw(0x4217912, 0x2a)
/usr/local/go/src/runtime/panic.go:617 +0x72
runtime.sigpanic()
/usr/local/go/src/runtime/signal_unix.go:374 +0x4a9
goroutine 3 [syscall, locked to thread]:
runtime.cgocall(0x413c830, 0xc000376c40, 0xc000001200)
/usr/local/go/src/runtime/cgocall.go:128 +0x5b fp=0xc000376c10 sp=0xc000376bd8 pc=0x400591b
github.com/go-gl/gl/v2.1/gl._Cfunc_glowDrawPixels(0x7fff3e7ab7d1, 0x25800000332, 0x140100001908, 0xc001186000)
_cgo_gotypes.go:13546 +0x45 fp=0xc000376c40 sp=0xc000376c10 pc=0x40baf55
github.com/go-gl/gl/v2.1/gl.DrawPixels.func1(0x25800000332, 0x140100001908, 0xc001186000)
/Users/hajimehoshi/go/pkg/mod/github.com/go-gl/[email protected]/v2.1/gl/package.go:20431 +0x90 fp=0xc000376c80 sp=0xc000376c40 pc=0x40fa730
github.com/go-gl/gl/v2.1/gl.DrawPixels(0x25800000332, 0x140100001908, 0xc001186000)
/Users/hajimehoshi/go/pkg/mod/github.com/go-gl/[email protected]/v2.1/gl/package.go:20431 +0x4b fp=0xc000376ca8 sp=0xc000376c80 pc=0x40bb56b
github.com/faiface/gui/win.(*Win).openGLFlush(0xc000152040, 0x0, 0x0, 0x332, 0x258)
/Users/hajimehoshi/gui/win/win.go:324 +0x3d3 fp=0xc000376dc0 sp=0xc000376ca8 pc=0x4101943
github.com/faiface/gui/win.(*Win).openGLThread(0xc000152040)
/Users/hajimehoshi/gui/win/win.go:280 +0x547 fp=0xc000376fc0 sp=0xc000376dc0 pc=0x41011b7
github.com/faiface/gui/win.New.func2(0xc000152040)
/Users/hajimehoshi/gui/win/win.go:84 +0x30 fp=0xc000376fd8 sp=0xc000376fc0 pc=0x4101b10
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1337 +0x1 fp=0xc000376fe0 sp=0xc000376fd8 pc=0x40569b1
created by github.com/faiface/gui/win.New
/Users/hajimehoshi/gui/win/win.go:82 +0x331
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.