Example #1
0
func draw(widget Widget, gc graphic.Context, clip geom.Rect, origin geom.Point) {
	bounds := widget.Bounds()

	if clip.Intersect(geom.Rect{
		X: bounds.X + origin.X,
		Y: bounds.Y + origin.Y,
		W: bounds.W,
		H: bounds.H,
	}).Empty() {
		return
	}

	gc.Save()
	gc.Configure(graphic.State{
		Transform: graphic.Translation(bounds.X, bounds.Y),
		Clip:      geom.Rect{W: bounds.W, H: bounds.H},
	})

	if d, ok := widget.(Drawable); ok {
		d.Draw(gc)
	}

	if c, ok := widget.(Container); ok {
		origin = bounds.Origin()

		for _, w := range c.Children() {
			draw(w, gc, clip, origin)
		}
	}

	gc.Restore()
}
Example #2
0
func (self HorizontalLayout) Layout(bounds geom.Rect, widgets ...Widget) {
	n := len(widgets)

	bounds.W -= float64(n-1) * self.Spacing
	bounds.W /= float64(n)

	for _, w := range widgets {
		w.SetBounds(bounds)
		bounds.X += bounds.W + self.Spacing
	}
}
Example #3
0
func (self VerticalLayout) Layout(bounds geom.Rect, widgets ...Widget) {
	n := len(widgets)

	bounds.H -= float64(n-1) * self.Spacing
	bounds.H /= float64(n)

	for _, w := range widgets {
		w.SetBounds(bounds)
		bounds.Y += bounds.H + self.Spacing
	}
}
Example #4
0
func redraw(widget Widget, bounds geom.Rect) {
	if view, ok := widget.(*View); ok {
		view.redraw(bounds)
		return
	}

	if parent := widget.Parent(); parent != nil {
		r := parent.Bounds()
		bounds.X += r.X
		bounds.Y += r.Y
		redraw(parent, bounds)
		return
	}
}
Example #5
0
func (self *View) changeMouseSelection(w driver.Window, p geom.Point, b mouse.ButtonSet) {
	if (self.state & viewMouseSelection) == 0 {
		self.state |= viewMouseSelection
		self.mouseSelectionOrigin = p
		self.mouseSelectionButtons = b

		if cur, err := w.Display().NewCursor(driver.CursorIBeam); err != nil {
			fmt.Fprintf(os.Stderr, "WARN: seting default cursor to I-Beam failed: %s\n", err)
		} else {
			self.changeDefaultCursor(cur)
		}
	}

	p0 := self.mouseSelectionOrigin
	p1 := p

	r := geom.Rect{X: p0.X, Y: p0.Y, W: p1.X - p0.X, H: p1.Y - p0.Y}

	if r.W >= 0.0 && r.W < 1.0 {
		r.W = 1.0
	} else if r.W < 0.0 && r.W > -1.0 {
		r.W = -1.0
	}

	if r.H >= 0.0 && r.H < 1.0 {
		r.H = 1.0
	} else if r.H < 0.0 && r.H > -1.0 {
		r.H = -1.0
	}

	if self.content != nil {
		mouseSelection(w, self.content, event.MouseSelection{
			Pressed: b,
			Bounds:  r,
		})
	}
}
Example #6
0
func (self *Image) SetBounds(bounds geom.Rect) {
	self.Control.SetBounds(bounds)
	self.area = self.Layout().Layout(bounds.Size(), self.imageSize())
}
Example #7
0
func makeCGRect(r geom.Rect) C.CGRect {
	return C.CGRect{
		origin: makeCGPoint(r.Origin()),
		size:   makeCGSize(r.Size()),
	}
}
Example #8
0
func (self *Frame) SetBounds(bounds geom.Rect) {
	self.Control.SetBounds(bounds)
	bounds.X = 0
	bounds.Y = 0
	self.Layout().Layout(bounds, self.Children()...)
}
Example #9
0
func RedrawRect(widget Widget, rect geom.Rect) {
	bounds := widget.Bounds()
	rect.X += bounds.X
	rect.Y += bounds.Y
	redraw(widget, rect)
}