docking

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Docking for MyGo

一个面向 MyGo 原生 UI 的轻量停靠组件,支持独立浮动窗口和四边停靠;交互参考 Qt Advanced Docking System,不追求功能一一对应。

运行示例

需要 Go 1.27.3 或更新版本。当前依赖 MyGo v0.11.1,版本以 go.mod 为准:

go run ./cmd/demo

最小接入示例:go run ./examples/minimal。

按住面板标题开始拖动后,独立浮动窗口会出现并跟随指针。将它移到工作区中间或主窗口外松开,即可保持浮动;移到工作区左、右、上、下边缘时,方向标记和半透明区域会提示停靠位置,松开即可停靠。浮动窗口可独立移动和调整大小,随主窗口关闭。

拖动分隔线可调整停靠区域大小;点击标题栏的关闭按钮隐藏面板,示例顶部的同名按钮可重新显示。

停靠区过窄时,标签栏可横向滚动,图钉和关闭按钮保持可用。面板内容可纵向滚动;面板提供者可以为内容根元素设置 MinHeight,确保空间不足时能滚动到下方控件。

点击停靠面板标题栏的图钉按钮可将该面板收起到对应边缘。悬停或点击边缘标签临时展开,鼠标离开后会自动收起;在面板内编辑时保持展开,点击外部可收起。展开后再次点击图钉可固定回停靠区,按 Esc 可收起临时面板。

标题获得键盘焦点后,也可以使用 Ctrl+Shift+方向键 停靠,Ctrl+Shift+F 浮动;macOS 使用 Command 代替 Ctrl。Esc 或系统取消指针操作会撤销正在进行的拖拽。

接入

停靠组件按照 MyGo 原生 UI 插件常见的 Go 包方式使用。每个面板只需提供唯一 ID、标题和 MyGo 视图函数;宿主决定注册哪些面板。示例中的 examples/demopanels 是一个独立的面板包。

发布后可在应用模块中安装:

go get github.com/Dormxb/docking-mygo@v0.1.0

导入包:

import docking "github.com/Dormxb/docking-mygo"
type App struct {
    dock docking.Workspace
    notes string // 面板自己的状态放在提供者中
}

func (a *App) init() error {
    return a.dock.Register(docking.Panel{
        ID: "notes",
        Title: "Notes",
        Content: func(c *ui.Context) {
            ui.TextArea(c, &a.notes).Fill()
        },
    }, docking.Left)
}

func (a *App) view(c *ui.Context) {
    a.dock.View(c, func(c *ui.Context) {
        ui.Text(c, "Main content")
    })
}

创建 MyGo 窗口后,将其连接到工作区:

win := mygo.NewWindow(mygo.WindowOptions{Content: ui.View(a.view)})
if err := a.dock.AttachWindow(win); err != nil {
    log.Fatal(err)
}

AttachWindow 必须在打开浮动面板之前调用。可运行的完整示例见 examples/minimal。

通过 Dock、Float、Close、Show 可以编程控制已注册面板,SetAutoHide(id, true/false) 控制边缘自动收起,Visible、AutoHidden 和 LocationOf 可以读取状态。Close 隐藏面板而不注销;自动收起的面板仍算可见。关闭并重新显示保留自动收起设置;移动到其他边缘或浮动会恢复普通停靠状态。组件及其状态应在 MyGo 窗口的主线程使用;从后台任务调用时用 Window.Update 切回主线程,保证窗口重绘。一个 Workspace 对应一个视图,不要同时挂到多个窗口。

面板切换位置或隐藏时,MyGo 可能卸载并重新构建对应 UI 元素。需要保留的数据应由面板提供者持有,不应保存 ui.Element 或依赖元素局部状态跨位置保留。

当前范围

  • 四个工作区边缘停靠;同一边缘的多个面板以标签切换。
  • 面板按需收起到四边标签,悬停或点击展开,可重新固定。
  • 独立的浮动子窗口,可拖出主窗口、拖回停靠、调整大小、关闭和恢复。
  • 拖动停靠预览,以及鼠标和键盘操作的停靠区分隔线。
  • 面板内容通过 Go 视图函数扩展,跟随当前 MyGo 主题。

当前仅支持在所属主窗口与其浮动窗口之间移动面板;尚未实现布局持久化、嵌套分组或跨不同工作区拖放。面板包在编译时由应用导入,尚不支持运行时加载第三方二进制插件。组件本身使用 MyGo 绘制,不嵌入 Asuka 的系统原生控件。

独立窗口、边缘收起和四边重新停靠已在 Windows 上通过 MyGo 自动化及 CUA Driver 系统鼠标输入验证;macOS、Linux 和多显示器混合缩放尚未验证。系统窗口坐标及移动能力受窗口管理器影响,尤其需要另行验证 Wayland。

验证

go test ./...
go vet ./...
mygo vet
# Windows:启动隔离的桌面进程并验证独立窗口与四边停靠
go test -tags docking_e2e ./e2e

Windows GUI 测试需要交互式桌面会话;仓库的 GitHub Actions 工作流运行常规测试、静态检查和示例构建。

许可证

本项目使用 MIT License。

Documentation

Overview

Package docking provides an embeddable docking workspace for MyGo native UI.

Panels are ordinary Go views, so applications can put them in independent packages and register only the ones they need. A Workspace belongs to one MyGo view and must be used on that view's main thread.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Location

type Location uint8

Location is where a panel is shown in a workspace.

const (
	Left Location = iota + 1
	Right
	Top
	Bottom
	Floating
)

type Panel

type Panel struct {
	ID      string
	Title   string
	Content func(*ui.Context)
}

Panel describes an independently supplied view. Its ID must be unique and stable within a workspace. Content is called in the current MyGo build pass. State which must survive docking belongs to the provider, not ui.Element.

type Workspace

type Workspace struct {
	// contains filtered or unexported fields
}

Workspace manages panels in one view. Its zero value is ready to use. A Workspace should not be used simultaneously in multiple windows.

func (*Workspace) AttachWindow

func (w *Workspace) AttachWindow(window *mygo.Window) error

AttachWindow connects the workspace to its owning window. Call it on the main thread after creating the window and before floating a panel. Its independent child windows close with the owner.

func (*Workspace) AutoHidden

func (w *Workspace) AutoHidden(id string) bool

AutoHidden reports whether a panel is assigned to an auto-hide rail.

func (*Workspace) Close

func (w *Workspace) Close(id string) error

Close hides a panel without destroying its provider's state.

func (*Workspace) Dock

func (w *Workspace) Dock(id string, edge Location) error

Dock moves a registered panel to an edge and shows it.

func (*Workspace) Float

func (w *Workspace) Float(id string) error

Float shows a registered panel in an independent child window. AttachWindow must be called before opening an independent window.

func (*Workspace) LocationOf

func (w *Workspace) LocationOf(id string) (Location, bool)

LocationOf returns the panel's last location, including when it is closed.

func (*Workspace) Register

func (w *Workspace) Register(p Panel, at Location) error

Register adds a panel at its initial location. A panel's ID and content are required; attempting to register the same ID twice returns an error.

func (*Workspace) SetAutoHide

func (w *Workspace) SetAutoHide(id string, enabled bool) error

SetAutoHide moves a docked panel to or from its edge's auto-hide rail. Closing and showing a panel preserves this setting. Floating panels must be docked before they can be auto-hidden.

func (*Workspace) Show

func (w *Workspace) Show(id string) error

Show reveals a panel at its last location and makes it active.

func (*Workspace) View

func (w *Workspace) View(c *ui.Context, central func(*ui.Context))

View draws the workspace and the application's central content. Embed it in a MyGo view; it fills the space its parent gives it. Panel and central callbacks should build their contents within the current parent.

func (*Workspace) Visible

func (w *Workspace) Visible(id string) bool

Visible reports whether a registered panel is shown.

Directories

Path Synopsis
cmd
demo command
examples
demopanels
Package demopanels is an example of panels supplied by another Go package.
Package demopanels is an example of panels supplied by another Go package.
minimal command
Package main demonstrates embedding a workspace with one independent panel.
Package main demonstrates embedding a workspace with one independent panel.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL