atomize-element-interface #2
@ -27,46 +27,47 @@ func NewCore (parent tomo.Element) (core *Core, control CoreControl) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (core Core) ColorModel () (model color.Model) {
|
func (core *Core) ColorModel () (model color.Model) {
|
||||||
return color.RGBAModel
|
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)
|
return core.canvas.At(x, y)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (core Core) Bounds () (bounds image.Rectangle) {
|
func (core *Core) Bounds () (bounds image.Rectangle) {
|
||||||
return core.canvas.Bounds()
|
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)
|
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()
|
return core.canvas.Buffer()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (core Core) Selectable () (selectable bool) {
|
func (core *Core) MinimumSize () (width, height int) {
|
||||||
return core.selectable
|
return core.metrics.minimumWidth, core.metrics.minimumHeight
|
||||||
}
|
}
|
||||||
|
|
||||||
func (core Core) Selected () (selected bool) {
|
func (core *Core) Resize (width, height int) {
|
||||||
return core.selected
|
if width < core.metrics.minimumWidth {
|
||||||
}
|
width = core.metrics.minimumWidth
|
||||||
|
}
|
||||||
func (core Core) AdvanceSelection (direction int) (ok bool) {
|
if height < core.metrics.minimumHeight {
|
||||||
return
|
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) {
|
func (core *Core) SetParentHooks (hooks tomo.ParentHooks) {
|
||||||
core.hooks = hooks
|
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
|
// 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
|
// be used as a canvas. It must not be directly embedded into an element, but
|
||||||
// instead kept as a private member.
|
// instead kept as a private member.
|
||||||
@ -79,22 +80,6 @@ func (control CoreControl) HasImage () (empty bool) {
|
|||||||
return !control.Bounds().Empty()
|
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) {
|
func (control CoreControl) PushRegion (bounds image.Rectangle) {
|
||||||
control.core.hooks.RunDraw(tomo.Cut(control, bounds))
|
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
|
// if there is an image buffer, and the current size is less
|
||||||
// than this new minimum size, send core.parent a resize event.
|
// than this new minimum size, send core.parent a resize event.
|
||||||
|
if control.HasImage() {
|
||||||
bounds := control.Bounds()
|
bounds := control.Bounds()
|
||||||
imageWidth,
|
imageWidth,
|
||||||
imageHeight,
|
imageHeight,
|
||||||
constrained := control.ConstrainSize (
|
constrained := control.ConstrainSize(bounds.Dx(), bounds.Dy())
|
||||||
bounds.Dx(),
|
|
||||||
bounds.Dy())
|
|
||||||
if constrained {
|
if constrained {
|
||||||
core.parent.Handle (tomo.EventResize {
|
core.parent.Resize(imageWidth, imageHeight)
|
||||||
Width: imageWidth,
|
}
|
||||||
Height: imageHeight,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user