gofer

package
v0.0.0-...-9bd7407 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2019 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Empty        = ' '
	TextPadRight = '›'
	TextPadLeft  = '‹'
)

Variables

This section is empty.

Functions

func BasicPoint

func BasicPoint(x, y int) *basicPoint

func GetMergeContent

func GetMergeContent(v View, from Point, to Point) [][]Rune

获取当前视图内一个区域的内容, 并转化子视图内容至当前视图内容中 约定, 父视图承诺处理好子视图左右边界上可能出现的 2倍宽字符 越界问题

func LogCrash

func LogCrash(str string)

func LogDebug

func LogDebug(str string)

func LogError

func LogError(str string)

func LogInfo

func LogInfo(str string)

func LogWarn

func LogWarn(str string)

func NewApp

func NewApp() *app

func NewRootView

func NewRootView() *rootView

func Receiver

func Receiver(v View) chan<- *UpdateUiMsg

func UpdateUI

func UpdateUI(v View, rect Rect)

向父视图发送更新UI的通知, Rect 坐标是基于当前视图的.

Types

type ApplicationDelegate

type ApplicationDelegate interface {
	Launched(root RootView)
	//返回值为是否继续执行退出
	WillStop(code int) bool
	//是否启用鼠标
	EnableMouse() bool
	//返回一个事件监听者
	EventListener() chan<- tcell.Event
}

type BasicRect

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

func BasicRectByPoint

func BasicRectByPoint(from, to Point) *BasicRect

func BasicRectByXY

func BasicRectByXY(x1, y1, x2, y2 int) *BasicRect

func (*BasicRect) ChangeBaseByPoint

func (r *BasicRect) ChangeBaseByPoint(base Point) (rn Rect)

func (*BasicRect) ChangeBaseByXY

func (r *BasicRect) ChangeBaseByXY(x, y int) (rn Rect)

func (*BasicRect) ContainPoint

func (r *BasicRect) ContainPoint(p Point) bool

func (*BasicRect) Copy

func (r *BasicRect) Copy() Rect

func (*BasicRect) From

func (r *BasicRect) From() Point

func (*BasicRect) Height

func (r *BasicRect) Height() int

func (*BasicRect) IntersectWith

func (r *BasicRect) IntersectWith(r1 Rect) bool

func (*BasicRect) SetFrom

func (r *BasicRect) SetFrom(from Point)

func (*BasicRect) SetHeight

func (r *BasicRect) SetHeight(h int)

func (*BasicRect) SetTo

func (r *BasicRect) SetTo(to Point)

func (*BasicRect) SetWidth

func (r *BasicRect) SetWidth(w int)

func (*BasicRect) String

func (r *BasicRect) String() string

func (*BasicRect) To

func (r *BasicRect) To() Point

func (*BasicRect) WhereIsPoint

func (r *BasicRect) WhereIsPoint(p Point) RectPointLoc

func (*BasicRect) Width

func (r *BasicRect) Width() int

type Point

type Point interface {
	fmt.Stringer

	SetX(x int)
	X() int
	SetY(y int)
	Y() int

	// 把当前点视为向量终点, (0, 0)视为起点, 返回反向向量的终点
	// 例: 当前为(3, 4), 该方法返回 (-3, -4)
	Reverse() (pn Point)
	// 复制一个自己
	Copy() (pn Point)

	// 使用 base 作为新的坐标轴原点, 更新自身坐标值.
	// 假设运算符号为 $, 示例如下:
	// p_old(3,4) $ base(-1, -2) = p_new(4, 6)
	ChangeBaseByXY(x, y int) (pn Point)
	ChangeBaseByPoint(base Point) (pn Point)

	// 概念中的移动, 改变自身坐标, 返回自身
	Up(int) Point
	Down(int) Point
	Left(int) Point
	Right(int) Point
}

func NewPoint

func NewPoint(x, y int) Point

type Rect

type Rect interface {
	fmt.Stringer
	SetFrom(from Point)
	From() Point
	SetTo(to Point)
	To() Point
	SetWidth(w int)
	Width() int
	SetHeight(h int)
	Height() int
	// 获取Point相对于矩形的位置描述. 如果Point是nil, 永远处理为 RectOutside
	WhereIsPoint(p Point) RectPointLoc
	// 判定点是否被矩形包含
	ContainPoint(p Point) bool
	// 是否与另一个矩形相交
	IntersectWith(r1 Rect) bool

	// 复制一个自己
	Copy() Rect

	// 使用 base 作为新的坐标轴原点, 更新自身坐标值.
	// 可参考 views.Point.ChangeBaseByXXX()
	ChangeBaseByXY(x, y int) (rn Rect)
	ChangeBaseByPoint(base Point) (rn Rect)
}

func NewRectByPoint

func NewRectByPoint(from, to Point) Rect

func NewRectByXY

func NewRectByXY(x1, y1, x2, y2 int) Rect

type RectPointLoc

type RectPointLoc int

矩形Rect 与 点Point 的位置关系

const (
	// 在矩形内, 并不是矩形边界
	RectInside RectPointLoc = iota
	// 在矩形内, 是矩形边界
	RectBorder
	// 在矩形外, 与其边界相邻
	RectAdjacent
	// 在矩形外, 不与其边界相邻
	RectOutside
)

type RootView

type RootView interface {
	View
}

type Rune

type Rune interface {
	SetMainc(rune)
	Mainc() rune
	SetCombc([]rune)
	Combc() []rune
	SetStyle(tcell.Style)
	Style() tcell.Style

	fmt.Stringer
	//给出当前内容需要的宽度
	Width() int
}

某视图中字符位的描述, 位置由使用 Rune 的程序维护. 默认实现为 basicRune

func BasicRune

func BasicRune(mainc rune, combc []rune, style tcell.Style) Rune

func NewRune

func NewRune(mainc rune, combc []rune, style tcell.Style) Rune

func StringToRunes

func StringToRunes(text string, style tcell.Style) []Rune

type UpdateUiMsg

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

更新UI的信息

func (*UpdateUiMsg) GetRect

func (msg *UpdateUiMsg) GetRect() Rect

func (*UpdateUiMsg) GetView

func (msg *UpdateUiMsg) GetView() View

type View

type View interface {
	fmt.Stringer

	// 增减子视图, 因为golang 是 内嵌型"继承", 所以需要真实的父类传入
	AddSubview(subview View, realSuper View) (ok bool)
	RemoveSubview(subview View) (ok bool)
	AddSubviewWithTag(subview View, tag string, realSuper View) (ok bool)
	RemoveSubviewWithTag(tag string) (ok bool)
	// 获取所有子视图
	GetSubviews() []View
	// 查找不到时, 返回 nil
	GetSubviewWithTag(tag string) View

	// 父视图, 不要随意调用 SetSuperView, 除非你知道自己在做什么
	SetSuperView(view View)
	SuperView() View

	// 获取视图的矩阵信息
	Rect() Rect

	// 视图宽高与其在父视图中的坐标
	SetLocation(loc Point)
	Location() Point
	SetWidth(w int)
	SetHeight(h int)
	Width() int
	Height() int

	// Z 是视图优先级, 默认为0
	// 约定父视图处理子视图优先级时, 优先级越低的子视图越容易被其他子视图遮挡.
	// 当多个子视图优先级相等时, 越后面被添加进父视图的, 优先级越高
	SetZ(z int)
	Z() int

	// 当前视图的默认风格
	SetStyle(style tcell.Style)
	Style() tcell.Style

	// 返回实现该接口的基类
	// 因为golang的继承是内嵌, 不是真的继承, 所以约定这里返回实现<code>View interface</code>的基类
	// 即, 所有"子类"均返回其内嵌("继承")的实现该接口的基类.
	// 比如该接口的默认实现是 *basicView, 那么所有 basicView 的子类均返回内嵌的 *basicView
	BaseView() View

	// 获取当前视图的内容. from, to 是当前视图内的两点, 不会为 nil
	//
	// 如果想自行实现一个特定功能的视图, 实现该方法即可控制自定义视图的内容.
	// 如果是展示文本的视图, 请实现者自行解决以下问题, 父视图会强制处理 子视图左右边界上可能出现的 2倍宽字符 越界问题.
	//      1. 中文等 2倍宽字符
	//      2. ZWJ(zero-width joiner) 问题
	//
	// 约定, 父视图承诺处理好子视图左右边界上可能出现的 2倍宽字符 越界问题.
	// 该问题会受到影响(以何种方式处理子视图优先级)
	//
	// 这里使用二维数组作为出参, 就算 [调用方] 要求给出部分视图内容, 数组元素(0,0)也一定是 [from] 这个点的数据, 约定 [调用方] 会自行转化坐标, 所以(0,0)不一定是当前视图的左上角
	GetContent(from Point, to Point) [][]Rune
}

View 是对 [视图] 的抽象, 这里的默认实现是 <code>type basicView struct</code>

func NewView

func NewView() View

Jump to

Keyboard shortcuts

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