Core now conforms to new API
Core actually now fulfills the Element interface on its own which is pretty cool.
This commit is contained in:
		
							parent
							
								
									466fdb8472
								
							
						
					
					
						commit
						01d8b64b24
					
				@ -27,46 +27,47 @@ func NewCore (parent tomo.Element) (core *Core, control CoreControl) {
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (core Core) ColorModel () (model color.Model) {
 | 
			
		||||
func (core *Core) ColorModel () (model color.Model) {
 | 
			
		||||
	return color.RGBAModel
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (core Core) At (x, y int) (pixel color.Color) {
 | 
			
		||||
func (core *Core) At (x, y int) (pixel color.Color) {
 | 
			
		||||
	return core.canvas.At(x, y)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (core Core) Bounds () (bounds image.Rectangle) {
 | 
			
		||||
func (core *Core) Bounds () (bounds image.Rectangle) {
 | 
			
		||||
	return core.canvas.Bounds()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (core Core) Set (x, y int, c color.Color) () {
 | 
			
		||||
func (core *Core) Set (x, y int, c color.Color) () {
 | 
			
		||||
	core.canvas.Set(x, y, c)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (core Core) Buffer () (data []color.RGBA, stride int) {
 | 
			
		||||
func (core *Core) Buffer () (data []color.RGBA, stride int) {
 | 
			
		||||
	return core.canvas.Buffer()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (core Core) Selectable () (selectable bool) {
 | 
			
		||||
	return core.selectable
 | 
			
		||||
func (core *Core) MinimumSize () (width, height int) {
 | 
			
		||||
	return core.metrics.minimumWidth, core.metrics.minimumHeight
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (core Core) Selected () (selected bool) {
 | 
			
		||||
	return core.selected
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (core Core) AdvanceSelection (direction int) (ok bool) {
 | 
			
		||||
	return
 | 
			
		||||
func (core *Core) Resize (width, height int) {
 | 
			
		||||
	if width < core.metrics.minimumWidth {
 | 
			
		||||
		width = core.metrics.minimumWidth
 | 
			
		||||
	}
 | 
			
		||||
	if height < core.metrics.minimumHeight {
 | 
			
		||||
		height = core.metrics.minimumHeight
 | 
			
		||||
	}
 | 
			
		||||
	bounds := core.canvas.Bounds()
 | 
			
		||||
	if width != bounds.Dx() || height != bounds.Dy() {
 | 
			
		||||
		core.canvas = tomo.NewBasicCanvas(width, height)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (core *Core) SetParentHooks (hooks tomo.ParentHooks) {
 | 
			
		||||
	core.hooks = hooks
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (core Core) MinimumSize () (width, height int) {
 | 
			
		||||
	return core.metrics.minimumWidth, core.metrics.minimumHeight
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// CoreControl is a struct that can exert control over a control struct. It can
 | 
			
		||||
// be used as a canvas. It must not be directly embedded into an element, but
 | 
			
		||||
// instead kept as a private member.
 | 
			
		||||
@ -79,22 +80,6 @@ func (control CoreControl) HasImage () (empty bool) {
 | 
			
		||||
	return !control.Bounds().Empty()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (control CoreControl) Select () (granted bool) {
 | 
			
		||||
	return control.core.hooks.RunSelectionRequest()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (control CoreControl) SetSelected (selected bool) {
 | 
			
		||||
	if !control.core.selectable { return }
 | 
			
		||||
	control.core.selected = selected
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (control CoreControl) SetSelectable (selectable bool) {
 | 
			
		||||
	if control.core.selectable == selectable { return }
 | 
			
		||||
	control.core.selectable = selectable
 | 
			
		||||
	if !selectable { control.core.selected = false }
 | 
			
		||||
	control.core.hooks.RunSelectabilityChange(selectable)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (control CoreControl) PushRegion (bounds image.Rectangle) {
 | 
			
		||||
	control.core.hooks.RunDraw(tomo.Cut(control, bounds))
 | 
			
		||||
}
 | 
			
		||||
@ -123,17 +108,14 @@ func (control CoreControl) SetMinimumSize (width, height int) {
 | 
			
		||||
 | 
			
		||||
	// if there is an image buffer, and the current size is less
 | 
			
		||||
	// than this new minimum size, send core.parent a resize event.
 | 
			
		||||
	bounds := control.Bounds()
 | 
			
		||||
	imageWidth,
 | 
			
		||||
	imageHeight,
 | 
			
		||||
	constrained := control.ConstrainSize (
 | 
			
		||||
		bounds.Dx(),
 | 
			
		||||
		bounds.Dy())
 | 
			
		||||
	if constrained {
 | 
			
		||||
		core.parent.Handle (tomo.EventResize {
 | 
			
		||||
			Width:  imageWidth,
 | 
			
		||||
			Height: imageHeight,
 | 
			
		||||
		})
 | 
			
		||||
	if control.HasImage() {
 | 
			
		||||
		bounds := control.Bounds()
 | 
			
		||||
		imageWidth,
 | 
			
		||||
		imageHeight,
 | 
			
		||||
		constrained := control.ConstrainSize(bounds.Dx(), bounds.Dy())
 | 
			
		||||
		if constrained {
 | 
			
		||||
			core.parent.Resize(imageWidth, imageHeight)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user