func appMain(driver gxui.Driver) { file := "./img/block.bmp" f, err := os.Open(file) if err != nil { fmt.Printf("Failed to open image '%s': %v\n", file, err) os.Exit(1) } source, _, err := image.Decode(f) if err != nil { fmt.Printf("Failed to read image '%s': %v\n", file, err) os.Exit(1) } theme := flags.CreateTheme(driver) img := theme.CreateImage() //mx := source.Bounds().Max window := theme.CreateWindow(1000, 1000, "Tetris") window.SetScale(flags.DefaultScaleFactor) window.AddChild(img) rgba := image.NewRGBA(source.Bounds()) draw.Draw(rgba, source.Bounds(), source, image.ZP, draw.Src) texture := driver.CreateTexture(rgba, 1) img.SetTexture(texture) window.OnClose(driver.Terminate) }
func Initdashboard(driver gxui.Driver) { Theme = flags.CreateTheme(driver) Windashboard = Createwindashboard(Theme) data.DBAnakKost = data.Createdbanakkost() data.DBSetoran = data.Createdatasetoran() data.DBPengeluaran = data.Createdatapengeluaran() }
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) }) }) }
func appMain(driver gxui.Driver) { theme := flags.CreateTheme(driver) // ┌───────┐║┌───────┐ // │ │║│ │ // │ A │║│ B │ // │ │║│ │ // └───────┘║└───────┘ // ═══════════════════ // ┌───────┐║┌───────┐ // │ │║│ │ // │ C │║│ D │ // │ │║│ │ // └───────┘║└───────┘ splitterAB := theme.CreateSplitterLayout() splitterAB.SetOrientation(gxui.Horizontal) splitterAB.AddChild(panelHolder("A", theme)) splitterAB.AddChild(panelHolder("B", theme)) splitterCD := theme.CreateSplitterLayout() splitterCD.SetOrientation(gxui.Horizontal) splitterCD.AddChild(panelHolder("C", theme)) splitterCD.AddChild(panelHolder("D", theme)) vSplitter := theme.CreateSplitterLayout() vSplitter.SetOrientation(gxui.Vertical) vSplitter.AddChild(splitterAB) vSplitter.AddChild(splitterCD) window := theme.CreateWindow(800, 600, "Panels") window.SetScale(flags.DefaultScaleFactor) window.AddChild(vSplitter) window.OnClose(driver.Terminate) }
func appMain(driver gxui.Driver) { theme := flags.CreateTheme(driver) table := theme.CreateTableLayout() table.SetGrid(3, 4) Colum1 := theme.CreateLabel() Colum1.SetText("Column1") Colum2 := theme.CreateLabel() Colum2.SetText("Column2") Colum3 := theme.CreateLabel() Colum3.SetText("Column3") table.SetChildAt(0, 0, 1, 1, Colum1) table.SetChildAt(1, 0, 1, 1, Colum2) table.SetChildAt(2, 0, 1, 1, Colum3) for r := 1; r < 4; r++ { for c := 0; c < 3; c++ { label := theme.CreateLabel() label.SetText(strconv.Itoa(r) + "_" + strconv.Itoa(c)) table.SetChildAt(c, r, 1, 1, label) fmt.Println(r, c) } } window := theme.CreateWindow(600, 600, "Table") window.AddChild(table) }
func gxuiOpenWindow(width uint, height uint, dblBuf *doublebuffer.DoubleBuffer, commands chan Message, events chan Message) { gl.StartDriver(func(driver gxui.Driver) { theme := flags.CreateTheme(driver) window := theme.CreateWindow(int(width), int(height), "MyGameEngine") window.SetScale(flags.DefaultScaleFactor) screen := theme.CreateImage() window.AddChild(screen) window.OnClose(func() { driver.Terminate() events <- Message{MESSAGE_EXIT, 0} }) window.OnKeyDown(func(e gxui.KeyboardEvent) { fmt.Println("keydown") // FIXME: without this line, randomly crash ... events <- Message{MESSAGE_KEY_DOWN, int(e.Key)} }) // repaint function go func() { for { <-commands last := screen.Texture() driver.CallSync(func() { texture := driver.CreateTexture(dblBuf.GetPreviousImage().GetBuffer(), 1) screen.SetTexture(texture) if last != nil { last.Release() } }) } }() }) }
func appMain(driver gxui.Driver) { theme := flags.CreateTheme(driver) window := theme.CreateWindow(800, 600, "iMan升级") window.OnClose(driver.Terminate) window.SetScale(flags.DefaultScaleFactor) window.SetPadding(math.Spacing{L: 50, R: 50, T: 50, B: 50}) button := theme.CreateButton() button.SetHorizontalAlignment(gxui.AlignCenter) button.SetSizeMode(gxui.Fill) toggle := func() { fullscreen := !window.Fullscreen() window.SetFullscreen(fullscreen) if fullscreen { button.SetText("窗口化") } else { button.SetText("全屏") } } box := theme.CreateTextBox() box.SetText("盒子") button.SetText("全屏") button.OnClick(func(gxui.MouseEvent) { toggle() }) window.AddChild(button) window.AddChild(box) }
func appMain(driver gxui.Driver) { theme := flags.CreateTheme(driver) hSplitter := theme.CreateSplitterLayout() hSplitter.SetOrientation(gxui.Horizontal) hSplitter.AddChild(panelHolder("L", theme)) hSplitter.AddChild(panelHolder("R", theme)) window := theme.CreateWindow(500, 600, "Panels") window.SetScale(flags.DefaultScaleFactor) window.AddChild(hSplitter) window.OnClose(driver.Terminate) }
func appMain(driver gxui.Driver) { theme := flags.CreateTheme(driver) width := int(nmj.Width) height := int(nmj.Heigth) window := theme.CreateWindow(width, height, "navmesh") canvas := driver.CreateCanvas(math.Size{W: width, H: height}) ps := nmj.Points // mouse isStart := true x1, y1, x2, y2 := int64(0), int64(0), int64(0), int64(0) window.OnMouseDown(func(me gxui.MouseEvent) { if nm.IsWalkOfPoint(navmesh.Point{X: int64(me.Point.X), Y: int64(me.Point.Y)}) { if isStart { x1 = int64(me.Point.X) y1 = int64(me.Point.Y) } else { x2 = int64(me.Point.X) y2 = int64(me.Point.Y) } if !isStart { drawWalkPath(window, theme, driver, x1, y1, x2, y2) } isStart = !isStart } }) // draw mesh for i := 0; i < len(ps); i++ { polys := make([]gxui.PolygonVertex, 0, len(ps[i])) for j := 0; j < len(ps[i]); j++ { polys = append(polys, gxui.PolygonVertex{ Position: math.Point{ int(ps[i][j].X), int(ps[i][j].Y), }}) } // canvas.DrawPolygon(polys, gxui.CreatePen(2, gxui.Gray80), gxui.CreateBrush(gxui.Gray40)) canvas.DrawPolygon(polys, gxui.CreatePen(2, gxui.Red), gxui.CreateBrush(gxui.Yellow)) } canvas.Complete() image := theme.CreateImage() image.SetCanvas(canvas) window.AddChild(image) window.OnClose(driver.Terminate) }
func appMain(driver gxui.Driver) { theme := flags.CreateTheme(driver) overlay := theme.CreateBubbleOverlay() holder := theme.CreatePanelHolder() holder.AddPanel(numberPicker(theme, overlay), "Default adapter") holder.AddPanel(colorPicker(theme), "Custom adapter") window := theme.CreateWindow(800, 600, "Lists") window.SetScale(flags.DefaultScaleFactor) window.AddChild(holder) window.AddChild(overlay) window.OnClose(driver.Terminate) window.SetPadding(math.Spacing{L: 10, T: 10, R: 10, B: 10}) }
func appMain(driver gxui.Driver) { theme := flags.CreateTheme(driver) // ┌───────┐║┌───────┐ // │ │║│ │ // │ A │║│ B │ // │ │║│ │ // └───────┘║└───────┘ // ═══════════════════ // ┌───────┐║┌───────┐ // │ │║│ │ // │ C │║│ D │ // │ │║│ │ // └───────┘║└───────┘ ftData, err := ioutil.ReadFile("static/font/simhei.ttf") if err != nil { log.Println(err) } ft, err := driver.CreateFont(ftData, 20) if err != nil { log.Println(err) } menu := theme.CreateLinearLayout() menu.SetDirection(gxui.LeftToRight) logo_label := theme.CreateLabel() logo_label.SetColor(gxui.White) logo_label.SetFont(ft) logo_label.SetText("百度盘") logo_label.SetSize(math.Size{300, 200}) menu.AddChild(logo_label) splitterCD := theme.CreateSplitterLayout() splitterCD.SetOrientation(gxui.Horizontal) splitterCD.AddChild(panelHolder("C", theme)) splitterCD.AddChild(panelHolder("D", theme)) vSplitter := theme.CreateSplitterLayout() vSplitter.SetOrientation(gxui.Vertical) vSplitter.AddChild(menu) vSplitter.AddChild(splitterCD) window := theme.CreateWindow(800, 600, "百度盘") window.SetScale(flags.DefaultScaleFactor) window.AddChild(vSplitter) window.OnClose(driver.Terminate) }
func appMain(driver gxui.Driver) { theme := flags.CreateTheme(driver) overlay := theme.CreateBubbleOverlay() holder := theme.CreatePanelHolder() holder.AddPanel(overview(theme), "Overview") holder.AddPanel(send(theme), "Send") holder.AddPanel(receive(theme), "Receive") holder.AddPanel(transactions(theme), "Transactions") window := theme.CreateWindow(800, 450, "Factoid Wallet") window.SetScale(flags.DefaultScaleFactor) window.AddChild(holder) window.AddChild(overlay) window.OnClose(driver.Terminate) window.SetPadding(math.Spacing{L: 10, T: 10, R: 10, B: 10}) }
func appMain(driver gxui.Driver) { theme := flags.CreateTheme(driver) label1 := theme.CreateLabel() label1.SetColor(gxui.White) label1.SetText("1x1") cell1x1 := theme.CreateLinearLayout() cell1x1.SetBackgroundBrush(gxui.CreateBrush(gxui.Blue40)) cell1x1.SetHorizontalAlignment(gxui.AlignCenter) cell1x1.AddChild(label1) label2 := theme.CreateLabel() label2.SetColor(gxui.White) label2.SetText("2x1") cell2x1 := theme.CreateLinearLayout() cell2x1.SetBackgroundBrush(gxui.CreateBrush(gxui.Green40)) cell2x1.SetHorizontalAlignment(gxui.AlignCenter) cell2x1.AddChild(label2) label3 := theme.CreateLabel() label3.SetColor(gxui.White) label3.SetText("1x2") cell1x2 := theme.CreateLinearLayout() cell1x2.SetBackgroundBrush(gxui.CreateBrush(gxui.Red40)) cell1x2.SetHorizontalAlignment(gxui.AlignCenter) cell1x2.AddChild(label3) table := theme.CreateTableLayout() table.SetGrid(3, 2) // columns, rows // row, column, horizontal span, vertical span table.SetChildAt(0, 0, 1, 1, cell1x1) table.SetChildAt(0, 1, 2, 1, cell2x1) table.SetChildAt(2, 0, 1, 2, cell1x2) window := theme.CreateWindow(800, 600, "Table") window.AddChild(table) window.OnClose(driver.Terminate) }
func appMain(driver gxui.Driver) { theme := flags.CreateTheme(driver) canvas := driver.CreateCanvas(math.Size{W: 500, H: 300}) layout := theme.CreateLinearLayout() layout.SetSizeMode(gxui.Fill) layout.SetDirection(gxui.TopToBottom) buttonsLayout := theme.CreateLinearLayout() buttonsLayout.SetSizeMode(gxui.Fill) buttonsLayout.SetDirection(gxui.LeftToRight) button := func(name string, action func()) gxui.Button { b := theme.CreateButton() b.SetText(name) b.OnClick(func(gxui.MouseEvent) { action() }) return b } okayButton := button("Okay", func() { log.Println("Okay") }) buttonsLayout.AddChild(okayButton) cancelButton := button("Cancel", func() { log.Println("Cancel") }) buttonsLayout.AddChild(cancelButton) drawPlot(canvas) canvas.Complete() image := theme.CreateImage() image.SetCanvas(canvas) window := theme.CreateWindow(800, 600, "bview") window.SetBackgroundBrush(gxui.CreateBrush(gxui.Gray50)) layout.AddChild(buttonsLayout) layout.AddChild(image) window.AddChild(layout) window.OnClose(driver.Terminate) window.SetPadding(math.Spacing{L: 10, T: 10, R: 10, B: 10}) window.OnResize(func() { log.Println(layout.Children().String()) }) }
func appMain(driver gxui.Driver) { theme := flags.CreateTheme(driver) layout := theme.CreateLinearLayout() layout.SetDirection(gxui.TopToBottom) adapter := &adapter{} // hook up node changed function to the adapter OnDataChanged event. adapter.changed = adapter.DataChanged // add all the species to the 'Animals' root node. items := addSpecies(adapter.add("Animals")) tree := theme.CreateTree() tree.SetAdapter(adapter) tree.Select(items["Doves"]) tree.Show(tree.Selected()) layout.AddChild(tree) row := theme.CreateLinearLayout() row.SetDirection(gxui.LeftToRight) layout.AddChild(row) expandAll := theme.CreateButton() expandAll.SetText("Expand All") expandAll.OnClick(func(gxui.MouseEvent) { tree.ExpandAll() }) row.AddChild(expandAll) collapseAll := theme.CreateButton() collapseAll.SetText("Collapse All") collapseAll.OnClick(func(gxui.MouseEvent) { tree.CollapseAll() }) row.AddChild(collapseAll) window := theme.CreateWindow(800, 600, "Tree view") window.SetScale(flags.DefaultScaleFactor) window.AddChild(layout) window.OnClose(driver.Terminate) window.SetPadding(math.Spacing{L: 10, T: 10, R: 10, B: 10}) }
func appMain(driver gxui.Driver) { theme := flags.CreateTheme(driver) label := theme.CreateLabel() label.SetText("Clou") splitterAB := theme.CreateSplitterLayout() splitterAB.SetOrientation(gxui.Horizontal) splitterAB.AddChild(panelHolder("Local", theme)) splitterAB.AddChild(panelHolder("Cloud", theme)) vSplitter := theme.CreateSplitterLayout() vSplitter.SetOrientation(gxui.Vertical) vSplitter.AddChild(splitterAB) window := theme.CreateWindow(800, 600, "Panels") window.AddChild(label) window.SetScale(flags.DefaultScaleFactor) window.AddChild(vSplitter) window.OnClose(driver.Terminate) }
func appMain(driver gxui.Driver) { theme := flags.CreateTheme(driver) window := theme.CreateWindow(800, 600, "Polygon") window.SetScale(flags.DefaultScaleFactor) canvas := driver.CreateCanvas(math.Size{W: 1000, H: 1000}) drawStar(canvas, math.Point{X: 100, Y: 100}, 50, 0.2, 6) drawStar(canvas, math.Point{X: 650, Y: 170}, 70, 0.5, 7) drawStar(canvas, math.Point{X: 40, Y: 300}, 20, 0, 5) drawStar(canvas, math.Point{X: 410, Y: 320}, 25, 0.9, 5) drawStar(canvas, math.Point{X: 220, Y: 520}, 45, 0, 6) drawMoon(canvas, math.Point{X: 400, Y: 300}, 200) canvas.Complete() image := theme.CreateImage() image.SetCanvas(canvas) window.AddChild(image) window.OnClose(driver.Terminate) }
func appMain(driver gxui.Driver) { theDriver = driver theme = flags.CreateTheme(driver) window := theme.CreateWindow(winW, winH, "Window") window.OnClose(driver.Terminate) window.SetScale(flags.DefaultScaleFactor) layout := theme.CreateLinearLayout() layout.SetBackgroundBrush(gxui.CreateBrush(gxui.Black)) layout.SetDirection(gxui.LeftToRight) layout.SetVerticalAlignment(gxui.AlignBottom) layout.SetSizeMode(gxui.Fill) nums := common.GenerateRandomNumbers(numBars, 0, valNum) for _, n := range nums { child := createBar() setBarHeight(child, n) layout.AddChild(child) bars = append(bars, child) } window.AddChild(layout) delegate := &GUIDelegate{} go func() { <-time.After(1 * time.Second) fmt.Println("ExecuteSort...") // sorting.ExecuteSort(sorting.InsertionSort, nums, delegate) // sorting.ExecuteSort(sorting.BubbleSort, nums, delegate) // sorting.ExecuteSort(sorting.SelectionSort, nums, delegate) // sorting.ExecuteSort(sorting.ShellSort, nums, delegate) // sorting.ExecuteSort(sorting.MergeSort, nums, delegate) sorting.ExecuteSort(sorting.QuickSort, nums, delegate) // fmt.Println(result) }() }
func appMain(driver gxui.Driver) { d = driver source := image.Image(newMandelbrot()) theme := flags.CreateTheme(driver) mx := source.Bounds().Max img = theme.CreateImage() window = theme.CreateWindow(mx.X, mx.Y, "Image viewer") window.SetScale(flags.DefaultScaleFactor) window.AddChild(img) rgba := image.NewRGBA(source.Bounds()) draw.Draw(rgba, source.Bounds(), source, image.ZP, draw.Src) texture = driver.CreateTexture(rgba, 1) img.SetTexture(texture) window.OnClick(windowOnClickHandler) window.OnClose(driver.Terminate) }
func appMain(driver gxui.Driver) { theme := flags.CreateTheme(driver) window := theme.CreateWindow(200, 150, "Window") window.OnClose(driver.Terminate) window.SetScale(flags.DefaultScaleFactor) window.SetPadding(math.Spacing{L: 10, R: 10, T: 10, B: 10}) button := theme.CreateButton() button.SetHorizontalAlignment(gxui.AlignCenter) button.SetSizeMode(gxui.Fill) toggle := func() { fullscreen := !window.Fullscreen() window.SetFullscreen(fullscreen) if fullscreen { button.SetText("Make windowed") } else { button.SetText("Make fullscreen") } } button.SetText("Make fullscreen") button.OnClick(func(gxui.MouseEvent) { toggle() }) window.AddChild(button) }
func appMain(driver gxui.Driver) { theme := flags.CreateTheme(driver) font, err := driver.CreateFont(gxfont.Default, 75) if err != nil { panic(err) } window := theme.CreateWindow(380, 100, "Hi") window.SetBackgroundBrush(gxui.CreateBrush(gxui.Gray50)) label := theme.CreateLabel() label.SetFont(font) label.SetText("Hello world") window.AddChild(label) ticker := time.NewTicker(time.Millisecond * 30) go func() { phase := float32(0) for _ = range ticker.C { c := gxui.Color{ R: 0.75 + 0.25*math.Cosf((phase+0.000)*math.TwoPi), G: 0.75 + 0.25*math.Cosf((phase+0.333)*math.TwoPi), B: 0.75 + 0.25*math.Cosf((phase+0.666)*math.TwoPi), A: 0.50 + 0.50*math.Cosf(phase*10), } phase += 0.01 driver.Call(func() { label.SetColor(c) }) } }() window.OnClose(ticker.Stop) window.OnClose(driver.Terminate) }
func appMain(driver gxui.Driver) { args := flag.Args() if len(args) != 1 { fmt.Print("usage: image_viewer image-path\n") os.Exit(1) } file := args[0] f, err := os.Open(file) if err != nil { fmt.Printf("Failed to open image '%s': %v\n", file, err) os.Exit(1) } source, _, err := image.Decode(f) if err != nil { fmt.Printf("Failed to read image '%s': %v\n", file, err) os.Exit(1) } theme := flags.CreateTheme(driver) img := theme.CreateImage() mx := source.Bounds().Max window := theme.CreateWindow(mx.X, mx.Y, "Image viewer") window.SetScale(flags.DefaultScaleFactor) window.AddChild(img) // Copy the image to a RGBA format before handing to a gxui.Texture rgba := image.NewRGBA(source.Bounds()) draw.Draw(rgba, source.Bounds(), source, image.ZP, draw.Src) texture := driver.CreateTexture(rgba, 1) img.SetTexture(texture) window.OnClose(driver.Terminate) }
func appMain(driver gxui.Driver) { theme := flags.CreateTheme(driver) font, err := driver.CreateFont(gxfont.Default, H1_FONT_SIZE) catch(err) window := theme.CreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, APP_TITLE) window.SetBackgroundBrush(gxui.CreateBrush(gxui.White)) window.SetScale(flags.DefaultScaleFactor) window.SetPadding(math.Spacing{L: 10, R: 10, T: 10, B: 10}) layout := theme.CreateLinearLayout() layout.SetSizeMode(gxui.Fill) layout.SetHorizontalAlignment(gxui.AlignCenter) layout.HorizontalAlignment().AlignCenter() fullscreenButton := theme.CreateButton() fullscreenButton.SetText("Make Fullscreen") fullscreenButton.OnClick(func(ev gxui.MouseEvent) { fullscreen := !window.Fullscreen() window.SetFullscreen(fullscreen) if fullscreen { fullscreenButton.SetText("Make Windowed") } else { fullscreenButton.SetText("Make Fullscreen") } }) h1Title := theme.CreateLabel() h1Title.SetFont(font) h1Title.SetColor(gxui.Color{R: 0, G: 0, B: 0, A: 1}) KinopoiskLabel := theme.CreateLabel() KinopoiskLabel.SetFont(font) KinopoiskLabel.SetColor(gxui.Color{R: 0, G: 0, B: 0, A: 1}) ImdbLabel := theme.CreateLabel() ImdbLabel.SetFont(font) ImdbLabel.SetColor(gxui.Color{R: 0, G: 0, B: 0, A: 1}) // https://github.com/google/gxui/blob/master/samples/image_viewer/main.go img := theme.CreateImage() getFilmButton := theme.CreateButton() getFilmButton.SetText("Get Film!") getFilmButton.OnClick(func(ev gxui.MouseEvent) { getFilm(driver, h1Title, KinopoiskLabel, ImdbLabel, img) }) getFilm(driver, h1Title, KinopoiskLabel, ImdbLabel, img) layout.AddChild(fullscreenButton) layout.AddChild(h1Title) layout.AddChild(KinopoiskLabel) layout.AddChild(ImdbLabel) layout.AddChild(getFilmButton) layout.AddChild(img) window.AddChild(layout) window.OnClose(driver.Terminate) }
func appMain(driver gxui.Driver) { theme := flags.CreateTheme(driver) font, err := driver.CreateFont(gxfont.Default, 75) if err != nil { panic(err) } window := theme.CreateWindow(800, 480, "Привет") window.SetBackgroundBrush(gxui.CreateBrush(gxui.Gray50)) window.SetBorderPen(gxui.Pen{Width: 5, Color: gxui.Yellow}) f, err := os.Open("wallpaper.jpg") if err != nil { fmt.Printf("Failed to open image %v\n", err) os.Exit(1) } source, _, err := image.Decode(f) if err != nil { fmt.Printf("Failed to open image %v\n", err) os.Exit(2) } wallpaper := theme.CreateImage() window.AddChild(wallpaper) // Copy the image to a RGBA format before handing to a gxui.Texture rgba := image.NewRGBA(source.Bounds()) draw.Draw(rgba, source.Bounds(), source, image.ZP, draw.Src) texture := driver.CreateTexture(rgba, 1) wallpaper.SetTexture(texture) layout := theme.CreateLinearLayout() layout.SetDirection(gxui.TopToBottom) window.AddChild(layout) label := theme.CreateLabel() label.SetFont(font) label.SetText("Здравствуй мир") label.OnMouseMove(func(e gxui.MouseEvent) { fmt.Printf("X=%d; Y=%d\n", e.Point.X, e.Point.Y) }) layout.AddChild(label) lTimer := theme.CreateLabel() lTimer.SetFont(font) lTimer.SetColor(gxui.Green30) layout.AddChild(lTimer) button := theme.CreateButton() button.SetText("Exit") button.SetPadding(math.Spacing{20, 10, 20, 10}) button.SetMargin(math.Spacing{20, 10, 20, 10}) button.OnClick(func(e gxui.MouseEvent) { window.Close() }) layout.AddChild(button) ticker := time.NewTicker(time.Millisecond * 30) go func() { phase := float32(0) for _ = range ticker.C { c := gxui.Color{ R: 0.75 + 0.25*math.Cosf((phase+0.000)*math.TwoPi), G: 0.75 + 0.25*math.Cosf((phase+0.333)*math.TwoPi), B: 0.75 + 0.25*math.Cosf((phase+0.666)*math.TwoPi), A: 0.50 + 0.50*math.Cosf(phase*10), } phase += 0.01 driver.Call(func() { label.SetColor(c) }) } }() ticker2 := time.NewTicker(time.Millisecond * 100) go func() { for t := range ticker.C { driver.Call(func() { lTimer.SetText(t.Format(time.Stamp)) }) } }() window.OnClose(ticker.Stop) window.OnClose(ticker2.Stop) window.OnClose(driver.Terminate) }
func appMain(driver gxui.Driver) { theme := flags.CreateTheme(driver) from := theme.CreateTextBox() from.SetDesiredWidth(500) from.SetText("from") from.OnGainedFocus(func() { if from.Text() == "from" { from.SetText("") } }) from.OnLostFocus(func() { if from.Text() == "" { from.SetText("from") } }) password := theme.CreateTextBox() password.SetDesiredWidth(500) password.SetText("password") password.OnGainedFocus(func() { if password.Text() == "password" { password.SetText("") } }) password.OnLostFocus(func() { if password.Text() == "" { password.SetText("password") } }) to := theme.CreateTextBox() to.SetDesiredWidth(500) to.SetText("to") to.OnGainedFocus(func() { if to.Text() == "to" { to.SetText("") } }) to.OnLostFocus(func() { if to.Text() == "" { to.SetText("to") } }) host := theme.CreateTextBox() host.SetDesiredWidth(500) host.SetText("host") host.OnGainedFocus(func() { if host.Text() == "host" { host.SetText("") } }) host.OnLostFocus(func() { if host.Text() == "" { host.SetText("host") } }) port := theme.CreateTextBox() port.SetDesiredWidth(500) port.SetText("port") port.OnGainedFocus(func() { if port.Text() == "port" { port.SetText("") } }) port.OnLostFocus(func() { if port.Text() == "" { port.SetText("port") } }) result := theme.CreateLabel() result.SetText("") message := theme.CreateTextBox() message.SetDesiredWidth(500) message.SetMultiline(true) message.SetText("message") message.OnGainedFocus(func() { if message.Text() == "message" { message.SetText("") } }) message.OnLostFocus(func() { if message.Text() == "" { message.SetText("message") } }) sendButton := theme.CreateButton() sendButton.SetText("Send") sendButton.OnClick(func(ev gxui.MouseEvent) { result.SetText("Processing...") _from := from.Text() _pass := password.Text() _to := to.Text() _host := host.Text() _port := port.Text() _msg := "From: " + _from + "\r\n" + "To: " + _to + "\r\n" + "Subject: Hello there\r\n\r\n" + message.Text() + "\r\n" auth := smtp.PlainAuth("", _from, _pass, _host) tlsconfig := &tls.Config{ InsecureSkipVerify: true, ServerName: _host, } conn, err := tls.Dial("tcp", _host+":"+_port, tlsconfig) if err != nil { result.SetText("Error:" + err.Error()) return } log.Printf("dial fine") c, err := smtp.NewClient(conn, _host) if err != nil { result.SetText("Error:" + err.Error()) return } log.Printf("client fine") if err = c.Auth(auth); err != nil { result.SetText("Error:" + err.Error()) return } log.Printf("auth fine") if err = c.Mail(_from); err != nil { result.SetText("Error:" + err.Error()) return } log.Printf("from fine") if err = c.Rcpt(_to); err != nil { result.SetText("Error:" + err.Error()) return } log.Printf("to fine") w, err := c.Data() if err != nil { result.SetText("Error:" + err.Error()) return } log.Printf("data fine") _, err = w.Write([]byte(_msg)) if err != nil { result.SetText("Error:" + err.Error()) return } log.Printf("write fine") err = w.Close() if err != nil { result.SetText("Error:" + err.Error()) return } log.Printf("close fine") c.Quit() log.Printf("fine") result.SetText("Message sent") return }) layout := theme.CreateLinearLayout() layout.SetSizeMode(gxui.Fill) layout.AddChild(from) layout.AddChild(password) layout.AddChild(to) layout.AddChild(host) layout.AddChild(port) layout.AddChild(message) layout.AddChild(sendButton) layout.AddChild(result) layout.SetHorizontalAlignment(gxui.AlignCenter) scroll := theme.CreateScrollLayout() scroll.SetScrollAxis(false, true) scroll.SetChild(layout) window := theme.CreateWindow(800, 600, "SMTP sender") window.SetScale(flags.DefaultScaleFactor) window.AddChild(scroll) window.OnClose(driver.Terminate) }
func appMain(driver gxui.Driver) { theme := flags.CreateTheme(driver) window := theme.CreateWindow(800, 600, "navmesh") canvas := driver.CreateCanvas(math.Size{W: 800, H: 600}) // mouse isStart := true var src_id, dest_id int32 // source & dest triangle id var src, dest Point3 window.OnMouseDown(func(me gxui.MouseEvent) { pt := Point3{X: float32(me.Point.X) / SCALE_FACTOR, Y: float32(me.Point.Y) / SCALE_FACTOR} id := getTriangleId(pt) if isStart { src_id = id src = pt } else { dest_id = id dest = pt } if !isStart { if src_id != -1 && dest_id != -1 { canvas := route(driver, src_id, dest_id, src, dest) image := theme.CreateImage() image.SetCanvas(canvas) window.AddChild(image) } } isStart = !isStart }) // draw mesh for k := 0; k < len(triangles); k++ { poly := []gxui.PolygonVertex{ gxui.PolygonVertex{ Position: math.Point{ int(SCALE_FACTOR * vertices[triangles[k][0]].X), int(SCALE_FACTOR * vertices[triangles[k][0]].Y), }}, gxui.PolygonVertex{ Position: math.Point{ int(SCALE_FACTOR * vertices[triangles[k][1]].X), int(SCALE_FACTOR * vertices[triangles[k][1]].Y), }}, gxui.PolygonVertex{ Position: math.Point{ int(SCALE_FACTOR * vertices[triangles[k][2]].X), int(SCALE_FACTOR * vertices[triangles[k][2]].Y), }}, } canvas.DrawPolygon(poly, gxui.CreatePen(3, gxui.Gray80), gxui.CreateBrush(gxui.Gray40)) //canvas.DrawPolygon(poly, gxui.CreatePen(2, gxui.Red), gxui.CreateBrush(gxui.Yellow)) } canvas.Complete() image := theme.CreateImage() image.SetCanvas(canvas) window.AddChild(image) window.OnClose(driver.Terminate) }
func appMain(driver gxui.Driver) { theme := flags.CreateTheme(driver) window := theme.CreateWindow(800, 600, "Open file...") window.SetScale(flags.DefaultScaleFactor) // fullpath is the textbox at the top of the window holding the current // selection's absolute file path. fullpath := theme.CreateTextBox() fullpath.SetDesiredWidth(math.MaxSize.W) // directories is the Tree of directories on the left of the window. // It uses the directoryAdapter to show the entire system's directory // hierarchy. directories := theme.CreateTree() directories.SetAdapter(&directoryAdapter{ directory: directory{ subdirs: roots.Roots(), }, }) // filesAdapter is the adapter used to show the currently selected directory's // content. The adapter has its data changed whenever the selected directory // changes. filesAdapter := &filesAdapter{} // files is the List of files in the selected directory to the right of the // window. files := theme.CreateList() files.SetAdapter(filesAdapter) open := theme.CreateButton() open.SetText("Open...") open.OnClick(func(gxui.MouseEvent) { fmt.Printf("File '%s' selected!\n", files.Selected()) window.Close() }) // If the user hits the enter key while the fullpath control has focus, // attempt to select the directory. fullpath.OnKeyDown(func(ev gxui.KeyboardEvent) { if ev.Key == gxui.KeyEnter || ev.Key == gxui.KeyKpEnter { path := fullpath.Text() if directories.Select(path) { directories.Show(path) } } }) // When the directory selection changes, update the files list directories.OnSelectionChanged(func(item gxui.AdapterItem) { dir := item.(string) filesAdapter.SetFiles(filesAt(dir)) fullpath.SetText(dir) }) // When the file selection changes, update the fullpath text files.OnSelectionChanged(func(item gxui.AdapterItem) { fullpath.SetText(item.(string)) }) // When the user double-clicks a directory in the file list, select it in the // directories tree view. files.OnDoubleClick(func(gxui.MouseEvent) { if path, ok := files.Selected().(string); ok { if fi, err := os.Stat(path); err == nil && fi.IsDir() { if directories.Select(path) { directories.Show(path) } } else { fmt.Printf("File '%s' selected!\n", path) window.Close() } } }) // Start with the CWD selected and visible. if cwd, err := os.Getwd(); err == nil { if directories.Select(cwd) { directories.Show(directories.Selected()) } } splitter := theme.CreateSplitterLayout() splitter.SetOrientation(gxui.Horizontal) splitter.AddChild(directories) splitter.AddChild(files) topLayout := theme.CreateLinearLayout() topLayout.SetDirection(gxui.TopToBottom) topLayout.AddChild(fullpath) topLayout.AddChild(splitter) btmLayout := theme.CreateLinearLayout() btmLayout.SetDirection(gxui.BottomToTop) btmLayout.SetHorizontalAlignment(gxui.AlignRight) btmLayout.AddChild(open) btmLayout.AddChild(topLayout) window.AddChild(btmLayout) window.OnClose(driver.Terminate) window.SetPadding(math.Spacing{L: 10, T: 10, R: 10, B: 10}) }
func appMain(driver gxui.Driver) { theme := flags.CreateTheme(driver) layout := theme.CreateLinearLayout() layout.SetSizeMode(gxui.Fill) buttonState := map[gxui.Button]func() bool{} update := func() { for button, f := range buttonState { button.SetChecked(f()) } } button := func(name string, action func(), isSelected func() bool) gxui.Button { b := theme.CreateButton() b.SetText(name) b.OnClick(func(gxui.MouseEvent) { action(); update() }) layout.AddChild(b) buttonState[b] = isSelected return b } button("TopToBottom", func() { layout.SetDirection(gxui.TopToBottom) }, func() bool { return layout.Direction().TopToBottom() }, ) button("LeftToRight", func() { layout.SetDirection(gxui.LeftToRight) }, func() bool { return layout.Direction().LeftToRight() }, ) button("BottomToTop", func() { layout.SetDirection(gxui.BottomToTop) }, func() bool { return layout.Direction().BottomToTop() }, ) button("RightToLeft", func() { layout.SetDirection(gxui.RightToLeft) }, func() bool { return layout.Direction().RightToLeft() }, ) button("AlignLeft", func() { layout.SetHorizontalAlignment(gxui.AlignLeft) }, func() bool { return layout.HorizontalAlignment().AlignLeft() }, ) button("AlignCenter", func() { layout.SetHorizontalAlignment(gxui.AlignCenter) }, func() bool { return layout.HorizontalAlignment().AlignCenter() }, ) button("AlignRight", func() { layout.SetHorizontalAlignment(gxui.AlignRight) }, func() bool { return layout.HorizontalAlignment().AlignRight() }, ) button("AlignTop", func() { layout.SetVerticalAlignment(gxui.AlignTop) }, func() bool { return layout.VerticalAlignment().AlignTop() }, ) button("AlignMiddle", func() { layout.SetVerticalAlignment(gxui.AlignMiddle) }, func() bool { return layout.VerticalAlignment().AlignMiddle() }, ) button("AlignBottom", func() { layout.SetVerticalAlignment(gxui.AlignBottom) }, func() bool { return layout.VerticalAlignment().AlignBottom() }, ) update() window := theme.CreateWindow(800, 600, "Linear layout") window.SetScale(flags.DefaultScaleFactor) window.AddChild(layout) window.OnClose(driver.Terminate) window.SetPadding(math.Spacing{L: 10, T: 10, R: 10, B: 10}) }
func appMain(driver gxui.Driver) { theme := flags.CreateTheme(driver) layout := theme.CreateLinearLayout() layout.SetSizeMode(gxui.Fill) addLabel := func(text string) { label := theme.CreateLabel() label.SetText(text) layout.AddChild(label) } addLabel("1. Fetch certificates from websites") addLabel("Insert IP or domain name here and press 'Fetch' button") urlTextBox := theme.CreateTextBox() urlTextBox.SetDesiredWidth(300) fetchButton := theme.CreateButton() fetchButton.SetText("Fetch") fetchButton.SetVisible(false) { lineLayout := theme.CreateLinearLayout() lineLayout.SetDirection(gxui.LeftToRight) lineLayout.AddChild(urlTextBox) lineLayout.AddChild(fetchButton) layout.AddChild(lineLayout) } statusLabel := theme.CreateLabel() statusLabel.SetMultiline(true) statusLabel.SetText("") layout.AddChild(statusLabel) certListAdapter := gxui.CreateDefaultAdapter() certList := theme.CreateList() certList.SetAdapter(certListAdapter) removeButton := theme.CreateButton() removeButton.SetText("Remove") { lineLayout := theme.CreateLinearLayout() lineLayout.SetDirection(gxui.LeftToRight) lineLayout.AddChild(certList) lineLayout.AddChild(removeButton) layout.AddChild(lineLayout) } addLabel("2. Select programmer serial port") portListAdapter := gxui.CreateDefaultAdapter() portList := theme.CreateList() portList.SetAdapter(portListAdapter) refreshButton := theme.CreateButton() refreshButton.SetText("Refresh List") { lineLayout := theme.CreateLinearLayout() lineLayout.SetDirection(gxui.LeftToRight) lineLayout.AddChild(portList) lineLayout.AddChild(refreshButton) layout.AddChild(lineLayout) } addLabel("3. Upload certificate to WiFi module") uploadButton := theme.CreateButton() uploadButton.SetText("Upload certificates") layout.AddChild(uploadButton) progressStatus := theme.CreateLabel() layout.AddChild(progressStatus) progressBar := theme.CreateProgressBar() size := math.MaxSize size.H = 20 progressBar.SetDesiredSize(size) layout.AddChild(progressBar) // Business logic portSelected := false updateUploadButton := func() { visible := portSelected && certListAdapter.Count() > 0 uploadButton.SetVisible(visible) } updateUploadButton() updateDownloadedCerts := func() { certListAdapter.SetItems(downloadedCerts) updateUploadButton() } downloadCert := func() { if uploading { return } url := urlTextBox.Text() if strings.Index(url, ":") == -1 { url += ":443" } data, err := certificates.EntryForAddress(url) if err != nil { log.Println("Error downloading certificate. " + err.Error()) statusLabel.SetText("Error downloading certificate. " + err.Error()) return } else { statusLabel.SetText("Download successful") } cert := &Cert{ Label: url, Data: data, } downloadedCerts = append(downloadedCerts, cert) urlTextBox.SetText("") updateDownloadedCerts() } urlTextBox.OnTextChanged(func([]gxui.TextBoxEdit) { isEmpty := (urlTextBox.Text() == "") fetchButton.SetVisible(!isEmpty) }) urlTextBox.OnKeyPress(func(event gxui.KeyboardEvent) { char := event.Key if char == gxui.KeyEnter || char == gxui.KeyKpEnter { isEmpty := (urlTextBox.Text() == "") if !isEmpty { downloadCert() } } }) fetchButton.OnClick(func(gxui.MouseEvent) { downloadCert() }) removeButton.OnClick(func(gxui.MouseEvent) { if uploading { return } selected := certList.Selected() i := certList.Adapter().ItemIndex(selected) downloadedCerts = append(downloadedCerts[:i], downloadedCerts[i+1:]...) updateDownloadedCerts() removeButton.SetVisible(false) }) certList.OnSelectionChanged(func(gxui.AdapterItem) { removeButton.SetVisible(true) }) removeButton.SetVisible(false) refreshPortList := func() { if uploading { return } if list, err := serial.GetPortsList(); err != nil { log.Println("Error fetching serial ports" + err.Error()) } else { portListAdapter.SetItems(list) } } refreshPortList() refreshButton.OnClick(func(gxui.MouseEvent) { refreshPortList() portSelected = false updateUploadButton() }) portList.OnSelectionChanged(func(gxui.AdapterItem) { portSelected = true updateUploadButton() }) updateProgress := func(msg string, percent int) { time.Sleep(time.Second) driver.CallSync(func() { if percent == -1 { progressStatus.SetColor(gxui.Red) progressBar.SetVisible(false) } else if percent == 100 { progressStatus.SetColor(gxui.Green) progressBar.SetVisible(false) } else { progressStatus.SetColor(gxui.White) progressBar.SetProgress(percent) progressBar.SetVisible(true) } progressStatus.SetText(msg) }) } progressBar.SetVisible(false) uploadButton.OnClick(func(gxui.MouseEvent) { if uploading { return } port := portList.Selected().(string) uploading = true go uploadCertificates(port, driver, updateProgress) log.Println(port) }) updateDownloadedCerts() window := theme.CreateWindow(800, 600, "Linear layout") window.SetTitle("WINC1500 SSL Certificate updater") window.SetScale(flags.DefaultScaleFactor) window.AddChild(layout) window.OnClose(driver.Terminate) window.SetPadding(math.Spacing{L: 10, T: 10, R: 10, B: 10}) window.Relayout() }