Compare commits
	
		
			2 Commits
		
	
	
		
			73a5fab0bc
			...
			5a32b06cef
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 5a32b06cef | |||
| fe50f5783b | 
							
								
								
									
										2
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								go.mod
									
									
									
									
									
								
							| @ -2,4 +2,4 @@ module git.tebibyte.media/tomo/objects | |||||||
| 
 | 
 | ||||||
| go 1.20 | go 1.20 | ||||||
| 
 | 
 | ||||||
| require git.tebibyte.media/tomo/tomo v0.43.0 | require git.tebibyte.media/tomo/tomo v0.45.0 | ||||||
|  | |||||||
							
								
								
									
										4
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								go.sum
									
									
									
									
									
								
							| @ -1,2 +1,2 @@ | |||||||
| git.tebibyte.media/tomo/tomo v0.43.0 h1:V0HT+7PluCQIeCrOzYT4s11MXStXPNVJnLZ5AnaOzCM= | git.tebibyte.media/tomo/tomo v0.45.0 h1:fQH0WIPidW275hOq9dE6R7p064xG1RGx2QU68Avlr84= | ||||||
| git.tebibyte.media/tomo/tomo v0.43.0/go.mod h1:WrtilgKB1y8O2Yu7X4mYcRiqOlPR8NuUnoA/ynkQWrs= | git.tebibyte.media/tomo/tomo v0.45.0/go.mod h1:WrtilgKB1y8O2Yu7X4mYcRiqOlPR8NuUnoA/ynkQWrs= | ||||||
|  | |||||||
							
								
								
									
										27
									
								
								icon.go
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								icon.go
									
									
									
									
									
								
							| @ -1,10 +1,13 @@ | |||||||
| package objects | package objects | ||||||
| 
 | 
 | ||||||
| import "git.tebibyte.media/tomo/tomo" | import "git.tebibyte.media/tomo/tomo" | ||||||
|  | import "git.tebibyte.media/tomo/tomo/canvas" | ||||||
| 
 | 
 | ||||||
| // Icon displays a single icon. | // Icon displays a single icon. | ||||||
| type Icon struct { | type Icon struct { | ||||||
| 	tomo.Box | 	tomo.Box | ||||||
|  | 	icon tomo.Icon | ||||||
|  | 	size tomo.IconSize | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func iconSizeString (size tomo.IconSize) string { | func iconSizeString (size tomo.IconSize) string { | ||||||
| @ -22,14 +25,28 @@ func NewIcon (icon tomo.Icon, size tomo.IconSize) *Icon { | |||||||
| 	} | 	} | ||||||
| 	this.SetRole(tomo.R("objects", "Icon")) | 	this.SetRole(tomo.R("objects", "Icon")) | ||||||
| 	this.SetIcon(icon, size) | 	this.SetIcon(icon, size) | ||||||
|  | 	this.OnIconSetChange(this.handleIconSetChange) | ||||||
| 	return this | 	return this | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // SetIcon sets the icon. | // SetIcon sets the icon. | ||||||
| func (this *Icon) SetIcon (icon tomo.Icon, size tomo.IconSize) { | func (this *Icon) SetIcon (icon tomo.Icon, size tomo.IconSize) { | ||||||
| 	iconTexture := icon.Texture(size) | 	if this.icon == icon { return } | ||||||
| 	bounds := iconTexture.Bounds() | 	this.icon = icon | ||||||
| 	this.SetAttr(tomo.AIcon(icon, size)) | 	this.setTexture(icon.Texture(size)) | ||||||
| 	this.SetAttr(tomo.AMinimumSize(bounds.Dx(), bounds.Dy())) | } | ||||||
| 	this.SetTag(iconSizeString(size), true) | 
 | ||||||
|  | func (this *Icon) handleIconSetChange () { | ||||||
|  | 	this.setTexture(this.icon.Texture(this.size)) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (this *Icon) setTexture (texture canvas.Texture) { | ||||||
|  | 	this.SetAttr(tomo.ATexture(texture)) | ||||||
|  | 	this.SetAttr(tomo.ATextureMode(tomo.TextureModeCenter)) | ||||||
|  | 	if texture == nil { | ||||||
|  | 		this.SetAttr(tomo.AMinimumSize(0, 0)) | ||||||
|  | 	} else { | ||||||
|  | 		bounds := texture.Bounds() | ||||||
|  | 		this.SetAttr(tomo.AttrMinimumSize(bounds.Max.Sub(bounds.Min))) | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ func NewMimeIcon (mime data.Mime, size tomo.IconSize) *MimeIcon { | |||||||
| 	this := &MimeIcon { | 	this := &MimeIcon { | ||||||
| 		Box: tomo.NewBox(), | 		Box: tomo.NewBox(), | ||||||
| 	} | 	} | ||||||
| 	this.SetRole(tomo.R("objects", "Icon")) | 	this.SetRole(tomo.R("objects", "MimeIcon")) | ||||||
| 	this.SetIcon(mime, size) | 	this.SetIcon(mime, size) | ||||||
| 	this.OnIconSetChange(this.handleIconSetChange) | 	this.OnIconSetChange(this.handleIconSetChange) | ||||||
| 	return this | 	return this | ||||||
| @ -27,7 +27,6 @@ func (this *MimeIcon) SetIcon (mime data.Mime, size tomo.IconSize) { | |||||||
| 	if this.mime == mime && this.size == size { return } | 	if this.mime == mime && this.size == size { return } | ||||||
| 	this.mime = mime | 	this.mime = mime | ||||||
| 	this.size = size | 	this.size = size | ||||||
| 	this.SetTag(iconSizeString(size), true) |  | ||||||
| 	this.setTexture(tomo.MimeIconTexture(mime, size)) | 	this.setTexture(tomo.MimeIconTexture(mime, size)) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user