Documentation ¶
Index ¶
- Constants
- Variables
- func CheckBox(id ID, bb Rect, text string, style *CheckBoxStyle) bool
- func ColorRect(bb Rect, fill gfx.Color, rounding float32)
- func Game2Gui(x, y float32) (x1, y1 float32)
- func Gui2Game(x, y float32) (x1, y1 float32)
- func HintAndScale() (hintx, hinty, skx, sky float32)
- func Image(id ID, bb Rect, tex gfx.Tex2D, style *ImageStyle)
- func InputText(id ID, bb Rect, hint string, style *InputStyle)
- func ListView()
- func Move(x, y float32)
- func Offset(dx, dy float32)
- func ProgressBar(id ID, bb Rect, fraction float32, style *ProgressBarStyle)
- func ScreenSize() (w, h float32)
- func SetFont(font font.Font)
- func SetScreenSize(w, h float32)
- func SetVirtualResolution(w, h float32)
- func SetZOrder(z int16) (old int16)
- func Text(id ID, bb Rect, text string, style *TextStyle)
- func TextSizeColored(id ID, bb Rect, text string, color gfx.Color, size float32)
- func UseTheme(style *Theme)
- func VirtualSize() (w, h float32)
- type Align
- type ButtonStyle
- type CheckBoxStyle
- type Context
- func (ctx *Context) Button(id ID, bb *Rect, text string, style *ButtonStyle) (event EventType)
- func (ctx *Context) CalcTextSize(text string, wrapWidth float32, fnt font.Font, fontSize float32) f32.Vec2
- func (ctx *Context) CheckSlider(id ID, bound *Rect) (v float32, e EventType)
- func (ctx *Context) ClickEvent(id ID, rect *Rect) EventType
- func (ctx *Context) ColorBackground(event EventType, bb *Rect, normal, pressed gfx.Color, round float32)
- func (ctx *Context) DraggingEvent(id ID, bound *Rect) EventType
- func (ctx *Context) DrawBorder(bb *Rect, color uint32, round, thick float32)
- func (ctx *Context) DrawCircle(x, y, radius float32, fill gfx.Color)
- func (ctx *Context) DrawCircleNoneFill(x, y, radius float32, strokeColor gfx.Color, segment int, thickness float32)
- func (ctx *Context) DrawDebugBorder(x, y, w, h float32, color uint32)
- func (ctx *Context) DrawGradient(bb Rect, c0, c1 gfx.Color, vertical bool)
- func (ctx *Context) DrawImage(bound *Rect, tex gfx.Tex2D, style *ImageStyle)
- func (ctx *Context) DrawQuad(vertex [4]f32.Vec2, fill gfx.Color)
- func (ctx *Context) DrawRect(bb *Rect, fill gfx.Color, round float32)
- func (ctx *Context) DrawText(bb *Rect, text string, style *TextStyle) (size f32.Vec2)
- func (ctx *Context) EndScroll()
- func (ctx *Context) Image(id ID, bb *Rect, tex gfx.Tex2D, style *ImageStyle)
- func (ctx *Context) ImageBackground(eventType EventType)
- func (ctx *Context) ImageButton(id ID, normal, pressed gfx.Tex2D, bb *Rect, style *ImageButtonStyle) (event EventType)
- func (ctx *Context) InputText(id ID, bb *Rect, hint string, style *InputStyle)
- func (ctx *Context) PushClipRect(minClip, maxClip f32.Vec2, intersectCurrent bool)
- func (ctx *Context) Slider(id ID, bb *Rect, value *float32, style *SliderStyle) (e EventType)
- func (ctx *Context) StartScroll(size, offset f32.Vec2)
- func (ctx *Context) Text(id ID, bb *Rect, text string, style *TextStyle)
- func (ctx *Context) UseTheme(style *Theme)
- type Cursor
- type DrawCmd
- type DrawIdx
- type DrawList
- func (dl *DrawList) AddBezierCurve(pos0 f32.Vec2, cp0, cp1 f32.Vec2, pos1 f32.Vec2, color uint32, ...)
- func (dl *DrawList) AddCircle(centre f32.Vec2, radius float32, color uint32, segments int, thickness float32)
- func (dl *DrawList) AddCircleFilled(centre f32.Vec2, radius float32, color uint32, segments int)
- func (dl *DrawList) AddCommand(elemCount int)
- func (dl *DrawList) AddConvexPolyFilled(points []f32.Vec2, color uint32)
- func (dl *DrawList) AddImage(texId uint16, a, b f32.Vec2, uva, uvb f32.Vec2, color uint32)
- func (dl *DrawList) AddImageNinePatch(texId uint16, min, max f32.Vec2, uva, uvb f32.Vec2, patch f32.Vec4, ...)
- func (dl *DrawList) AddImageQuad(texId uint16, a, b, c, d f32.Vec2, uva, uvb, uvc, uvd f32.Vec2, color uint32)
- func (dl *DrawList) AddImageRound(texId uint16, a, b f32.Vec2, uva, uvb f32.Vec2, color uint32, rounding float32, ...)
- func (dl *DrawList) AddLine(a, b f32.Vec2, color uint32, thickness float32)
- func (dl *DrawList) AddPolyLine(points []f32.Vec2, color uint32, thickness float32, closed bool)
- func (dl *DrawList) AddQuad(a, b, c, d f32.Vec2, color uint32, thickness float32)
- func (dl *DrawList) AddQuadFilled(a, b, c, d f32.Vec2, color uint32)
- func (dl *DrawList) AddRect(a, b f32.Vec2, color uint32, rounding float32, roundFlags FlagCorner, ...)
- func (dl *DrawList) AddRectFilled(min, max f32.Vec2, color uint32, rounding float32, corner FlagCorner)
- func (dl *DrawList) AddRectFilledMultiColor()
- func (dl *DrawList) AddText(pos f32.Vec2, text string, font font.Font, fontSize float32, color uint32, ...) (size f32.Vec2)
- func (dl *DrawList) AddTriangle(a, b, c f32.Vec2, color uint32, thickness float32)
- func (dl *DrawList) AddTriangleFilled(a, b, c f32.Vec2, color uint32)
- func (dl *DrawList) Clear()
- func (dl *DrawList) Commands() []DrawCmd
- func (dl *DrawList) CurrentClipRect() (clip f32.Vec4)
- func (dl *DrawList) CurrentTextureId() (id uint16)
- func (dl *DrawList) Empty() bool
- func (dl *DrawList) GetClipRectMax() f32.Vec2
- func (dl *DrawList) GetClipRectMin() f32.Vec2
- func (dl *DrawList) Initialize()
- func (dl *DrawList) PathArcTo(centre f32.Vec2, radius float32, min, max float32, segments int)
- func (dl *DrawList) PathArcToFast(centre f32.Vec2, radius float32, min12, max12 int)
- func (dl *DrawList) PathBezierCurveTo(p2, p3, p4 f32.Vec2, segments int)
- func (dl *DrawList) PathClear()
- func (dl *DrawList) PathFillConvex(col uint32)
- func (dl *DrawList) PathLineTo(pos f32.Vec2)
- func (dl *DrawList) PathLineToMergeDuplicate(pos f32.Vec2)
- func (dl *DrawList) PathRect(a, b f32.Vec2, rounding float32, corners FlagCorner)
- func (dl *DrawList) PathStroke(color uint32, thickness float32, closed bool)
- func (dl *DrawList) PopClipRect()
- func (dl *DrawList) PopTextureId()
- func (dl *DrawList) PrimQuadUV(a, b, c, d f32.Vec2, uva, uvb, uvc, uvd f32.Vec2, color uint32)
- func (dl *DrawList) PrimRect(min, max f32.Vec2, color uint32)
- func (dl *DrawList) PrimRectUV(a, c f32.Vec2, uva, uvc f32.Vec2, color uint32)
- func (dl *DrawList) PrimReserve(idxCount, vtxCount int)
- func (dl *DrawList) PushClipRect(min, max f32.Vec2, intersectCurrentClip bool)
- func (dl *DrawList) PushClipRectFullScreen()
- func (dl *DrawList) PushTextureId(texId uint16)
- func (dl *DrawList) Size() (idx, vdx int)
- func (dl *DrawList) UpdateClipRect()
- func (dl *DrawList) UpdateTextureId()
- type DrawListFlags
- type DrawVert
- type EventType
- type FlagCorner
- type FontRender
- type ID
- type IdMap
- type ImageButtonStyle
- type ImageStyle
- type InputStyle
- type Padding
- type ProgressBarStyle
- type Rect
- type SliderStyle
- type TextStyle
- type Theme
- type UIRenderFeature
- type Visibility
Constants ¶
const ( FlagCornerNone FlagCorner = 0x0000 FlagCornerTopLeft = 0x0001 FlagCornerTopRight = 0x0002 FlagCornerBottomRight = 0x0004 FlagCornerBottomLeft = 0x0008 FlagCornerAll = 0x000F )
const ( AlignCenter Align = iota AlignLeft = 1 << iota AlignRight = 1 << iota AlignTop = 1 << iota AlignBottom = 1 << iota )
const (
DefaultZOrder = int16(0xFFFF>>1 - 100)
)
const EventNone = EventType(0)
Variables ¶
var DebugDraw = false
Functions ¶
func HintAndScale ¶
func HintAndScale() (hintx, hinty, skx, sky float32)
func InputText ¶
func InputText(id ID, bb Rect, hint string, style *InputStyle)
Widgets: InputEditor
func ProgressBar ¶
func ProgressBar(id ID, bb Rect, fraction float32, style *ProgressBarStyle)
Widget: ProgressBar, Slider
func ScreenSize ¶
func ScreenSize() (w, h float32)
ScreenSize return the physical width&height of the screen.
func SetVirtualResolution ¶
func SetVirtualResolution(w, h float32)
SetVirtualResolution set the virtual resolution.
func TextSizeColored ¶
func VirtualSize ¶
func VirtualSize() (w, h float32)
Types ¶
type ButtonStyle ¶
type CheckBoxStyle ¶
type CheckBoxStyle struct { }
type Context ¶
一个Context维护UI层逻辑: 1. 一个 DrawList,负责生成顶点 2. 共享的 Theme,指针引用,多个 Context 之间可以共享 3. State 维护,负责维护当前的 UI 状态,比如动画,按钮,列表... 窗口在 Context 之上维护,默认的Context可以随意的绘制 在窗口内绘制的UI会受到窗口的管理.
func DefaultContext ¶
func DefaultContext() *Context
func NewContext ¶
func (*Context) CalcTextSize ¶
func (*Context) CheckSlider ¶
func (*Context) ColorBackground ¶
func (ctx *Context) ColorBackground(event EventType, bb *Rect, normal, pressed gfx.Color, round float32)
偷师 flat-ui 中的设计,把空间的前景和背景分离,背景单独根据事件来变化.. 在 Android 中,Widget的前景和背景都可以根据控件状态发生变化 但是在大部分UI中,比如 Text/Image 只会改变背景的状态 偷懒的自定义UI,不做任何状态的改变... 所以说呢, 我们也采用偷懒的做法呗。。
func (*Context) DrawBorder ¶
func (*Context) DrawCircle ¶
default segment = 12 TODO, circle scale factor
func (*Context) DrawCircleNoneFill ¶
func (ctx *Context) DrawCircleNoneFill(x, y, radius float32, strokeColor gfx.Color, segment int, thickness float32)
segment default=12
func (*Context) DrawDebugBorder ¶
func (*Context) DrawGradient ¶
func (*Context) DrawImage ¶
func (ctx *Context) DrawImage(bound *Rect, tex gfx.Tex2D, style *ImageStyle)
func (*Context) ImageBackground ¶
func (*Context) ImageButton ¶
func (*Context) InputText ¶
func (ctx *Context) InputText(id ID, bb *Rect, hint string, style *InputStyle)
Widgets: InputEditor
func (*Context) PushClipRect ¶
Clip:
func (*Context) StartScroll ¶
Scroll 效果的关键是使用裁切限制滚动区域,然后 通过计算拖拽,来得到争取的偏移
type DrawCmd ¶
type DrawCmd struct { FirstIndex uint16 ElemCount uint16 ClipRect f32.Vec4 TextureId uint16 // contains filtered or unexported fields }
DrawList provide method to write primitives to buffer
type DrawList ¶
type DrawList struct { CmdBuffer []DrawCmd IdxBuffer []DrawIdx VtxBuffer []DrawVert // Data *DrawListSharedData OwnerName string // 窗口名 VtxCurrentIdx int // VtxBuffer.Size // 指向当前正在使用的 cmdbuffer 的位置 VtxWriter []DrawVert IdxWriter []DrawIdx ClipRectStack []f32.Vec4 TextureIdStack []uint16 FullScreen f32.Vec4 TexUVWhitePixel f32.Vec2 CircleVtx12 [12]f32.Vec2 Font font.Font FontSize float32 Flags DrawListFlags ZOrder int16 // contains filtered or unexported fields }
func NewDrawList ¶
func NewDrawList() *DrawList
func (*DrawList) AddBezierCurve ¶
func (*DrawList) AddCircleFilled ¶
func (*DrawList) AddCommand ¶
每次绘制都会产生一个 Command (可能会造成内存浪费! 1k cmd = 1000 * 6 * 4 = 24k) 为了减少内存可以一边添加一边尝试向前合并
func (*DrawList) AddConvexPolyFilled ¶
Non Anti-aliased Fill
func (*DrawList) AddImageNinePatch ¶
func (dl *DrawList) AddImageNinePatch(texId uint16, min, max f32.Vec2, uva, uvb f32.Vec2, patch f32.Vec4, color uint32)
NinePatch Algorithm
12 13 14 15 x1 x2 max +----+----+----+ | | | | | | |p1 | +----+----+----+ y2 | | | | | |p0 | | +----+----+----+ y1 | | | | | | | | +----+----+----+
min
0 1 2 3
patch = {x1, x2, y1, y2} % TextureSize
func (*DrawList) AddImageQuad ¶
func (*DrawList) AddImageRound ¶
func (*DrawList) AddPolyLine ¶
此处生成最终的顶点数据和索引数据 当前并不支持抗锯齿!!简单的用顶点生成线段
func (*DrawList) AddQuadFilled ¶
func (*DrawList) AddRect ¶
func (dl *DrawList) AddRect(a, b f32.Vec2, color uint32, rounding float32, roundFlags FlagCorner, thickness float32)
所有非填充图形看来都是使用路径实现的
func (*DrawList) AddRectFilled ¶
func (*DrawList) AddRectFilledMultiColor ¶
func (dl *DrawList) AddRectFilledMultiColor()
func (*DrawList) AddTriangle ¶
func (*DrawList) AddTriangleFilled ¶
func (*DrawList) CurrentClipRect ¶
func (*DrawList) CurrentTextureId ¶
func (*DrawList) GetClipRectMax ¶
func (*DrawList) GetClipRectMin ¶
func (*DrawList) Initialize ¶
func (dl *DrawList) Initialize()
func (*DrawList) PathArcToFast ¶
此处圆角的算法: 使用一个12边形近似圆形,采用中心放射算法,计算出 各个角度的sin/cos, 然后通过公式,得到圆圆形顶点 f(x) = centre.x + cos()*radius f(y) = centre.y + sin()*radius 以上, 可以提前算好 sin/cos 加速整个过程
func (*DrawList) PathBezierCurveTo ¶
func (*DrawList) PathFillConvex ¶
func (*DrawList) PathLineTo ¶
func (*DrawList) PathLineToMergeDuplicate ¶
func (*DrawList) PathRect ¶
func (dl *DrawList) PathRect(a, b f32.Vec2, rounding float32, corners FlagCorner)
func (*DrawList) PathStroke ¶
default: thickness=1.0
func (*DrawList) PopClipRect ¶
func (dl *DrawList) PopClipRect()
func (*DrawList) PopTextureId ¶
func (dl *DrawList) PopTextureId()
func (*DrawList) PrimQuadUV ¶
func (*DrawList) PrimRectUV ¶
func (*DrawList) PrimReserve ¶
primitive operation, auto scale by 1024
func (*DrawList) PushClipRect ¶
Clip 相关的操作
func (*DrawList) PushClipRectFullScreen ¶
func (dl *DrawList) PushClipRectFullScreen()
func (*DrawList) PushTextureId ¶
func (*DrawList) UpdateTextureId ¶
func (dl *DrawList) UpdateTextureId()
type DrawListFlags ¶
type DrawListFlags uint32
const ( FlagAntiAliasedLine DrawListFlags = iota FlagAntiAliasedFill )
type EventType ¶
type EventType uint8
func Button ¶
func Button(id ID, bb Rect, text string, style *ButtonStyle) (event EventType)
Widget: Button
func ImageButton ¶
func (EventType) JustPressed ¶
func (EventType) JustReleased ¶
type FlagCorner ¶
type FlagCorner uint32
Rounding corner: A: 0x0000 0001 top-left B: 0x0000 0002 top-right C: 0x0000 0004 down-right D: 0x0000 0008 down-left
type FontRender ¶
type FontRender struct { *DrawList // contains filtered or unexported fields }
工具结构,负责把字符串转化为顶点.. 拥有所有需要的条件属性
func (*FontRender) RenderText ¶
当前的实现中,不考虑裁切优化,全部绘制所有字符
func (*FontRender) RenderWrapped ¶
type ImageButtonStyle ¶
type ImageButtonStyle struct { ImageStyle Padding }
type ImageStyle ¶
type InputStyle ¶
type InputStyle struct { Visibility Color, HintColor uint32 Size float32 }
type ProgressBarStyle ¶
type ProgressBarStyle struct { }
type SliderStyle ¶
type Theme ¶
type Theme struct { Text TextStyle Button ButtonStyle Image ImageStyle ImageButton ImageButtonStyle Slider SliderStyle // global config.. Normal gfx.Color Pressed gfx.Color // item 之间的空隙 Spacing float32 // default font font.Font }
var ThemeDark *Theme
var ThemeLight *Theme
type UIRenderFeature ¶
type UIRenderFeature struct { *gfx.MeshRender *DrawList *gfx.Camera Buffer struct { // contains filtered or unexported fields } // contains filtered or unexported fields }
func (*UIRenderFeature) Draw ¶
func (f *UIRenderFeature) Draw(nodes gfx.RenderNodes)
TODO rotation..
func (*UIRenderFeature) Extract ¶
func (f *UIRenderFeature) Extract(v *gfx.View)
func (*UIRenderFeature) Flush ¶
func (f *UIRenderFeature) Flush()
func (*UIRenderFeature) Register ¶
func (f *UIRenderFeature) Register(rs *gfx.RenderSystem)
func (*UIRenderFeature) SetDrawList ¶
func (f *UIRenderFeature) SetDrawList(dl *DrawList)