Closed
Description
Checklist
- I have searched the issue tracker for open issues that relate to the same feature, before opening a new one.
- This issue only relates to a single feature. I will open new issues for any other features.
Is your feature request related to a problem?
I wanted to use colored icons for my app. I used the ones available like NewPrimaryThemedResource(), NewErrorThemedResource() and NewDisabledResource().
But I also want to use warning and success color.
Is it possible to construct a solution with the existing API?
I modified theme/icons.go and it worked as expected. Here is the code :
// WarningThemedResource is a resource wrapper that will return a version of the resource with the main color changed
// to the theme warning color.
type WarningThemedResource struct {
source fyne.Resource
}
// NewWarningThemedResource creates a resource that adapts to the warning color for the current theme.
func NewWarningThemedResource(orig fyne.Resource) *WarningThemedResource {
res := &WarningThemedResource{source: orig}
return res
}
// Name returns the underlying resource name (used for caching).
func (res *WarningThemedResource) Name() string {
return "warning_" + res.source.Name()
}
// Content returns the underlying content of the resource adapted to the current background color.
func (res *WarningThemedResource) Content() []byte {
return svg.Colorize(res.source.Content(), WarningColor())
}
// Original returns the underlying resource that this primary themed resource was adapted from
func (res *WarningThemedResource) Original() fyne.Resource {
return res.source
}
// SuccessThemedResource is a resource wrapper that will return a version of the resource with the main color changed
// to the theme success color.
type SuccessThemedResource struct {
source fyne.Resource
}
// NewSuccessThemedResource creates a resource that adapts to the success color for the current theme.
func NewSuccessThemedResource(orig fyne.Resource) *SuccessThemedResource {
res := &SuccessThemedResource{source: orig}
return res
}
// Name returns the underlying resource name (used for caching).
func (res *SuccessThemedResource) Name() string {
return "success_" + res.source.Name()
}
// Content returns the underlying content of the resource adapted to the current background color.
func (res *SuccessThemedResource) Content() []byte {
return svg.Colorize(res.source.Content(), SuccessColor())
}
// Original returns the underlying resource that this primary themed resource was adapted from
func (res *SuccessThemedResource) Original() fyne.Resource {
return res.source
}
Describe the solution you'd like to see.
Adding themed warning and success allow to create green and orange icons.
this code will work
icon_status_sent = theme.NewWarningThemedResource(resourceSentSvg)
icon_status_paid = theme.NewSuccessThemedResource(resourcePaidSvg)
Metadata
Assignees
Labels
No labels
Activity