{"action":"created","issue":{"url":"https://api.github.com/repos/golang/go/issues/11818","labels_url":"https://api.github.com/repos/golang/go/issues/11818/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/11818/comments","events_url":"https://api.github.com/repos/golang/go/issues/11818/events","html_url":"https://github.com/golang/go/issues/11818","id":96493478,"number":11818,"title":"proposal: golang.org/x/exp/shiny: an experimental GUI library.","user":{"login":"nigeltao","id":8565232,"avatar_url":"https://avatars.githubusercontent.com/u/8565232?v=3","gravatar_id":"","url":"https://api.github.com/users/nigeltao","html_url":"https://github.com/nigeltao","followers_url":"https://api.github.com/users/nigeltao/followers","following_url":"https://api.github.com/users/nigeltao/following{/other_user}","gists_url":"https://api.github.com/users/nigeltao/gists{/gist_id}","starred_url":"https://api.github.com/users/nigeltao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nigeltao/subscriptions","organizations_url":"https://api.github.com/users/nigeltao/orgs","repos_url":"https://api.github.com/users/nigeltao/repos","events_url":"https://api.github.com/users/nigeltao/events{/privacy}","received_events_url":"https://api.github.com/users/nigeltao/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/golang/go/labels/Proposal","name":"Proposal","color":"ededed"},{"url":"https://api.github.com/repos/golang/go/labels/Proposal-Accepted","name":"Proposal-Accepted","color":"009800"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":65,"created_at":"2015-07-22T07:23:32Z","updated_at":"2015-08-11T15:54:30Z","closed_at":null,"body":"Purpose.\r\n\r\nFirst and foremost, this is an experiment. This is not 'the official Go GUI (Graphical User Interface) library' or the only blessed way to do things. Unlike a well-understood problem like decoding a JPEG image into an in-memory buffer, there are many possible approaches to GUIs, including existing code both under golang.org/x/mobile and elsewhere. This is simply an exploration. I've reached the point where I have an interesting if minimal demo, and I'd like to share and discuss the code, design and ideas.\r\n\r\n\r\nName.\r\n\r\nThere's nothing particularly deep about the \"shiny\" name. I just like shiny things.\r\n\r\nThe code would live at golang.org/x/exp/shiny. To emphasize what I've said above, this is an experiment, and this is *a* GUI library, not *the* GUI library, so it's not e.g. golang.org/x/gui.\r\n\r\nIt is under golang.org/x because I want to use the same code review process as everything else under golang.org/x, a process I use every working day.\r\n\r\n\r\nOverview.\r\n\r\nThere are two layers: a lower-level window layer, and a higher-level widget layer.\r\n\r\nFor the lower layer, the primary concept is a Window. On the input side, a shiny.Window looks similar to what the golang.org/x/mobile/app package currently calls an App: you get a channel of events, such as key and mouse events.\r\n\r\nThe output side is where things diverge. x/mobile/app assumes that you paint pixels with OpenGL, either directly via the x/mobile/gl package, or indirectly via e.g. x/mobile/exp/sprite uses x/mobile/exp/gl/glutil uses x/mobile/gl. Instead, shiny has twin concepts of Buffers and Textures which map naturally to an OpenGL implementation, but also allow other implementations such as one that speaks a pure X11 protocol, without the need for cgo and OpenGL shared libraries. I assume that you could do somewhat similar things on Windows and Mac.\r\n\r\nA Buffer is an in-memory, in-process bucket of bytes. A Texture is an opaque handle to something 'out-of-process'. A Buffer's contents can be Uploaded to a Texture, and Textures can be Drawn to the Window. As an optimization, it may be possible to Upload a Buffer directly to a Window.\r\n\r\nFor OpenGL, you can think of a Buffer as the result of a simple make([]byte, etc) call, and a Texture as an OpenGL texture. For X11, you can think of a Buffer as MIT-SHM shared memory (if applicable) and a Texture as a (server-side) Pixmap.\r\n\r\nUploads are 1:1 between source (Buffer) and destination (Texture) pixels. Draws can be subject to an arbitrary affine transformation (including simpler copies and scales) between source (Texture) and destination (Window) pixels. For OpenGL, affine transforms are simple shader programs. For X11, they are provided by the XRender extension.\r\n\r\nFor the higher layer, you construct a tree of widgets like buttons, text areas and containers. This shouldn't be overly surprising, except for the fact that the Go language doesn't have traditional object-oriented inheritance. The details of how that works is best explained with actual code, so I'll save it for a CL, if this proposal is approved.\r\n\r\nThe widget set is pure Go, like Swing instead of AWT or SWT. Sweating the details of a production-quality widget set is an enormous amount of work, and hitting that level of quality is not a short term goal. The primary goal is to explore what's possible in the GUI space with Go, and not necessarily to crank out a production-ready classic Win32 or Cocoa app any time soon.\r\n\r\nA secondary goal is to drive development of the Freetype Go port - it has some basic functionality but also some long-standing known deficiencies. Writing a quality GUI text editor is again a substantial amount of work, and I don't intend to build one, but I intend that working on shiny will push the Freetype Go library to be good enough to let someone or some team do exactly that, if they had the time and inclination.\r\n\r\n\r\nRelationship to golang.org/x/mobile.\r\n\r\nThere is a lot of overlap between shiny and x/mobile, and obviously I have contributed to both. The key difference, I think, is that the x/mobile code is rightly focused on mobile apps, where the dominant model is each app has only one (full-screen) window, whereas shiny starts more from a desktop perspective. To mix some metaphors, triangulating from different starting points (mobile vs desktop GUIs) can help avoid overfitting to local optima. In the medium term, the two should end up sharing a lot of code, but it's not obvious to me right now whether x/mobile should depend on shiny or vice versa, and it would be premature to pick a winner now. As I keep saying, there are many possible approaches, and I think it's valid to explore more than one of them concurrently.\r\n\r\nThere is also the operational concern that I would like the freedom for shiny to depend on third party libraries, such as github.com/golang/freetype and github.com/BurntSushi/xgb, but I'd also like to keep the golang.org/x/mobile tree free of such dependencies, at least for now.\r\n\r\n\r\nRelationship to github.com/google/gxui.\r\n\r\nI'm obviously aware of their work, but the two projects aren't strongly linked. As I've said, there are many possible approaches that are worth trying here. Longer term, we might discuss what we can take from each other's codebase, but it's premature to do that now.\r\n\r\n\r\nClosing Remarks.\r\n\r\nI'll repeat that this is experimental and exploratory. I just have a demo and I'd like to share it. I know that there could be a lot of excitement in the community for a 'Go GUI library', but please don't set your expectations too high at this stage, and the existance of this project should not invalidate any other Go GUI projects."},"comment":{"url":"https://api.github.com/repos/golang/go/issues/comments/129942504","html_url":"https://github.com/golang/go/issues/11818#issuecomment-129942504","issue_url":"https://api.github.com/repos/golang/go/issues/11818","id":129942504,"user":{"login":"andlabs","id":718242,"avatar_url":"https://avatars.githubusercontent.com/u/718242?v=3","gravatar_id":"","url":"https://api.github.com/users/andlabs","html_url":"https://github.com/andlabs","followers_url":"https://api.github.com/users/andlabs/followers","following_url":"https://api.github.com/users/andlabs/following{/other_user}","gists_url":"https://api.github.com/users/andlabs/gists{/gist_id}","starred_url":"https://api.github.com/users/andlabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andlabs/subscriptions","organizations_url":"https://api.github.com/users/andlabs/orgs","repos_url":"https://api.github.com/users/andlabs/repos","events_url":"https://api.github.com/users/andlabs/events{/privacy}","received_events_url":"https://api.github.com/users/andlabs/received_events","type":"User","site_admin":false},"created_at":"2015-08-11T15:54:30Z","updated_at":"2015-08-11T15:54:30Z","body":"How do I clone exp for contributing without using `go get`? Just clone it from github?"}}