Пример #1
0
func CreateList(theme *Theme) gxui.List {
	l := &List{}
	l.Init(l, theme)
	l.OnGainedFocus(l.Redraw)
	l.OnLostFocus(l.Redraw)
	l.SetPadding(math.CreateSpacing(2))
	l.SetBorderPen(gxui.TransparentPen)
	l.theme = theme
	return l
}
Пример #2
0
func (o *BubbleOverlay) LayoutChildren() {
	for _, child := range o.outer.Children() {
		bounds := o.outer.Size().Rect().Contract(o.outer.Padding())
		arrowPadding := math.CreateSpacing(o.arrowLength)
		cm := child.Control.Margin()
		cs := child.Control.DesiredSize(math.ZeroSize, bounds.Size().Contract(cm).Max(math.ZeroSize))
		cr := cs.Expand(arrowPadding).EdgeAlignedFit(bounds, o.targetPoint).Contract(arrowPadding)
		child.Layout(cr)
	}
}
Пример #3
0
func appMain(driver gxui.Driver) {
	theme := dark.CreateTheme(driver)
	window := theme.CreateWindow(800, 600, "Polygon")

	container := theme.CreateLinearLayout()

	//	texture := driver.CreateTexture(getImage(cacheDir, tweet.User.ProfileImageURL), 96)
	f, err := os.Open("data/icont19.png")
	if err != nil {
		log.Fatalln(err)
	}
	defer f.Close()
	im, _, err := image.Decode(f)
	if err != nil {
		log.Fatalln(err)
	}

	for i := 0; i < 100; i++ {
		pict := theme.CreateImage()
		texture := driver.CreateTexture(im, 96)
		texture.SetFlipY(true)
		pict.SetTexture(texture)
		pict.SetExplicitSize(math.Size{32, 32})
		pict.SetMargin(math.CreateSpacing(4))
		container.AddChild(pict)
	}

	label := theme.CreateLabel()
	label.SetText("hogehogehoge")
	label.SetMargin(math.CreateSpacing(200))
	container.AddChild(label)

	window.OnClose(driver.Terminate)

	window.AddChild(container)

	gxui.EventLoop(driver)
}
Пример #4
0
func (i *Image) DesiredSize(min, max math.Size) math.Size {
	s := max
	switch i.scalingMode {
	case gxui.ScalingExplicitSize:
		s = i.explicitSize
	case gxui.Scaling1to1:
		switch {
		case i.texture != nil:
			s = i.texture.Size()
		case i.canvas != nil:
			s = i.canvas.Size()
		}
	}
	return s.Expand(math.CreateSpacing(int(i.BorderPen().Width))).Clamp(min, max)
}
Пример #5
0
func CreateDropDownList(theme *Theme) gxui.DropDownList {
	l := &DropDownList{}
	l.Init(l, theme)
	l.OnGainedFocus(l.Redraw)
	l.OnLostFocus(l.Redraw)
	l.List().OnAttach(l.Redraw)
	l.List().OnDetach(l.Redraw)
	l.OnMouseEnter(func(gxui.MouseEvent) {
		l.SetBorderPen(theme.DropDownListOverStyle.Pen)
	})
	l.OnMouseExit(func(gxui.MouseEvent) {
		l.SetBorderPen(theme.DropDownListDefaultStyle.Pen)
	})
	l.SetPadding(math.CreateSpacing(2))
	l.SetBorderPen(theme.DropDownListDefaultStyle.Pen)
	l.SetBackgroundBrush(theme.DropDownListDefaultStyle.Brush)
	l.theme = theme
	return l
}
Пример #6
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})
}