Exemple #1
0
func appMain(driver gxui.Driver) {
	theme := dark.CreateTheme(driver)

	window := theme.CreateWindow(800, 600, "Hi")
	window.SetBackgroundBrush(gxui.CreateBrush(gxui.Gray50))

	fontData, err := ioutil.ReadFile(sysFont("幼圆")) //this font comes from windows
	if err != nil {
		log.Fatalf("error reading font: %v", err)
	}
	font, err := driver.CreateFont(fontData, 50)
	if err != nil {
		panic(err)
	}
	label := theme.CreateLabel()
	label.SetFont(font)
	label.SetColor(gxui.Red50)
	label.SetText("支持一下中文")

	button := theme.CreateButton()
	button.SetText("点我一下")

	window.AddChild(label)
	window.AddChild(button)

	window.OnClose(driver.Terminate)

}
Exemple #2
0
func CreateFont(size int, driver gxui.Driver) gxui.Font {
	font, err := driver.CreateFont(gxfont.Monospace, size)
	if err != nil {
		panic(err)
	}
	return font
}
Exemple #3
0
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),
	}
}
Exemple #4
0
func appMain(driver gxui.Driver) {
	theme := flags.CreateTheme(driver)

	// ┌───────┐║┌───────┐
	// │       │║│       │
	// │   A   │║│   B   │
	// │       │║│       │
	// └───────┘║└───────┘
	// ═══════════════════
	// ┌───────┐║┌───────┐
	// │       │║│       │
	// │   C   │║│   D   │
	// │       │║│       │
	// └───────┘║└───────┘

	ftData, err := ioutil.ReadFile("static/font/simhei.ttf")
	if err != nil {
		log.Println(err)
	}
	ft, err := driver.CreateFont(ftData, 20)
	if err != nil {
		log.Println(err)
	}
	menu := theme.CreateLinearLayout()
	menu.SetDirection(gxui.LeftToRight)
	logo_label := theme.CreateLabel()
	logo_label.SetColor(gxui.White)
	logo_label.SetFont(ft)
	logo_label.SetText("百度盘")
	logo_label.SetSize(math.Size{300, 200})
	menu.AddChild(logo_label)

	splitterCD := theme.CreateSplitterLayout()
	splitterCD.SetOrientation(gxui.Horizontal)
	splitterCD.AddChild(panelHolder("C", theme))
	splitterCD.AddChild(panelHolder("D", theme))

	vSplitter := theme.CreateSplitterLayout()
	vSplitter.SetOrientation(gxui.Vertical)
	vSplitter.AddChild(menu)
	vSplitter.AddChild(splitterCD)

	window := theme.CreateWindow(800, 600, "百度盘")
	window.SetScale(flags.DefaultScaleFactor)
	window.AddChild(vSplitter)
	window.OnClose(driver.Terminate)
}
Exemple #5
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)
}
Exemple #6
0
func appMain(driver gxui.Driver) {
	theme := flags.CreateTheme(driver)

	font, err := driver.CreateFont(gxfont.Default, H1_FONT_SIZE)
	catch(err)

	window := theme.CreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, APP_TITLE)
	window.SetBackgroundBrush(gxui.CreateBrush(gxui.White))
	window.SetScale(flags.DefaultScaleFactor)
	window.SetPadding(math.Spacing{L: 10, R: 10, T: 10, B: 10})

	layout := theme.CreateLinearLayout()
	layout.SetSizeMode(gxui.Fill)
	layout.SetHorizontalAlignment(gxui.AlignCenter)
	layout.HorizontalAlignment().AlignCenter()

	fullscreenButton := theme.CreateButton()
	fullscreenButton.SetText("Make Fullscreen")
	fullscreenButton.OnClick(func(ev gxui.MouseEvent) {
		fullscreen := !window.Fullscreen()
		window.SetFullscreen(fullscreen)

		if fullscreen {
			fullscreenButton.SetText("Make Windowed")
		} else {
			fullscreenButton.SetText("Make Fullscreen")
		}
	})

	h1Title := theme.CreateLabel()
	h1Title.SetFont(font)
	h1Title.SetColor(gxui.Color{R: 0, G: 0, B: 0, A: 1})

	KinopoiskLabel := theme.CreateLabel()
	KinopoiskLabel.SetFont(font)
	KinopoiskLabel.SetColor(gxui.Color{R: 0, G: 0, B: 0, A: 1})

	ImdbLabel := theme.CreateLabel()
	ImdbLabel.SetFont(font)
	ImdbLabel.SetColor(gxui.Color{R: 0, G: 0, B: 0, A: 1})

	// https://github.com/google/gxui/blob/master/samples/image_viewer/main.go
	img := theme.CreateImage()

	getFilmButton := theme.CreateButton()
	getFilmButton.SetText("Get Film!")
	getFilmButton.OnClick(func(ev gxui.MouseEvent) {
		getFilm(driver, h1Title, KinopoiskLabel, ImdbLabel, img)
	})

	getFilm(driver, h1Title, KinopoiskLabel, ImdbLabel, img)

	layout.AddChild(fullscreenButton)
	layout.AddChild(h1Title)
	layout.AddChild(KinopoiskLabel)
	layout.AddChild(ImdbLabel)
	layout.AddChild(getFilmButton)
	layout.AddChild(img)
	window.AddChild(layout)

	window.OnClose(driver.Terminate)
}
Exemple #7
0
func MainWindow(driver gxui.Driver) {
	theme = dark.CreateTheme(driver)

	fontData, err := ioutil.ReadFile("./fonts/Microsoft Yahei.ttf")
	if err != nil {
		log.Fatalf("error reading font: %v", err)
	}
	font, err := driver.CreateFont(fontData, 20)
	if err != nil {
		panic(err)
	}
	theme.SetDefaultFont(font)

	headLayout := theme.CreateLinearLayout()
	headLayout.SetSizeMode(gxui.Fill)
	headLayout.SetHorizontalAlignment(gxui.AlignCenter)
	headLayout.SetDirection(gxui.TopToBottom)
	headLayout.SetSize(math.Size{W: 100, H: 50})

	label := theme.CreateLabel()
	label.SetMargin(math.CreateSpacing(10))
	label.SetText("豆瓣FM红心歌单下载")

	headLayout.AddChild(label)

	bodyLayout := theme.CreateLinearLayout()
	bodyLayout.SetSizeMode(gxui.Fill)
	bodyLayout.SetHorizontalAlignment(gxui.AlignCenter)
	bodyLayout.SetSize(math.Size{W: 100, H: 400})
	bodyLayout.SetDirection(gxui.TopToBottom)
	// bodyLayout.SetMargin(math.Spacing{T: 50})

	userHint := theme.CreateLabel()
	userHint.SetMargin(math.CreateSpacing(10))
	userHint.SetText("用户名")
	bodyLayout.AddChild(userHint)
	usernameField := theme.CreateTextBox()
	bodyLayout.AddChild(usernameField)

	passHint := theme.CreateLabel()
	passHint.SetMargin(math.CreateSpacing(10))
	passHint.SetText("密码")
	bodyLayout.AddChild(passHint)
	passwordField := theme.CreateTextBox()
	bodyLayout.AddChild(passwordField)

	footLayout := theme.CreateLinearLayout()
	footLayout.SetSizeMode(gxui.Fill)
	footLayout.SetHorizontalAlignment(gxui.AlignCenter)
	footLayout.SetDirection(gxui.TopToBottom)
	// footLayout.SetMargin(math.Spacing{T: 450})

	button := theme.CreateButton()
	button.SetText("登录并下载")
	button.OnClick(func(gxui.MouseEvent) {
		user := usernameField.Text()
		password := passwordField.Text()
		if user == "" || password == "" {
			return
		}
		label.SetText(user + "&" + password)
	})
	footLayout.AddChild(button)

	window := theme.CreateWindow(600, 800, "豆瓣FM下载器")
	window.SetBackgroundBrush(gxui.CreateBrush(gxui.White))

	window.AddChild(headLayout)
	window.AddChild(bodyLayout)
	window.AddChild(footLayout)

	window.OnClose(driver.Terminate)
	window.SetPadding(math.Spacing{L: 10, T: 10, R: 10, B: 10})
}
Exemple #8
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(800, 480, "Привет")
	window.SetBackgroundBrush(gxui.CreateBrush(gxui.Gray50))
	window.SetBorderPen(gxui.Pen{Width: 5, Color: gxui.Yellow})

	f, err := os.Open("wallpaper.jpg")
	if err != nil {
		fmt.Printf("Failed to open image %v\n", err)
		os.Exit(1)
	}

	source, _, err := image.Decode(f)
	if err != nil {
		fmt.Printf("Failed to open image %v\n", err)
		os.Exit(2)
	}

	wallpaper := theme.CreateImage()
	window.AddChild(wallpaper)

	// Copy the image to a RGBA format before handing to a gxui.Texture
	rgba := image.NewRGBA(source.Bounds())
	draw.Draw(rgba, source.Bounds(), source, image.ZP, draw.Src)
	texture := driver.CreateTexture(rgba, 1)
	wallpaper.SetTexture(texture)

	layout := theme.CreateLinearLayout()
	layout.SetDirection(gxui.TopToBottom)
	window.AddChild(layout)

	label := theme.CreateLabel()
	label.SetFont(font)
	label.SetText("Здравствуй мир")
	label.OnMouseMove(func(e gxui.MouseEvent) {
		fmt.Printf("X=%d; Y=%d\n", e.Point.X, e.Point.Y)
	})
	layout.AddChild(label)

	lTimer := theme.CreateLabel()
	lTimer.SetFont(font)
	lTimer.SetColor(gxui.Green30)
	layout.AddChild(lTimer)

	button := theme.CreateButton()
	button.SetText("Exit")
	button.SetPadding(math.Spacing{20, 10, 20, 10})
	button.SetMargin(math.Spacing{20, 10, 20, 10})
	button.OnClick(func(e gxui.MouseEvent) {
		window.Close()
	})
	layout.AddChild(button)

	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)
			})
		}
	}()

	ticker2 := time.NewTicker(time.Millisecond * 100)
	go func() {
		for t := range ticker.C {
			driver.Call(func() {
				lTimer.SetText(t.Format(time.Stamp))
			})
		}
	}()

	window.OnClose(ticker.Stop)
	window.OnClose(ticker2.Stop)
	window.OnClose(driver.Terminate)
}