本文整理汇总了Golang中github.com/js-arias/sparta.Widget类的典型用法代码示例。如果您正苦于以下问题:Golang Widget类的具体用法?Golang Widget怎么用?Golang Widget使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Widget类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: trViewExpose
func trViewExpose(tv sparta.Widget, e interface{}) bool {
dt := tv.Property(sparta.Data)
if dt == nil {
return false
}
data := dt.(*trData)
draw := tv.(*widget.Canvas)
for _, n := range data.node {
draw.Draw(n.ancLine)
if n.level > 0 {
draw.Draw(n.descLine)
} else if len(n.name.Text) > 0 {
draw.Draw(n.name)
}
}
if n := data.sel; n != nil {
rect := widget.Rectangle{
Rect: image.Rect(n.pos.X-3, n.pos.Y-3, n.pos.X+3, n.pos.Y+3),
}
draw.Draw(rect)
rect.Rect = image.Rect(n.pos.X-2, n.pos.Y-2, n.pos.X+2, n.pos.Y+2)
rect.Fill = true
draw.SetColor(sparta.Foreground, color.RGBA{G: 255})
draw.Draw(rect)
}
return false
}
示例2: txKey
// TxKey gets keyboard events.
func txKey(tx sparta.Widget, e interface{}) bool {
data := tx.Property(sparta.Data).(*pageData)
ev := e.(sparta.KeyEvent)
switch ev.Key {
case sparta.KeyDown:
if (data.pos + 1) < (len(poem) - data.page + 1) {
data.pos++
}
tx.Update()
case sparta.KeyUp:
if (data.pos - 1) >= 0 {
data.pos--
}
tx.Update()
case sparta.KeyPageUp:
if data.pos == 0 {
break
}
data.pos -= data.page
if data.pos < 0 {
data.pos = 0
}
tx.Update()
case sparta.KeyPageDown:
if data.pos == (len(poem) - data.page) {
break
}
data.pos += data.page
if data.pos > (len(poem) - data.page + 1) {
data.pos = len(poem) - data.page
}
tx.Update()
}
return true
}
示例3: pgExpose
// pgExpose draws the polygons.
func pgExpose(pg sparta.Widget, e interface{}) bool {
data := pg.Property(sparta.Data).([]widget.Polygon)
c := pg.(*widget.Canvas)
c.Draw(data[0])
c.Draw(data[1])
return false
}
示例4: trViewInitList
func trViewInitList(m, tv sparta.Widget) {
l, err := localDB.List(jdh.Trees, new(jdh.Values))
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", cmd.ErrStr(err))
return
}
data := &trList{}
for {
phy := &jdh.Phylogeny{}
if err := l.Scan(phy); err != nil {
if err == io.EOF {
break
}
fmt.Fprintf(os.Stderr, "%s\n", cmd.ErrStr(err))
return
}
if (len(phy.Id) == 0) || (len(phy.Root) == 0) {
continue
}
data.phyLs = append(data.phyLs, phy)
}
if len(data.phyLs) == 0 {
return
}
m.SetProperty(sparta.Data, data)
trViewInitTree(m, tv)
}
示例5: txNavInfoExpose
func txNavInfoExpose(tx sparta.Widget, e interface{}) bool {
d := tx.Property(sparta.Data)
if d == nil {
return false
}
data := d.(*txTaxAnc)
c := tx.(*widget.Canvas)
txt := widget.Text{}
txt.Pos.X = 2
txt.Pos.Y = 2
txt.Text = "Id: " + data.tax.Id
c.Draw(txt)
txt.Pos.Y += sparta.HeightUnit
txt.Text = data.tax.Name
c.Draw(txt)
txt.Pos.Y += sparta.HeightUnit
txt.Text = data.tax.Authority
c.Draw(txt)
txt.Pos.Y += sparta.HeightUnit
txt.Text = data.tax.Rank.String()
c.Draw(txt)
txt.Pos.Y += sparta.HeightUnit
if data.tax.IsValid {
txt.Text = "Valid"
c.Draw(txt)
if data.anc != nil {
txt.Pos.Y += sparta.HeightUnit
txt.Text = "Parent: " + data.anc.Name
c.Draw(txt)
}
} else {
txt.Text = "Synonym of " + data.anc.Name
c.Draw(txt)
}
if len(data.tax.Extern) > 0 {
txt.Pos.Y += sparta.HeightUnit
txt.Text = "Extern ids:"
c.Draw(txt)
for _, e := range data.tax.Extern {
txt.Pos.Y += sparta.HeightUnit
txt.Text = " " + e
c.Draw(txt)
}
}
if len(data.tax.Comment) > 0 {
txt.Pos.Y += sparta.HeightUnit
txt.Text = "Comments:"
c.Draw(txt)
cmt := strings.Split(data.tax.Comment, "\n")
for _, e := range cmt {
txt.Pos.Y += sparta.HeightUnit
txt.Text = " " + e
c.Draw(txt)
}
}
return false
}
示例6: sendEvent
// SendEvent sends an event to a widget.
func sendEvent(dest sparta.Widget, comm sparta.CommandEvent) {
dwin := dest.Window().(*window)
var id w32.HWND
if comm.Source != nil {
id = comm.Source.Window().(*window).id
}
w32.PostMessage(dwin.id, w32.WM_USER, uintptr(id), uintptr(comm.Value))
}
示例7: snConf
// SnConf sets the new values of the sine function points
func snConf(sn sparta.Widget, e interface{}) bool {
ev := e.(sparta.ConfigureEvent)
// Get data from the widget.
data := sn.Property(sparta.Data).([]image.Point)
sine(data, ev.Rect.Dx(), ev.Rect.Dy())
return false
}
示例8: trViewInitTree
func trViewInitTree(m, tv sparta.Widget) {
d := m.Property(sparta.Data).(*trList)
if d.pos >= len(d.phyLs) {
return
}
title := fmt.Sprintf("%s: %s [id: %s]", cmd.Name, d.phyLs[d.pos].Name, d.phyLs[d.pos].Id)
m.SetProperty(sparta.Caption, title)
rect := tv.Property(sparta.Geometry).(image.Rectangle)
curTree := setTree(d.phyLs[d.pos], rect)
curTree.putOnScreen()
tv.SetProperty(sparta.Data, curTree)
tv.Update()
}
示例9: propagateWheel
func propagateWheel(w sparta.Widget, pt image.Point) sparta.Widget {
rect := w.Property(sparta.Geometry).(image.Rectangle)
childs := w.Property(sparta.Childs)
if childs == nil {
return w
}
for _, ch := range childs.([]sparta.Widget) {
rect = ch.Property(sparta.Geometry).(image.Rectangle)
if pt.In(rect) {
return propagateWheel(ch, pt.Add(rect.Min))
}
}
return w
}
示例10: txEdInitList
func txEdInitList(m, l sparta.Widget, data *txList, i int, syns bool) {
if data == nil {
data = newTxList(nil, localDB, syns)
} else {
d := newTxList(data.desc[i], data.db, syns)
if len(d.desc) == 0 {
if l.Property(sparta.Name).(string) == "validList" {
data.sels = []int{i}
} else {
sel := false
for _, s := range data.sels {
if s == i {
sel = true
break
}
}
if !sel {
data.sels = append(data.sels, i)
}
}
} else {
data = d
}
}
if l.Property(sparta.Name).(string) == "taxonList" {
m.SetProperty(sparta.Data, data)
}
l.SetProperty(widget.ListList, data)
}
示例11: obExpose
// ObExpose draws the objects.
func obExpose(ob sparta.Widget, e interface{}) bool {
data := ob.Property(sparta.Data).(*objData)
c := ob.(*widget.Canvas)
// Set color sets a color temporalely for the following dawing
// operations. Contrast this with the property sparta.Background
// and sparta.Foreground.
c.SetColor(sparta.Foreground, color.RGBA{255, 0, 0, 0})
c.Draw(widget.Rectangle{Rect: data.arc.Rect})
c.SetColor(sparta.Foreground, color.RGBA{0, 255, 0, 0})
c.Draw(data.l1)
c.Draw(data.l2)
c.SetColor(sparta.Foreground, color.RGBA{0, 0, 255, 0})
c.Draw(data.arc)
return false
}
示例12: snExpose
// SnExpose draw the sine function.
func snExpose(sn sparta.Widget, e interface{}) bool {
// get point data.
data := sn.Property(sparta.Data).([]image.Point)
// get widget geometry
geo := sn.Property(sparta.Geometry).(image.Rectangle)
c := sn.(*widget.Canvas)
// The widget canvas ruses the function Draw to draw particular
// objects, it depends on the data type to decide what to draw.
// Here a line (the "x" axis), is draw.
c.Draw([]image.Point{image.Pt(0, geo.Dy()/2), image.Pt(geo.Dx(), geo.Dy()/2)})
// Then the sine function is draw.
c.Draw(data)
return false
}
示例13: spNavInitSpeList
func spNavInitSpeList(m, s sparta.Widget) {
d := m.Property(sparta.Data)
l := wnd["speList"]
if d == nil {
l.SetProperty(widget.ListList, nil)
return
}
data := d.(*txList)
if len(data.sels) == 0 {
l.SetProperty(widget.ListList, nil)
return
}
tax := data.desc[data.sels[0]]
ls := newSpList(tax, data.db)
l.SetProperty(widget.ListList, ls)
}
示例14: txExpose
// TxExpose draws the poem.
func txExpose(tx sparta.Widget, e interface{}) bool {
data := tx.Property(sparta.Data).(*pageData)
rect := tx.Property(sparta.Geometry).(image.Rectangle)
c := tx.(*widget.Canvas)
// Text store the text to be drawing
txt := widget.Text{}
txt.Pos.X = 2
for i, ln := range poem[data.pos:] {
// The position of the text is the top-right corner of
// the rectange that enclose the text.
txt.Pos.Y = (i * sparta.HeightUnit) + 2
if txt.Pos.Y > rect.Dy() {
break
}
txt.Text = ln
c.Draw(txt)
}
return false
}
示例15: mConf
func mConf(m sparta.Widget, e interface{}) bool {
// the sparta.Childs property return the children of a widget.
ch := m.Property(sparta.Childs).([]sparta.Widget)
ev := e.(sparta.ConfigureEvent)
for _, c := range ch {
// We check the name propery of each widget and use it
// to set the new geometry of each widget.
switch nm := c.Property(sparta.Name).(string); nm {
case "sine":
c.SetProperty(sparta.Geometry, image.Rect(0, 0, ev.Rect.Dx()/2, ev.Rect.Dy()/2))
case "polygon":
c.SetProperty(sparta.Geometry, image.Rect(ev.Rect.Dx()/2, 0, ev.Rect.Dx(), ev.Rect.Dy()/2))
case "objects":
c.SetProperty(sparta.Geometry, image.Rect(0, ev.Rect.Dy()/2, ev.Rect.Dx()/2, ev.Rect.Dy()))
case "poem":
c.SetProperty(sparta.Geometry, image.Rect(ev.Rect.Dx()/2, ev.Rect.Dy()/2, ev.Rect.Dx(), ev.Rect.Dy()))
}
}
return false
}