Coder Social home page Coder Social logo

gui's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gui's Issues

Keyboard key combinations for shortcuts

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?

Go imports: github.com/faiface/gui/win: no matching versions for query "latest"

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

Maybe change Event to be an interface instead of struct?

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)
		}
	}
}

gui-xor

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)

Legacy in GUI developments

Hi @faiface, thank you so much for writing this inspiring and awesome package.

I read your README and got a few questions:

  1. You mentioned that you'd like to get rid of C dependencies, such as 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?
  2. You also mentioned that "Due to stupid limitations imposed by operating systems, the internal code that fetches events from the OS must run on the main thread of the program." I learned the constraint from the golang-nuts mailing list but never dig into the historical reason about this. Perhaps you know more about how the limitation was introduced and why is it still exists today? Furthermore, if we get rid of the C dependencies from Go, how could the main thread limitation be improved from here?

Thank you very much for your reading and happy new year :)

Need clarification on events

image

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})

examples/imageviewer: DrawText does not draw to a draw.Image

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.

func DrawText(text string, face font.Face, clr color.Color) image.Image {
drawer := &font.Drawer{
Src: &image.Uniform{clr},
Face: face,
Dot: fixed.P(0, 0),
}
b26_6, _ := drawer.BoundString(text)
bounds := image.Rect(
b26_6.Min.X.Floor(),
b26_6.Min.Y.Floor(),
b26_6.Max.X.Ceil(),
b26_6.Max.Y.Ceil(),
)
drawer.Dst = image.NewRGBA(bounds)
drawer.DrawString(text)
return drawer.Dst
}

Crash when resizing examples/imageviewer

$ 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      

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.