func font(driver gxui.Driver) gxui.Font { desiredFonts := settings.DesiredFonts() if len(desiredFonts) == 0 { return nil } fontReader, err := fonts.Load(desiredFonts...) if err != nil { log.Printf("Error searching for fonts %v: %s", desiredFonts, err) return nil } if closer, ok := fontReader.(io.Closer); ok { defer closer.Close() } fontBytes, err := ioutil.ReadAll(fontReader) if err != nil { log.Printf("Failed to read font file: %s", err) return nil } font, err := driver.CreateFont(fontBytes, 12) if err != nil { log.Printf("Could not parse font: %s", err) return nil } return font }
func CreateTheme(driver gxui.Driver) gxui.Theme { defaultFont, err := driver.CreateFont(gxfont.Default, 12) if err == nil { defaultFont.LoadGlyphs(32, 126) } else { fmt.Printf("Warning: Failed to load default font - %v\n", err) } defaultMonospaceFont, err := driver.CreateFont(gxfont.Monospace, 12) if err == nil { defaultFont.LoadGlyphs(32, 126) } else { fmt.Printf("Warning: Failed to load default monospace font - %v\n", err) } scrollBarRailDefaultBg := gxui.Black scrollBarRailDefaultBg.A = 0.7 scrollBarRailOverBg := gxui.Gray20 scrollBarRailOverBg.A = 0.7 neonBlue := gxui.ColorFromHex(0xFF5C8CFF) focus := gxui.ColorFromHex(0xA0C4D6FF) return &basic.Theme{ DriverInfo: driver, DefaultFontInfo: defaultFont, DefaultMonospaceFontInfo: defaultMonospaceFont, WindowBackground: gxui.Black, // fontColor brushColor penColor BubbleOverlayStyle: basic.CreateStyle(gxui.Gray80, gxui.Gray20, gxui.Gray40, 1.0), ButtonDefaultStyle: basic.CreateStyle(gxui.Gray80, gxui.Gray10, gxui.Gray20, 1.0), ButtonOverStyle: basic.CreateStyle(gxui.Gray90, gxui.Gray15, gxui.Gray50, 1.0), ButtonPressedStyle: basic.CreateStyle(gxui.Gray20, gxui.Gray70, gxui.Gray30, 1.0), CodeSuggestionListStyle: basic.CreateStyle(gxui.Gray80, gxui.Gray20, gxui.Gray10, 1.0), DropDownListDefaultStyle: basic.CreateStyle(gxui.Gray80, gxui.Gray10, gxui.Gray20, 1.0), DropDownListOverStyle: basic.CreateStyle(gxui.Gray80, gxui.Gray15, gxui.Gray50, 1.0), FocusedStyle: basic.CreateStyle(gxui.Gray80, gxui.Transparent, focus, 1.0), HighlightStyle: basic.CreateStyle(gxui.Gray80, gxui.Transparent, neonBlue, 2.0), LabelStyle: basic.CreateStyle(gxui.Gray80, gxui.Transparent, gxui.Transparent, 0.0), PanelBackgroundStyle: basic.CreateStyle(gxui.Gray80, gxui.Gray10, gxui.Gray15, 1.0), ScrollBarBarDefaultStyle: basic.CreateStyle(gxui.Gray80, gxui.Gray30, gxui.Gray40, 1.0), ScrollBarBarOverStyle: basic.CreateStyle(gxui.Gray80, gxui.Gray50, gxui.Gray60, 1.0), ScrollBarRailDefaultStyle: basic.CreateStyle(gxui.Gray80, scrollBarRailDefaultBg, gxui.Transparent, 1.0), ScrollBarRailOverStyle: basic.CreateStyle(gxui.Gray80, scrollBarRailOverBg, gxui.Gray20, 1.0), SplitterBarDefaultStyle: basic.CreateStyle(gxui.Gray80, gxui.Gray10, gxui.Gray10, 1.0), SplitterBarOverStyle: basic.CreateStyle(gxui.Gray80, gxui.Gray10, gxui.Gray50, 1.0), TabActiveHighlightStyle: basic.CreateStyle(gxui.Gray90, neonBlue, neonBlue, 0.0), TabDefaultStyle: basic.CreateStyle(gxui.Gray80, gxui.Gray30, gxui.Gray40, 1.0), TabOverStyle: basic.CreateStyle(gxui.Gray90, gxui.Gray30, gxui.Gray50, 1.0), TabPressedStyle: basic.CreateStyle(gxui.Gray20, gxui.Gray70, gxui.Gray30, 1.0), TextBoxDefaultStyle: basic.CreateStyle(gxui.Gray80, gxui.Gray10, gxui.Gray20, 1.0), TextBoxOverStyle: basic.CreateStyle(gxui.Gray80, gxui.Gray10, gxui.Gray50, 1.0), } }
func appMain(driver gxui.Driver) { theme := flags.CreateTheme(driver) font, err := driver.CreateFont(gxfont.Default, 75) if err != nil { panic(err) } window := theme.CreateWindow(380, 100, "Hi") window.SetBackgroundBrush(gxui.CreateBrush(gxui.Gray50)) label := theme.CreateLabel() label.SetFont(font) label.SetText("Hello world") window.AddChild(label) ticker := time.NewTicker(time.Millisecond * 30) go func() { phase := float32(0) for _ = range ticker.C { c := gxui.Color{ R: 0.75 + 0.25*math.Cosf((phase+0.000)*math.TwoPi), G: 0.75 + 0.25*math.Cosf((phase+0.333)*math.TwoPi), B: 0.75 + 0.25*math.Cosf((phase+0.666)*math.TwoPi), A: 0.50 + 0.50*math.Cosf(phase*10), } phase += 0.01 driver.Call(func() { label.SetColor(c) }) } }() window.OnClose(ticker.Stop) window.OnClose(driver.Terminate) }