本文整理匯總了Golang中github.com/nelsam/gxui.Driver類的典型用法代碼示例。如果您正苦於以下問題:Golang Driver類的具體用法?Golang Driver怎麽用?Golang Driver使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Driver類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: appMain
func appMain(driver gxui.Driver) {
theme := flags.CreateTheme(driver)
label := theme.CreateLabel()
label.SetText("This is a progress bar:")
progressBar := theme.CreateProgressBar()
progressBar.SetDesiredSize(math.Size{W: 400, H: 20})
progressBar.SetTarget(100)
layout := theme.CreateLinearLayout()
layout.AddChild(label)
layout.AddChild(progressBar)
layout.SetHorizontalAlignment(gxui.AlignCenter)
window := theme.CreateWindow(800, 600, "Progress bar")
window.SetScale(flags.DefaultScaleFactor)
window.AddChild(layout)
window.OnClose(driver.Terminate)
progress := 0
pause := time.Millisecond * 500
var timer *time.Timer
timer = time.AfterFunc(pause, func() {
driver.Call(func() {
progress = (progress + 3) % progressBar.Target()
progressBar.SetProgress(progress)
timer.Reset(pause)
})
})
}
示例3: font
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
}
示例4: CreateTheme
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),
}
}
示例5: Init
func (w *Window) Init(outer WindowOuter, driver gxui.Driver, width, height int, title string) {
w.Attachable.Init(outer)
w.BackgroundBorderPainter.Init(outer)
w.Container.Init(outer)
w.Paddable.Init(outer)
w.PaintChildren.Init(outer)
w.outer = outer
w.driver = driver
w.onClose = gxui.CreateEvent(func() {})
w.onResize = gxui.CreateEvent(func() {})
w.onMouseMove = gxui.CreateEvent(func(gxui.MouseEvent) {})
w.onMouseEnter = gxui.CreateEvent(func(gxui.MouseEvent) {})
w.onMouseExit = gxui.CreateEvent(func(gxui.MouseEvent) {})
w.onMouseDown = gxui.CreateEvent(func(gxui.MouseEvent) {})
w.onMouseUp = gxui.CreateEvent(func(gxui.MouseEvent) {})
w.onMouseScroll = gxui.CreateEvent(func(gxui.MouseEvent) {})
w.onKeyDown = gxui.CreateEvent(func(gxui.KeyboardEvent) {})
w.onKeyUp = gxui.CreateEvent(func(gxui.KeyboardEvent) {})
w.onKeyRepeat = gxui.CreateEvent(func(gxui.KeyboardEvent) {})
w.onKeyStroke = gxui.CreateEvent(func(gxui.KeyStrokeEvent) {})
w.onClick = gxui.CreateEvent(func(gxui.MouseEvent) {})
w.onDoubleClick = gxui.CreateEvent(func(gxui.MouseEvent) {})
w.focusController = gxui.CreateFocusController(outer)
w.mouseController = gxui.CreateMouseController(outer, w.focusController)
w.keyboardController = gxui.CreateKeyboardController(outer)
w.onResize.Listen(func() {
w.outer.LayoutChildren()
w.Draw()
})
w.SetBorderPen(gxui.TransparentPen)
w.setViewport(driver.CreateWindowedViewport(width, height, title))
// Window starts shown
w.Attach()
// Interface compliance test
_ = gxui.Window(w)
}