func main() { // MainWindow is a rootless widget that can contain other widgets. // You can create as many as you want. You should drefine a name and // a title of the window (depending on the backend, this name will // be captured by the OS). // // Names are not necessary, but it is a good practice to have names, // so this will make the identification of widgets earier (using the // sparta.Name property). widget.NewMainWindow("one", "Window one") widget.NewMainWindow("two", "Window two") // sparta.Run runs the event loop of the application backend. sparta.Run() }
func txEdRun(c *cmdapp.Command, args []string) { cmd = c openLocal(c) title := fmt.Sprintf("%s: please wait", c.Name) m := widget.NewMainWindow("main", title) geo := m.Property(sparta.Geometry).(image.Rectangle) widget.NewButton(m, "upTax", "up", image.Rect(5, 5, 5+(sparta.WidthUnit*10), 5+(3*sparta.HeightUnit/2))) widget.NewButton(m, "val", "validate", image.Rect(10+(sparta.WidthUnit*10), 5, 10+(sparta.WidthUnit*20), 5+(3*sparta.HeightUnit/2))) widget.NewButton(m, "upVal", "up", image.Rect(270, 5, 270+(sparta.WidthUnit*10), 5+(3*sparta.HeightUnit/2))) widget.NewButton(m, "syn", "syn ->", image.Rect(205, 10+(3*sparta.HeightUnit/2), 205+(sparta.WidthUnit*10), 10+(6*sparta.HeightUnit/2))) widget.NewButton(m, "move", "move ->", image.Rect(205, 15+(6*sparta.HeightUnit/2), 205+(sparta.WidthUnit*10), 15+(9*sparta.HeightUnit/2))) l := widget.NewList(m, "taxonList", image.Rect(5, 10+(3*sparta.HeightUnit/2), 200, geo.Dy()-10)) wnd["taxonList"] = l s := widget.NewList(m, "validList", image.Rect(210+(sparta.WidthUnit*10), 10+(3*sparta.HeightUnit/2), 405+(sparta.WidthUnit*10), geo.Dy()-10)) wnd["validList"] = s m.Capture(sparta.Configure, txEdConf) m.Capture(sparta.Command, txEdComm) sparta.Block(nil) go func() { txEdInitList(m, l, nil, 0, true) txEdInitList(m, s, nil, 0, false) txEdSetCaption(m) sparta.Unblock(nil) }() sparta.Run() }
func txNavRun(c *cmdapp.Command, args []string) { cmd = c var db jdh.DB if len(extDBFlag) != 0 { openExt(c, extDBFlag, "") db = extDB } else { openLocal(c) db = localDB } title := fmt.Sprintf("%s: please wait", c.Name) m := widget.NewMainWindow("main", title) geo := m.Property(sparta.Geometry).(image.Rectangle) widget.NewButton(m, "upTax", "up", image.Rect(5, 5, 5+(sparta.WidthUnit*10), 5+(3*sparta.HeightUnit/2))) tx := widget.NewCanvas(m, "info", image.Rect(210, 10+(3*sparta.HeightUnit/2), geo.Dx()-10, geo.Dy()-10)) tx.SetProperty(sparta.Border, true) tx.Capture(sparta.Expose, txNavInfoExpose) wnd["info"] = tx l := widget.NewList(m, "taxonList", image.Rect(5, 10+(3*sparta.HeightUnit/2), 200, geo.Dy()-10)) wnd["taxonList"] = l m.Capture(sparta.Configure, txNavConf) m.Capture(sparta.Command, txNavComm) sparta.Block(nil) go txNavInitList(m, l, db, nil, 0) sparta.Run() }
func spNavRun(c *cmdapp.Command, args []string) { cmd = c var db jdh.DB openLocal(c) db = localDB title := fmt.Sprintf("%s: please wait", c.Name) m := widget.NewMainWindow("main", title) geo := m.Property(sparta.Geometry).(image.Rectangle) widget.NewButton(m, "upTax", "up", image.Rect(5, 5, 5+(sparta.WidthUnit*10), 5+(3*sparta.HeightUnit/2))) dy := geo.Dy() - 10 - (10 + (3 * sparta.HeightUnit / 2)) l := widget.NewList(m, "taxonList", image.Rect(5, 10+(3*sparta.HeightUnit/2), 200, (dy/2)+10+(3*sparta.HeightUnit/2))) wnd["taxonList"] = l s := widget.NewList(m, "speList", image.Rect(210, 10+(3*sparta.HeightUnit/2), 410, (dy/2)+10+(3*sparta.HeightUnit/2))) wnd["speList"] = s tx := widget.NewCanvas(m, "info", image.Rect(5, (dy/2)+20+(3*sparta.HeightUnit/2), geo.Dx()-10, geo.Dy()-10)) tx.SetProperty(sparta.Border, true) tx.Capture(sparta.Expose, spNavInfoExpose) wnd["info"] = tx m.Capture(sparta.Configure, spNavConf) m.Capture(sparta.Command, spNavComm) sparta.Block(nil) go func() { spNavInitTaxList(m, l, db, nil, 0) sparta.Unblock(nil) }() sparta.Run() }
func trViewRun(c *cmdapp.Command, args []string) { cmd = c openLocal(c) title := fmt.Sprintf("%s: please wait", c.Name) m := widget.NewMainWindow("main", title) geo := m.Property(sparta.Geometry).(image.Rectangle) tv := widget.NewCanvas(m, "tree", image.Rect(0, 0, geo.Dx(), geo.Dy())) wnd["tree"] = tv tv.Capture(sparta.Expose, trViewExpose) tv.Capture(sparta.KeyEv, trViewKey) tv.Capture(sparta.Mouse, trViewMouse) tv.Update() m.Capture(sparta.Configure, trViewConf) go trViewInitList(m, tv) sparta.Run() }
func main() { rand.Seed(time.Now().Unix()) // The main window. m := widget.NewMainWindow("main", "Event Window") // Functions to capture the events. // // Capture close event.This event is produced when attepting to // close a rootless widget (such as MainWindow), or when a child // is closed. m.Capture(sparta.CloseEv, closeFunc) // Capture command event. This event is produced when another // process, or a widget send a message to another widget. m.Capture(sparta.Command, commandFunc) // Capture configure event. This event is produced when a widget // changes its size. m.Capture(sparta.Configure, configureFunc) // Capture Expose event. This event is produced when a previously // obscured part of a widget is exposed (in some backends, other // backends save obscured part of the widget and simply copy them // when the widget is exposed. Expose event are also produced when // the widget is resized (configure), and when an explicit update // method is called. m.Capture(sparta.Expose, exposeFunc) // Capture Key event. This event is produced when a key in the // keyboard is pressed or released. m.Capture(sparta.KeyEv, keyFunc) // Capture Mouse event. This event is produced when the mouse is // moved, a button is pressed or released. m.Capture(sparta.Mouse, mouseFunc) // this helper function is used to send command events to the window. // it will send a random number each second. go func() { for { time.Sleep(10 * time.Second) sparta.SendEvent(m, sparta.CommandEvent{Value: rand.Intn(255)}) } }() sparta.Run() }
func main() { m := widget.NewMainWindow("main", "Canvas") // The method Property returns an interface of the asked property. If // the widget does not process that property, it will return nil. // sparta.Geometry is a property that indicate the dimensions (and // position) of the widget relative to its parent. geo := m.Property(sparta.Geometry).(image.Rectangle) // NewCanvas creates a new drawable canvas. sn := widget.NewCanvas(m, "sine", image.Rect(0, 0, geo.Dx()/2, geo.Dy()/2)) // The method SetProperty sets a property in the widget. // We want that the widget have a border, so we set sparta.Border as true. sn.SetProperty(sparta.Border, true) // create the points for the sine function. pts := make([]image.Point, 1000) // set the initial values of the sine function. sine(pts, geo.Dx()/2, geo.Dy()/2) // sparta.Data is a property that store client defined data of a widget. sn.SetProperty(sparta.Data, pts) // We want to process the configure event, to update the position of // the sine points. sn.Capture(sparta.Configure, snConf) // We wnat to process the expose event, to draw the content of the widget. sn.Capture(sparta.Expose, snExpose) // We send and update request to guarantee that the content of the // widget will be drawn. sn.Update() pg := widget.NewCanvas(m, "polygon", image.Rect(geo.Dx()/2, 0, geo.Dx(), geo.Dy()/2)) pg.SetProperty(sparta.Border, true) // We set the background of the widget to be light grey, using the // property sparta.Background. pg.SetProperty(sparta.Background, color.RGBA{190, 190, 190, 0}) // We set the foreground of the widget (i.e. the color used to draw // objects to be drak grey, using the property sparta.Foreground. pg.SetProperty(sparta.Foreground, color.RGBA{90, 90, 90, 0}) poly := []widget.Polygon{ widget.Polygon{Pt: make([]image.Point, len(polyPts))}, widget.Polygon{Pt: make([]image.Point, len(polyPts)), Fill: true}, } setPoly(poly, geo.Dx()-(geo.Dx()/2), geo.Dy()/2) pg.SetProperty(sparta.Data, poly) pg.Capture(sparta.Configure, pgConf) pg.Capture(sparta.Expose, pgExpose) pg.Update() ob := widget.NewCanvas(m, "objects", image.Rect(0, geo.Dy()/2, geo.Dx()/2, geo.Dy())) ob.SetProperty(sparta.Border, true) objs := &objData{ l1: make([]image.Point, 2), l2: make([]image.Point, 2), arc: widget.Arc{ Angle2: math.Pi * 2, Fill: true, }, } setObj(objs, geo.Dx()/2, geo.Dy()-(geo.Dy()/2)) ob.SetProperty(sparta.Data, objs) ob.Capture(sparta.Configure, obConf) ob.Capture(sparta.Expose, obExpose) ob.Update() tx := widget.NewCanvas(m, "poem", image.Rect(geo.Dx()/2, geo.Dy()/2, geo.Dx(), geo.Dy())) tx.SetProperty(sparta.Border, true) // In sparta the size of a text glyph is given by sparta.HeightUnit // and sparta.WidthUnit. txtData := &pageData{ pos: 0, page: (geo.Dy() - (geo.Dy() / 2)) / sparta.HeightUnit, } tx.SetProperty(sparta.Data, txtData) tx.Capture(sparta.Configure, txConf) tx.Capture(sparta.Expose, txExpose) // To navigate the text we also capture the mouse and the keyboard. tx.Capture(sparta.Mouse, txMouse) tx.Capture(sparta.KeyEv, txKey) tx.Update() // We want to capture the mainwindow configure event so if the // mainWindow changes its size, we can update the size and position // of the all other widgets. m.Capture(sparta.Configure, mConf) sparta.Run() }