graph

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package graph provides a scene-graph editing framework.

It implements a model for interactive graphical editing with items, scenes, tools, selections, undo/redo, and coordinate transformations.

Key types:

  • Item/IItem: base graph item with bounds, parent-child hierarchy
  • SceneItem: root container for graph items
  • GraphView: scrollable, zoomable view of a scene
  • Selection: multi-item selection with decoration handles
  • Tool/Part: input handling chain (select, move, resize, marquee)
  • UndoStack: command-based undo/redo

Index

Constants

View Source
const HANDLE_SIZE = 3.2

Variables

This section is empty.

Functions

func AddMoveSubtree

func AddMoveSubtree(cmd *MoveCommand, item IItem, dx, dy float64)

AddMoveSubtree records item at its shifted position, plus every descendant that keeps its own scene coordinates. A container does not carry its children on its own — SetPos moves the one item and OnMove only re-lays it out — so a tree whose coordinates are absolute (ged never turns on local coords) would leave the children sitting where they were.

HasLocalCoord is the boundary: below such an item the children are stored relative to it and already ride along, so descending past it would move them a second time.

A descendant rides along whatever its own IsLockPos says: the lock pins a widget inside its container, and moving the container is not a request to rearrange what is in it. Only the selected item's own lock, tested by the caller, keeps a move out.

Exported for the callers that build their own MoveCommand because each item has its own target rather than one shared delta — ged's multi-item align.

func HandleIcon

func HandleIcon(shape int, active bool) paint.Icon

func KeepAspect

func KeepAspect(x0, y0, x1, y1 float64, x2, y2 *float64)

func LoadIcon

func LoadIcon(s string) paint.Icon

func ParentOrigin

func ParentOrigin(parent IItem) (ox, oy float64)

ParentOrigin returns, in scene coordinates, the origin of the coordinate space `parent` gives its children — i.e. exactly what CoordOffset() reports for every child of `parent`. A nil parent means the scene origin.

It mirrors the recurrence in Item.CoordOffset: only a parent that opts into local coordinates (HasLocalCoord) shifts its children by its own position; a parent without them hands its children the space it lives in, unchanged.

func ShiftSubtree

func ShiftSubtree(item IItem, dx, dy float64)

ShiftSubtree moves item by (dx, dy) right now, carrying exactly the descendants AddMoveSubtree would have recorded. It is for the corrections that are applied outside the undo stack — ged's post-drag grid snap tidies the resting place of a move that is already committed — which still have to take the subtree with them.

func TranslateBetweenParents

func TranslateBetweenParents(from, to IItem, x, y float64) (x1, y1 float64)

TranslateBetweenParents maps (x, y) — a position expressed in `from`'s child coordinate space — into `to`'s child coordinate space so the point keeps its scene position. It is the whole coordinate rule of a re-parent: changing an item's owner must not move it on screen.

The delta is zero whenever both parents hand their children the same space, which is the case for every parent that does not set HasLocalCoord.

func TraversalCond_Selectable

func TraversalCond_Selectable(p IItem) (self, descendants bool)

func TraversalCond_SelectableAndMoveable

func TraversalCond_SelectableAndMoveable(p IItem) (self, descendants bool)

Types

type AddCommand

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

func NewAddCommand

func NewAddCommand() *AddCommand

func (*AddCommand) AddItem

func (cmd *AddCommand) AddItem(item, parent IItem)

func (*AddCommand) Count

func (cmd *AddCommand) Count() int

func (*AddCommand) Redo

func (cmd *AddCommand) Redo()

func (*AddCommand) Text

func (cmd *AddCommand) Text() string

func (*AddCommand) Undo

func (cmd *AddCommand) Undo()

type ArrowTool

type ArrowTool struct {
	Tool
}

func (*ArrowTool) Init

func (this *ArrowTool) Init(tool ITool)

type DbgTreeModel

type DbgTreeModel struct {
	gui.GuiModel
	// contains filtered or unexported fields
}

/////////////////////////////////////////////////////////

func NewDbgTreeModel

func NewDbgTreeModel() *DbgTreeModel

func (*DbgTreeModel) ColCount

func (m *DbgTreeModel) ColCount() int

指定节点下的子结点的列数

func (*DbgTreeModel) Data

func (m *DbgTreeModel) Data(idx gui.ModelIndex, role gui.ItemDataRole) interface{}

获取单元格数据

func (*DbgTreeModel) Flags

func (m *DbgTreeModel) Flags(idx gui.ModelIndex) gui.ItemFlags

子节点的属性标记, 例如是否可选

func (*DbgTreeModel) HeaderData

func (m *DbgTreeModel) HeaderData(section int, vertical bool, role gui.ItemDataRole) interface{}

func (*DbgTreeModel) Index

func (m *DbgTreeModel) Index(row, col int, parent gui.ModelIndex) gui.ModelIndex

获取parent下第row行col列的索引

func (*DbgTreeModel) Parent

func (m *DbgTreeModel) Parent(idx gui.ModelIndex) gui.ModelIndex

获取父节点的索引

func (*DbgTreeModel) RowCount

func (m *DbgTreeModel) RowCount(parent gui.ModelIndex) int

指定节点下子结点的行数

func (*DbgTreeModel) SetRootItems

func (m *DbgTreeModel) SetRootItems(items []IItem)

type DbgTreeView

type DbgTreeView struct {
	gui.TreeView
}

func NewDbgTreeView

func NewDbgTreeView() *DbgTreeView

func (*DbgTreeView) DbgTreeModel

func (this *DbgTreeView) DbgTreeModel() *DbgTreeModel

func (*DbgTreeView) Init

func (this *DbgTreeView) Init(iw gui.IWidget)

func (*DbgTreeView) SetRootItems

func (this *DbgTreeView) SetRootItems(items []IItem)

type Decor

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

func (*Decor) ActiveHandle

func (this *Decor) ActiveHandle() int

func (*Decor) DrawDefaultHandle

func (this *Decor) DrawDefaultHandle(g paint.Painter, x, y float64, shape int, active bool)

func (*Decor) HandleAt

func (this *Decor) HandleAt(x, y float64) int

func (*Decor) HandleCursor

func (this *Decor) HandleCursor(handle int) *gui.Cursor

func (*Decor) HandleSize

func (this *Decor) HandleSize() float64

func (*Decor) HoverHandle

func (this *Decor) HoverHandle() int

func (*Decor) Init

func (this *Decor) Init(self IDecor)

func (*Decor) IsHitCircleHandle

func (this *Decor) IsHitCircleHandle(xc, yc, x, y float64) bool

func (*Decor) IsHitCircleHandle1

func (this *Decor) IsHitCircleHandle1(xc, yc, r, x, y float64) bool

func (*Decor) IsHitDiamonHandle

func (this *Decor) IsHitDiamonHandle(xc, yc, x, y float64) bool

func (*Decor) IsHitDiamonHandle1

func (this *Decor) IsHitDiamonHandle1(xc, yc, r, x, y float64) bool

func (*Decor) IsHitRectHandle

func (this *Decor) IsHitRectHandle(xc, yc, x, y float64) bool

func (*Decor) IsHitRectHandle1

func (this *Decor) IsHitRectHandle1(xc, yc, r, x, y float64) bool

func (*Decor) IsMovingHandle

func (this *Decor) IsMovingHandle() bool

func (*Decor) Item

func (this *Decor) Item() IItem

func (*Decor) NakedDecor

func (this *Decor) NakedDecor() *Decor

func (*Decor) OnBeginMoveHandle

func (this *Decor) OnBeginMoveHandle(handle int, x, y float64)

func (*Decor) OnClickHandle

func (this *Decor) OnClickHandle(handle int, x, y float64)

func (*Decor) OnDraw

func (this *Decor) OnDraw(g paint.Painter)

func (*Decor) OnEndMoveHandle

func (this *Decor) OnEndMoveHandle(handle int, x, y float64)

func (*Decor) OnMoveHandle

func (this *Decor) OnMoveHandle(handle int, x, y float64)

func (*Decor) Scene

func (this *Decor) Scene() IScene

func (*Decor) SetActiveHandle

func (this *Decor) SetActiveHandle(n int)

func (*Decor) SetMovingHandle

func (this *Decor) SetMovingHandle(b bool)

func (*Decor) Update

func (this *Decor) Update()

func (*Decor) View

func (this *Decor) View() IView

type DecorPart

type DecorPart struct {
	Part
	// contains filtered or unexported fields
}

func NewDecorPart

func NewDecorPart() *DecorPart

func (*DecorPart) HandleSize

func (this *DecorPart) HandleSize() float64

func (*DecorPart) MapToDecor

func (this *DecorPart) MapToDecor(x, y float64) (x1, y1 float64)

func (*DecorPart) OnLeftDown

func (this *DecorPart) OnLeftDown(x, y float64)

func (*DecorPart) OnLeftDragStart

func (this *DecorPart) OnLeftDragStart(x, y float64)

func (*DecorPart) OnLeftUp

func (this *DecorPart) OnLeftUp(x, y float64)

func (*DecorPart) OnMouseMove

func (this *DecorPart) OnMouseMove(x, y float64)

type DeleteCommand

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

DeleteCommand is the undoable mirror image of AddCommand: where AddCommand attaches items on Redo and detaches them on Undo, DeleteCommand detaches on Redo and re-attaches on Undo. It exists so the designer's "Delete" drops a selection without data loss — Ctrl+Z brings every removed widget back at its original parent and z-order slot instead of losing it.

Add() records only the item; the parent and index are snapshotted in Redo() (the pre-applied → applied transition PushCommand's Push() drives), exactly like ged's zorderCommand snapshots oldIdx there. Capturing at detach time — not in Add() — is what makes the reverse-order restore in Undo() correct for a multi-item batch: detaching at live indices i0,i1,… and re-inserting at those same indices in reverse inverts the whole sequence (the undo of a;b;c is c⁻¹;b⁻¹;a⁻¹), so even deleting every child of a parent restores their order. Like AddCommand it is built in the pre-applied state and Push() calls Redo() to apply it; the isUndo guard panics on out-of-order calls.

func NewDeleteCommand

func NewDeleteCommand(label string) *DeleteCommand

NewDeleteCommand returns an empty command. label is shown by Text().

func (*DeleteCommand) Add

func (cmd *DeleteCommand) Add(item IItem)

Add records that item is to be deleted. Call it before the command is applied (the pre-applied state PushCommand expects); the item's parent and index are captured later, in Redo(), against the live tree.

func (*DeleteCommand) Count

func (cmd *DeleteCommand) Count() int

Count returns the number of items the command deletes.

func (*DeleteCommand) Redo

func (cmd *DeleteCommand) Redo()

func (*DeleteCommand) Text

func (cmd *DeleteCommand) Text() string

func (*DeleteCommand) Undo

func (cmd *DeleteCommand) Undo()

type GraphView

type GraphView struct {
	gui.ScrollArea
	// contains filtered or unexported fields
}

func NewView

func NewView() *GraphView

func (*GraphView) Actions

func (this *GraphView) Actions() (ret []gui.IAction)

func (*GraphView) ActiveTool

func (this *GraphView) ActiveTool() ITool

func (*GraphView) AddAction

func (this *GraphView) AddAction(a gui.IAction)

func (*GraphView) AddStandardTools

func (this *GraphView) AddStandardTools()

func (*GraphView) AddTool

func (this *GraphView) AddTool(tool ...ITool)

func (*GraphView) DefaultTool

func (this *GraphView) DefaultTool() ITool

func (*GraphView) DirtyList

func (this *GraphView) DirtyList() []string

func (*GraphView) Draw

func (this *GraphView) Draw(g paint.Painter)

func (*GraphView) FindHandleAt

func (this *GraphView) FindHandleAt(xMm, yMm float64) (decor IDecor, handle int)

func (*GraphView) GetPropertyView

func (this *GraphView) GetPropertyView() prop.IPropertyView

func (*GraphView) Icon

func (this *GraphView) Icon() paint.Icon

func (*GraphView) Init

func (this *GraphView) Init(iw gui.IWidget)

func (*GraphView) IsItemSelected

func (this *GraphView) IsItemSelected(a IItem) bool

func (*GraphView) IsPageMarginVisible

func (this *GraphView) IsPageMarginVisible() bool

IsPageMarginVisible reports whether the page margin is part of the page. Subclasses that paint their own page-sized overlay need it to size that overlay exactly like Draw sizes the page.

func (*GraphView) Layout

func (this *GraphView) Layout()

func (*GraphView) MapFromScene

func (this *GraphView) MapFromScene(x, y float64) (x1, y1 float64)

从场景坐标转到视图坐标 注: 视图坐标等同于Widget坐标, 不随滚动条变化

func (*GraphView) MapRectFromScene

func (this *GraphView) MapRectFromScene(x, y, w, h float64) (x1, y1, w1, h1 float64)

从场景坐标转到视图坐标 注: 视图坐标等同于Widget坐标, 不随滚动条变化

func (*GraphView) MapRectFromScene1

func (this *GraphView) MapRectFromScene1(rect geom.Rect) geom.Rect

func (*GraphView) MapRectToScene

func (this *GraphView) MapRectToScene(x, y, w, h float64) (x1, y1, w1, h1 float64)

注: 视图坐标等同于Widget坐标, 不随滚动条变化

func (*GraphView) MapRectToScene1

func (this *GraphView) MapRectToScene1(rect geom.Rect) geom.Rect

func (*GraphView) MapToScene

func (this *GraphView) MapToScene(x, y float64) (x1, y1 float64)

从视图坐标转到场景坐标. 注: 视图坐标等同于Widget坐标, 不随滚动条变化

func (*GraphView) OnHorzScroll

func (this *GraphView) OnHorzScroll(sender gui.IWidget)

func (*GraphView) OnIdle

func (this *GraphView) OnIdle()

func (*GraphView) OnLeftDown

func (this *GraphView) OnLeftDown(x, y float64)

func (*GraphView) OnLeftUp

func (this *GraphView) OnLeftUp(x, y float64)

func (*GraphView) OnMouseMove

func (this *GraphView) OnMouseMove(x, y float64)

func (*GraphView) OnMouseWheel

func (this *GraphView) OnMouseWheel(x, y, z float64)

func (*GraphView) OnVertScroll

func (this *GraphView) OnVertScroll(sender gui.IWidget)

func (*GraphView) PaddingPx

func (this *GraphView) PaddingPx() (left, right, top, bottom float64)

获取页面和窗口边界之间的最小填充距离, 像素. 注: 这个函数获取的只是最小填充距离, 由于有布局的影响, 实际填充距离可能和这个值不符.

func (*GraphView) PageLayout

func (this *GraphView) PageLayout() PageLayout

func (*GraphView) PageOriginPx

func (this *GraphView) PageOriginPx() (x0, y0 float64)

获取页面左上角相对于像素原点的偏移量 注: 页面通常不紧贴着视图边界, 这个值可能随着视图的缩放而变化

func (*GraphView) PageSizeMm

func (this *GraphView) PageSizeMm(includeMargin bool) (width, height float64)

func (*GraphView) PageSizePx

func (this *GraphView) PageSizePx(includeMargin bool, zoom float64) (width, height float64)

func (*GraphView) PropertyConfigName

func (this *GraphView) PropertyConfigName() (cfgName string)

func (*GraphView) Save

func (this *GraphView) Save() bool

func (*GraphView) Scene

func (this *GraphView) Scene() IScene

func (*GraphView) SceneOriginPx

func (this *GraphView) SceneOriginPx() (x0, y0 float64)

获取场景左上角相对于像素原点的偏移量

func (*GraphView) SceneSizeMm

func (this *GraphView) SceneSizeMm() (width, height float64)

func (*GraphView) ScrollSizePx

func (this *GraphView) ScrollSizePx() (width, height float64)

func (*GraphView) Selection

func (this *GraphView) Selection() *Selection

func (*GraphView) SetActiveTool

func (this *GraphView) SetActiveTool(tool ITool)

func (*GraphView) SetDefaultTool

func (this *GraphView) SetDefaultTool(tool ITool)

func (*GraphView) SetPaddingMm

func (this *GraphView) SetPaddingMm(left, right, top, bottom float64)

func (*GraphView) SetPaddingPx

func (this *GraphView) SetPaddingPx(left, right, top, bottom float64)

设置页面和窗口边界之间的最小填充距离, 像素坐标, 不足1像素按1像素计算.

func (*GraphView) SetPageLayout

func (this *GraphView) SetPageLayout(mode PageLayout)

func (*GraphView) SetPageMarginVisible

func (this *GraphView) SetPageMarginVisible(b bool)

func (*GraphView) SetPropertyConfigName

func (this *GraphView) SetPropertyConfigName(cfgName string)

func (*GraphView) SetPropertyView

func (this *GraphView) SetPropertyView(propView prop.IPropertyView)

func (*GraphView) SetScene

func (this *GraphView) SetScene(scene IScene)

func (*GraphView) SetZoomFactor

func (this *GraphView) SetZoomFactor(z float64)

func (*GraphView) SigGenDecors

func (this *GraphView) SigGenDecors(fn func(s interface{}, item IItem) []IDecor)

func (*GraphView) SigItemAttached

func (this *GraphView) SigItemAttached(fn func(s interface{}, item, parent IItem))

func (*GraphView) SigItemDeselected

func (this *GraphView) SigItemDeselected(fn func(s interface{}, item IItem))

func (*GraphView) SigItemDetached

func (this *GraphView) SigItemDetached(fn func(s interface{}, item, parent IItem))

func (*GraphView) SigItemSelected

func (this *GraphView) SigItemSelected(fn func(s interface{}, item IItem))

func (*GraphView) SigSelectionChanged

func (this *GraphView) SigSelectionChanged(fn func(s interface{}, selection *Selection))

func (*GraphView) SigZoomChanged

func (this *GraphView) SigZoomChanged(fn func(s interface{}, zoom float64))

SigZoomChanged registers a callback fired whenever the view's zoom factor moves to a new value. Fires after Layout, so observers see the new zoom AND a re-laid-out viewport. Used by silkide to keep the status-bar zoom % cell synced with Ctrl+wheel zoom — without the signal, only the keyboard shortcuts would update the cell and wheel-driven zoom would silently desync the indicator.

func (*GraphView) Title

func (this *GraphView) Title() string

func (*GraphView) Tools

func (this *GraphView) Tools() []ITool

func (*GraphView) ZoomFactor

func (this *GraphView) ZoomFactor() float64

type IDecor

type IDecor interface {
	HandleAt(x, y float64) int
	HandleCursor(handle int) *gui.Cursor
	OnDraw(g paint.Painter)

	NakedDecor() *Decor

	Item() IItem
	View() IView
	// contains filtered or unexported methods
}

type IItem

type IItem interface {
	Self() IItem
	NakedItem() *Item

	Parent() IItem
	SetParent(a IItem)
	// SetParentAt re-parents this item and inserts it at a specific index
	// among the new parent's children (Children() order). It lets undo/redo
	// restore an item to the exact slot it held before a move; plain
	// SetParent always tail-inserts and so loses that position. index == -1
	// appends (identical to SetParent).
	SetParentAt(a IItem, index int)
	Root() IItem
	Scene() IScene

	DrawAll(g paint.Painter)
	DrawSelf(g paint.Painter)
	DrawOutline(g paint.Painter)
	DrawChildren(g paint.Painter)

	X() float64
	Y() float64
	Width() float64
	Height() float64

	SetX(x float64)
	SetY(y float64)
	SetWidth(w float64)
	SetHeight(h float64)

	Pos() (x, y float64)
	SetPos(x, y float64)
	Size() (width, height float64)
	SetSize(width, height float64)
	Bounds() (x, y, width, height float64)
	Bounds1() geom.Rect
	SetBounds1(geom.Rect)
	SetBounds(x, y, width, height float64)

	EaveBounds() (x, y, width, height float64)
	EaveBounds1() geom.Rect

	IsVisible() bool
	SetVisible(bool)

	IsSelectable() bool
	SetSelectable(b bool)

	IsLockPos() bool
	SetLockPos(b bool)

	IsLockSize() bool
	SetLockSize(b bool)

	Show()
	Hide()

	HasLocalCoord() bool
	SetLocalCoord(bool)

	HasChildren() bool
	Children() []IItem

	// slow
	IndexInParent() int

	IsHitBody(x, y float64) bool
	MaybeHitBody(x, y float64) bool

	// 从子树中查找指定坐标处第一个满足指定条件的图元.
	// 如果未指定条件, 则默认使用 TraversalCond_Selectable.
	// 如果有多个图元满足要求, 则上层图元优先.
	// 此方法通常用来实现点选/拖放等鼠标操作
	FindItemAt(x, y float64, cond TraversalCond) IItem

	// 从子树中查找指定坐标处所有满足指定条件的图元.
	// 如果未指定条件, 则默认使用 TraversalCond_Selectable.
	// 返回结果中上层图元排在前面, 和绘图顺序相反
	FindItemsAt(x, y float64, cond TraversalCond) []IItem

	// 从子树中查找指定矩形内所有满足指定条件的图元.
	// 如果未指定条件, 则默认使用 TraversalCond_Selectable.
	// 如果allIntersected为true, 则返回结果中也包含部分相交的图元
	// 返回结果中上层图元排在前面, 和绘图顺序相反
	// 相交/包含检测仅考虑图元的边框, 不考虑内部形状.
	FindItemsInRectF(x, y, width, height float64, cond TraversalCond) []IItem
	FindItemsInRect(bounds geom.Rect, cond TraversalCond) []IItem

	// 获取从ancestor到当前结点的路径中的全部结点,
	// 如果路径存在, 则返回值不为空, 且ancestor在最前, 当前节点在最后.
	// 如果路径不存在, 则返回值为nil
	Path(ancestor IItem) []IItem

	Update()

	// 获取以当前节点为根的整棵子树的全部结点.
	// 返回的结点的排列顺序和绘图顺序相同(Pre-Order遍历)
	TreeItems() []IItem

	MapToChild(x, y float64) (x1, y1 float64)
	MapFromChild(x, y float64) (x1, y1 float64)
	MapToScene(x, y float64) (x1, y1 float64)
	MapFromScene(x, y float64) (x1, y1 float64)
	MapToItem(a IItem, x, y float64) (x1, y1 float64)
	MapFromItem(a IItem, x, y float64) (x1, y1 float64)

	MapRectToChild(x, y, width, height float64) (x1, y1, width1, height1 float64)
	MapRectFromChild(x, y, width, height float64) (x1, y1, width1, height1 float64)
	MapRectToScene(x, y, width, height float64) (x1, y1, width1, height1 float64)
	MapRectFromScene(x, y, width, height float64) (x1, y1, width1, height1 float64)
	MapRectToItem(a IItem, x, y, width, height float64) (x1, y1, width1, height1 float64)
	MapRectFromItem(a IItem, x, y, width, height float64) (x1, y1, width1, height1 float64)

	MapRectToChild1(rect geom.Rect) geom.Rect
	MapRectFromChild1(rect geom.Rect) geom.Rect
	MapRectToScene1(rect geom.Rect) geom.Rect
	MapRectFromScene1(rect geom.Rect) geom.Rect
	MapRectToItem1(a IItem, rect geom.Rect) geom.Rect
	MapRectFromItem1(a IItem, rect geom.Rect) geom.Rect

	CoordOffset() (dx, dy float64)

	GenDecors() []IDecor

	Icon() paint.Icon

	String() string

	Title() string

	// 获取字符串形式表示的从ancestor到当前结点的路径,
	// 此函数返回的值只用作调试信息
	DebugPathString(ancestor IItem) string
	DebugLabel() string
	DebugFlagsString() (ret string)

	//OnResize()
	Layout()
	SizeHints() gui.SizeHints

	Detach()

	// 调整此图元在兄弟图元中的堆叠顺序. 队首图元最先绘制(在最底层),
	// 队尾图元最后绘制(在最上层).
	Raise()
	Lower()
	BringToFront()
	SendToBack()
}

type IPart

type IPart interface {
}

type IScene

type IScene interface {
	IItem

	NakedScene() *SceneItem

	View() IView

	UndoStack() gui.IUndoStack

	SigItemAttached(func(s interface{}, item, parent IItem))
	SigItemDetached(func(s interface{}, item, parent IItem))

	SetPropertyConfigName(cfgName string)
	PropertyConfigName() (cfgName string)

	DirtyList() []string
	Save() bool

	PushCommand(cmd gui.ICommand)

	SetTitle(s string)

	IsClean() bool
}

type ITool

type ITool interface {
	Self() ITool
	Action() gui.IAction

	Text() string
	SetText(text string)
	Icon() paint.Icon
	SetIcon(icon paint.Icon)
	Name() string
	SetName(name string)
	IsEnabled() bool
	SetEnabled(b bool)
	IsActive() bool

	Activate()

	OnDraw(g paint.Painter)

	OnLeftDown(x, y float64)
	OnLeftUp(x, y float64)
	OnMouseMove(x, y float64)
	OnLeftClick(x, y float64)
	OnLeftDragStart(x, y float64)
	// contains filtered or unexported methods
}

func NewArrowTool

func NewArrowTool() ITool

func NewRectTool

func NewRectTool() ITool

type IView

type IView interface {
	gui.IWidget
	Scene() IScene
	Selection() *Selection

	AddTool(tool ...ITool)
	Tools() []ITool
	SetActiveTool(tool ITool)
	SetDefaultTool(tool ITool)
	DefaultTool() ITool
	ActiveTool() ITool

	SetScene(IScene)

	// 判断图元是否在当前视图中被选中
	IsItemSelected(IItem) bool

	// 从视图坐标转到场景坐标.
	// 注: 视图坐标等同于Widget坐标, 不随滚动条变化
	MapToScene(x, y float64) (x1, y1 float64)

	// 从场景坐标转到视图坐标
	// 注: 视图坐标等同于Widget坐标, 不随滚动条变化
	MapFromScene(x, y float64) (x1, y1 float64)

	// 从视图坐标转到场景坐标.
	// 注: 视图坐标等同于Widget坐标, 不随滚动条变化
	MapRectToScene(x, y, w, h float64) (x1, y1, w1, h1 float64)

	// 从场景坐标转到视图坐标
	// 注: 视图坐标等同于Widget坐标, 不随滚动条变化
	MapRectFromScene(x, y, w, h float64) (x1, y1, w1, h1 float64)

	MapRectToScene1(rect geom.Rect) geom.Rect
	MapRectFromScene1(rect geom.Rect) geom.Rect

	ZoomFactor() float64

	SigItemSelected(func(s interface{}, item IItem))
	SigItemDeselected(func(s interface{}, item IItem))
	SigItemAttached(func(s interface{}, item, parent IItem))
	SigItemDetached(func(s interface{}, item, parent IItem))
	SigGenDecors(func(s interface{}, item IItem) []IDecor)
	SigSelectionChanged(func(s interface{}, selection *Selection))

	FindHandleAt(xMm, yMm float64) (decor IDecor, handle int)

	SetPropertyView(prop.IPropertyView)

	SetPropertyConfigName(cfgName string)
	PropertyConfigName() (cfgName string)

	// 布局, 一般由内部调用
	Layout()
	// contains filtered or unexported methods
}

type Item

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

func (*Item) Bounds

func (this *Item) Bounds() (x, y, width, height float64)

func (*Item) Bounds1

func (this *Item) Bounds1() geom.Rect

func (*Item) BringToFront

func (this *Item) BringToFront()

BringToFront moves this item in front of all its siblings.

func (*Item) Children

func (this *Item) Children() []IItem

func (*Item) CoordOffset

func (this *Item) CoordOffset() (dx, dy float64)

func (*Item) DebugFlagsString

func (this *Item) DebugFlagsString() (ret string)

func (*Item) DebugLabel

func (this *Item) DebugLabel() string

func (*Item) DebugPathString

func (this *Item) DebugPathString(ancestor IItem) string

func (*Item) Detach

func (this *Item) Detach()

func (*Item) DrawAll

func (this *Item) DrawAll(g paint.Painter)

func (*Item) DrawChildren

func (this *Item) DrawChildren(g paint.Painter)

func (*Item) DrawOutline

func (this *Item) DrawOutline(g paint.Painter)

func (*Item) DrawSelf

func (this *Item) DrawSelf(g paint.Painter)

func (*Item) EaveBounds

func (this *Item) EaveBounds() (x, y, width, height float64)

func (*Item) EaveBounds1

func (this *Item) EaveBounds1() geom.Rect

func (*Item) EnumProperties

func (this *Item) EnumProperties(list prop.IPropertyList)

func (*Item) FindItemAt

func (this *Item) FindItemAt(x, y float64, cond TraversalCond) IItem

func (*Item) FindItemsAt

func (this *Item) FindItemsAt(x, y float64, cond TraversalCond) []IItem

func (*Item) FindItemsInRect

func (this *Item) FindItemsInRect(bounds geom.Rect, cond TraversalCond) []IItem

func (*Item) FindItemsInRectF

func (this *Item) FindItemsInRectF(cx, cy, cw, ch float64, cond TraversalCond) []IItem

func (*Item) GenDecors

func (this *Item) GenDecors() []IDecor

func (*Item) HasChildren

func (this *Item) HasChildren() bool

func (*Item) HasLocalCoord

func (this *Item) HasLocalCoord() bool

func (*Item) Height

func (this *Item) Height() float64

func (*Item) Hide

func (this *Item) Hide()

func (*Item) Icon

func (this *Item) Icon() paint.Icon

func (*Item) IndexInParent

func (this *Item) IndexInParent() int

func (*Item) Init

func (this *Item) Init(ig IItem)

func (*Item) IsHitBody

func (this *Item) IsHitBody(x, y float64) bool

func (*Item) IsLockPos

func (this *Item) IsLockPos() bool

func (*Item) IsLockSize

func (this *Item) IsLockSize() bool

func (*Item) IsSelectable

func (this *Item) IsSelectable() bool

func (*Item) IsVisible

func (this *Item) IsVisible() bool

func (*Item) Layout

func (this *Item) Layout()

func (*Item) Lower

func (this *Item) Lower()

Lower moves this item one step toward the back (drawn earlier).

func (*Item) MapFromChild

func (this *Item) MapFromChild(x, y float64) (x1, y1 float64)

func (*Item) MapFromItem

func (this *Item) MapFromItem(a IItem, x, y float64) (x1, y1 float64)

func (*Item) MapFromScene

func (this *Item) MapFromScene(x, y float64) (x1, y1 float64)

func (*Item) MapRectFromChild

func (this *Item) MapRectFromChild(x, y, width, height float64) (x1, y1, width1, height1 float64)

func (*Item) MapRectFromChild1

func (this *Item) MapRectFromChild1(rect geom.Rect) geom.Rect

func (*Item) MapRectFromItem

func (this *Item) MapRectFromItem(a IItem, x, y, width, height float64) (x1, y1, width1, height1 float64)

func (*Item) MapRectFromItem1

func (this *Item) MapRectFromItem1(a IItem, rect geom.Rect) geom.Rect

func (*Item) MapRectFromScene

func (this *Item) MapRectFromScene(x, y, width, height float64) (x1, y1, width1, height1 float64)

func (*Item) MapRectFromScene1

func (this *Item) MapRectFromScene1(rect geom.Rect) geom.Rect

func (*Item) MapRectToChild

func (this *Item) MapRectToChild(x, y, width, height float64) (x1, y1, width1, height1 float64)

func (*Item) MapRectToChild1

func (this *Item) MapRectToChild1(rect geom.Rect) geom.Rect

func (*Item) MapRectToItem

func (this *Item) MapRectToItem(a IItem, x, y, width, height float64) (x1, y1, width1, height1 float64)

func (*Item) MapRectToItem1

func (this *Item) MapRectToItem1(a IItem, rect geom.Rect) geom.Rect

func (*Item) MapRectToScene

func (this *Item) MapRectToScene(x, y, width, height float64) (x1, y1, width1, height1 float64)

func (*Item) MapRectToScene1

func (this *Item) MapRectToScene1(rect geom.Rect) geom.Rect

func (*Item) MapToChild

func (this *Item) MapToChild(x, y float64) (x1, y1 float64)

func (*Item) MapToItem

func (this *Item) MapToItem(a IItem, x, y float64) (x1, y1 float64)

func (*Item) MapToScene

func (this *Item) MapToScene(x, y float64) (x1, y1 float64)

func (*Item) MaybeHitBody

func (this *Item) MaybeHitBody(x, y float64) bool

func (*Item) NakedItem

func (this *Item) NakedItem() *Item

func (*Item) OnMove

func (this *Item) OnMove()

func (*Item) OnResize

func (this *Item) OnResize()

func (*Item) Parent

func (this *Item) Parent() IItem

func (*Item) Path

func (this *Item) Path(ancestor IItem) []IItem

func (*Item) Pos

func (this *Item) Pos() (x, y float64)

func (*Item) Raise

func (this *Item) Raise()

Raise moves this item one step toward the front (drawn later).

func (*Item) Root

func (this *Item) Root() IItem

func (*Item) Scene

func (this *Item) Scene() IScene

func (*Item) Self

func (this *Item) Self() IItem

func (*Item) SendToBack

func (this *Item) SendToBack()

SendToBack moves this item behind all its siblings.

func (*Item) SetBounds

func (this *Item) SetBounds(x, y, width, height float64)

func (*Item) SetBounds1

func (this *Item) SetBounds1(bounds geom.Rect)

func (*Item) SetHeight

func (this *Item) SetHeight(h float64)

func (*Item) SetLocalCoord

func (this *Item) SetLocalCoord(b bool)

func (*Item) SetLockPos

func (this *Item) SetLockPos(b bool)

func (*Item) SetLockSize

func (this *Item) SetLockSize(b bool)

func (*Item) SetParent

func (this *Item) SetParent(newParent IItem)

func (*Item) SetParentAt

func (this *Item) SetParentAt(newParent IItem, index int)

SetParentAt re-parents this item and inserts it at the given 0-based position among newParent's children, in the same head-first order that Children() and IndexInParent() use (head == index 0 == back / drawn first; tail == front). It exists so an undo can put an item back in the exact sibling slot it occupied before a move — plain SetParent always appends at the tail and so loses the original position.

index == -1 is the "append" sentinel and reproduces SetParent's tail insert; any other out-of-range value is clamped into [0, n] (n == current child count), so index >= n also appends and index < -1 inserts at the head. A nil newParent detaches (index ignored). Re-parenting to the current parent is a no-op — use Raise/Lower/BringToFront/SendToBack to reorder within a single parent.

func (*Item) SetPos

func (this *Item) SetPos(x, y float64)

func (*Item) SetSelectable

func (this *Item) SetSelectable(b bool)

func (*Item) SetSize

func (this *Item) SetSize(width, height float64)

func (*Item) SetVisible

func (this *Item) SetVisible(b bool)

func (*Item) SetWidth

func (this *Item) SetWidth(w float64)

func (*Item) SetX

func (this *Item) SetX(x float64)

func (*Item) SetY

func (this *Item) SetY(y float64)

func (*Item) Show

func (this *Item) Show()

func (*Item) Size

func (this *Item) Size() (width, height float64)

func (*Item) SizeHints

func (this *Item) SizeHints() gui.SizeHints

func (*Item) String

func (this *Item) String() string

func (*Item) Title

func (this *Item) Title() string

func (*Item) TreeItems

func (this *Item) TreeItems() []IItem

func (*Item) Update

func (this *Item) Update()

func (*Item) Width

func (this *Item) Width() float64

func (*Item) X

func (this *Item) X() float64

func (*Item) Y

func (this *Item) Y() float64

type MarqueePart

type MarqueePart struct {
	Part
	// contains filtered or unexported fields
}

func NewMarqueePart

func NewMarqueePart() *MarqueePart

func (*MarqueePart) OnDraw

func (this *MarqueePart) OnDraw(g paint.Painter)

func (*MarqueePart) OnLeftDragStart

func (this *MarqueePart) OnLeftDragStart(x, y float64)

func (*MarqueePart) OnLeftUp

func (this *MarqueePart) OnLeftUp(x, y float64)

func (*MarqueePart) OnMouseMove

func (this *MarqueePart) OnMouseMove(x, y float64)

type MoveCommand

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

func NewMoveCommand

func NewMoveCommand() *MoveCommand

func (*MoveCommand) AddItem

func (cmd *MoveCommand) AddItem(item IItem, toX, toY float64)

func (*MoveCommand) Count

func (cmd *MoveCommand) Count() int

func (*MoveCommand) MergeWidth

func (cmd *MoveCommand) MergeWidth(next gui.ICommand) bool

MergeWidth folds next into cmd so a held arrow key leaves one undo step instead of one per key repeat. gui.UndoStack.Push probes the command below the stack top for this exact — misspelled — method name and, when it returns true, redoes next without growing the stack.

cmd has already been redone, so its records hold the positions from before the gesture started, which is precisely what a later Undo must restore. Absorbing next is therefore a no-op on cmd's records. That only holds while cmd records every item next touches: an item moved by next but absent from cmd would keep no undo record at all, so such a list refuses the merge and lets the stack start a fresh step instead.

The test is containment, not equality. A later step in the same gesture may legitimately drive fewer items — ResizeCommand's generator drops an item once it reaches the size floor — and cmd still holds that item's pre-gesture state, so the burst stays one undo step. Both lists are built by walking the selection in order, so one pass over cmd's records decides it.

func (*MoveCommand) Redo

func (cmd *MoveCommand) Redo()

func (*MoveCommand) SetMergeToken

func (cmd *MoveCommand) SetMergeToken(token uint64)

SetMergeToken tags cmd as belonging to one continuous gesture, such as the burst of auto-repeat events a held arrow key produces. Commands sharing a non-zero token collapse into a single undo step; the zero default means "never merge", so a caller that does not opt in keeps one command per push.

func (*MoveCommand) Text

func (cmd *MoveCommand) Text() string

func (*MoveCommand) Undo

func (cmd *MoveCommand) Undo()

type MovePart

type MovePart struct {
	Part
	// contains filtered or unexported fields
}

func NewMovePart

func NewMovePart() *MovePart

func (*MovePart) OnDraw

func (this *MovePart) OnDraw(g paint.Painter)

func (*MovePart) OnLeftDragStart

func (this *MovePart) OnLeftDragStart(x, y float64)

func (*MovePart) OnLeftUp

func (this *MovePart) OnLeftUp(x, y float64)

func (*MovePart) OnMouseMove

func (this *MovePart) OnMouseMove(x, y float64)

type PageLayout

type PageLayout int
const (
	PL_FIT_WIDTH PageLayout = iota
	PL_FIT_HEIGHT
	PL_FIT_VIEW
	PL_FREE_ZOOM
)

func ParsePageLayout

func ParsePageLayout(s string) PageLayout

func (PageLayout) String

func (v PageLayout) String() string

type Part

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

func (*Part) Activate

func (this *Part) Activate() bool

func (*Part) CurrentPos

func (this *Part) CurrentPos() (x, y float64)

func (*Part) DownPos

func (this *Part) DownPos() (x, y float64)

func (*Part) Init

func (this *Part) Init(self IPart)

func (*Part) IsActive

func (this *Part) IsActive() bool

func (*Part) IsDraging

func (this *Part) IsDraging() bool

func (*Part) Scene

func (this *Part) Scene() IScene

func (*Part) Self

func (this *Part) Self() IPart

func (*Part) Tool

func (this *Part) Tool() ITool

func (*Part) TrackRect

func (this *Part) TrackRect() geom.Rect

func (*Part) View

func (this *Part) View() IView

type RectItem

type RectItem struct {
	Item
}

func NewRectItem

func NewRectItem() *RectItem

func (*RectItem) DrawSelf

func (this *RectItem) DrawSelf(g paint.Painter)

type RectPart

type RectPart struct {
	Part
	// contains filtered or unexported fields
}

func NewRectPart

func NewRectPart() *RectPart

func (*RectPart) OnDraw

func (this *RectPart) OnDraw(g paint.Painter)

func (*RectPart) OnLeftDragStart

func (this *RectPart) OnLeftDragStart(x, y float64)

func (*RectPart) OnLeftUp

func (this *RectPart) OnLeftUp(x, y float64)

func (*RectPart) OnMouseMove

func (this *RectPart) OnMouseMove(x, y float64)

type RectTool

type RectTool struct {
	Tool
}

func (*RectTool) Init

func (this *RectTool) Init(tool ITool)

type ReparentCommand

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

ReparentCommand is an undoable structural edit that moves a set of items between parents — the basis for the designer's "Lay Out" (wrap a selection in a new container) and "Break Layout" (dissolve a container) operations, both of which are pure reparenting once the container item exists.

Redo replays the moves in insertion order, tail-appending each item into its target (the operations' natural behaviour). Undo restores every item to its original parent AT ITS ORIGINAL INDEX (reparentRecord.fromIndex), so a Redo followed by an Undo returns the tree to byte-identical sibling order.

Undo does NOT simply walk the records in reverse: SetParentAt inserts at an absolute index, so items returning to the SAME parent must be reinserted in increasing fromIndex order (a lower slot must be filled before a higher one). Undo therefore stable-sorts the records by fromIndex before applying them. The relative order between DIFFERENT parents does not matter — inserting a child into a parent that has not been reattached yet is fine, because the child is carried along when that parent is itself restored — so a single global sort by fromIndex is enough and is robust to whatever order the caller recorded the moves in ("Lay Out" records in canvas-position order, not child order).

Like AddCommand, the command is built in the pre-applied state and PushCommand's Push() calls Redo() to apply it.

func NewReparentCommand

func NewReparentCommand(label string) *ReparentCommand

NewReparentCommand returns an empty command. label is shown by Text().

func (*ReparentCommand) Add

func (cmd *ReparentCommand) Add(item, from, to IItem)

Add records that `item` moves from `from` to `to` when the command is applied. Pass to=nil to detach, from=nil if the item had no parent before the command.

Add must be called before the command is applied (the pre-applied state, as PushCommand expects): it snapshots the item's current index via IndexInParent(), which at this point is its position inside `from`, so Undo can later restore that exact slot.

func (*ReparentCommand) AddMoved

func (cmd *ReparentCommand) AddMoved(item, from, to IItem, toX, toY float64)

AddMoved records a re-parent that also repositions the item: like Add, plus the item lands at (toX, toY) in `to`'s child coordinate space. Callers get (toX, toY) from TranslateBetweenParents so the item keeps its scene position across the move.

Undo restores the original position along with the original slot, so a re-parent that had to shift coordinates does not leave the item at the shifted position once it is back inside its old parent.

func (*ReparentCommand) Count

func (cmd *ReparentCommand) Count() int

Count returns the number of reparent records.

func (*ReparentCommand) Redo

func (cmd *ReparentCommand) Redo()

func (*ReparentCommand) Text

func (cmd *ReparentCommand) Text() string

func (*ReparentCommand) Undo

func (cmd *ReparentCommand) Undo()

type ResizeCommand

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

func NewResizeCommand

func NewResizeCommand() *ResizeCommand

func (*ResizeCommand) AddItem

func (cmd *ResizeCommand) AddItem(item IItem, rect geom.Rect)

func (*ResizeCommand) Count

func (cmd *ResizeCommand) Count() int

func (*ResizeCommand) MergeWidth

func (cmd *ResizeCommand) MergeWidth(next gui.ICommand) bool

MergeWidth folds next into cmd so a held Ctrl+arrow leaves one undo step instead of one per key repeat. Same contract and same reasoning as MoveCommand.MergeWidth — keep the two in step; only the record type differs.

func (*ResizeCommand) Redo

func (cmd *ResizeCommand) Redo()

func (*ResizeCommand) SetMergeToken

func (cmd *ResizeCommand) SetMergeToken(token uint64)

SetMergeToken tags cmd as belonging to one continuous gesture; see MoveCommand.SetMergeToken for the contract.

func (*ResizeCommand) Text

func (cmd *ResizeCommand) Text() string

func (*ResizeCommand) Undo

func (cmd *ResizeCommand) Undo()

type ResizeDecor

type ResizeDecor struct {
	Decor
	// contains filtered or unexported fields
}

func NewResizeDecor

func NewResizeDecor() *ResizeDecor

func (*ResizeDecor) HandleAt

func (this *ResizeDecor) HandleAt(x, y float64) int

func (*ResizeDecor) HandleCursor

func (this *ResizeDecor) HandleCursor(handle int) *gui.Cursor

func (*ResizeDecor) Init

func (this *ResizeDecor) Init(self IDecor)

func (*ResizeDecor) OnBeginMoveHandle

func (this *ResizeDecor) OnBeginMoveHandle(handle int, x, y float64)

func (*ResizeDecor) OnDraw

func (this *ResizeDecor) OnDraw(g paint.Painter)

func (*ResizeDecor) OnEndMoveHandle

func (this *ResizeDecor) OnEndMoveHandle(handle int, x, y float64)

func (*ResizeDecor) OnMoveHandle

func (this *ResizeDecor) OnMoveHandle(handle int, x, y float64)

type SameSizeMode

type SameSizeMode int

SameSizeMode selects which extents a same-size command copies from its reference item.

const (
	SameSizeWidth SameSizeMode = iota
	SameSizeHeight
	SameSizeBoth
)

type SceneItem

type SceneItem struct {
	Item
	// contains filtered or unexported fields
}

func (*SceneItem) DirtyList

func (this *SceneItem) DirtyList() []string

func (*SceneItem) Init

func (this *SceneItem) Init(i IItem)

func (*SceneItem) IsClean

func (this *SceneItem) IsClean() bool

func (*SceneItem) NakedScene

func (this *SceneItem) NakedScene() *SceneItem

func (*SceneItem) OnMove

func (this *SceneItem) OnMove()

func (*SceneItem) OnResize

func (this *SceneItem) OnResize()

func (*SceneItem) PropertyConfigName

func (this *SceneItem) PropertyConfigName() (cfgName string)

func (*SceneItem) PushCommand

func (this *SceneItem) PushCommand(cmd gui.ICommand)

PushCommand is the one door every design mutation goes through: it is the only place in the tree allowed to touch UndoStack().Push, so a scene that overrides it (ged.GedScene, which announces the change) sees every command. Pushing onto the stack directly from a tool or a view compiles and undoes correctly while leaving every listener showing the pre-edit design.

func (*SceneItem) Save

func (this *SceneItem) Save() bool

func (*SceneItem) SetPropertyConfigName

func (this *SceneItem) SetPropertyConfigName(cfgName string)

func (*SceneItem) SetTitle

func (this *SceneItem) SetTitle(t string)

func (*SceneItem) SigItemAttached

func (this *SceneItem) SigItemAttached(fn func(s interface{}, item, parent IItem))

func (*SceneItem) SigItemDetached

func (this *SceneItem) SigItemDetached(fn func(s interface{}, item, parent IItem))

func (*SceneItem) Title

func (this *SceneItem) Title() string

func (*SceneItem) UndoStack

func (this *SceneItem) UndoStack() gui.IUndoStack

func (*SceneItem) Update

func (this *SceneItem) Update()

func (*SceneItem) View

func (this *SceneItem) View() IView

type SelectNode

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

func (*SelectNode) OnDraw

func (p *SelectNode) OnDraw(g paint.Painter)

type SelectPart

type SelectPart struct {
	Part
	// contains filtered or unexported fields
}

func NewSelectPart

func NewSelectPart() *SelectPart

func (*SelectPart) OnLeftClick

func (this *SelectPart) OnLeftClick(x, y float64)

type Selection

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

func (*Selection) Add

func (s *Selection) Add(a IItem)

func (*Selection) AddMulti

func (s *Selection) AddMulti(v []IItem)

func (*Selection) Clear

func (s *Selection) Clear()

func (*Selection) Contains

func (s *Selection) Contains(a IItem) bool

func (*Selection) Count

func (s *Selection) Count() int

func (*Selection) DebugDump

func (s *Selection) DebugDump()

func (*Selection) FindHandleAt

func (s *Selection) FindHandleAt(xMm, yMm float64) (decor IDecor, handle int)

func (*Selection) GenerateMoveCommand

func (s *Selection) GenerateMoveCommand(dx, dy float64) *MoveCommand

func (*Selection) GenerateReparentCommand

func (s *Selection) GenerateReparentCommand(newParent IItem) *ReparentCommand

GenerateReparentCommand hands every selected item to newParent, keeping each item where it is on screen (TranslateBetweenParents), and returns one command whose Undo restores the original parent, sibling index and position. Returns nil when nothing would actually change, so a caller can forward that as a quiet no-op instead of pushing an empty command — same contract as GenerateMoveCommand.

Skipped, and why:

  • an item whose ancestor is also selected: the ancestor carries it along, exactly as GenerateMoveCommand skips it;
  • an IsLockPos item: a drag leaves it behind (GenerateMoveCommand skips it too), so handing it a new owner would split one gesture in two;
  • an item already parented to newParent: SetParentAt is a documented no-op for it, and recording no-ops would make Count() claim work that is not there;
  • a newParent inside the item's own subtree: SetParentAt has no cycle guard, and a cyclic child ring hangs every later traversal.

func (*Selection) GenerateResizeCommand

func (s *Selection) GenerateResizeCommand(dw, dh, minSize float64) *ResizeCommand

GenerateResizeCommand grows every selected item by (dw, dh) millimetres, anchored at each item's top-left corner and floored at minSize by resizeRectBy. Returns nil when nothing would actually change, so a caller can forward that as a quiet no-op instead of pushing an empty command.

Unlike the drag-handle path in ResizeDecor, an IsLockPos item is kept here: the top-left anchor means resizing never moves it, so a position lock has nothing to violate. Only IsLockSize opts an item out.

func (*Selection) GenerateSameSizeCommand

func (s *Selection) GenerateSameSizeCommand(mode SameSizeMode, minSize float64) *ResizeCommand

GenerateSameSizeCommand resizes every selected item onto the width and/or height of the LAST selected item, each item keeping its own X/Y. Add appends, so the last item is the one the designer picked most recently — the reference convention every form designer uses for "make same size".

Same exclusions and same nil contract as GenerateResizeCommand: a size-locked or ancestor-selected item is left out, and nothing left to do returns nil so the caller forwards a quiet no-op instead of pushing an empty command. The reference needs no special case — resizing it onto its own size is not a change, so the unchanged-rect filter drops it.

func (*Selection) Invert

func (s *Selection) Invert(a IItem)

func (*Selection) InvertMulti

func (s *Selection) InvertMulti(v []IItem)

func (*Selection) IsEmpty

func (s *Selection) IsEmpty() bool

func (*Selection) IsSingle

func (s *Selection) IsSingle() bool

func (*Selection) ItemList

func (s *Selection) ItemList() (ret []IItem)

func (*Selection) OnDraw

func (s *Selection) OnDraw(g paint.Painter)

func (*Selection) Remove

func (s *Selection) Remove(a IItem)

func (*Selection) RemoveMulti

func (s *Selection) RemoveMulti(v []IItem)

type Tool

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

func (*Tool) Action

func (this *Tool) Action() gui.IAction

func (*Tool) Activate

func (this *Tool) Activate()

func (*Tool) ActivePart

func (this *Tool) ActivePart() IPart

func (*Tool) AddPart

func (this *Tool) AddPart(part ...IPart)

func (*Tool) CurrentPos

func (this *Tool) CurrentPos() (x, y float64)

func (*Tool) DownPos

func (this *Tool) DownPos() (x, y float64)

func (*Tool) GraphView

func (this *Tool) GraphView() IView

func (*Tool) Icon

func (this *Tool) Icon() paint.Icon

func (*Tool) Init

func (this *Tool) Init(self ITool)

func (*Tool) IsActive

func (this *Tool) IsActive() bool

func (*Tool) IsEnabled

func (this *Tool) IsEnabled() bool

func (*Tool) Name

func (this *Tool) Name() string

func (*Tool) OnDraw

func (this *Tool) OnDraw(g paint.Painter)

func (*Tool) OnLeftClick

func (this *Tool) OnLeftClick(x, y float64)

func (*Tool) OnLeftDown

func (this *Tool) OnLeftDown(x, y float64)

func (*Tool) OnLeftDragStart

func (this *Tool) OnLeftDragStart(x, y float64)

func (*Tool) OnLeftUp

func (this *Tool) OnLeftUp(x, y float64)

func (*Tool) OnMouseMove

func (this *Tool) OnMouseMove(x, y float64)

func (*Tool) Scene

func (this *Tool) Scene() IScene

func (*Tool) Self

func (this *Tool) Self() ITool

func (*Tool) SetEnabled

func (this *Tool) SetEnabled(b bool)

func (*Tool) SetIcon

func (this *Tool) SetIcon(icon paint.Icon)

func (*Tool) SetIcon1

func (this *Tool) SetIcon1(s string)

func (*Tool) SetName

func (this *Tool) SetName(name string)

func (*Tool) SetText

func (this *Tool) SetText(text string)

func (*Tool) Text

func (this *Tool) Text() string

type TraversalCond

type TraversalCond func(IItem) (self, descendants bool)

图元树的遍历条件. 在绘图系统中, 查找/绘制/单选/框选等操作都涉及到图元的遍历, 相关的方法都接受一个TraversalCond参数, 用来筛选出满足条件的图元. TraversalCond需要提供两个返回值:

self : 当前结点是否满足要求
descendants : 是否需要遍历当前结点的子孙结点

Jump to

Keyboard shortcuts

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