Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advanced Color Picker in Fyne2.0 show Black as using my customed theme's primary color which is set before. #1970

Closed
apieceof opened this issue Feb 17, 2021 · 6 comments
Labels
bug Something isn't working

Comments

@apieceof
Copy link

Describe the bug:

Advanced Color Picker in Fyne2.0 won't show my customed theme's primary color which is set before.

To Reproduce:

Steps to reproduce the behaviour:

  1. Click on 'Select Theme Color: ' to choose my customed theme which is "Blue","Orange" or "Yellow"
  2. Click on 'Customed Theme Color Picker:'
  3. Click on 'Advanced'
  4. See error

Screenshots:

github_step1
github_step2
github_step3

Example code:

func DemoDialog (tl string, win fyne.Window) {
        isFirstTime := true
	pickChg:= false
	customColor = color.RGBA{A: 255}

	//Select box
	selLabel := widget.NewLabelWithStyle("Select Theme Color: ", fyne.TextAlignCenter, fyne.TextStyle{
		Bold:      false,
		Italic:    false,
		Monospace: true,
	})
	colorSelect = widget.NewSelect([]string{"Light", "Dark", "Blue", "Orange", "Yellow"}, nil)
	colorSelect.SetSelected("Light")

	//Select box onChanged func
	colorSelect.OnChanged = func(value string) {
		selectColor = SelectTheme(colorSelect.Selected, isFirstTime, nil)
		r, g, b, _ := (selectColor).RGBA()
		fmt.Println(r>>8,g>>8,b>>8)
		isFirstTime = false
		pickChg = false
	}

	//Advanced color picker
	advButton := widget.NewButton( "Customed Theme Color Picker: ", func() {
		picker := dialog.NewColorPicker("Pick a Color", "Please pick your color:", func(c color.Color) {
			if customColor != c {
				SelectTheme("Custom", isFirstTime, c)
				isFirstTime = false
			}
			pickChg = true
			customColor = c
		}, win)
		picker.Advanced = true
		picker.Show()})

	//
	selBox := container.NewVBox(selLabel, colorSelect)
	cusBox := container.NewVBox(advButton)

	//
	target := container.NewHBox(selBox, cusBox)

	set := dialog.NewCustomConfirm(tl, "Apply", "Exit", target, func( applyClicked bool ){
		if !applyClicked && !isFirstTime {
			//restore to current
			RestoreTheme()
		}
		if applyClicked  {
			if !pickChg {
				SelectTheme(colorSelect.Selected, isFirstTime, customColor)
			} else {
				SelectTheme("Custom", isFirstTime, customColor)
			}
		}
		isFirstTime = true
	}, win)
	set.Show()
}

func main() {
	// Main menu
	fileMenu := fyne.NewMenu("File", fyne.NewMenuItem("Log", func() { fmt.Println("File -> Log") }))
	helpMenu := fyne.NewMenu("Help", fyne.NewMenuItem("About", func() { fmt.Println("Help -> 
                             About") }))
	settingMenu := fyne.NewMenu("Settings",  fyne.NewMenuItem("Demo Code", func() {
		screen.DemoDialog("Demo", window)}
           ))
	mainMenu := fyne.NewMainMenu(fileMenu, helpMenu, settingMenu)
	window.SetMainMenu(mainMenu)
}
**Where** SelectTheme will go to my customed Theme to replace fyne.Theme interface

func SelectTheme (sel string, shouldBackup bool, customCol color.Color) color.Color{
	if shouldBackup {
		//save cur theme to restore
		frontglobal.BackupTheme = frontglobal.SupTheme
	}
	switch sel {
	default:
		frontglobal.SupTheme.SetThemeParameter(0)
		fyne.CurrentApp().Settings().SetTheme(frontglobal.SupTheme)
	case "Dark":
		frontglobal.SupTheme.SetThemeParameter(1)
		fyne.CurrentApp().Settings().SetTheme(frontglobal.SupTheme)
	case "Blue":
		frontglobal.SupTheme.SetThemeParameter(2)
		fyne.CurrentApp().Settings().SetTheme(frontglobal.SupTheme)
	case "Orange":
		frontglobal.SupTheme.SetThemeParameter(3)
		fyne.CurrentApp().Settings().SetTheme(frontglobal.SupTheme)
	case "Yellow":
		frontglobal.SupTheme.SetThemeParameter(4)
		fyne.CurrentApp().Settings().SetTheme(frontglobal.SupTheme)
	case "Custom":
		frontglobal.SupTheme.PrimaryColorSup = customCol
		frontglobal.SupTheme.SetThemeParameter(5)
		fyne.CurrentApp().Settings().SetTheme(frontglobal.SupTheme)
	}
	return frontglobal.SupTheme.PrimaryColorSup
}

Device (please complete the following information):

  • OS: Ubuntu
  • Version: 18.04.4 LTS
  • Go version: go1.15.5 linux/amd64
  • Fyne version: 2.0
@apieceof apieceof added the bug Something isn't working label Feb 17, 2021
@andydotxyz
Copy link
Member

Please can you provide a minimal code that exhibits the error and that we can compile and run?
There is a chance that the problem you are describing is caused by custom theme code not in this report.

@andydotxyz andydotxyz added question A question has been asked and removed bug Something isn't working labels Feb 17, 2021
@apieceof
Copy link
Author

Hi @andydotxyz,

Here is the short code for more clear explanation of my question:

package main

import (
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/dialog"
	"fyne.io/fyne/v2/theme"
	"fyne.io/fyne/v2/widget"
	"image/color"
)

type TestTheme struct {}

func (TestTheme) Color(a fyne.ThemeColorName, b fyne.ThemeVariant) color.Color {
	if a == theme.ColorNamePrimary {
		return color.RGBA{R: 100, G: 100, B: 100, A: 255}
	}
	return theme.DarkTheme().Color(a, b)
}
func (TestTheme) Font(a fyne.TextStyle) fyne.Resource {
	return theme.DarkTheme().Font(a)
}
func (TestTheme) Icon(a fyne.ThemeIconName) fyne.Resource {
	return theme.DarkTheme().Icon(a)
}
func (TestTheme) Size(a fyne.ThemeSizeName) float32 {
	return theme.DarkTheme().Size(a)
}

func main() {
	window := app.NewWithID("example").NewWindow("example")
	settingMenu := fyne.NewMenu("Settings",  fyne.NewMenuItem("Demo Code", func() {
		SettingDialog("Demo", window)},
	))
	mainMenu := fyne.NewMainMenu(settingMenu)
	window.SetMainMenu(mainMenu)
	window.Resize(fyne.NewSize(800, 800))
	fyne.CurrentApp().Settings().SetTheme(TestTheme{})
	window.ShowAndRun()
}

func SettingDialog(tl string, win fyne.Window) {
	//Advanced color picker
	advButton := widget.NewButton( "Test", func() {
		picker := dialog.NewColorPicker("Pick a Color", "Please pick your color:", func(color.Color) {
		}, win)
		picker.Advanced = true
		picker.Show()
	})
	cusBox := container.NewVBox(advButton)
	set := dialog.NewCustomConfirm(tl, "Apply", "Exit", cusBox, nil, win)
	set.Show()
}

@andydotxyz
Copy link
Member

Great, thanks - I can see the issue now

@andydotxyz andydotxyz added bug Something isn't working and removed question A question has been asked labels Feb 18, 2021
@andydotxyz
Copy link
Member

It turns out to be an issue with our un-multiply-alpha code.
You can fix this in your code until we update by returning NRGBA instead of RGBA (i.e. not-pre-multiplied).

andydotxyz added a commit to andydotxyz/fyne that referenced this issue Feb 18, 2021
@andydotxyz
Copy link
Member

Feel free to test that fix @apieceof :)

andydotxyz added a commit that referenced this issue Feb 18, 2021
andydotxyz added a commit that referenced this issue Feb 18, 2021
@andydotxyz
Copy link
Member

Fixed in upcoming 2.0.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants