本文整理匯總了Golang中github.com/nelsam/gxui.Theme.CreateImage方法的典型用法代碼示例。如果您正苦於以下問題:Golang Theme.CreateImage方法的具體用法?Golang Theme.CreateImage怎麽用?Golang Theme.CreateImage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/nelsam/gxui.Theme
的用法示例。
在下文中一共展示了Theme.CreateImage方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: createIconButton
func createIconButton(driver gxui.Driver, theme gxui.Theme, iconPath string) gxui.Button {
button := theme.CreateButton()
button.SetType(gxui.PushButton)
fileBytes, err := assets.Asset(iconPath)
if err != nil {
log.Printf("Error: Failed to read asset %s: %s", iconPath, err)
return button
}
f := bytes.NewBuffer(fileBytes)
src, _, err := image.Decode(f)
if err != nil {
log.Printf("Error: Failed to decode image %s: %s", iconPath, err)
return button
}
src = resize.Resize(24, 24, src, resize.Bilinear)
rgba := image.NewRGBA(src.Bounds())
draw.Draw(rgba, src.Bounds(), src, image.ZP, draw.Src)
texture := driver.CreateTexture(rgba, 1)
icon := theme.CreateImage()
icon.SetTexture(texture)
button.AddChild(icon)
return button
}
示例2: Create
func (a *customAdapter) Create(theme gxui.Theme, index int) gxui.Control {
phase := float32(index) / 1000
c := gxui.Color{
R: 0.5 + 0.5*math.Sinf(math.TwoPi*(phase+0.000)),
G: 0.5 + 0.5*math.Sinf(math.TwoPi*(phase+0.333)),
B: 0.5 + 0.5*math.Sinf(math.TwoPi*(phase+0.666)),
A: 1.0,
}
i := theme.CreateImage()
i.SetBackgroundBrush(gxui.CreateBrush(c))
i.SetMargin(math.Spacing{L: 3, T: 3, R: 3, B: 3})
i.OnMouseEnter(func(ev gxui.MouseEvent) {
i.SetBorderPen(gxui.CreatePen(2, gxui.Gray80))
})
i.OnMouseExit(func(ev gxui.MouseEvent) {
i.SetBorderPen(gxui.TransparentPen)
})
i.OnMouseDown(func(ev gxui.MouseEvent) {
i.SetBackgroundBrush(gxui.CreateBrush(c.MulRGB(0.7)))
})
i.OnMouseUp(func(ev gxui.MouseEvent) {
i.SetBackgroundBrush(gxui.CreateBrush(c))
})
return i
}
示例3: colorPicker
// Color picker uses the customAdapter for driving a list
func colorPicker(theme gxui.Theme) gxui.Control {
layout := theme.CreateLinearLayout()
layout.SetDirection(gxui.TopToBottom)
label0 := theme.CreateLabel()
label0.SetText("Color palette:")
layout.AddChild(label0)
adapter := &customAdapter{}
list := theme.CreateList()
list.SetAdapter(adapter)
list.SetOrientation(gxui.Horizontal)
layout.AddChild(list)
label1 := theme.CreateLabel()
label1.SetMargin(math.Spacing{T: 30})
label1.SetText("Selected color:")
layout.AddChild(label1)
selected := theme.CreateImage()
selected.SetExplicitSize(math.Size{W: 32, H: 32})
layout.AddChild(selected)
list.OnSelectionChanged(func(item gxui.AdapterItem) {
if item != nil {
control := list.ItemControl(item)
selected.SetBackgroundBrush(control.(gxui.Image).BackgroundBrush())
}
})
return layout
}
示例4: Create
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
}