FAQ
Chrome allows separating and merging tabs, each is a separate
application. Not sure about the i
I see. I haven't noticed that. I thought it is just like an MDI application
under windows...Found multi-processed.
Of cause, you are right in technical part.
But as a human, it is cool to drag `activity monitor` into `chrome` as a
chrome tab...And i think window manager is also a part of GUI system, no?

I'm not going to define a callback func in the structure...
>
Why not?
Freedom. :)
Such style does mean all objects created by the structure have this
feature. It is easy of cause when all objects do like to have this feature.
But maybe some special objects don't want it, like me, in someway, as a
Chinese, i'm a bit special. Maybe that's the reason, i don't want all
objects do have same functions. Just free. I'm not sure. Maybe this answer
comes from feeling, something more humanity.
Event systems are about:...
Yes, the usage 1 is what i want !!! I like the code!!!
But if it is easy to do, why there's no such standard lib?

And i'm thinking, there are also some extra things maybe:
- how to perform `fn(source, message, data)` in Emit func
func (e Emitter) Emit(source interface{}, message string, data interface{}){
    for _, fn := range e[message] {
         fn(source, message, data)
       }
}
What about use gorountines to executing dirty job?
And of cause i can do it in the callback,
t.On("lights-changed", func(source interface{}, message string, data
interface{}){
  go download_large_file...//some dirty work
})
But i don't want. I just want to supply a parameter that figure out the
task should be done in an async way. That makes me feel more simple then
add `go` before `download_large_file` process.
t.On("lights-changed", DIRTY_WORK, func(source interface{}, message string,
data interface{}){
  download_large_file...
})
And if there exists such a library can do the job, i even don't want to
code more
t.On("clicked",urlField.text, DIRTY_WORK,download_lib.download);
So, actually, that is the Qt style then (without DIRTY_WORK)...seems more
readable than anonymous callback function...
- what about broadcasting? (or one signal send to lots objects)
t.On('clicked',urlField.text,[[DIRTY_WORK,download_lib.download],[
NOT_DIRTY_WORK,log.log]])
(of cause, i can write a callback, but i also want some simple resolution)
... maybe others ...

On Tuesday, May 10, 2016 at 9:22:14 PM UTC+8, Egon wrote:
On Tuesday, 10 May 2016 15:52:48 UTC+3, Wang Yarco wrote:

Some applications do it. e.g. Chrome. But that is more of a window
manager issue not the application. The application rarely has the necessary
knowledge to dock two arbitrary applications. I wouldn't be surprised if
some WM already does it.
I didn't see that if you mean the things between chrome and its
applications (those standalone extensions).
Chrome allows separating and merging tabs, each is a separate application.
Not sure about the i

Building such an event system isn't complicated
https://play.golang.org/p/u15m5UHbU-. The complex part is the rest of UI.
No. That is not the thing i want to say. I mean this:
type Timer struct{
dayLightOrMidnight bool
}

func(this*Person)sleep(){
}
func(this*Person)playGame(){
}

t := new(Timer)
p := new(Person)
// i want connect the two objects
I'm not going to define a callback func in the structure...
Why not?

In your logic, before you do `button.Press`, you've already known, there
will be `OnClick` event on the struct `Button`; But in my logic, before you
do connection, there's nothing defined...
Just like the interface in golang vs interface in other languages!
Event systems are about:
* Who will create the event,
* who will define the events and
* who will manage the events?

// e.g.
package event

type Handler func(sender interface{}, message string, data interface{})

type Emitter map[string][]Handler

func (e Emitter) On(event string, fn Handler) {
e[event] = append(e[event], fn)
}

func (e Emitter) Emit(source interface{}, message string, data
interface{}){
for _, fn := range e[message] {
fn(source, message, data)
}
}

var All map[string]Emitter = map[string]Emitter{}

func Connect(source interface{}, message string, fn Handler) {
//TODO: check, source must be a pointer
e, ok := All[source]
if !ok {
e = Emitter{}
All[source] = e
}
}

func Emit(source interface{}, message string, data interface{}) {
if e, ok := All[source]; ok {
e.Emit(source, message, data)
}
}

// usage 1

type Lights struct {
State bool
}

func (lights *Lights) Close() { event.Disconnect(lights) }
func (lights *Lights) Toggle() {
lights.State = !lights.State
event.Emit(lights, "lights-changed", lights.State)
}

func main(){
t := &Lights{}
event.Connect(t, "lights-changed", func(source interface{}, message
string, data interface{}){
// ...
})

t.Toggle()
t.Toggle()
}

// usage 2

type Lights struct {
Emitter
State bool
}

func NewLights() *Lights { return &Lights{Emitter{}, false} }

func (lights *Lights) Close() { lights.Emitter = nil }
func (lights *Lights) Toggle() {
lights.State = !lights.State
lights.Emit(lights, "lights-changed", lights.State)
}

func main(){
t := &Lights{}
t.On("lights-changed", func(source interface{}, message string, data
interface{}){
// ...
})

t.Toggle()
t.Toggle()
}

*Obviously there are even more options.*
On Tuesday, May 10, 2016 at 1:36:36 PM UTC+8, Egon wrote:


On Tuesday, 10 May 2016 03:33:10 UTC+3, Wang Yarco wrote:

Great Doc!
+ one my idea, i've just got it several days ago (but don't know where
to add it into your doc):
It should support something like:
[ app A window 1 ] [ app B window 1 ]
When drag `app A window 1` into to `app B window 1`, `app A window 1`
will automatically become a dock window in `app B window 1` just like other
dock window in `app B window 1`.
I mean such actions could happen between apps! Not just windows in an
app!
(It seems no current GUI system have such feature)
Some applications do it. e.g. Chrome. But that is more of a window
manager issue not the application. The application rarely has the necessary
knowledge to dock two arbitrary applications. I wouldn't be surprised if
some WM already does it.

So for example, if i'm doing code in macvim, and the same time open a
pdf for reference, i can combine the two into one big window ( seems like
in one application!)

Anyway, go back to our discussion, actually, my attention is the `event
system`. Not the GUI...
Why i take it so much important? The reason is `event system` is a
different thinking in logic.
You call a function, that is active mode; You trigger a function, that
is passive mode.
Building such an event system isn't complicated
https://play.golang.org/p/u15m5UHbU-. The complex part is the rest of
UI.

That is the thing in our real world. Either you live in active mode or
you live in passive mode...
So, if no such `event system`, the language itself is just half done...
(that is my feeling)
On Tuesday, May 10, 2016 at 2:18:00 AM UTC+8, Egon wrote:
On Monday, 9 May 2016 18:19:06 UTC+3, Wang Yarco wrote:

Well, i haven't tried everything. But that is the most elegant
solution as i know.
Here's my preliminary research
<https://docs.google.com/document/d/1QtqrrSG1lbnmk8wPTOVNEjfby3zfymS8vHtM8cxy67I/edit>
on different approaches.

Em...though https://github.com/therecipe/qt
<https://www.google.com/url?q=https%3A%2F%2Fgithub.com%2Ftherecipe%2Fqt&sa=D&sntz=1&usg=AFQjCNEPpv5rg-P4P4c8gPXSEFnMM5FwYQ>
seems good...but i would still choose Qt/c++ when i want to do desk
application.
I think only a pure qt/go solution could persuade me to use it.
(not something like bridge between qt and go...if so, why not just
use c++? at least, i have qt creator)
On Monday, May 9, 2016 at 6:38:16 PM UTC+8, Egon wrote:
On Monday, 9 May 2016 13:19:30 UTC+3, Wang Yarco wrote:

I've heard something like someone developing GUI lib for golang.
But i doubt it, cause even Qt didn't achieve this (i mean, great success in
business. It just goes from one company to another. I like Qt). So i'm
thinking why google not purchase Qt? It seems tell them to do another
version of Qt in go not a big problem, no need reinvent it.

...Then i see golang is lack of event system. But if the future
plan of golang will include GUI part, it should have such event system like:

In Qt:
connect(from some object,clicked,to some object,func);

or even like in NodeJs/Js:
obj.on('clicked',func);

Or am i wrong?
Why? How many alternative approaches have you tried? Why do you
assume there exists a "one-size-fits-all-UI-solution"? :)

Also, you can already use Qt from Go (e.g.
https://github.com/go-qml/qml, https://github.com/therecipe/qt and
more
https://github.com/golang/go/wiki/projects#guis-and-widget-toolkits
).

+ Egon
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 12 of 21 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMay 9, '16 at 10:19a
activeMay 12, '16 at 10:26a
posts21
users5
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase