Just treat resources as image holders for now
This commit is contained in:
		
							parent
							
								
									a5819955f7
								
							
						
					
					
						commit
						beb6159a23
					
				
					 4 changed files with 31 additions and 2 deletions
				
			
		|  | @ -4,6 +4,7 @@ import ( | |||
| 	"bytes" | ||||
| 	"fmt" | ||||
| 	"image" | ||||
| 	"image/color" | ||||
| 
 | ||||
| 	"fyne.io/fyne/v2" | ||||
| 	"fyne.io/fyne/v2/app" | ||||
|  | @ -25,7 +26,12 @@ func main() { | |||
| 	fmt.Println(i.Bounds()) | ||||
| 	b.SetProfileImage(i) | ||||
| 	b.OutlineWidth = 5 | ||||
| 	w.SetContent(container.NewBorder(nil, nil, nil, nil, b)) | ||||
| 	b2 := profilebtn.NewProfileBtn() | ||||
| 	b2.SetProfileResource(resourceProfilepicdoesnotexistJpg) | ||||
| 	b2.OutlineWidth = 3 | ||||
| 	b3 := profilebtn.NewProfileBtn() | ||||
| 	b3.OutlineColor = color.RGBA{0x4f, 0, 0xfc, 0xff} | ||||
| 	w.SetContent(container.NewBorder(container.NewHBox(b2, b3), nil, nil, nil, b)) | ||||
| 	w.Resize(fyne.NewSize(640, 480)) | ||||
| 	w.ShowAndRun() | ||||
| } | ||||
|  |  | |||
							
								
								
									
										
											BIN
										
									
								
								pkg/profilebtn/profileBtn.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								pkg/profilebtn/profileBtn.png
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 30 KiB | 
|  | @ -1,6 +1,7 @@ | |||
| package profilebtn | ||||
| 
 | ||||
| import ( | ||||
| 	"bytes" | ||||
| 	"image" | ||||
| 	"image/color" | ||||
| 	"image/draw" | ||||
|  | @ -42,11 +43,21 @@ func NewProfileBtn() *profileBtn { | |||
| 	w.ExtendBaseWidget(w) | ||||
| 	w.OutlineWidth = 0 | ||||
| 	w.OutlineColor = color.White | ||||
| 	w.SetProfileResource(nil) | ||||
| 	return w | ||||
| } | ||||
| 
 | ||||
| func (b *profileBtn) SetProfileResource(r fyne.Resource) { | ||||
| 	b.profileImage = canvas.NewImageFromResource(r).Image | ||||
| 	if r != nil { | ||||
| 		i, _, err := image.Decode(bytes.NewReader(r.Content())) | ||||
| 		if err == nil { | ||||
| 			b.profileImage = i | ||||
| 			return | ||||
| 		} | ||||
| 	} | ||||
| 	t, _, _ := image.Decode(bytes.NewReader(resourceProfileBtnPng.StaticContent)) | ||||
| 	b.profileImage = t | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| func (b *profileBtn) SetProfileImage(i image.Image) { | ||||
|  |  | |||
							
								
								
									
										12
									
								
								pkg/profilebtn/resources.go
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								pkg/profilebtn/resources.go
									
										
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
		Loading…
	
	Add table
		
		Reference in a new issue