bone

package module
v0.0.0-...-cc4dccb Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2018 License: MIT Imports: 10 Imported by: 0

README

bone

一个mvvm框架 仿照angular
bone\gwin 演示了如何封装windows 本地窗口
bone\gwin\example 一个显示时间的小例子

已经实现了 依赖注入和数据绑定 缺少自动排版以及for if 扩展指令的实现 短期内可能没有时间继续写

Documentation

Overview

Package bone 一个跨平台的MVVM框架 可以方便的和native窗口结合起来 windows 可以参考bone/gwin来实现

Index

Constants

View Source
const (
	ET_MOUSE_ENTER = iota
	ET_MOUSE_MOVE
	ET_MOUSE_DOWN
	ET_MOUSE_UP
	ET_MOUSE_CLICK
	ET_MOUSE_DCLICK
	ET_MOUSE_LEAVE
	ET_MOUSE_WHEEL

	ET_KEY_DOWN
	ET_CHAR
	ET_KEY_UP

	ET_COMPOSITION_START
	ET_COMPOSITION_UPDATE
	ET_COMPOSITION_END

	ET_FOCUS_OUT
	ET_FOCUS_IN
	ET_BLUR
	ET_FOCUS

	ET_CUSTOM
	ET_COUNT
)

鼠标事件类型

View Source
const (
	EF_NONE              = 0 // Used to denote no flags explicitly
	EF_CAPS_LOCK_ON      = 1 << 0
	EF_SHIFT_DOWN        = 1 << 1
	EF_CONTROL_DOWN      = 1 << 2
	EF_ALT_DOWN          = 1 << 3
	EF_LEFT_MOUSE_DOWN   = 1 << 4
	EF_MIDDLE_MOUSE_DOWN = 1 << 5
	EF_RIGHT_MOUSE_DOWN  = 1 << 6
	EF_COMMAND_DOWN      = 1 << 7 // GUI Key (e.g. Command on OS X keyboards,
	// Search on Chromebook keyboards,
	// Windows on MS-oriented keyboards)
	EF_NUM_LOCK_ON = 1 << 8
	EF_IS_KEY_PAD  = 1 << 9
	EF_IS_LEFT     = 1 << 10
	EF_IS_RIGHT    = 1 << 11
)

EventFlags定义

View Source
const (
	EP_CAPTURING = 1 + iota
	EP_TARGET
	EP_BUBBLING
)

EventPhase 常量定义

View Source
const (
	REASON_FOCUS_TRAVERSAL = iota
	REASON_FOCUS_STORE
	REASON_FOCUS_DIRECT_CHANGE
)
View Source
const (
	FOCUS_FORWARD = iota
	FOCUS_BACKWARD
)

Variables

This section is empty.

Functions

func Import

func Import(key string, component Component) error

Import 导入组件名

Types

type BLogger

type BLogger interface {
	Trace(v ...interface{})
	Tracef(format string, v ...interface{})
	Debug(v ...interface{})
	Debugf(format string, v ...interface{})
	Info(v ...interface{})
	Infof(format string, v ...interface{})
	Warn(v ...interface{})
	Warnf(format string, v ...interface{})
	Error(v ...interface{})
	Errorf(format string, v ...interface{})
	Fatal(v ...interface{})
	Fatalf(format string, v ...interface{})
}

BLogger 定义的日志接口 方便第三方实现

type Bone

type Bone struct {
	*Injector
	// contains filtered or unexported fields
}

func NewBone

func NewBone(ij *Injector, data interface{}, doc xmlDoc) *Bone

func (*Bone) AddChild

func (be *Bone) AddChild(child *Bone, index int)

func (*Bone) AddChildToBack

func (be *Bone) AddChildToBack(child *Bone)

func (*Bone) CallVM

func (be *Bone) CallVM(method string)

CallVM 调用data里的方法

func (*Bone) ChildAt

func (be *Bone) ChildAt(index int) *Bone

func (*Bone) ChildrenCount

func (be *Bone) ChildrenCount() int

func (*Bone) Parent

func (be *Bone) Parent() *Bone

func (*Bone) Remove

func (be *Bone) Remove(child *Bone)

func (*Bone) RemoveChildren

func (be *Bone) RemoveChildren()

func (*Bone) TopView

func (be *Bone) TopView() *View

type Bootstrap

type Bootstrap interface {
	Run() //消息循环的空闲例程
}

Bootstrap 接口

func NewBootstrap

func NewBootstrap(template string, logger BLogger, provider []interface{}) Bootstrap

NewBootstrap 返回1个Bootstrap

type Canvas

type Canvas struct {
	*View
}

Canvas 内置标签

func NewCanvas

func NewCanvas() *Canvas

NewCanvas 返回1个Canvas

type Color

type Color uint32

Color 颜色

func (*Color) GetA

func (c *Color) GetA() uint8

GetA 得到alpha分量

func (*Color) GetB

func (c *Color) GetB() uint8

GetB 得到blue分量

func (*Color) GetG

func (c *Color) GetG() uint8

GetG 得到green分量

func (*Color) GetR

func (c *Color) GetR() uint8

GetR 得到red分量

func (*Color) SetARGB

func (c *Color) SetARGB(a, r, g, b uint8)

SetARGB 设置颜色

type ColorF

type ColorF struct {
	A float32
	R float32
	G float32
	B float32
}

ColorF 颜色百分比

type Component

type Component struct {
	Template    string
	TemplateURI string
	Provider    []reflect.Type //用于依赖注入 只能是结构的指针类型 可以实现Constructor方法来作为构造方法
	DataContext reflect.Type   //可以实现Constructor方法来作为构造方法
}

Component 元信息 根据Component创建1个Bone

type DepProperty

type DepProperty interface {
	Set(value interface{})
	Get() interface{}
}

DepProperty 用于数据绑定

func NewDepProperty

func NewDepProperty(value interface{}, setted, getted func(sender interface{}, value interface{})) DepProperty

NewDepProperty 返回1个依赖对象

type Dependence

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

Dependence 依赖

func (*Dependence) AddSub

func (dp *Dependence) AddSub(watcher *Watcher)

AddSub 添加订阅 当支持if 和 for指令时 可能需要实现RemoveSub

func (*Dependence) Notify

func (dp *Dependence) Notify(source WatchedTarget)

Notify 通知

type Event

type Event interface {
	Target() View
	Propagation() bool
	Bubble() bool
	// contains filtered or unexported methods
}

Event 鼠标键盘及自定义事件对象

type EventFlags

type EventFlags int

EventFlags like cef

type EventPhase

type EventPhase int

EventPhase 事件阶段

type EventType

type EventType int

EventType 事件类型

type FocusChangeDirection

type FocusChangeDirection int

type FocusChangeReason

type FocusChangeReason int

type FocusManager

type FocusManager struct {
}

type FocusSearch

type FocusSearch interface {
}

type FocusTraversable

type FocusTraversable interface {
	FocusSearch() FocusSearch
	FocusTraversableParent() FocusTraversable
	FocusTraversableParentView() View
}

type Injector

type Injector struct {
	Parent *Injector

	Provider []interface{}
}

Injector 依赖注入

func (*Injector) Call

func (ij *Injector) Call(fv reflect.Value) ([]reflect.Value, error)

Call 注意这里ij可以为nil 只要fv的参数为0 Panic if t is not kind of Func

func (*Injector) Get

func (ij *Injector) Get(t reflect.Type) reflect.Value

Get 依赖注入 获取指定类型对应的Value

type KeyboardCode

type KeyboardCode int

KeyboardCode 按键码

type PMColor

type PMColor uint32

PMColor 预乘颜色

type Root

type Root struct {
	*View
}

Root 包含根节点

func NewRoot

func NewRoot(v *View) *Root

type Scope

type Scope interface {
	Parent() Scope
	FieldByName(key string, tp reflect.Type) (interface{}, error)
	MethodByName(key string, tp reflect.Type) (interface{}, error)
	InterfaceByName(keys []string, tp reflect.Type, find func(reflect.Value, string, bool) reflect.Value) (interface{}, error)
}

Scope 数据绑定 上下文

func CreateScope

func CreateScope(data interface{}, key string, parent Scope) Scope

CreateScope 创建上下文

type SliceDepProperty

type SliceDepProperty interface {
	SetSlice(value []interface{})
	GetSlice() []interface{}
	Push(item interface{}) int
	Pop() interface{}
	Unshift(item interface{}) int
	Shift() interface{}
	Splice(start, howmany int, items ...interface{}) []interface{}
}

SliceDepProperty 用于数据绑定

func NewSliceDepProperty

func NewSliceDepProperty(value []interface{}, setted, getted func(sender interface{}, value []interface{})) SliceDepProperty

NewSliceDepProperty 返回1个依赖对象

type TaskDispatcher

type TaskDispatcher interface {
	Invoke(do func())
}

TaskDispatcher 保证在UI线程执行

type View

type View struct {

	//依赖属性
	Widget DepProperty
	//通知
	WhenCreated    func(sender *View)
	WhenAttached   func(sender *View, parent, child interface{})
	WhenDeattached func(sender *View, parent, child interface{})
	// contains filtered or unexported fields
}

func NewView

func NewView(className string) *View

NewView 返回1个View go不能继承 所以其他内置标签只能包含1个view 为了区别每个view 使用className

func (*View) AddChild

func (v *View) AddChild(child *View, index int)

func (*View) AddChildToBack

func (v *View) AddChildToBack(child *View)

func (*View) ChildAt

func (v *View) ChildAt(index int) *View

func (*View) ChildrenCount

func (v *View) ChildrenCount() int

func (*View) ClassName

func (v *View) ClassName() string

ClassName 返回类型

func (*View) GetWidget

func (v *View) GetWidget() *Widget

GetWidget 获得Widget

func (*View) IndexOfChild

func (v *View) IndexOfChild(child *View) int

func (*View) Parent

func (v *View) Parent() *View

func (*View) Remove

func (v *View) Remove(child *View)

func (*View) RemoveChildren

func (v *View) RemoveChildren()

type WatchedTarget

type WatchedTarget interface {
	Get() interface{}
	SetFrom(WatchedTarget, interface{})
	Equal(interface{}) bool
	AddSub(watcher *Watcher)
}

WatchedTarget 可以被Watcher监听的接口

type Watcher

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

Watcher 观测属性的变化

func (*Watcher) Run

func (wr *Watcher) Run()

Run 异步执行

func (*Watcher) Update

func (wr *Watcher) Update()

Update 需要更新时调用update函数

type WatcherManager

type WatcherManager interface {
	Create(source, target WatchedTarget,
		computer func(sender interface{}, new interface{}) interface{}) *Watcher
	SetMode(async bool)
	Mode() bool
}

WatcherManager 用于管理Watcher

type Widget

type Widget struct {
	Native interface{}
}

Widget 与View区别开用于代表Native 控件

Directories

Path Synopsis
Package gwin windows ui lib 这是演示本地窗口和bone如何结合 并不是生产环境下的UI库 建议自己开发可以使用的UI库
Package gwin windows ui lib 这是演示本地窗口和bone如何结合 并不是生产环境下的UI库 建议自己开发可以使用的UI库

Jump to

Keyboard shortcuts

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