Icon no longer embeds tomo.Box
This commit is contained in:
		
							parent
							
								
									c043f9bf8d
								
							
						
					
					
						commit
						697229d183
					
				
							
								
								
									
										23
									
								
								icon.go
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								icon.go
									
									
									
									
									
								
							@ -3,9 +3,11 @@ package objects
 | 
			
		||||
import "git.tebibyte.media/tomo/tomo"
 | 
			
		||||
import "git.tebibyte.media/tomo/tomo/canvas"
 | 
			
		||||
 | 
			
		||||
var _ tomo.Object = new(Icon)
 | 
			
		||||
 | 
			
		||||
// Icon displays a single icon.
 | 
			
		||||
type Icon struct {
 | 
			
		||||
	tomo.Box
 | 
			
		||||
	box  tomo.Box
 | 
			
		||||
	icon tomo.Icon
 | 
			
		||||
	size tomo.IconSize
 | 
			
		||||
}
 | 
			
		||||
@ -21,14 +23,19 @@ func iconSizeString (size tomo.IconSize) string {
 | 
			
		||||
// NewIcon creates a new icon from an icon ID.
 | 
			
		||||
func NewIcon (icon tomo.Icon, size tomo.IconSize) *Icon {
 | 
			
		||||
	this := &Icon {
 | 
			
		||||
		Box: tomo.NewBox(),
 | 
			
		||||
		box: tomo.NewBox(),
 | 
			
		||||
	}
 | 
			
		||||
	this.SetRole(tomo.R("objects", "Icon"))
 | 
			
		||||
	this.box.SetRole(tomo.R("objects", "Icon"))
 | 
			
		||||
	this.SetIcon(icon, size)
 | 
			
		||||
	this.OnIconSetChange(this.handleIconSetChange)
 | 
			
		||||
	this.box.OnIconSetChange(this.handleIconSetChange)
 | 
			
		||||
	return this
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetBox returns the underlying box.
 | 
			
		||||
func (this *Icon) GetBox () tomo.Box {
 | 
			
		||||
	return this.box
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// SetIcon sets the icon.
 | 
			
		||||
func (this *Icon) SetIcon (icon tomo.Icon, size tomo.IconSize) {
 | 
			
		||||
	if this.icon == icon { return }
 | 
			
		||||
@ -42,12 +49,12 @@ func (this *Icon) handleIconSetChange () {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *Icon) setTexture (texture canvas.Texture) {
 | 
			
		||||
	this.SetAttr(tomo.ATexture(texture))
 | 
			
		||||
	this.SetAttr(tomo.ATextureMode(tomo.TextureModeCenter))
 | 
			
		||||
	this.box.SetAttr(tomo.ATexture(texture))
 | 
			
		||||
	this.box.SetAttr(tomo.ATextureMode(tomo.TextureModeCenter))
 | 
			
		||||
	if texture == nil {
 | 
			
		||||
		this.SetAttr(tomo.AMinimumSize(0, 0))
 | 
			
		||||
		this.box.SetAttr(tomo.AMinimumSize(0, 0))
 | 
			
		||||
	} else {
 | 
			
		||||
		bounds := texture.Bounds()
 | 
			
		||||
		this.SetAttr(tomo.AttrMinimumSize(bounds.Max.Sub(bounds.Min)))
 | 
			
		||||
		this.box.SetAttr(tomo.AttrMinimumSize(bounds.Max.Sub(bounds.Min)))
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user