本文整理汇总了Golang中github.com/google/gxui/math.Point类的典型用法代码示例。如果您正苦于以下问题:Golang Point类的具体用法?Golang Point怎么用?Golang Point使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Point类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: ChildToParent
func ChildToParent(coord math.Point, from Control, to Parent) math.Point {
c := from
for {
p := c.Parent()
if p == nil {
panic(fmt.Errorf("Control detached: %s", Path(c)))
}
child := p.Children().Find(c)
if child == nil {
Dump(p)
panic(fmt.Errorf("Control's parent (%p %T) did not contain control (%p %T).", &p, p, &c, c))
}
coord = coord.Add(child.Offset)
if p == to {
return coord
}
if control, ok := p.(Control); ok {
c = control
} else {
Dump(p)
panic(fmt.Errorf("ChildToParent (%p %T) -> (%p %T) reached non-control parent (%p %T).",
&from, from, &to, to, &p, p))
}
}
}
开发者ID:langxj,项目名称:gxui,代码行数:26,代码来源:utils.go
示例2: change
func change(point *math.Point, direction string) {
switch direction {
case Top:
point.Y -= 20
case Right:
point.X += 20
case Bottom:
point.Y += 20
case Left:
point.X -= 20
}
}
开发者ID:fesenko,项目名称:snake,代码行数:12,代码来源:snake.go
示例3: PixelAt
func (i *Image) PixelAt(p math.Point) (math.Point, bool) {
ir := i.calculateDrawRect()
if tex := i.Texture(); tex != nil {
s := tex.SizePixels()
p = p.Sub(ir.Min).
ScaleX(float32(s.W) / float32(ir.W())).
ScaleY(float32(s.H) / float32(ir.H()))
if s.Rect().Contains(p) {
return p, true
}
}
return math.Point{X: -1, Y: -1}, false
}
开发者ID:langxj,项目名称:gxui,代码行数:13,代码来源:image.go
示例4: PaintCarets
func (t *DefaultTextBoxLine) PaintCarets(c gxui.Canvas) {
controller := t.textbox.controller
for i, cnt := 0, controller.SelectionCount(); i < cnt; i++ {
e := controller.Caret(i)
l := controller.LineIndex(e)
if l == t.lineIndex {
s := controller.LineStart(l)
m := t.outer.MeasureRunes(s, e)
top := math.Point{X: t.caretWidth + m.W, Y: 0}
bottom := top.Add(math.Point{X: 0, Y: t.Size().H})
t.outer.PaintCaret(c, top, bottom)
}
}
}
开发者ID:langxj,项目名称:gxui,代码行数:14,代码来源:default_textbox_line.go
示例5: ContainsPoint
func (c *Container) ContainsPoint(p math.Point) bool {
if !c.outer.IsVisible() || !c.outer.Size().Rect().Contains(p) {
return false
}
for _, v := range c.children {
if v.Control.ContainsPoint(p.Sub(v.Offset)) {
return true
}
}
if c.IsMouseEventTarget() {
return true
}
return false
}
开发者ID:liulnn,项目名称:gxui,代码行数:14,代码来源:container.go
示例6: draw
func draw(p Pendulum, canvas gxui.Canvas, x, y int) {
attachment := math.Point{X: ANIMATION_WIDTH/2 + x, Y: y}
phi := p.GetPhi()
ball := math.Point{X: x + ANIMATION_WIDTH/2 + math.Round(float32(l*omath.Sin(phi))), Y: y + math.Round(float32(l*omath.Cos(phi)))}
line := gxui.Polygon{gxui.PolygonVertex{attachment, 0}, gxui.PolygonVertex{ball, 0}}
canvas.DrawLines(line, gxui.DefaultPen)
m := math.Point{int(BALL_RADIUS), int(BALL_RADIUS)}
rect := math.Rect{ball.Sub(m), ball.Add(m)}
canvas.DrawRoundedRect(rect, BALL_RADIUS, BALL_RADIUS, BALL_RADIUS, BALL_RADIUS, gxui.TransparentPen, gxui.CreateBrush(gxui.Yellow))
}
开发者ID:jefferyyuan,项目名称:RosettaCodeData,代码行数:14,代码来源:animate-a-pendulum.go
示例7: Measure
func (f *font) Measure(fl *gxui.TextBlock) math.Size {
size := math.Size{W: 0, H: f.glyphMaxSizeDips.H}
var offset math.Point
for _, r := range fl.Runes {
if r == '\n' {
offset.X = 0
offset.Y += f.glyphMaxSizeDips.H
continue
}
offset.X += f.advanceDips(r)
size = size.Max(math.Size{W: offset.X, H: offset.Y + f.glyphMaxSizeDips.H})
}
return size
}
开发者ID:cainiaocome,项目名称:gxui,代码行数:14,代码来源:font.go
示例8: TopControlsUnder
func TopControlsUnder(p math.Point, c Parent) ControlPointList {
children := c.Children()
for i := len(children) - 1; i >= 0; i-- {
child := children[i]
cp := p.Sub(child.Offset)
if child.Control.ContainsPoint(cp) {
l := ControlPointList{ControlPoint{child.Control, cp}}
if cc, ok := child.Control.(Parent); ok {
l = append(l, TopControlsUnder(cp, cc)...)
}
return l
}
}
return ControlPointList{}
}
开发者ID:langxj,项目名称:gxui,代码行数:15,代码来源:utils.go
示例9: BreadcrumbsAt
func BreadcrumbsAt(p Container, pnt math.Point) string {
s := reflect.TypeOf(p).String()
for _, c := range p.Children() {
b := c.Control.Size().Rect().Offset(c.Offset)
if b.Contains(pnt) {
switch t := c.Control.(type) {
case Container:
return s + " > " + BreadcrumbsAt(t, pnt.Sub(c.Offset))
default:
return s + " > " + reflect.TypeOf(c.Control).String()
}
}
}
return s
}
开发者ID:liulnn,项目名称:gxui,代码行数:15,代码来源:debug.go
示例10: ControlsUnder
func ControlsUnder(p math.Point, c Parent) ControlPointList {
toVisit := []ParentPoint{ParentPoint{c, p}}
l := ControlPointList{}
for len(toVisit) > 0 {
c = toVisit[0].C
p = toVisit[0].P
toVisit = toVisit[1:]
for _, child := range c.Children() {
cp := p.Sub(child.Offset)
if child.Control.ContainsPoint(cp) {
l = append(l, ControlPoint{child.Control, cp})
if cc, ok := child.Control.(Parent); ok {
toVisit = append(toVisit, ParentPoint{cc, cp})
}
}
}
}
return l
}
开发者ID:langxj,项目名称:gxui,代码行数:19,代码来源:utils.go
示例11: PaintSelections
func (t *DefaultTextBoxLine) PaintSelections(c gxui.Canvas) {
controller := t.textbox.controller
ls, le := controller.LineStart(t.lineIndex), controller.LineEnd(t.lineIndex)
selections := controller.Selections()
if t.textbox.selectionDragging {
interval.Replace(&selections, t.textbox.selectionDrag)
}
interval.Visit(&selections, gxui.CreateTextSelection(ls, le, false), func(s, e uint64, _ int) {
if s < e {
x := t.outer.MeasureRunes(ls, int(s)).W
m := t.outer.MeasureRunes(int(s), int(e))
top := math.Point{X: t.caretWidth + x, Y: 0}
bottom := top.Add(m.Point())
t.outer.PaintSelection(c, top, bottom)
}
})
}
开发者ID:langxj,项目名称:gxui,代码行数:19,代码来源:default_textbox_line.go
示例12: WindowToChild
func WindowToChild(coord math.Point, to Control) math.Point {
c := to
for {
p := c.Parent()
if p == nil {
panic("Control's parent was nil")
}
child := p.Children().Find(c)
if child == nil {
Dump(p)
panic(fmt.Errorf("Control's parent (%p %T) did not contain control (%p %T).", &p, p, &c, c))
}
coord = coord.Sub(child.Offset)
if _, ok := p.(Window); ok {
return coord
}
c = p.(Control)
}
}
开发者ID:langxj,项目名称:gxui,代码行数:19,代码来源:utils.go
示例13: SetScrollOffset
func (l *ScrollLayout) SetScrollOffset(scrollOffset math.Point) bool {
var cs math.Size
if l.child != nil {
cs = l.child.Control.Size()
}
s := l.innerSize
scrollOffset = scrollOffset.Min(cs.Sub(s).Point()).Max(math.Point{})
l.scrollBarX.Control.SetVisible(l.canScrollX && cs.W > s.W)
l.scrollBarY.Control.SetVisible(l.canScrollY && cs.H > s.H)
l.scrollBarX.Control.(gxui.ScrollBar).SetScrollPosition(l.scrollOffset.X, l.scrollOffset.X+s.W)
l.scrollBarY.Control.(gxui.ScrollBar).SetScrollPosition(l.scrollOffset.Y, l.scrollOffset.Y+s.H)
if l.scrollOffset != scrollOffset {
l.scrollOffset = scrollOffset
l.Relayout()
return true
}
return false
}
开发者ID:langxj,项目名称:gxui,代码行数:22,代码来源:scroll_layout.go
示例14: Layout
func (f *font) Layout(fl *gxui.TextBlock) (offsets []math.Point) {
sizeDips := math.Size{}
offsets = make([]math.Point, len(fl.Runes))
var offset math.Point
for i, r := range fl.Runes {
if r == '\n' {
offset.X = 0
offset.Y += f.glyphMaxSizeDips.H
continue
}
offsets[i] = offset
offset.X += f.advanceDips(r)
sizeDips = sizeDips.Max(math.Size{W: offset.X, H: offset.Y + f.glyphMaxSizeDips.H})
}
origin := f.align(fl.AlignRect, sizeDips, f.ascentDips, fl.H, fl.V)
for i, p := range offsets {
offsets[i] = p.Add(origin)
}
return offsets
}
开发者ID:cainiaocome,项目名称:gxui,代码行数:22,代码来源:font.go
示例15: DesiredSize
func (l *LinearLayout) DesiredSize(min, max math.Size) math.Size {
if l.sizeMode.Fill() {
return max
}
bounds := min.Rect()
children := l.outer.Children()
horizontal := l.direction.Orientation().Horizontal()
offset := math.Point{X: 0, Y: 0}
for _, c := range children {
cs := c.Control.DesiredSize(math.ZeroSize, max)
cm := c.Control.Margin()
cb := cs.Expand(cm).Rect().Offset(offset)
if horizontal {
offset.X += cb.W()
} else {
offset.Y += cb.H()
}
bounds = bounds.Union(cb)
}
return bounds.Size().Expand(l.outer.Padding()).Clamp(min, max)
}
开发者ID:langxj,项目名称:gxui,代码行数:24,代码来源:linear_layout.go
示例16: align
func (f *font) align(rect math.Rect, size math.Size, ascent int, h gxui.HorizontalAlignment, v gxui.VerticalAlignment) math.Point {
var origin math.Point
switch h {
case gxui.AlignLeft:
origin.X = rect.Min.X
case gxui.AlignCenter:
origin.X = rect.Mid().X - (size.W / 2)
case gxui.AlignRight:
origin.X = rect.Max.X - size.W
}
switch v {
case gxui.AlignTop:
origin.Y = rect.Min.Y + ascent
case gxui.AlignMiddle:
origin.Y = rect.Mid().Y - (size.H / 2) + ascent
case gxui.AlignBottom:
origin.Y = rect.Max.Y - size.H + ascent
}
return origin
}
开发者ID:cainiaocome,项目名称:gxui,代码行数:20,代码来源:font.go
示例17: positionAt
func (s *ScrollBar) positionAt(p math.Point) int {
o := s.orientation
frac := float32(o.Major(p.XY())) / float32(o.Major(s.Size().WH()))
max := s.ScrollLimit()
return int(float32(max) * frac)
}
开发者ID:langxj,项目名称:gxui,代码行数:6,代码来源:scroll_bar.go
示例18: ParentToChild
func ParentToChild(coord math.Point, from Parent, to Control) math.Point {
return coord.Sub(ChildToParent(math.ZeroPoint, to, from))
}
开发者ID:langxj,项目名称:gxui,代码行数:3,代码来源:utils.go
注:本文中的github.com/google/gxui/math.Point类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论