示例#1
0
文件: draw_paint.go 项目: langxj/gxui
func (d *DrawPaint) Init(outer DrawPaintOuter, theme gxui.Theme) {
	d.outer = outer
	d.driver = theme.Driver()

	if debugVerifyDetachOnGC {
		runtime.SetFinalizer(d.outer, verifyDetach)
	}
}
示例#2
0
func (d *DrawPaint) Init(outer DrawPaintOuter, theme gxui.Theme) {
	d.outer = outer
	d.driver = theme.Driver()
	outer.OnDetach(func() {
		if d.canvas != nil {
			d.canvas.Release()
			d.canvas = nil
		}
	})

	if debugVerifyDetachOnGC {
		runtime.SetFinalizer(d.outer, verifyDetach)
	}
}
示例#3
0
文件: tree.go 项目: langxj/gxui
func (treeControlCreator) Create(theme gxui.Theme, control gxui.Control, node *mixins.TreeToListNode) gxui.Control {
	img := theme.CreateImage()
	imgSize := math.Size{W: 10, H: 10}

	ll := theme.CreateLinearLayout()
	ll.SetDirection(gxui.LeftToRight)

	btn := theme.CreateButton()
	btn.SetBackgroundBrush(gxui.TransparentBrush)
	btn.SetBorderPen(gxui.CreatePen(1, gxui.Gray30))
	btn.SetMargin(math.Spacing{L: 1, R: 1, T: 1, B: 1})
	btn.OnClick(func(ev gxui.MouseEvent) {
		if ev.Button == gxui.MouseButtonLeft {
			node.ToggleExpanded()
		}
	})
	btn.AddChild(img)

	update := func() {
		expanded := node.IsExpanded()
		canvas := theme.Driver().CreateCanvas(imgSize)
		btn.SetVisible(!node.IsLeaf())
		switch {
		case !btn.IsMouseDown(gxui.MouseButtonLeft) && expanded:
			canvas.DrawPolygon(expandedPoly, gxui.TransparentPen, gxui.CreateBrush(gxui.Gray70))
		case !btn.IsMouseDown(gxui.MouseButtonLeft) && !expanded:
			canvas.DrawPolygon(collapsedPoly, gxui.TransparentPen, gxui.CreateBrush(gxui.Gray70))
		case expanded:
			canvas.DrawPolygon(expandedPoly, gxui.TransparentPen, gxui.CreateBrush(gxui.Gray30))
		case !expanded:
			canvas.DrawPolygon(collapsedPoly, gxui.TransparentPen, gxui.CreateBrush(gxui.Gray30))
		}
		canvas.Complete()
		img.SetCanvas(canvas)
	}
	btn.OnMouseDown(func(gxui.MouseEvent) { update() })
	btn.OnMouseUp(func(gxui.MouseEvent) { update() })
	update()

	gxui.WhileAttached(btn, node.OnChange, update)

	ll.AddChild(btn)
	ll.AddChild(control)
	ll.SetPadding(math.Spacing{L: 16 * node.Depth()})
	return ll
}
// CreateIcon is create icon control
func CreateIcon(theme gxui.Theme, icon rune, size int) gxui.Label {
	if theme == nil || size < 0 {
		return nil
	}
	control := theme.CreateLabel()
	font, ok := MaterialIconFonts[size]
	if !ok {
		var err error
		font, err = theme.Driver().CreateFont(MaterialIcon, size)
		if err != nil {
			return nil
		}
		MaterialIconFonts[size] = font
	}
	control.SetFont(font)
	control.SetText(string(icon))
	return control
}
示例#5
0
文件: tree.go 项目: linux-mac/gxui
func (t *Tree) CreateExpandButton(theme gxui.Theme, node *mixins.TreeInternalNode) gxui.Button {
	img := theme.CreateImage()
	imgSize := math.Size{W: 10, H: 10}

	btn := theme.CreateButton()
	btn.SetBackgroundBrush(gxui.TransparentBrush)
	btn.SetBorderPen(gxui.CreatePen(1, gxui.Gray30))
	btn.SetMargin(math.Spacing{L: 1, R: 1, T: 1, B: 1})
	btn.OnClick(func(ev gxui.MouseEvent) {
		if ev.Button == gxui.MouseButtonLeft {
			if node.IsExpanded() {
				node.Collapse()
			} else {
				node.Expand()
			}
		}
	})
	btn.AddChild(img)

	updateStyle := func() {
		canvas := theme.Driver().CreateCanvas(imgSize)
		switch {
		case !btn.IsMouseDown(gxui.MouseButtonLeft) && node.IsExpanded():
			canvas.DrawPolygon(expandedPoly, gxui.TransparentPen, gxui.CreateBrush(gxui.Gray70))
		case !btn.IsMouseDown(gxui.MouseButtonLeft) && !node.IsExpanded():
			canvas.DrawPolygon(collapsedPoly, gxui.TransparentPen, gxui.CreateBrush(gxui.Gray70))
		case node.IsExpanded():
			canvas.DrawPolygon(expandedPoly, gxui.TransparentPen, gxui.CreateBrush(gxui.Gray30))
		case !node.IsExpanded():
			canvas.DrawPolygon(collapsedPoly, gxui.TransparentPen, gxui.CreateBrush(gxui.Gray30))
		}
		canvas.Complete()
		img.SetCanvas(canvas)
	}
	btn.OnMouseDown(func(gxui.MouseEvent) { updateStyle() })
	btn.OnMouseUp(func(gxui.MouseEvent) { updateStyle() })
	node.OnExpandedChanged(func(e bool) { updateStyle() })
	updateStyle()
	return btn
}
示例#6
0
文件: layoutable.go 项目: liulnn/gxui
func (l *Layoutable) Init(outer LayoutableOuter, theme gxui.Theme) {
	l.outer = outer
	l.driver = theme.Driver()
}