GoGi

原生的 Go(golang)图形界面系统(2D 和 3D),建立在 GoKi 树框架上。「Native Go (golang) Graphical Interface system (2D and 3D), built on GoKi tree framework」

Github stars Tracking Chart

alt tag

GoGi 是 GoKi Go 语言(golang)全强度树结构系统的一部分(日语中 ki = 木 = tree)。

包 gi 是一个基于透视图的 2D 和 3D GUI/图形界面(Gi),它的功能类似于 HTML/CSS/SVG 和 Qt。

注意:由于使用了 math.Round、os.UserCacheDir 和 reflect.Value.IsZero(),需要 Go 1.13 以上版本。

请参阅 Wiki 了解更多的文档(日益广泛),安装 说明(主要是基本的 Go 构建过程,但由于 glfw 的原因,现在所有平台都依赖于 cgo,所以请查看每个平台的详细信息),以及 Google Groups goki-gi 电子邮件列表和新的 github 讨论 工具。

GoGi 使用 GoKi 树的基础架构,用完全原生的习语 Go 实现了一个基于透视图的 GUI 框架,最初基于 Shiny 驱动的、最小的、特定于操作系统的后端接口,现在使用 go-gl/glfw,并支持 MacOS、Linux 和 Windows。

整体设计集成了广泛使用的框架的现有标准和约定,包括 Qt(整体 widget 设计)、HTML/CSS(样式)和 SVG(渲染)。核心的 Layout 对象自动化了大部分与 GUI 构建相关的复杂性(包括滚动),所以程序员主要只需要添加元素,并设置它们的样式属性 -- 类似于 HTML。主要的 2D 框架还集成了 3D 透视图,支持这些框架的有趣组合(见 gi3d 包和 examples/gi3d)。目前 GoGi 专注于桌面系统,但没有什么可以阻止它适应移动设备。

参见 Gide,了解一个用 GoGi(一个 IDE)编写的完整的、复杂的应用程序,同样,Emergent 神经网络模拟环境(整个项目的主要动机),以及这个资源库中的各种例子,可以得到很多有用的演示 -- 从 Widgets 例子开始,该示例有一些教程介绍。

主要特性

拥有所有标准的小部件,包括按钮、菜单、滑块、TextField、SpinBox、ComboBox 等。按钮、菜单、滑块、TextField、SpinBox、ComboBox 等,具有工具提示、悬停、聚焦、复制/粘贴(完全支持本地剪贴板)、拖放 -- 全套标准 GUI 功能。请参阅 gi/examples/widgets,查看所有 widgets 的演示。

  • Layout(布局)自动组织和自动调整大小,以配置不同比例、分辨率和平台的 "工作" 界面。自动记忆和恢复跨会话的窗口位置和大小,并支持标准的 Ctrl+ 和 Ctrl- 缩放显示比例。
  • 基于 CSS 的样式允许自定义一切--本机样式属性兼容 HTML(使用所有标准的 em、px、pct 等单位),包括所有文本渲染的HTML "富文本" 样式(例如,在 Label widget 中)-- 可以用内联标签(<strong>、<em> 等)装饰任何文本,甚至包括链接。样式现在被分离到 gist 包中,以便于导航。
  • 相比于 Qt 等同类替代品需要几分钟到几小时的时间来编译,编译只需几秒钟,而且对 cgo 的依赖性最小。从 2019 年 4 月起,我们现在依赖于 glfw 跨平台 GUI 基础系统,以及 go-gl/gl OpenGL 绑定,以支持框架的 3D(gi3d)方面。
  • 完全自给自足 -- 不使用操作系统特定的原生部件--导致跨平台的代码更简单、更一致,并且能够使用标准的 Ctrl/Cmd+Plus 或 Minus 键和偏好设置来扩展 HiDPI。这也允许将一个完整的 2D GUI 嵌入到 3D 场景中,例如。
  • SVG 元素(在 svg 子包中)支持 SVG 渲染 -- 用于内部的图标,并可用于高级图形显示 -- 参见 gi/examples/svg 查看器和编辑器,以及一些测试 .svg 文件。
  • 模型/视图范式具有基于反射的视图元素,可以显示和操作所有标准的 Go 类型(在 giv 子包中),从单个类型(例如,在 SpinBox 中显示 int、float,在 ComboBox 选择器中显示 "enum" const int 类型)到复合数据结构,包括结构字段的 StructView 编辑器,地图和切片元素的 MapView 和 SliceView 显示(包括元素的完整编辑/添加/删除),以及用于结构切片的全功能 TableView 和用于 GoKi 树的 TreeView。
    • TreeView 可以实现一个内置的 GUI 编辑器/检查器,用于设计 gui 元素本身。只要在任何窗口中按 Control+Alt+I 就可以调出这个编辑器/检查器。场景图可以从 JSON 文件中自动保存/加载,以提供一个基本的 GUI 设计框架 -- 只需加载并添加适当的连接。
  • 与 Gio 等即时模式 GUI 相比,GoGi 是一个 "标准的" 保留模式(基于透视图)GUI。因此,GoGi 会自动为您处理好一切,但结果是您牺牲了对每个细节的控制。即时模式给了您充分的控制权,但同时也给您带来了控制权的全部负担 -- 您必须亲自为每一个行为编码。在 GoGi 中,您可以通过样式化和基于闭包的 "回调" 方法进行广泛的控制,就像您在标准的前端 Web 应用程序中一样(因此它可能会被许多用户所熟悉),但如果您想做一些非常不同的事情,您可能需要编写一种新类型的 Widget,这可能会更加困难,因为您需要了解更多的整体基础设施。因此,如果你可能会做一些相当标准的事情,并且不觉得需要绝对的控制,GoGi 可能会是一个更容易的体验。

代码概述

2D 节点主要有三种类型:

  1. Viewport2D 节点管理自己的 image.RGBA 位图,可以直接上传到 oswin.Texture(基于GPU),然后直接上传到 oswin.Window。父 Window 有一个主 Viewport2D,它支持整个窗口,也是大多数 Widget 的渲染对象。
    1. 弹出对话框和菜单有他们自己的视口,它们被分层在主窗口视口之上。
    2. SVG 及其子类:Icon 是 SVG 渲染节点的容器。
  2. 使用完全基于 CSS 的样式的 Widget 节点(如 Box 模型等),通常被放置在 Layout 中 -- 它们使用任意 DPI 的单位系统将尺寸转化为实际渲染的点(实际的原始分辨率依赖性像素的术语 -- "像素" 在这一点上已经被有效地增用为 96 dpi的独立显示单位)。Widgets 具有非重叠的边界框(BBox -- 为所有相关参考帧缓存)。
  3. SVG 渲染节点,直接在 girl.Paint 对象上设置属性,通常有自己的几何体等 -- 它们应该在一个父 SVG 视口内,它们的 geom 单位完全由变换等决定,我们不支持任何进一步的单位规范 -- 只支持原始浮动值。

一般 Widget 方法的约定:

  • SetValue 类方法是用 UpdateStart/End 包装的,但不发出信号,SetValueAction 调用 SetValue 并发出信号。
  • SetValueAction 调用 SetValue 并发出信号。这样可以让 widget 的其他用户也能接收到信号而不触发自己,但通常你要的是更新,所以在基本版中有这个功能是有意义的。ValueView 尤其需要这种行为。
  • 查看系统如何工作的最好方法是在示例目录中,以及通过 Control+Alt+I 使用交互式反射编辑器交互式修改任何现有的 gui。

后台

oswin 和 gpu 包提供了硬件级实现的接口抽象。目前,gpu 的实现是 OpenGL,但 Vulkan 也在计划之中,希望对 gpu 接口的改动不大。基本的平台特定细节由 glfw(3.3版本)处理,还有一些其他平台特定代码。

所有主要的 "前端" 代码只是通过 girl 渲染库处理 image.RGBA,使用 girl.Paint 方法,这是改编自 https://github.com/fogleman/gg,我们使用 https://github.com/srwiley/rasterx 对图像进行基于 CPU 的光栅化,速度快,SVG 性能好。Viewport2D 图像上传到 GPU 支持的 oswin.Texture 中,并用 sprite 叠加合成到窗口。

状态/新闻

2020 年 11 月发布的 1.1 版本,在 gist 样式包中分解出了样式参数和代码,在 girl 渲染库中分解出了基本的渲染代码,包括完整的文字布局和渲染系统。

2020 年 4 月发布 1.0 版本! 3D gi3d 组件已经可以使用,代码已经被学生和研究人员广泛测试,包括在 gide 下的广泛测试。目前,API将保持稳定。

活跃的用户应该加入 Google Groups goki-gi 电子邮件列表,以获得更详细的状态更新。

如果有任何不工作的情况,请提交 Issues

3/2019:python 包装器现在可用!你现在可以从 python 中做大部分 GoGi。请参阅那里的 README.md 文件以了解更多细节。




Overview

Name With Ownergoki/gi
Primary LanguageGo
Program languageGo (Language Count: 5)
PlatformLinux, Mac, Windows
License:BSD 3-Clause "New" or "Revised" License
Release Count113
Last Release Namev2.0.0-dev0.0.28 (Posted on 2023-12-26 15:37:42)
First Release Namev0.9.0 (Posted on 2018-11-14 13:19:41)
Created At2024-01-11 06:22:58
Pushed At2024-04-05 04:39:40
Last Commit At
Stargazers Count8
Watchers Count1
Fork Count0
Commits Count2k
Has Issues Enabled
Issues Count0
Issue Open Count0
Pull Requests Count0
Pull Requests Open Count0
Pull Requests Close Count0
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

alt tag

GoGi is part of the GoKi Go language (golang) full strength tree structure system (ki = 木 = tree in Japanese)

package gi is a scenegraph-based 2D and 3D GUI / graphics interface (Gi) in Go.

Go Report Card
GoDoc
Travis

NOTE: Requires Go version 1.11+ due to use of math.Round and os.UserCacheDir.

See the Wiki for more docs (increasingly extensive), Install instructions (mostly just standard go get ..., but does now depend on cgo so see details for each platform), and Google Groups goki-gi emailing list.

GoGi uses the GoKi tree infrastructure to implement a scenegraph-based GUI framework in full native idiomatic Go, with minimal OS-specific backend interfaces based originally on the Shiny drivers, now using go-gl/glfw, and supporting MacOS, Linux, and Windows. The overall design is an attempt to integrate existing standards and conventions from widely-used frameworks, including Qt (overall widget design), HTML / CSS (styling), and SVG (rendering). The main 2D framework also integrates with a 3D scenegraph, supporting interesting combinations of these frameworks (see gi3d package and examples/gi3d). Currently GoGi is focused on desktop systems, but nothing should prevent adaptation to mobile.

See Gide for a complete, complex application written in GoGi (an IDE), and likewise the Emergent neural network simulation environment (the prime motivator for the whole project), along with the various examples in this repository for lots of useful demonstrations -- start with the Widgets example which has a bit of a tutorial introduction.

Main Features

  • Has all the standard widgets: Button, Menu, Slider, TextField, SpinBox, ComboBox etc, with tooltips, hover, focus, copy / paste (full native clipboard support), drag-n-drop -- the full set of standard GUI functionality. See gi/examples/widgets for a demo of all the widgets.

  • Powerful Layout logic auto-sizes everything -- very easy to configure interfaces that just work across different scales, resolutions, platforms. Automatically remembers and reinstates window positions and sizes across sessions, and supports standard Ctrl+ and Ctrl- zooming of display scale.

  • CSS-based styling allows easy customization of everything -- native style properties are fully HTML compatible (with all standard em, px, pct etc units), including full HTML "rich text" styling for all text rendering (e.g., in Label widget) -- can decorate any text with inline tags (<strong>, <em> etc), and even include links.

  • Compiles in seconds, compared to many minutes to hours for comparable alternatives such as Qt, and with minimal cgo dependency. As of April 2019 we now depend on the glfw cross-platform GUI infrastructure system, and the go-gl/gl OpenGL bindings, to support the 3D (gi3d) aspect of the framework.

  • Fully self-contained -- does not use OS-specific native widgets -- results in simpler, consistent code across platforms, and is fully HiDPI capable and scalable using standard Ctrl/Cmd+Plus or Minus key, and in Preferences. This also allows a complete 2D GUI to be embedded into a 3D scene, for example.

  • SVG element (in svg sub-package) supports full SVG rendering -- used for Icons internally and available for advanced graphics displays -- see gi/examples/svg for viewer and start on editor, along with a number of test .svg files.

  • Powerful Model / View paradigm with reflection-based view elements that display and manipulate all the standard Go types (in giv sub-package), from individual types (e.g., int, float display in a SpinBox, "enum" const int types in a ComboBox chooser) to composite data structures, including StructView editor of struct fields, MapView and SliceView displays of map and slice elements (including full editing / adding / deleting of elements), and full-featured TableView for a slice-of-struct and TreeView for GoKi trees.

    • TreeView enables a built-in GUI editor / inspector for designing gui elements themselves. Just press Control+Alt+I in any window to pull up this editor / inspector. Scene graphs can be automatically saved / loaded from JSON files, to provide a basic GUI designer framework -- just load and add appropriate connections..

Screenshot of Widgets demo

Screenshot of Widgets demo, Darker

Code Overview

There are three main types of 2D nodes:

  • Viewport2D nodes that manage their own image.RGBA bitmap and can upload that directly to the oswin.Texture (GPU based) that then uploads directly to the oswin.Window. The parent Window has a master Viewport2D that backs the entire window, and is what most Widget's render into.

    • Popup Dialog and Menu's have their own viewports that are layered on top of the main window viewport.
    • SVG and its subclass Icon are containers for SVG-rendering nodes.
  • Widget nodes that use the full CSS-based styling (e.g., the Box model etc), are typically placed within a Layout -- they use units system with arbitrary DPI to transform sizes into actual rendered dots (term for actual raw resolution-dependent pixels -- "pixel" has been effectively co-opted as a 96dpi display-independent unit at this point). Widgets have non-overlapping bounding boxes (BBox -- cached for all relevant reference frames).

  • SVG rendering nodes that directly set properties on the Paint object and typically have their own geometry etc -- they should be within a parent SVG viewport, and their geom units are determined entirely by the transforms etc and we do not support any further unit specification -- just raw float values.

General Widget method conventions:

  • SetValue kinds of methods are wrapped in UpdateStart / End, but do NOT emit a signal.
  • SetValueAction calls SetValue and emits the signal.
    This allows other users of the widget that also recv the signal to not trigger themselves, but typically you want the update, so it makes sense to have that in the basic version. ValueView in particular requires this kind of behavior.

The best way to see how the system works are in the examples directory, and by interactively modifying any existing gui using the interactive reflective editor via Control+Alt+I.

Backend

The oswin and gpu packages provide interface abstractions for hardware-level implementations. Currently the gpu implementation is OpenGL, but Vulkan is planned, hopefully with not too many changes to the gpu interface. The basic platform-specific details are handled by glfw (version 3.3), along with a few other bits of platform-specific code.

All of the main "front end" code just deals with image.RGBA through the Paint methods, which was adapted from https://github.com/fogleman/gg, and we use https://github.com/srwiley/rasterx for CPU-based rasterization to the image, which is very fast and SVG performant. The Viewport2D image is uploaded to a GPU-backed oswin.Texture and composited with sprite overlays up to the window.

Status

  • As of 12/13/2020 the 3D gi3d component of the framework is very near to completion, and the code has been widely tested by students and researchers, and can be considered "production ready". A 1.0 version release is imminent, along with API stability.

  • Active users should join Google Groups goki-gi emailing list to receive more detailed status updates.

  • Please file Issues for anything that does not work.

  • 3/2019: python wrapper is now available! you can do most of GoGi from python now. See README.md file there for more details.

To the top