-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paththemed_resource.go
50 lines (42 loc) · 1.31 KB
/
themed_resource.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// auto-generated
// Code generated by 'fynematic'. DO NOT EDIT.
// Copyright (C) 2018 Fyne.io developers (see AUTHORS)
// All rights reserved.
//
// Use of the source code in this file is governed by a BSD 3-Clause License
// license that can be found at
// https://github.com/fyne-io/fyne/blob/v2.0.2/LICENSE
//
// Original: https://github.com/fyne-io/fyne/blob/v2.0.2/cmd/fyne_demo/data/icons.go
package main
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/theme"
)
// ThemedResource is a resource wrapper that will return an appropriate resource
// for the currently selected theme.
type ThemedResource struct {
dark, light fyne.Resource
}
func isLight() bool {
r, g, b, _ := theme.ForegroundColor().RGBA()
return r < 0xaaaa && g < 0xaaaa && b < 0xaaaa
}
// Name returns the underlying resource name (used for caching)
func (res *ThemedResource) Name() string {
if isLight() {
return res.light.Name()
}
return res.dark.Name()
}
// Content returns the underlying content of the correct resource for the current theme
func (res *ThemedResource) Content() []byte {
if isLight() {
return res.light.Content()
}
return res.dark.Content()
}
// NewThemedResource creates a resource that adapts to the current theme setting.
func NewThemedResource(dark, light fyne.Resource) *ThemedResource {
return &ThemedResource{dark, light}
}