Skip to content

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

Closed
@apieceof

Description

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions