diff --git a/.gitignore b/.gitignore
index fe31f76..97610c7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,7 +4,6 @@
*.dll
*.so
*.dylib
-demo
# Test binary, build with `go test -c`
*.test
diff --git a/demo/absoluteLayoutDemo.go b/demo/absoluteLayoutDemo.go
new file mode 100644
index 0000000..af17eac
--- /dev/null
+++ b/demo/absoluteLayoutDemo.go
@@ -0,0 +1,16 @@
+package main
+
+import (
+ "github.com/anoshenko/rui"
+)
+
+const absoluteLayoutDemoText = `
+AbsoluteLayout {
+ width = 100%, height = 100%,
+ content = [ View { id = view1, width = 32px, height = 32px, left = 100px, top = 200px, background-color = #FF0000FF } ]
+}
+`
+
+func createAbsoluteLayoutDemo(session rui.Session) rui.View {
+ return rui.CreateViewFromText(session, absoluteLayoutDemoText)
+}
diff --git a/demo/audioPlayerDemo.go b/demo/audioPlayerDemo.go
new file mode 100644
index 0000000..6b722d4
--- /dev/null
+++ b/demo/audioPlayerDemo.go
@@ -0,0 +1,142 @@
+package main
+
+import (
+ "fmt"
+
+ "github.com/anoshenko/rui"
+)
+
+const audioPlayerDemoText = `
+GridLayout {
+ cell-height = "auto, auto, 1fr, auto", width = 100%, height = 100%,
+ content = [
+ ListLayout {
+ row = 0, orientation = start-to-end, padding = 4px,
+ content = [
+ Checkbox {
+ id = showAudioPlayerControls, content = "Controls"
+ },
+ Checkbox {
+ id = showAudioPlayerLoop, content = "Loop"
+ },
+ Checkbox {
+ id = showAudioPlayerMuted, content = "Muted"
+ },
+ ],
+ },
+ AudioPlayer {
+ row = 1, id = audioPlayer, src = "https://alxanosoft.com/jazzy-loop-1.mp3",
+ },
+ ListLayout {
+ row = 2, orientation = start-to-end, vertical-align = top, padding = 8px,
+ content = [
+ NumberPicker {
+ id = audioPlayerSlider, width = 200px, type = slider
+ }
+ Button {
+ id = audioPlayerPlay, content = "Play", margin-left = 16px
+ }
+ ]
+ },
+ Resizable {
+ row = 3, side = top, background-color = lightgrey, height = 200px,
+ content = EditView {
+ id = audioPlayerEventsLog, type = multiline, read-only = true, wrap = true,
+ }
+ },
+ ]
+}`
+
+var audioPlayerPause = true
+
+func createAudioPlayerDemo(session rui.Session) rui.View {
+ view := rui.CreateViewFromText(session, audioPlayerDemoText)
+ if view == nil {
+ return nil
+ }
+
+ createListener := func(event string) func() {
+ return func() {
+ rui.AppendEditText(view, "audioPlayerEventsLog", event+"\n")
+ rui.ScrollViewToEnd(view, "audioPlayerEventsLog")
+ }
+ }
+ createListener2 := func(event string) func(value float64) {
+ return func(value float64) {
+ rui.AppendEditText(view, "audioPlayerEventsLog", fmt.Sprintf("%s: %g\n", event, value))
+ rui.ScrollViewToEnd(view, "audioPlayerEventsLog")
+ }
+ }
+
+ rui.Set(view, "showAudioPlayerControls", rui.CheckboxChangedEvent, func(state bool) {
+ rui.Set(view, "audioPlayer", rui.Controls, state)
+ })
+
+ rui.Set(view, "showAudioPlayerLoop", rui.CheckboxChangedEvent, func(state bool) {
+ rui.Set(view, "audioPlayer", rui.Loop, state)
+ })
+
+ rui.Set(view, "showAudioPlayerMuted", rui.CheckboxChangedEvent, func(state bool) {
+ rui.Set(view, "audioPlayer", rui.Muted, state)
+ })
+
+ for _, event := range []string{rui.AbortEvent, rui.CanPlayEvent, rui.CanPlayThroughEvent,
+ rui.CompleteEvent, rui.EmptiedEvent, rui.EndedEvent, rui.LoadStartEvent,
+ rui.LoadedMetadataEvent, rui.PlayingEvent, rui.SeekedEvent, rui.SeekingEvent,
+ rui.StalledEvent, rui.SuspendEvent, rui.WaitingEvent} {
+
+ rui.Set(view, "audioPlayer", event, createListener(event))
+ }
+
+ for _, event := range []string{rui.DurationChangedEvent, rui.RateChangedEvent, rui.VolumeChangedEvent} {
+
+ rui.Set(view, "audioPlayer", event, createListener2(event))
+ }
+
+ rui.Set(view, "audioPlayer", rui.PlayEvent, func() {
+ rui.AppendEditText(view, "audioPlayerEventsLog", "play-event\n")
+ rui.ScrollViewToEnd(view, "audioPlayerEventsLog")
+ rui.Set(view, "audioPlayerPlay", rui.Content, "Pause")
+ audioPlayerPause = false
+ })
+
+ rui.Set(view, "audioPlayer", rui.PauseEvent, func() {
+ rui.AppendEditText(view, "audioPlayerEventsLog", "pause-event\n")
+ rui.ScrollViewToEnd(view, "audioPlayerEventsLog")
+ rui.Set(view, "audioPlayerPlay", rui.Content, "Play")
+ audioPlayerPause = true
+ })
+
+ rui.Set(view, "audioPlayer", rui.LoadedDataEvent, func() {
+ rui.AppendEditText(view, "audioPlayerEventsLog", "loaded-data-event\n")
+ rui.ScrollViewToEnd(view, "audioPlayerEventsLog")
+ rui.Set(view, "audioPlayerSlider", rui.Max, rui.MediaPlayerDuration(view, "audioPlayer"))
+ })
+
+ rui.Set(view, "audioPlayer", rui.TimeUpdateEvent, func(time float64) {
+ rui.AppendEditText(view, "audioPlayerEventsLog", fmt.Sprintf("time-update-event %gs\n", time))
+ rui.ScrollViewToEnd(view, "audioPlayerEventsLog")
+ rui.Set(view, "audioPlayerSlider", rui.Value, time)
+ })
+
+ rui.Set(view, "audioPlayer", rui.PlayerErrorEvent, func(code int, message string) {
+ rui.AppendEditText(view, "audioPlayerEventsLog", fmt.Sprintf("player-error-event: code = %d, message = '%s'\n", code, message))
+ rui.ScrollViewToEnd(view, "audioPlayerEventsLog")
+ })
+
+ rui.Set(view, "audioPlayerPlay", rui.ClickEvent, func() {
+ if audioPlayerPause {
+ rui.MediaPlayerPlay(view, "audioPlayer")
+ } else {
+ rui.MediaPlayerPause(view, "audioPlayer")
+ }
+ })
+
+ rui.Set(view, "audioPlayerSlider", rui.NumberChangedEvent, func(value float64) {
+ if audioPlayerPause {
+ rui.SetMediaPlayerCurrentTime(view, "audioPlayer", value)
+ }
+ })
+
+ return view
+}
diff --git a/demo/backgroundDemo.go b/demo/backgroundDemo.go
new file mode 100644
index 0000000..6010b07
--- /dev/null
+++ b/demo/backgroundDemo.go
@@ -0,0 +1,81 @@
+package main
+
+import "github.com/anoshenko/rui"
+
+const backgroundDemoText = `
+GridLayout {
+ style = demoPage,
+ content = [
+ ListLayout {
+ width = 100%, height = 100%, padding = 32px,
+ content = [
+ TextView {
+ id = backgroundView, width = 100%, height = 150%, padding = 16px,
+ text = "Sample text", text-size = 4em,
+ border = _{ style = dotted, width = 8px, color = #FF008800 },
+ background = image { src = cat.jpg }
+ }
+ ]
+ },
+ ListLayout {
+ style = optionsPanel,
+ content = [
+ GridLayout {
+ style = optionsTable,
+ content = [
+ TextView { row = 0, text = "Image" },
+ DropDownList { row = 0, column = 1, id = backgroundImage1, current = 0, items = ["cat.jpg", "winds.png", "gifsInEmail.gif", "mountain.svg"]},
+ TextView { row = 1, text = "Fit" },
+ DropDownList { row = 1, column = 1, id = backgroundFit1, current = 0, items = ["none", "contain", "cover"]},
+ TextView { row = 2, text = "Horizontal align" },
+ DropDownList { row = 2, column = 1, id = backgroundHAlign1, current = 0, items = ["left", "right", "center"]},
+ TextView { row = 3, text = "Vertical align" },
+ DropDownList { row = 3, column = 1, id = backgroundVAlign1, current = 0, items = ["top", "bottom", "center"]},
+ TextView { row = 4, text = "Repeat" },
+ DropDownList { row = 4, column = 1, id = backgroundRepeat1, current = 0, items = ["no-repeat", "repeat", "repeat-x", "repeat-y", "round", "space"]},
+ TextView { row = 5, text = "Clip" },
+ DropDownList { row = 5, column = 1, id = backgroundClip1, current = 0, items = ["padding-box", "border-box", "content-box", "text"]},
+ TextView { row = 6, text = "Attachment" },
+ DropDownList { row = 6, column = 1, id = backgroundAttachment1, current = 0, items = ["scroll", "fixed", "local"]},
+ ]
+ }
+ ]
+ }
+ ]
+}
+`
+
+func createBackgroundDemo(session rui.Session) rui.View {
+ view := rui.CreateViewFromText(session, backgroundDemoText)
+ if view == nil {
+ return nil
+ }
+
+ updateBackground1 := func(list rui.DropDownList, number int) {
+ images := []string{"cat.jpg", "winds.png", "gifsInEmail.gif", "mountain.svg"}
+ image := rui.NewBackgroundImage(rui.Params{
+ rui.Source: images[rui.GetDropDownCurrent(view, "backgroundImage1")],
+ rui.Fit: rui.GetDropDownCurrent(view, "backgroundFit1"),
+ rui.HorizontalAlign: rui.GetDropDownCurrent(view, "backgroundHAlign1"),
+ rui.VerticalAlign: rui.GetDropDownCurrent(view, "backgroundVAlign1"),
+ rui.Repeat: rui.GetDropDownCurrent(view, "backgroundRepeat1"),
+ rui.BackgroundClip: rui.GetDropDownCurrent(view, "backgroundClip1"),
+ rui.Attachment: rui.GetDropDownCurrent(view, "backgroundAttachment1"),
+ })
+ rui.Set(view, "backgroundView", rui.Background, image)
+ }
+
+ for _, id := range []string{
+ "backgroundImage1",
+ "backgroundFit1",
+ "backgroundHAlign1",
+ "backgroundVAlign1",
+ "backgroundRepeat1",
+ "backgroundClip1",
+ "backgroundAttachment1",
+ } {
+ rui.Set(view, id, rui.DropDownEvent, updateBackground1)
+ }
+
+ return view
+}
diff --git a/demo/canvasDemo.go b/demo/canvasDemo.go
new file mode 100644
index 0000000..e9ad43e
--- /dev/null
+++ b/demo/canvasDemo.go
@@ -0,0 +1,334 @@
+package main
+
+import (
+ "math"
+ "strconv"
+
+ "github.com/anoshenko/rui"
+)
+
+const canvasDemoText = `
+GridLayout {
+ width = 100%, height = 100%, cell-height = "auto, 1fr",
+ content = [
+ DropDownList {
+ id = canvasType, current = 0, margin = 8px,
+ items = ["Image", "Rectangles & ellipse", "Text style", "Text align", "Line style", "Transformations"]
+ },
+ CanvasView {
+ id = canvas, row = 1, width = 100%, height = 100%,
+ }
+ ]
+}
+`
+
+var sampleImage rui.Image
+
+func rectangleCanvasDemo(canvas rui.Canvas) {
+ width := canvas.Width()
+ height := canvas.Height()
+
+ canvas.Save()
+
+ canvas.SetSolidColorFillStyle(0xFF008000)
+ canvas.SetSolidColorStrokeStyle(0xFFFF0000)
+ w2 := width / 2
+ h2 := height / 2
+ canvas.FillRect(10, 10, w2-20, h2-20)
+ canvas.StrokeRect(9.5, 9.5, w2-19, h2-19)
+
+ canvas.SetLinearGradientFillStyle(w2+10, 10, 0xFFFF0000, width-20, 10, 0xFF0000FF, []rui.GradientPoint{
+ {Offset: 0.3, Color: 0xFFFFFF00},
+ {Offset: 0.5, Color: 0xFF00FF00},
+ {Offset: 0.7, Color: 0xFF00FFFF},
+ })
+ canvas.SetLinearGradientStrokeStyle(10, 10, 0xFFFF00FF, 10, h2-20, 0xFF00FFFF, []rui.GradientPoint{
+ {Offset: 0.5, Color: 0xFF00FF00},
+ })
+ canvas.SetLineWidth(5)
+ canvas.FillAndStrokeRoundedRect(w2+7.5, 7.5, w2-15, h2-15, 20)
+
+ canvas.SetRadialGradientFillStyle(w2/2-20, h2+h2/2-20, 10, 0xFFFF0000, w2/2+20, h2+h2/2+20, w2/2, 0xFF0000FF, []rui.GradientPoint{
+ {Offset: 0.3, Color: 0xFFFFFF00},
+ {Offset: 0.5, Color: 0xFF00FF00},
+ {Offset: 0.7, Color: 0xFF00FFFF},
+ })
+ canvas.SetRadialGradientStrokeStyle(w2/2, h2+h2/2, h2/2, 0xFFFFFF00, w2/2, h2+h2/2, h2, 0xFF00FFFF, []rui.GradientPoint{
+ {Offset: 0.5, Color: 0xFF00FF00},
+ })
+ canvas.SetLineWidth(7)
+ canvas.FillAndStrokeRect(10, h2+10, w2-20, h2-20)
+
+ //canvas.SetSolidColorFillStyle(0xFF00FFFF)
+ canvas.SetImageFillStyle(sampleImage, rui.RepeatXY)
+ canvas.SetSolidColorStrokeStyle(0xFF0000FF)
+ canvas.SetLineWidth(4)
+ canvas.FillAndStrokeEllipse(w2+w2/2, h2+h2/2, w2/2-10, h2/2-10, 0)
+
+ canvas.Restore()
+}
+
+func textCanvasDemo(canvas rui.Canvas) {
+
+ canvas.Save()
+ canvas.SetTextAlign(rui.LeftAlign)
+ canvas.SetTextBaseline(rui.TopBaseline)
+
+ canvas.SetSolidColorFillStyle(0xFF000000)
+ canvas.FillText(10, 10, "Default font")
+ canvas.StrokeText(300, 10, "Default font")
+
+ canvas.SetSolidColorFillStyle(0xFF800000)
+ canvas.SetSolidColorStrokeStyle(0xFF800080)
+ canvas.SetFont("courier", rui.Pt(12))
+ canvas.FillText(10, 30, "courier, 12pt")
+ canvas.StrokeText(300, 30, "courier, 12pt")
+
+ canvas.SetSolidColorFillStyle(0xFF008000)
+ canvas.SetSolidColorStrokeStyle(0xFF008080)
+ canvas.SetFontWithParams("Courier new, courier", rui.Pt(12), rui.FontParams{
+ Italic: true,
+ })
+ canvas.FillText(10, 50, `Courier new, 12pt, italic`)
+ canvas.StrokeText(300, 50, `Courier new, 12pt, italic`)
+
+ canvas.SetSolidColorFillStyle(0xFF000080)
+ canvas.SetLinearGradientStrokeStyle(10, 70, 0xFF00FF00, 10, 90, 0xFFFF00FF, nil)
+ canvas.SetFontWithParams("sans-serif", rui.Pt(12), rui.FontParams{
+ SmallCaps: true,
+ })
+ canvas.FillText(10, 70, "sans-serif, 12pt, small-caps")
+ canvas.StrokeText(300, 70, "sans-serif, 12pt, small-caps")
+
+ canvas.SetLinearGradientFillStyle(10, 90, 0xFFFF0000, 10, 110, 0xFF0000FF, nil)
+ canvas.SetSolidColorStrokeStyle(0xFF800080)
+ canvas.SetFontWithParams("serif", rui.Pt(12), rui.FontParams{
+ Weight: 7,
+ })
+ canvas.FillText(10, 90, "serif, 12pt, weight: 7(bold)")
+ canvas.StrokeText(300, 90, "serif, 12pt, weight: 7(bold)")
+
+ widthSample := "Text width sample"
+ w := canvas.TextWidth(widthSample, "sans-serif", rui.Px(20))
+ canvas.SetFont("sans-serif", rui.Px(20))
+ canvas.SetSolidColorFillStyle(rui.Blue)
+ canvas.SetTextBaseline(rui.BottomBaseline)
+ canvas.FillText(10, 150, widthSample)
+
+ canvas.SetSolidColorStrokeStyle(rui.Black)
+ canvas.SetLineWidth(1)
+ canvas.DrawLine(10, 150, 10, 170)
+ canvas.DrawLine(10+w, 150, 10+w, 170)
+ canvas.DrawLine(10, 168, 10+w, 168)
+ canvas.DrawLine(10, 168, 20, 165)
+ canvas.DrawLine(10, 168, 20, 171)
+ canvas.DrawLine(10+w, 168, w, 165)
+ canvas.DrawLine(10+w, 168, w, 171)
+
+ canvas.SetSolidColorFillStyle(rui.Black)
+ canvas.SetFont("sans-serif", rui.Px(8))
+ canvas.SetTextAlign(rui.CenterAlign)
+ canvas.FillText(10+w/2, 167, strconv.FormatFloat(w, 'g', -1, 64))
+
+ canvas.Restore()
+}
+
+func textAlignCanvasDemo(canvas rui.Canvas) {
+ canvas.Save()
+ canvas.SetFont("sans-serif", rui.Pt(10))
+ canvas.SetSolidColorFillStyle(0xFF000000)
+ canvas.SetSolidColorStrokeStyle(0xFF00FFFF)
+
+ baseline := []string{"Alphabetic", "Top", "Middle", "Bottom", "Hanging", "Ideographic"}
+ align := []string{"Left", "Right", "Center", "Start", "End"}
+ center := []float64{20, 120, 70, 20, 120}
+ for b, bText := range baseline {
+ for a, aText := range align {
+ canvas.SetTextAlign(a)
+ canvas.SetTextBaseline(b)
+ x := float64(a * 140)
+ y := float64(b * 40)
+
+ canvas.DrawLine(x+4, y+20, x+132, y+20)
+ canvas.DrawLine(x+center[a], y+2, x+center[a], y+38)
+ canvas.FillText(x+center[a], y+20, bText+","+aText)
+ }
+ }
+ canvas.Restore()
+}
+
+func lineStyleCanvasDemo(canvas rui.Canvas) {
+ canvas.Save()
+
+ canvas.SetSolidColorStrokeStyle(0xFF00FFFF)
+ canvas.SetLineWidth(1)
+ canvas.DrawLine(20, 30, 20, 90)
+ canvas.DrawLine(170, 30, 170, 90)
+
+ canvas.SetSolidColorStrokeStyle(0xFF0000FF)
+ canvas.SetFont("courier", rui.Pt(12))
+ canvas.SetTextBaseline(rui.MiddleBaseline)
+ canvas.FillText(80, 15, "SetLineCap(...)")
+
+ canvas.SetFont("courier", rui.Pt(10))
+ for i, cap := range []string{"ButtCap", "RoundCap", "SquareCap"} {
+ canvas.SetSolidColorStrokeStyle(0xFF00FFFF)
+ canvas.SetLineWidth(1)
+ y := float64(40 + 20*i)
+ canvas.DrawLine(10, y, 180, y)
+ canvas.SetSolidColorStrokeStyle(0xFF000000)
+ canvas.SetLineWidth(10)
+ canvas.SetLineCap(i)
+ canvas.DrawLine(20, y, 170, y)
+ canvas.FillText(200, y, cap)
+ }
+
+ canvas.SetSolidColorStrokeStyle(0xFF0000FF)
+ canvas.SetFont("courier", rui.Pt(12))
+ canvas.FillText(80, 115, "SetLineJoin(...)")
+
+ canvas.SetSolidColorStrokeStyle(0xFF000000)
+ canvas.SetLineWidth(10)
+ canvas.SetLineCap(rui.ButtCap)
+
+ canvas.SetFont("courier", rui.Pt(10))
+ for i, join := range []string{"MiterJoin", "RoundJoin", "BevelJoin"} {
+ y := float64(140 + 40*i)
+ path := rui.NewPath()
+ path.MoveTo(20, y)
+ path.LineTo(50, y+40)
+ path.LineTo(80, y)
+ path.LineTo(110, y+40)
+ path.LineTo(140, y)
+ path.LineTo(170, y+40)
+ path.LineTo(200, y)
+ canvas.SetLineJoin(i)
+ canvas.StrokePath(path)
+ canvas.FillText(210, y+20, join)
+ }
+
+ canvas.SetSolidColorStrokeStyle(0xFF0000FF)
+ canvas.SetFont("courier", rui.Pt(12))
+ canvas.FillText(20, 300, "SetLineDash([]float64{16, 8, 4, 8}, ...)")
+
+ canvas.SetFont("courier", rui.Pt(10))
+ canvas.SetLineDash([]float64{16, 8, 4, 8}, 0)
+ canvas.SetSolidColorStrokeStyle(0xFF000000)
+ canvas.SetLineWidth(4)
+
+ canvas.SetLineCap(rui.ButtCap)
+ canvas.DrawLine(20, 330, 200, 330)
+ canvas.FillText(220, 330, "SetLineCap(ButtCap)")
+
+ canvas.SetLineDash([]float64{16, 8, 4, 8}, 4)
+ canvas.DrawLine(20, 360, 200, 360)
+ canvas.FillText(220, 360, "offset = 4")
+
+ canvas.SetLineDash([]float64{16, 8, 4, 8}, 0)
+ canvas.SetLineCap(rui.RoundCap)
+ canvas.SetShadow(4, 4, 2, 0xFF808080)
+ canvas.DrawLine(20, 390, 200, 390)
+ canvas.ResetShadow()
+ canvas.FillText(220, 390, "SetLineCap(RoundCap)")
+
+ canvas.Restore()
+}
+
+func transformCanvasDemo(canvas rui.Canvas) {
+ drawFigure := func() {
+ w := int(canvas.Width() / 2)
+ h := int(canvas.Height() / 2)
+ nx := (w/2)/20 + 1
+ ny := (h/2)/20 + 1
+ x0 := float64((w - nx*20) / 2)
+ y0 := float64((h - ny*20) / 2)
+ x1 := x0 + float64((nx-1)*20)
+ y1 := y0 + float64((ny-1)*20)
+
+ canvas.SetFont("serif", rui.Pt(10))
+ canvas.SetSolidColorFillStyle(rui.Black)
+
+ canvas.SetTextAlign(rui.CenterAlign)
+ canvas.SetTextBaseline(rui.BottomBaseline)
+ for i := 0; i < nx; i++ {
+ x := x0 + float64(i*20)
+ canvas.DrawLine(x, y0, x, y1)
+ canvas.FillText(x, y0-4, strconv.Itoa(i))
+ }
+
+ canvas.SetTextAlign(rui.RightAlign)
+ canvas.SetTextBaseline(rui.MiddleBaseline)
+ for i := 0; i < ny; i++ {
+ y := y0 + float64(i*20)
+ canvas.DrawLine(x0, y, x1, y)
+ canvas.FillText(x0-4, y, strconv.Itoa(i))
+ }
+ }
+
+ canvas.SetFont("courier", rui.Pt(14))
+ canvas.SetSolidColorFillStyle(rui.Black)
+ canvas.SetTextAlign(rui.CenterAlign)
+ canvas.SetTextBaseline(rui.TopBaseline)
+
+ canvas.FillText(canvas.Width()/4, 8, "Original")
+ canvas.FillText(canvas.Width()*3/4, 8, "SetScale(1.2, 0.8)")
+ canvas.FillText(canvas.Width()/4, canvas.Height()/2+8, "SetRotation(math.Pi / 6)")
+ canvas.FillText(canvas.Width()*3/4, canvas.Height()/2+8, "SetTransformation(0.8, 1.2, 0.2, 0.4, ...)")
+
+ drawFigure()
+
+ canvas.SetScale(1.2, 0.8)
+ canvas.SetTranslation(canvas.Width()/2.4, 0)
+ drawFigure()
+
+ canvas.ResetTransformation()
+ canvas.SetTranslation(canvas.Width()/8, canvas.Height()/2-canvas.Height()/8)
+ canvas.SetRotation(math.Pi / 6)
+ drawFigure()
+
+ canvas.ResetTransformation()
+ //canvas.SetTranslation(canvas.Width()/2, canvas.Height()/2)
+ canvas.SetTransformation(0.8, 1.2, 0.2, 0.4, canvas.Width()/(2*0.8)-canvas.Width()/8, canvas.Height()/(2*1.2)-canvas.Height()/16)
+ drawFigure()
+}
+
+var image rui.Image
+
+func imageCanvasDemo(canvas rui.Canvas) {
+ if image != nil {
+ canvas.DrawImage(50, 20, image)
+ } else {
+ image = rui.LoadImage("tile00.svg", func(img rui.Image) {
+ if img.LoadingStatus() == rui.ImageReady {
+ canvas.View().Redraw()
+ }
+ }, canvas.View().Session())
+ }
+}
+
+func createCanvasDemo(session rui.Session) rui.View {
+ view := rui.CreateViewFromText(session, canvasDemoText)
+ if view == nil {
+ return nil
+ }
+
+ rui.Set(view, "canvas", rui.DrawFunction, imageCanvasDemo)
+
+ rui.Set(view, "canvasType", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ drawFuncs := []func(rui.Canvas){
+ imageCanvasDemo,
+ rectangleCanvasDemo,
+ textCanvasDemo,
+ textAlignCanvasDemo,
+ lineStyleCanvasDemo,
+ transformCanvasDemo,
+ }
+ if number >= 0 && number < len(drawFuncs) {
+ rui.Set(view, "canvas", rui.DrawFunction, drawFuncs[number])
+ }
+ })
+
+ sampleImage = rui.LoadImage("image_sample.png", nil, session)
+
+ return view
+}
diff --git a/demo/checkboxDemo.go b/demo/checkboxDemo.go
new file mode 100644
index 0000000..5f3fb60
--- /dev/null
+++ b/demo/checkboxDemo.go
@@ -0,0 +1,69 @@
+package main
+
+import "github.com/anoshenko/rui"
+
+const checkboxDemoText = `
+GridLayout {
+ style = demoPage,
+ content = [
+ GridLayout {
+ width = 100%, height = 100%, cell-vertical-align = center, cell-horizontal-align = center,
+ content = [
+ GridLayout {
+ width = 250px, height = 80px,
+ border = _{ style = solid, width = 1px, color = gray },
+ content = [
+ Checkbox {
+ id = checkbox, width = 100%, height = 100%,
+ content = "Checkbox content"
+ }
+ ]
+ }
+ ]
+ },
+ ListLayout {
+ style = optionsPanel,
+ content = [
+ GridLayout {
+ style = optionsTable,
+ content = [
+ TextView { row = 0, text = "Vertical align" },
+ DropDownList { row = 0, column = 1, id = checkboxVAlign, current = 0, items = ["top", "bottom", "center", "stretch"]},
+ TextView { row = 1, text = "Horizontal align" },
+ DropDownList { row = 1, column = 1, id = checkboxHAlign, current = 0, items = ["left", "right", "center", "stretch"]},
+ TextView { row = 2, text = "Checkbox vertical align" },
+ DropDownList { row = 2, column = 1, id = checkboxBoxVAlign, current = 0, items = ["top", "bottom", "center"]},
+ TextView { row = 3, text = "Checkbox horizontal align" },
+ DropDownList { row = 3, column = 1, id = checkboxBoxHAlign, current = 0, items = ["left", "right", "center"]},
+ ]
+ }
+ ]
+ }
+ ]
+}
+`
+
+func createCheckboxDemo(session rui.Session) rui.View {
+ view := rui.CreateViewFromText(session, checkboxDemoText)
+ if view == nil {
+ return nil
+ }
+
+ rui.Set(view, "checkboxVAlign", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ rui.Set(view, "checkbox", rui.VerticalAlign, number)
+ })
+
+ rui.Set(view, "checkboxHAlign", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ rui.Set(view, "checkbox", rui.HorizontalAlign, number)
+ })
+
+ rui.Set(view, "checkboxBoxVAlign", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ rui.Set(view, "checkbox", rui.CheckboxVerticalAlign, number)
+ })
+
+ rui.Set(view, "checkboxBoxHAlign", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ rui.Set(view, "checkbox", rui.CheckboxHorizontalAlign, number)
+ })
+
+ return view
+}
diff --git a/demo/clipDemo.go b/demo/clipDemo.go
new file mode 100644
index 0000000..d12dc2f
--- /dev/null
+++ b/demo/clipDemo.go
@@ -0,0 +1,54 @@
+package main
+
+import "github.com/anoshenko/rui"
+
+const clipDemoText = `
+GridLayout {
+ width = 100%, height = 100%, cell-height = "auto, 1fr",
+ cell-horizontal-align = center, cell-vertical-align = center,
+ content = [
+ DropDownList {
+ id = clipType, current = 0, margin = 8px, max-width = 100%,
+ items = ["none",
+ "inset(20%, 10%, 20%, 10%, 16px / 32px)",
+ "circle(50%, 45%, 45%)",
+ "ellipse(50%, 50%, 35%, 50%)",
+ "polygon(50%, 2.4%, 34.5%, 33.8%, 0%, 38.8%, 25%, 63.1%, 19.1%, 97.6%, 50%, 81.3%, 80.9%, 97.6%, 75%, 63.1%, 100%, 38.8%, 65.5%, 33.8%)"],
+ },
+ ImageView {
+ id = clipImage, row = 1, src = "cat.jpg",
+ }
+ ]
+}
+`
+
+func createClipDemo(session rui.Session) rui.View {
+ view := rui.CreateViewFromText(session, clipDemoText)
+ if view == nil {
+ return nil
+ }
+
+ rui.Set(view, "clipType", rui.DropDownEvent, func(number int) {
+ switch number {
+ case 0:
+ rui.Set(view, "clipImage", rui.Clip, nil)
+
+ case 1:
+ rui.Set(view, "clipImage", rui.Clip, rui.InsetClip(rui.Percent(20), rui.Percent(10),
+ rui.Percent(20), rui.Percent(10), rui.NewRadiusProperty(rui.Params{
+ rui.X: rui.Px(16),
+ rui.Y: rui.Px(32),
+ })))
+ case 2:
+ rui.Set(view, "clipImage", rui.Clip, rui.CircleClip(rui.Percent(50), rui.Percent(45), rui.Percent(45)))
+
+ case 3:
+ rui.Set(view, "clipImage", rui.Clip, rui.EllipseClip(rui.Percent(50), rui.Percent(50), rui.Percent(35), rui.Percent(50)))
+
+ case 4:
+ rui.Set(view, "clipImage", rui.Clip, rui.PolygonClip([]interface{}{"50%", "2.4%", "34.5%", "33.8%", "0%", "38.8%", "25%", "63.1%", "19.1%", "97.6%", "50%", "81.3%", "80.9%", "97.6%", "75%", "63.1%", "100%", "38.8%", "65.5%", "33.8%"}))
+ }
+ })
+
+ return view
+}
diff --git a/demo/columnLayoutDemo.go b/demo/columnLayoutDemo.go
new file mode 100644
index 0000000..61572a2
--- /dev/null
+++ b/demo/columnLayoutDemo.go
@@ -0,0 +1,139 @@
+package main
+
+import "github.com/anoshenko/rui"
+
+const columnLayoutText = `
+GridLayout {
+ style = demoPage,
+ content = [
+ ColumnLayout {
+ id = columnLayout, padding = 12px,
+ content = [
+ TextView { text = "Alice’s Adventures in Wonderland", style = header1 },
+ TextView { text = "by Lewis Carroll", semantics = blockquote, margin-bottom = 0.5em, text-size = 0.8em, text-align = center },
+ TextView { text = "CHAPTER I. Down the Rabbit-Hole", style = header2 },
+ TextView { text = "Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, “and what is the use of a book,” thought Alice “without pictures or conversations?”", style = paragraph },
+ TextView { text = "So she was considering in her own mind (as well as she could, for the hot day made her feel very sleepy and stupid), whether the pleasure of making a daisy-chain would be worth the trouble of getting up and picking the daisies, when suddenly a White Rabbit with pink eyes ran close by her.", style = paragraph },
+ TextView { text = "There was nothing so very remarkable in that; nor did Alice think it so very much out of the way to hear the Rabbit say to itself, “Oh dear! Oh dear! I shall be late!” (when she thought it over afterwards, it occurred to her that she ought to have wondered at this, but at the time it all seemed quite natural); but when the Rabbit actually took a watch out of its waistcoat-pocket, and looked at it, and then hurried on, Alice started to her feet, for it flashed across her mind that she had never before seen a rabbit with either a waistcoat-pocket, or a watch to take out of it, and burning with curiosity, she ran across the field after it, and fortunately was just in time to see it pop down a large rabbit-hole under the hedge.", style = paragraph },
+ TextView { text = "In another moment down went Alice after it, never once considering how in the world she was to get out again.", style = paragraph },
+ TextView { text = "The rabbit-hole went straight on like a tunnel for some way, and then dipped suddenly down, so suddenly that Alice had not a moment to think about stopping herself before she found herself falling down a very deep well.", style = paragraph },
+ TextView { text = "Either the well was very deep, or she fell very slowly, for she had plenty of time as she went down to look about her and to wonder what was going to happen next. First, she tried to look down and make out what she was coming to, but it was too dark to see anything; then she looked at the sides of the well, and noticed that they were filled with cupboards and book-shelves; here and there she saw maps and pictures hung upon pegs. She took down a jar from one of the shelves as she passed; it was labelled “ORANGE MARMALADE”, but to her great disappointment it was empty: she did not like to drop the jar for fear of killing somebody underneath, so managed to put it into one of the cupboards as she fell past it.", style = paragraph },
+ TextView { text = "“Well!” thought Alice to herself, “after such a fall as this, I shall think nothing of tumbling down stairs! How brave they’ll all think me at home! Why, I wouldn’t say anything about it, even if I fell off the top of the house!” (Which was very likely true.)", style = paragraph },
+ TextView { text = "Down, down, down. Would the fall never come to an end? “I wonder how many miles I’ve fallen by this time?” she said aloud. “I must be getting somewhere near the centre of the earth. Let me see: that would be four thousand miles down, I think—” (for, you see, Alice had learnt several things of this sort in her lessons in the schoolroom, and though this was not a very good opportunity for showing off her knowledge, as there was no one to listen to her, still it was good practice to say it over) “—yes, that’s about the right distance—but then I wonder what Latitude or Longitude I’ve got to?” (Alice had no idea what Latitude was, or Longitude either, but thought they were nice grand words to say.)", style = paragraph },
+ TextView { text = "Presently she began again. “I wonder if I shall fall right through the earth! How funny it’ll seem to come out among the people that walk with their heads downward! The Antipathies, I think—” (she was rather glad there was no one listening, this time, as it didn’t sound at all the right word) “—but I shall have to ask them what the name of the country is, you know. Please, Ma’am, is this New Zealand or Australia?” (and she tried to curtsey as she spoke—fancy curtseying as you’re falling through the air! Do you think you could manage it?) “And what an ignorant little girl she’ll think me for asking! No, it’ll never do to ask: perhaps I shall see it written up somewhere.”", style = paragraph },
+ TextView { text = "Down, down, down. There was nothing else to do, so Alice soon began talking again. “Dinah’ll miss me very much to-night, I should think!” (Dinah was the cat.) “I hope they’ll remember her saucer of milk at tea-time. Dinah my dear! I wish you were down here with me! There are no mice in the air, I’m afraid, but you might catch a bat, and that’s very like a mouse, you know. But do cats eat bats, I wonder?” And here Alice began to get rather sleepy, and went on saying to herself, in a dreamy sort of way, “Do cats eat bats? Do cats eat bats?” and sometimes, “Do bats eat cats?” for, you see, as she couldn’t answer either question, it didn’t much matter which way she put it. She felt that she was dozing off, and had just begun to dream that she was walking hand in hand with Dinah, and saying to her very earnestly, “Now, Dinah, tell me the truth: did you ever eat a bat?” when suddenly, thump! thump! down she came upon a heap of sticks and dry leaves, and the fall was over.", style = paragraph },
+ TextView { text = "Alice was not a bit hurt, and she jumped up on to her feet in a moment: she looked up, but it was all dark overhead; before her was another long passage, and the White Rabbit was still in sight, hurrying down it. There was not a moment to be lost: away went Alice like the wind, and was just in time to hear it say, as it turned a corner, “Oh my ears and whiskers, how late it’s getting!” She was close behind it when she turned the corner, but the Rabbit was no longer to be seen: she found herself in a long, low hall, which was lit up by a row of lamps hanging from the roof.", style = paragraph },
+ TextView { text = "There were doors all round the hall, but they were all locked; and when Alice had been all the way down one side and up the other, trying every door, she walked sadly down the middle, wondering how she was ever to get out again.", style = paragraph },
+ TextView { text = "Suddenly she came upon a little three-legged table, all made of solid glass; there was nothing on it except a tiny golden key, and Alice’s first thought was that it might belong to one of the doors of the hall; but, alas! either the locks were too large, or the key was too small, but at any rate it would not open any of them. However, on the second time round, she came upon a low curtain she had not noticed before, and behind it was a little door about fifteen inches high: she tried the little golden key in the lock, and to her great delight it fitted!", style = paragraph },
+ TextView { text = "Alice opened the door and found that it led into a small passage, not much larger than a rat-hole: she knelt down and looked along the passage into the loveliest garden you ever saw. How she longed to get out of that dark hall, and wander about among those beds of bright flowers and those cool fountains, but she could not even get her head through the doorway; “and even if my head would go through,” thought poor Alice, “it would be of very little use without my shoulders. Oh, how I wish I could shut up like a telescope! I think I could, if I only knew how to begin.” For, you see, so many out-of-the-way things had happened lately, that Alice had begun to think that very few things indeed were really impossible.", style = paragraph },
+ TextView { text = "There seemed to be no use in waiting by the little door, so she went back to the table, half hoping she might find another key on it, or at any rate a book of rules for shutting people up like telescopes: this time she found a little bottle on it, (“which certainly was not here before,” said Alice,) and round the neck of the bottle was a paper label, with the words “DRINK ME,” beautifully printed on it in large letters.", style = paragraph },
+ TextView { text = "It was all very well to say “Drink me,” but the wise little Alice was not going to do that in a hurry. “No, I’ll look first,” she said, “and see whether it’s marked ‘poison’ or not”; for she had read several nice little histories about children who had got burnt, and eaten up by wild beasts and other unpleasant things, all because they would not remember the simple rules their friends had taught them: such as, that a red-hot poker will burn you if you hold it too long; and that if you cut your finger very deeply with a knife, it usually bleeds; and she had never forgotten that, if you drink much from a bottle marked “poison,” it is almost certain to disagree with you, sooner or later.", style = paragraph },
+ TextView { text = "However, this bottle was not marked “poison,” so Alice ventured to taste it, and finding it very nice, (it had, in fact, a sort of mixed flavour of cherry-tart, custard, pine-apple, roast turkey, toffee, and hot buttered toast,) she very soon finished it off.", style = paragraph },
+ ]
+ },
+ ListLayout {
+ style = optionsPanel,
+ content = [
+ GridLayout {
+ style = optionsTable,
+ content = [
+ TextView { row = 0, text = "Column count" },
+ DropDownList { row = 0, column = 1, id = columnCount, current = 0,
+ items = ["0", "1", "2", "3", "4", "5"],
+ },
+ TextView { row = 1, text = "Column width" },
+ DropDownList { row = 1, column = 1, id = columnWidth, current = 0,
+ items = ["auto", "100px", "200px", "40em"]
+ },
+ TextView { row = 2, text = "Column gap" },
+ DropDownList { row = 2, column = 1, id = columnGap, current = 0,
+ items = ["auto", "5%", "12px", "4em"]
+ },
+ TextView { row = 3, text = "Column separator" },
+ DropDownList { row = 3, column = 1, id = columnSeparator, current = 0,
+ items = ["none", "1px solid", "2px dotted red", "3px dashed blue", "4px double"]},
+ Checkbox { row = 4, column = 0:1, id = columnAvoidBreak, content = "Avoid break" }
+ ]
+ },
+ ]
+ }
+ ]
+}
+`
+
+func createColumnLayoutDemo(session rui.Session) rui.View {
+ view := rui.CreateViewFromText(session, columnLayoutText)
+ if view == nil {
+ return nil
+ }
+
+ rui.Set(view, "columnCount", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ rui.Set(view, "columnLayout", rui.ColumnCount, number)
+ })
+
+ rui.Set(view, "columnWidth", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ items := []rui.SizeUnit{rui.AutoSize(), rui.Px(100), rui.Px(200), rui.Em(40)}
+ if number >= 0 && number < len(items) {
+ rui.Set(view, "columnLayout", rui.ColumnWidth, items[number])
+ }
+ })
+
+ rui.Set(view, "columnGap", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ items := []rui.SizeUnit{rui.AutoSize(), rui.Percent(5), rui.Px(8), rui.Em(4)}
+ if number >= 0 && number < len(items) {
+ rui.Set(view, "columnLayout", rui.ColumnGap, items[number])
+ }
+ })
+
+ rui.Set(view, "columnSeparator", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ switch number {
+ case 0:
+ rui.Set(view, "columnLayout", rui.ColumnSeparator, nil)
+
+ case 1:
+ rui.Set(view, "columnLayout", rui.ColumnSeparator,
+ rui.NewColumnSeparator(rui.Params{
+ rui.Width: rui.Px(1),
+ rui.Style: rui.SolidLine,
+ }))
+
+ case 2:
+ rui.Set(view, "columnLayout", rui.ColumnSeparator,
+ rui.NewColumnSeparator(rui.Params{
+ rui.Width: rui.Px(2),
+ rui.Style: rui.DottedLine,
+ rui.ColorProperty: rui.Red,
+ }))
+
+ case 3:
+ rui.Set(view, "columnLayout", rui.ColumnSeparator,
+ rui.NewColumnSeparator(rui.Params{
+ rui.Width: rui.Px(3),
+ rui.Style: rui.DashedLine,
+ rui.ColorProperty: rui.Blue,
+ }))
+
+ case 4:
+ rui.Set(view, "columnLayout", rui.ColumnSeparator,
+ rui.NewColumnSeparator(rui.Params{
+ rui.Width: rui.Px(4),
+ rui.Style: rui.DoubleLine,
+ }))
+ }
+ })
+
+ rui.Set(view, "columnAvoidBreak", rui.CheckboxChangedEvent, func(checkbox rui.Checkbox, checked bool) {
+ if layout := rui.ColumnLayoutByID(view, "columnLayout"); layout != nil {
+ for _, v := range layout.Views() {
+ v.Set(rui.AvoidBreak, checked)
+ }
+ }
+ number := rui.GetColumnCount(view, "columnLayout")
+ if number > 0 {
+ rui.Set(view, "columnLayout", rui.ColumnCount, 0)
+ rui.Set(view, "columnLayout", rui.ColumnCount, number)
+ }
+ })
+
+ return view
+}
diff --git a/demo/controlsDemo.go b/demo/controlsDemo.go
new file mode 100644
index 0000000..e510458
--- /dev/null
+++ b/demo/controlsDemo.go
@@ -0,0 +1,148 @@
+package main
+
+import (
+ "fmt"
+ "math"
+ "time"
+
+ "github.com/anoshenko/rui"
+)
+
+const controlsDemoText = `
+ListLayout {
+ width = 100%, height = 100%, orientation = vertical, padding = 16px,
+ content = [
+ DetailsView {
+ margin = 8px,
+ summary = "Details title",
+ content = "Details content"
+ }
+ ListLayout { orientation = horizontal, vertical-align = center, padding = 8px,
+ border = _{ width = 1px, style = solid, color = #FF000000 }, radius = 4px,
+ content = [
+ Checkbox { id = controlsCheckbox, content = "Checkbox" },
+ Button { id = controlsCheckboxButton, margin-left = 32px, content = "Check checkbox" },
+ ]
+ },
+ ListLayout { orientation = horizontal, margin-top = 16px, padding = 8px, vertical-align = center,
+ border = _{ width = 1px, style = solid, color = #FF000000 }, radius = 4px,
+ content = [
+ Button { id = controlsProgressDec, content = "<<" },
+ Button { id = controlsProgressInc, content = ">>", margin-left = 12px },
+ ProgressBar { id = controlsProgress, max = 100, value = 50, margin-left = 12px },
+ TextView { id = controlsProgressLabel, text = "50 / 100", margin-left = 12px },
+ ]
+ },
+ ListLayout { orientation = horizontal, margin-top = 16px, padding = 8px, vertical-align = center,
+ border = _{ width = 1px, style = solid, color = #FF000000 }, radius = 4px,
+ content = [
+ "Enter number (-5...10)",
+ NumberPicker { id = controlsNumberEditor, type = editor, width = 80px,
+ margin-left = 12px, min = -5, max = 10, step = 0.1, value = 0
+ },
+ NumberPicker { id = controlsNumberSlider, type = slider, width = 150px,
+ margin-left = 12px, min = -5, max = 10, step = 0.1, value = 0
+ }
+ ]
+ },
+ ListLayout { orientation = horizontal, margin-top = 16px, padding = 8px, vertical-align = center,
+ border = _{ width = 1px, style = solid, color = #FF000000 }, radius = 4px,
+ content = [
+ "Select color",
+ ColorPicker { id = controlsColorPicker, value = #0000FF,
+ margin = _{ left = 12px, right = 24px}
+ },
+ "Result",
+ View { id = controlsColorResult, width = 24px, height = 24px, margin-left = 12px, background-color = #0000FF }
+ ]
+ },
+ ListLayout { orientation = horizontal, margin-top = 16px, padding = 8px, vertical-align = center,
+ border = _{ width = 1px, style = solid, color = #FF000000 }, radius = 4px,
+ content = [
+ "Select a time and date:",
+ TimePicker { id = controlsTimePicker, min = "00:00", margin-left = 12px },
+ DatePicker { id = controlsDatePicker, min = "2001-01-01", margin-right = 24px },
+ "Result:",
+ TextView { id = controlsDateResult, margin-left = 12px }
+ ]
+ },
+ Button {
+ id = controlsMessage, margin-top = 16px, content = "Show message"
+ }
+ ]
+}
+`
+
+func createControlsDemo(session rui.Session) rui.View {
+ view := rui.CreateViewFromText(session, controlsDemoText)
+ if view == nil {
+ return nil
+ }
+
+ rui.Set(view, "controlsCheckbox", rui.CheckboxChangedEvent, func(checkbox rui.Checkbox, checked bool) {
+ if checked {
+ rui.Set(view, "controlsCheckboxButton", rui.Content, "Uncheck checkbox")
+ } else {
+ rui.Set(view, "controlsCheckboxButton", rui.Content, "Check checkbox")
+ }
+ })
+
+ rui.Set(view, "controlsCheckboxButton", rui.ClickEvent, func(rui.View) {
+ checked := rui.IsCheckboxChecked(view, "controlsCheckbox")
+ rui.Set(view, "controlsCheckbox", rui.Checked, !checked)
+ })
+
+ setProgressBar := func(dx float64) {
+ if value := rui.GetProgressBarValue(view, "controlsProgress"); value >= 0 {
+ max := rui.GetProgressBarMax(view, "controlsProgress")
+ newValue := math.Min(math.Max(0, value+dx), max)
+ if newValue != value {
+ rui.Set(view, "controlsProgress", rui.Value, newValue)
+ rui.Set(view, "controlsProgressLabel", rui.Text, fmt.Sprintf("%g / %g", newValue, max))
+ }
+ }
+ }
+
+ rui.Set(view, "controlsProgressDec", rui.ClickEvent, func(rui.View) {
+ setProgressBar(-1)
+ })
+
+ rui.Set(view, "controlsProgressInc", rui.ClickEvent, func(rui.View) {
+ setProgressBar(+1)
+ })
+
+ rui.Set(view, "controlsNumberEditor", rui.NumberChangedEvent, func(v rui.NumberPicker, newValue float64) {
+ rui.Set(view, "controlsNumberSlider", rui.Value, newValue)
+ })
+
+ rui.Set(view, "controlsNumberSlider", rui.NumberChangedEvent, func(v rui.NumberPicker, newValue float64) {
+ rui.Set(view, "controlsNumberEditor", rui.Value, newValue)
+ })
+
+ rui.Set(view, "controlsColorPicker", rui.ColorChangedEvent, func(v rui.ColorPicker, newColor rui.Color) {
+ rui.Set(view, "controlsColorResult", rui.BackgroundColor, newColor)
+ })
+
+ rui.Set(view, "controlsTimePicker", rui.Value, demoTime)
+ rui.Set(view, "controlsDatePicker", rui.Value, demoTime)
+
+ rui.Set(view, "controlsTimePicker", rui.TimeChangedEvent, func(v rui.TimePicker, newDate time.Time) {
+ demoTime = time.Date(demoTime.Year(), demoTime.Month(), demoTime.Day(), newDate.Hour(), newDate.Minute(),
+ newDate.Second(), newDate.Nanosecond(), demoTime.Location())
+ rui.Set(view, "controlsDateResult", rui.Text, demoTime.Format(time.RFC1123))
+ })
+
+ rui.Set(view, "controlsDatePicker", rui.DateChangedEvent, func(v rui.DatePicker, newDate time.Time) {
+ demoTime = time.Date(newDate.Year(), newDate.Month(), newDate.Day(), demoTime.Hour(), demoTime.Minute(),
+ demoTime.Second(), demoTime.Nanosecond(), demoTime.Location())
+ rui.Set(view, "controlsDateResult", rui.Text, demoTime.Format(time.RFC1123))
+ })
+
+ rui.Set(view, "controlsMessage", rui.ClickEvent, func(rui.View) {
+ rui.ShowMessage("Hello", "Hello world!!!", session)
+ })
+
+ return view
+}
+
+var demoTime = time.Now()
diff --git a/demo/editDemo.go b/demo/editDemo.go
new file mode 100644
index 0000000..b406e44
--- /dev/null
+++ b/demo/editDemo.go
@@ -0,0 +1,70 @@
+package main
+
+import (
+ "github.com/anoshenko/rui"
+)
+
+const editDemoText = `
+ListLayout {
+ width = 100%, height = 100%, orientation = vertical, padding = 16px,
+ content = [
+ GridLayout {
+ row-gap = 12px, column-gap = 8px, cell-width = "auto, 1fr, auto", cell-vertical-align = center,
+ content = [
+ TextView { row = 0, column = 0, text = "User name" },
+ EditView { row = 0, column = 1, id = editUserName, min-width = 200px, hint = "Required", type = text },
+ TextView { row = 1, column = 0, text = "Password" },
+ EditView { row = 1, column = 1, id = editPassword, min-width = 200px, hint = "8 characters minimum", type = password },
+ TextView { row = 2, column = 0, text = "Confirm password" },
+ EditView { row = 2, column = 1, id = editConfirmPassword, min-width = 200px, hint = "Required", type = password },
+ TextView { row = 2, column = 2, id = confirmLabel, text = "" },
+ TextView { row = 3, column = 0, text = "Main e-mail" },
+ EditView { row = 3, column = 1, id = editMainEmail, min-width = 200px, hint = "Required", type = email },
+ TextView { row = 4, column = 0, text = "Additional e-mails" },
+ EditView { row = 4, column = 1, id = editAdditionalEmails, min-width = 200px, hint = "Optional", type = emails },
+ TextView { row = 5, column = 0, text = "Home page" },
+ EditView { row = 5, column = 1, id = editHomePage, min-width = 200px, hint = "Optional", type = url },
+ TextView { row = 6, column = 0, text = "Phone" },
+ EditView { row = 6, column = 1, id = editPhone, min-width = 200px, hint = "Optional", type = phone },
+ EditView { row = 7, column = 0:1, id = editMultiLine, height = 200px, type = multiline },
+ Checkbox { row = 7, column = 2, id = editMultiLineWrap, content = "Wrap", margin-left = 12px }
+ ]
+ },
+ ]
+}
+`
+
+func createEditDemo(session rui.Session) rui.View {
+ view := rui.CreateViewFromText(session, editDemoText)
+ if view == nil {
+ return nil
+ }
+
+ setConfirmLabel := func(password, confirmPassword string) {
+ if password == confirmPassword {
+ rui.Set(view, "confirmLabel", rui.TextColor, rui.Green)
+ if password != "" {
+ rui.Set(view, "confirmLabel", rui.Text, "✓")
+ } else {
+ rui.Set(view, "confirmLabel", rui.Text, "")
+ }
+ } else {
+ rui.Set(view, "confirmLabel", rui.TextColor, rui.Red)
+ rui.Set(view, "confirmLabel", rui.Text, "✗")
+ }
+ }
+
+ rui.Set(view, "editPassword", rui.EditTextChangedEvent, func(edit rui.EditView, newText string) {
+ setConfirmLabel(newText, rui.GetText(view, "editConfirmPassword"))
+ })
+
+ rui.Set(view, "editConfirmPassword", rui.EditTextChangedEvent, func(edit rui.EditView, newText string) {
+ setConfirmLabel(rui.GetText(view, "editPassword"), newText)
+ })
+
+ rui.Set(view, "editMultiLineWrap", rui.CheckboxChangedEvent, func(checkbox rui.Checkbox, checked bool) {
+ rui.Set(view, "editMultiLine", rui.Wrap, checked)
+ })
+
+ return view
+}
diff --git a/demo/filterDemo.go b/demo/filterDemo.go
new file mode 100644
index 0000000..a8c2004
--- /dev/null
+++ b/demo/filterDemo.go
@@ -0,0 +1,170 @@
+package main
+
+import (
+ "fmt"
+ "strings"
+
+ "github.com/anoshenko/rui"
+)
+
+const filterDemoText = `
+GridLayout {
+ style = demoPage,
+ content = [
+ GridLayout {
+ width = 100%, height = 100%, cell-vertical-align = center, cell-horizontal-align = center,
+ content = [
+ ImageView { id = filterImage, src = "mountain.svg" },
+ ]
+ },
+ ListLayout {
+ style = optionsPanel,
+ content = [
+ GridLayout {
+ style = optionsTable,
+ content = [
+ Checkbox { id = blurCheckbox, row = 0, content = "Blur" },
+ NumberPicker { id = blurSlider, row = 1, type = slider, min = 0, max = 25, step = 0.1, disabled = true },
+ TextView { id = blurValue, row = 1, column = 1, text = "0px", width = 40px },
+ Checkbox { id = brightnessCheckbox, row = 2, content = "Brightness" },
+ NumberPicker { id = brightnessSlider, row = 3, type = slider, min = 0, max = 200, step = 1, disabled = true },
+ TextView { id = brightnessValue, row = 3, column = 1, text = "0%", width = 40px },
+ Checkbox { id = contrastCheckbox, row = 4, content = "Contrast" },
+ NumberPicker { id = contrastSlider, row = 5, type = slider, min = 0, max = 200, step = 1, disabled = true },
+ TextView { id = contrastValue, row = 5, column = 1, text = "0%", width = 40px },
+ Checkbox { id = grayscaleCheckbox, row = 6, content = "Grayscale" },
+ NumberPicker { id = grayscaleSlider, row = 7, type = slider, min = 0, max = 100, step = 1, disabled = true },
+ TextView { id = grayscaleValue, row = 7, column = 1, text = "0%", width = 40px },
+ Checkbox { id = invertCheckbox, row = 8, content = "Invert" },
+ NumberPicker { id = invertSlider, row = 9, type = slider, min = 0, max = 100, step = 1, disabled = true },
+ TextView { id = invertValue, row = 9, column = 1, text = "0%", width = 40px },
+ Checkbox { id = saturateCheckbox, row = 10, content = "Saturate" },
+ NumberPicker { id = saturateSlider, row = 11, type = slider, min = 0, max = 200, step = 1, disabled = true },
+ TextView { id = saturateValue, row = 11, column = 1, text = "0%", width = 40px },
+ Checkbox { id = sepiaCheckbox, row = 12, content = "Sepia" },
+ NumberPicker { id = sepiaSlider, row = 13, type = slider, min = 0, max = 100, step = 1, disabled = true },
+ TextView { id = sepiaValue, row = 13, column = 1, text = "0%", width = 40px },
+ Checkbox { id = opacityCheckbox, row = 14, content = "Opacity" },
+ NumberPicker { id = opacitySlider, row = 15, type = slider, min = 0, max = 100, step = 1, disabled = true },
+ TextView { id = opacityValue, row = 15, column = 1, text = "0%", width = 40px },
+ Checkbox { id = huerotateCheckbox, row = 16, content = "hue-rotate" },
+ NumberPicker { id = huerotateSlider, row = 17, type = slider, min = 0, max = 720, step = 1, disabled = true },
+ TextView { id = huerotateValue, row = 17, column = 1, text = "0°", width = 40px },
+ Checkbox { id = shadowCheckbox, row = 18, content = "drop-shadow" },
+ ColorPicker { id = dropShadowColor, row = 18, column = 1, color = black, disabled = true },
+ NumberPicker { id = shadowXSlider, row = 19, type = slider, min = -20, max = 20, step = 1, value = 0, disabled = true },
+ TextView { id = shadowXValue, row = 19, column = 1, text = "x:0px", width = 40px },
+ NumberPicker { id = shadowYSlider, row = 20, type = slider, min = -20, max = 20, step = 1, value = 0, disabled = true },
+ TextView { id = shadowYValue, row = 20, column = 1, text = "y:0px", width = 40px },
+ NumberPicker { id = shadowBlurSlider, row = 21, type = slider, min = 0, max = 40, step = 1, disabled = true },
+ TextView { id = shadowBlurValue, row = 21, column = 1, text = "b:0px", width = 40px },
+ ]
+ }
+ ]
+ }
+ ]
+}
+`
+
+var filterParams = rui.Params{}
+
+func createFilterDemo(session rui.Session) rui.View {
+ view := rui.CreateViewFromText(session, filterDemoText)
+ if view == nil {
+ return nil
+ }
+
+ setEvents := func(tag string) {
+ rui.Set(view, tag+"Checkbox", rui.CheckboxChangedEvent, func(state bool) {
+ slider := tag + "Slider"
+ rui.Set(view, slider, rui.Disabled, !state)
+ if state {
+ filterParams[tag] = rui.GetNumberPickerValue(view, slider)
+ } else {
+ delete(filterParams, tag)
+ }
+ rui.Set(view, "filterImage", rui.Filter, rui.NewViewFilter(filterParams))
+ })
+
+ rui.Set(view, tag+"Slider", rui.NumberChangedEvent, func(value float64) {
+ var text string
+ if tag == rui.Blur {
+ text = fmt.Sprintf("%.2gpx", value)
+ } else {
+ text = fmt.Sprintf("%g%%", value)
+ }
+ rui.Set(view, tag+"Value", rui.Text, text)
+ filterParams[tag] = value
+ rui.Set(view, "filterImage", rui.Filter, rui.NewViewFilter(filterParams))
+ })
+ }
+
+ for _, tag := range []string{rui.Blur, rui.Brightness, rui.Contrast, rui.Grayscale, rui.Invert, rui.Saturate, rui.Sepia, rui.Opacity} {
+ setEvents(tag)
+ }
+
+ rui.Set(view, "huerotateCheckbox", rui.CheckboxChangedEvent, func(state bool) {
+ rui.Set(view, "huerotateSlider", rui.Disabled, !state)
+ if state {
+ filterParams[rui.HueRotate] = rui.AngleUnit{
+ Type: rui.Degree,
+ Value: rui.GetNumberPickerValue(view, "huerotateSlider"),
+ }
+ } else {
+ delete(filterParams, rui.HueRotate)
+ }
+ rui.Set(view, "filterImage", rui.Filter, rui.NewViewFilter(filterParams))
+ })
+
+ rui.Set(view, "huerotateSlider", rui.NumberChangedEvent, func(value float64) {
+ rui.Set(view, "huerotateValue", rui.Text, fmt.Sprintf("%g°", value))
+ filterParams[rui.HueRotate] = rui.AngleUnit{Type: rui.Degree, Value: value}
+ rui.Set(view, "filterImage", rui.Filter, rui.NewViewFilter(filterParams))
+ })
+
+ updateShadow := func() {
+ xOff := rui.SizeUnit{
+ Type: rui.SizeInPixel,
+ Value: rui.GetNumberPickerValue(view, "shadowXSlider"),
+ }
+ yOff := rui.SizeUnit{
+ Type: rui.SizeInPixel,
+ Value: rui.GetNumberPickerValue(view, "shadowYSlider"),
+ }
+ blur := rui.SizeUnit{
+ Type: rui.SizeInPixel,
+ Value: rui.GetNumberPickerValue(view, "shadowBlurSlider"),
+ }
+ color := rui.GetColorPickerValue(view, "dropShadowColor")
+
+ filterParams[rui.DropShadow] = rui.NewTextShadow(xOff, yOff, blur, color)
+ rui.Set(view, "filterImage", rui.Filter, rui.NewViewFilter(filterParams))
+ }
+
+ rui.Set(view, "shadowCheckbox", rui.CheckboxChangedEvent, func(state bool) {
+ for _, tag := range []string{"shadowXSlider", "shadowYSlider", "shadowBlurSlider", "dropShadowColor"} {
+ rui.Set(view, tag, rui.Disabled, !state)
+ }
+ if state {
+ updateShadow()
+ } else {
+ delete(filterParams, rui.DropShadow)
+ rui.Set(view, "filterImage", rui.Filter, rui.NewViewFilter(filterParams))
+ }
+ })
+
+ for _, tag := range []string{"shadowXSlider", "shadowYSlider", "shadowBlurSlider"} {
+ rui.Set(view, tag, rui.NumberChangedEvent, func(picker rui.NumberPicker, value float64) {
+ tag := strings.Replace(picker.ID(), "Slider", "Value", -1)
+ text := rui.GetText(view, tag)
+ rui.Set(view, tag, rui.Text, fmt.Sprintf("%s%gpx", text[:2], value))
+ updateShadow()
+ })
+ }
+
+ rui.Set(view, "dropShadowColor", rui.ColorChangedEvent, func(value rui.Color) {
+ updateShadow()
+ })
+
+ return view
+}
diff --git a/demo/gridLayoutDemo.go b/demo/gridLayoutDemo.go
new file mode 100644
index 0000000..d2d53f9
--- /dev/null
+++ b/demo/gridLayoutDemo.go
@@ -0,0 +1,103 @@
+package main
+
+import (
+ "github.com/anoshenko/rui"
+)
+
+const gridLayoutDemoText = `
+GridLayout {
+ style = demoPage,
+ content = [
+ GridLayout {
+ id = gridLayout, width = 100%, height = 100%,
+ cell-width = "150px, 1fr, 30%", cell-height = "25%, 200px, 1fr",
+ content = [
+ TextView { row = 0, column = 0:1,
+ text = "View 1", text-align = center, vertical-align = center,
+ background-color = #DDFF0000, radius = 8px, padding = 32px,
+ border = _{ style = solid, width = 1px, color = #FFA0A0A0 }
+ },
+ TextView { row = 0:1, column = 2,
+ text = "View 2", text-align = center, vertical-align = center,
+ background-color = #DD00FF00, radius = 8px, padding = 32px,
+ border = _{ style = solid, width = 1px, color = #FFA0A0A0 }
+ },
+ TextView { row = 1:2, column = 0,
+ text = "View 3", text-align = center, vertical-align = center,
+ background-color = #DD0000FF, radius = 8px, padding = 32px,
+ border = _{ style = solid, width = 1px, color = #FFA0A0A0 }
+ },
+ TextView { row = 1, column = 1,
+ text = "View 4", text-align = center, vertical-align = center,
+ background-color = #DDFF00FF, radius = 8px, padding = 32px,
+ border = _{ style = solid, width = 1px, color = #FFA0A0A0 }
+ },
+ TextView { row = 2, column = 1:2,
+ text = "View 5", text-align = center, vertical-align = center,
+ background-color = #DD00FFFF, radius = 8px, padding = 32px,
+ border = _{ style = solid, width = 1px, color = #FFA0A0A0 }
+ },
+ ]
+ },
+ ListLayout {
+ style = optionsPanel,
+ content = [
+ GridLayout {
+ style = optionsTable,
+ content = [
+ TextView { row = 0, text = "Vertical align" },
+ DropDownList { row = 0, column = 1, id = gridVAlign, current = 3,
+ items = ["top", "bottom", "center", "stretch"]
+ },
+ TextView { row = 1, text = "Horizontal align" },
+ DropDownList { row = 1, column = 1, id = gridHAlign, current = 3,
+ items = ["left", "right", "center", "stretch"]
+ },
+ TextView { row = 2, text = "Column gap" },
+ DropDownList { row = 2, column = 1, id = gridColumnGap, current = 0, items = ["0", "8px"] },
+ TextView { row = 3, text = "Row gap" },
+ DropDownList { row = 3, column = 1, id = gridRowGap, current = 0, items = ["0", "8px"] },
+ ]
+ }
+ ]
+ }
+ ]
+}
+`
+
+func createGridLayoutDemo(session rui.Session) rui.View {
+ view := rui.CreateViewFromText(session, gridLayoutDemoText)
+ if view == nil {
+ return nil
+ }
+
+ rui.Set(view, "gridHAlign", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ rui.Set(view, "gridLayout", rui.CellHorizontalAlign, number)
+ })
+
+ rui.Set(view, "gridVAlign", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ rui.Set(view, "gridLayout", rui.CellVerticalAlign, number)
+ })
+
+ rui.Set(view, "gridColumnGap", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ switch number {
+ case 0:
+ rui.Set(view, "gridLayout", rui.GridColumnGap, rui.SizeUnit{Type: rui.Auto, Value: 0})
+
+ case 1:
+ rui.Set(view, "gridLayout", rui.GridColumnGap, rui.Px(8))
+ }
+ })
+
+ rui.Set(view, "gridRowGap", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ switch number {
+ case 0:
+ rui.Set(view, "gridLayout", rui.GridRowGap, rui.SizeUnit{Type: rui.Auto, Value: 0})
+
+ case 1:
+ rui.Set(view, "gridLayout", rui.GridRowGap, rui.Px(8))
+ }
+ })
+
+ return view
+}
diff --git a/demo/imageViewDemo.go b/demo/imageViewDemo.go
new file mode 100644
index 0000000..4771b13
--- /dev/null
+++ b/demo/imageViewDemo.go
@@ -0,0 +1,63 @@
+package main
+
+import (
+ "github.com/anoshenko/rui"
+)
+
+const imageViewDemoText = `
+GridLayout {
+ style = demoPage,
+ content = [
+ ImageView {
+ id = imageView1, width = 100%, height = 100%, src = "cat.jpg",
+ border = _{ style = solid, width = 1px, color = #FF008800 }
+ },
+ ListLayout {
+ style = optionsPanel,
+ content = [
+ GridLayout {
+ style = optionsTable,
+ content = [
+ TextView { row = 0, text = "Image" },
+ DropDownList { row = 0, column = 1, id = imageViewImage, current = 0, items = ["cat.jpg", "winds.png", "gifsInEmail.gif", "mountain.svg"]},
+ TextView { row = 1, text = "Fit" },
+ DropDownList { row = 1, column = 1, id = imageViewFit, current = 0, items = ["none", "fill", "contain", "cover", "scale-down"]},
+ TextView { row = 2, text = "Horizontal align" },
+ DropDownList { row = 2, column = 1, id = imageViewHAlign, current = 2, items = ["left", "right", "center"]},
+ TextView { row = 3, text = "Vertical align" },
+ DropDownList { row = 3, column = 1, id = imageViewVAlign, current = 2, items = ["top", "bottom", "center"]},
+ ]
+ }
+ ]
+ }
+ ]
+}
+`
+
+func createImageViewDemo(session rui.Session) rui.View {
+ view := rui.CreateViewFromText(session, imageViewDemoText)
+ if view == nil {
+ return nil
+ }
+
+ rui.Set(view, "imageViewImage", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ images := []string{"cat.jpg", "winds.png", "gifsInEmail.gif", "mountain.svg"}
+ if number < len(images) {
+ rui.Set(view, "imageView1", rui.Source, images[number])
+ }
+ })
+
+ rui.Set(view, "imageViewFit", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ rui.Set(view, "imageView1", rui.Fit, number)
+ })
+
+ rui.Set(view, "imageViewHAlign", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ rui.Set(view, "imageView1", rui.ImageHorizontalAlign, number)
+ })
+
+ rui.Set(view, "imageViewVAlign", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ rui.Set(view, "imageView1", rui.ImageVerticalAlign, number)
+ })
+
+ return view
+}
diff --git a/demo/keyEventsDemo.go b/demo/keyEventsDemo.go
new file mode 100644
index 0000000..db46ae1
--- /dev/null
+++ b/demo/keyEventsDemo.go
@@ -0,0 +1,57 @@
+package main
+
+import (
+ "strconv"
+ "strings"
+
+ "github.com/anoshenko/rui"
+)
+
+func keyEventHandle(view rui.View, event rui.KeyEvent, tag string) {
+ var buffer strings.Builder
+
+ buffer.WriteString(tag)
+ buffer.WriteString(`: TimeStamp = `)
+ buffer.WriteString(strconv.FormatUint(event.TimeStamp, 10))
+ buffer.WriteString(`, Key = "`)
+ buffer.WriteString(event.Key)
+ buffer.WriteString(`", Code = "`)
+ buffer.WriteString(event.Code)
+ buffer.WriteString(`"`)
+
+ appendBool := func(name string, value bool) {
+ buffer.WriteString(`, `)
+ buffer.WriteString(name)
+ if value {
+ buffer.WriteString(` = true`)
+ } else {
+ buffer.WriteString(` = false`)
+ }
+ }
+ appendBool("Repeat", event.Repeat)
+ appendBool("CtrlKey", event.CtrlKey)
+ appendBool("ShiftKey", event.ShiftKey)
+ appendBool("AltKey", event.AltKey)
+ appendBool("MetaKey", event.MetaKey)
+ buffer.WriteString(";\n\n")
+
+ rui.AppendEditText(view, "", buffer.String())
+ rui.ScrollViewToEnd(view, "")
+}
+
+func createKeyEventsDemo(session rui.Session) rui.View {
+ return rui.NewEditView(session, rui.Params{
+ rui.Width: rui.Percent(100),
+ rui.Height: rui.Percent(100),
+ rui.ReadOnly: true,
+ rui.Wrap: true,
+ rui.Hint: "Set the focus and press a key",
+ rui.EditViewType: rui.MultiLineText,
+ rui.KeyDownEvent: func(view rui.View, event rui.KeyEvent) {
+ keyEventHandle(view, event, rui.KeyDownEvent)
+ },
+ rui.KeyUpEvent: func(view rui.View, event rui.KeyEvent) {
+ keyEventHandle(view, event, rui.KeyUpEvent)
+ },
+ })
+}
diff --git a/demo/listLayoutDemo.go b/demo/listLayoutDemo.go
new file mode 100644
index 0000000..bb115cf
--- /dev/null
+++ b/demo/listLayoutDemo.go
@@ -0,0 +1,90 @@
+package main
+
+import (
+ "github.com/anoshenko/rui"
+)
+
+const listLayoutDemoText = `
+GridLayout {
+ style = demoPage,
+ content = [
+ ListLayout {
+ id = listLayout, width = 100%, height = 100%, orientation = up-down,
+ content = [
+ GridLayout { width = 200px, height = 100px, content = ["View 1"], horizontal-align = center, vertical-align = center,
+ background-color = #FFAAAAAA, radius = 8px, padding = 8px, margin = 4px,
+ border = _{ style = solid, width = 1px, color = black }
+ },
+ GridLayout { width = 100px, height = 200px, content = ["View 2"], horizontal-align = center, vertical-align = center,
+ background-color = #FFB0B0B0, radius = 8px, padding = 8px, margin = 4px,
+ border = _{ style = solid, width = 1px, color = black }
+ },
+ GridLayout { width = 150px, height = 150px, content = ["View 3"], horizontal-align = center, vertical-align = center,
+ background-color = #FFBBBBBB, radius = 8px, padding = 8px, margin = 4px,
+ border = _{ style = solid, width = 1px, color = black }
+ },
+ GridLayout { width = 150px, height = 100px, content = ["View 4"], horizontal-align = center, vertical-align = center,
+ background-color = #FFC0C0C0, radius = 8px, padding = 8px, margin = 4px,
+ border = _{ style = solid, width = 1px, color = black }
+ },
+ GridLayout { width = 200px, height = 150px, content = ["View 5"], horizontal-align = center, vertical-align = center,
+ background-color = #FFCCCCCC, radius = 8px, padding = 8px, margin = 4px,
+ border = _{ style = solid, width = 1px, color = black }
+ },
+ GridLayout { width = 100px, height = 100px, content = ["View 6"], horizontal-align = center, vertical-align = center,
+ background-color = #FFDDDDDD, radius = 8px, padding = 8px, margin = 4px,
+ border = _{ style = solid, width = 1px, color = black }
+ },
+ GridLayout { width = 150px, height = 200px, content = ["View 7"], horizontal-align = center, vertical-align = center,
+ background-color = #FFEEEEEE, radius = 8px, padding = 8px, margin = 4px,
+ border = _{ style = solid, width = 1px, color = black }
+ },
+ ]
+ },
+ ListLayout {
+ style = optionsPanel,
+ content = [
+ GridLayout {
+ style = optionsTable,
+ content = [
+ TextView { row = 0, text = "Orientation" },
+ DropDownList { row = 0, column = 1, id = listOrientation, current = 0,
+ items = ["up-down", "start-to-end", "bottom-up", "end-to-start"]
+ },
+ TextView { row = 1, text = "Wrap" },
+ DropDownList { row = 1, column = 1, id = listWrap, current = 0, items = ["off", "on", "reverse"]},
+ TextView { row = 2, text = "Vertical align" },
+ DropDownList { row = 2, column = 1, id = listVAlign, current = 0, items = ["top", "bottom", "center", "stretch"]},
+ TextView { row = 3, text = "Horizontal align" },
+ DropDownList { row = 3, column = 1, id = listHAlign, current = 0, items = ["left", "right", "center", "stretch"]},
+ ]
+ },
+ ]
+ }
+ ]
+}`
+
+func createListLayoutDemo(session rui.Session) rui.View {
+ view := rui.CreateViewFromText(session, listLayoutDemoText)
+ if view == nil {
+ return nil
+ }
+
+ rui.Set(view, "listOrientation", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ rui.Set(view, "listLayout", rui.Orientation, number)
+ })
+
+ rui.Set(view, "listWrap", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ rui.Set(view, "listLayout", rui.Wrap, number)
+ })
+
+ rui.Set(view, "listHAlign", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ rui.Set(view, "listLayout", rui.HorizontalAlign, number)
+ })
+
+ rui.Set(view, "listVAlign", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ rui.Set(view, "listLayout", rui.VerticalAlign, number)
+ })
+
+ return view
+}
diff --git a/demo/listViewDemo.go b/demo/listViewDemo.go
new file mode 100644
index 0000000..f2a36ac
--- /dev/null
+++ b/demo/listViewDemo.go
@@ -0,0 +1,95 @@
+package main
+
+import (
+ "github.com/anoshenko/rui"
+)
+
+const listViewDemoText = `
+GridLayout {
+ style = demoPage,
+ content = [
+ ListView {
+ id = listView, width = 100%, height = 100%, orientation = vertical,
+ items = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7", "Item 8", "Item 9", "Item 10", "Item 11", "Item 12", "Item 13", "Item 14", "Item 15", "Item 16", "Item 17", "Item 18"]
+ },
+ ListLayout {
+ style = optionsPanel,
+ content = [
+ GridLayout {
+ style = optionsTable,
+ content = [
+ TextView { row = 0, text = "Orientation" },
+ DropDownList { row = 0, column = 1, id = listViewOrientation, current = 0, items = ["vertical", "horizontal", "bottom up", "end to start"]},
+ TextView { row = 1, text = "Wrap" },
+ DropDownList { row = 1, column = 1, id = listWrap, current = 0, items = ["off", "on", "reverse"]},
+ TextView { row = 2, text = "Item height" },
+ DropDownList { row = 2, column = 1, id = listItemHeight, current = 0, items = ["auto", "25%", "50px"]},
+ TextView { row = 3, text = "Item width" },
+ DropDownList { row = 3, column = 1, id = listItemWidth, current = 0, items = ["auto", "25%", "200px"]},
+ TextView { row = 4, text = "Item vertical align" },
+ DropDownList { row = 4, column = 1, id = listItemVAlign, current = 0, items = ["top", "bottom", "center"]},
+ TextView { row = 5, text = "Item horizontal align" },
+ DropDownList { row = 5, column = 1, id = listItemHAlign, current = 0, items = ["left", "right", "center"]},
+ TextView { row = 6, text = "Checkbox" },
+ DropDownList { row = 6, column = 1, id = listCheckbox, current = 0, items = ["none", "single", "multiple"]},
+ TextView { row = 7, text = "Checkbox vertical align" },
+ DropDownList { row = 7, column = 1, id = listCheckboxVAlign, current = 0, items = ["top", "bottom", "center"]},
+ TextView { row = 8, text = "Checkbox horizontal align" },
+ DropDownList { row = 8, column = 1, id = listCheckboxHAlign, current = 0, items = ["left", "right", "center"]},
+ ]
+ }
+ ]
+ }
+ ]
+}`
+
+func createListViewDemo(session rui.Session) rui.View {
+ view := rui.CreateViewFromText(session, listViewDemoText)
+ if view == nil {
+ return nil
+ }
+
+ rui.Set(view, "listViewOrientation", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ rui.Set(view, "listView", rui.Orientation, number)
+ })
+
+ rui.Set(view, "listWrap", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ rui.Set(view, "listView", rui.Wrap, number)
+ })
+
+ setItemSize := func(tag string, number int, values []rui.SizeUnit) {
+ if number >= 0 && number < len(values) {
+ rui.Set(view, "listView", tag, values[number])
+ }
+ }
+
+ rui.Set(view, "listItemWidth", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ setItemSize(rui.ItemWidth, number, []rui.SizeUnit{rui.AutoSize(), rui.Percent(25), rui.Px(200)})
+ })
+
+ rui.Set(view, "listItemHeight", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ setItemSize(rui.ItemHeight, number, []rui.SizeUnit{rui.AutoSize(), rui.Percent(25), rui.Px(50)})
+ })
+
+ rui.Set(view, "listItemVAlign", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ rui.Set(view, "listView", rui.VerticalAlign, number)
+ })
+
+ rui.Set(view, "listItemHAlign", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ rui.Set(view, "listView", rui.HorizontalAlign, number)
+ })
+
+ rui.Set(view, "listCheckbox", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ rui.Set(view, "listView", rui.ItemCheckbox, number)
+ })
+
+ rui.Set(view, "listCheckboxVAlign", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ rui.Set(view, "listView", rui.CheckboxVerticalAlign, number)
+ })
+
+ rui.Set(view, "listCheckboxHAlign", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ rui.Set(view, "listView", rui.CheckboxHorizontalAlign, number)
+ })
+
+ return view
+}
diff --git a/demo/main.go b/demo/main.go
new file mode 100644
index 0000000..1da38ea
--- /dev/null
+++ b/demo/main.go
@@ -0,0 +1,163 @@
+package main
+
+import (
+ "embed"
+ "fmt"
+
+ "github.com/anoshenko/rui"
+)
+
+//go:embed resources
+var resources embed.FS
+
+const rootViewText = `
+GridLayout {
+ id = rootLayout, width = 100%, height = 100%, cell-height = "auto, 1fr",
+ content = [
+ GridLayout {
+ id = rootTitle, width = 100%, cell-width = "auto, 1fr",
+ cell-vertical-align = center, background-color = #ffc0ded9,
+ content = [
+ ImageView {
+ id = rootTitleButton, padding = 8px, src = menu_icon.svg,
+ },
+ TextView {
+ id = rootTitleText, column = 1, padding-left = 8px, text = "Title",
+ }
+ ],
+ },
+ StackLayout {
+ id = rootViews, row = 1,
+ }
+ ]
+}
+`
+
+type demoPage struct {
+ title string
+ creator func(session rui.Session) rui.View
+ view rui.View
+}
+
+type demoSession struct {
+ rootView rui.View
+ pages []demoPage
+}
+
+func (demo *demoSession) OnStart(session rui.Session) {
+ rui.DebugLog("Session start")
+}
+
+func (demo *demoSession) OnFinish(session rui.Session) {
+ rui.DebugLog("Session finish")
+}
+
+func (demo *demoSession) OnResume(session rui.Session) {
+ rui.DebugLog("Session resume")
+}
+
+func (demo *demoSession) OnPause(session rui.Session) {
+ rui.DebugLog("Session pause")
+}
+
+func (demo *demoSession) OnDisconnect(session rui.Session) {
+ rui.DebugLog("Session disconnect")
+}
+
+func (demo *demoSession) OnReconnect(session rui.Session) {
+ rui.DebugLog("Session reconnect")
+}
+
+func createDemo(session rui.Session) rui.SessionContent {
+ sessionContent := new(demoSession)
+ sessionContent.pages = []demoPage{
+ {"Text style", createTextStyleDemo, nil},
+ {"View border", viewDemo, nil},
+ {"Background image", createBackgroundDemo, nil},
+ {"ListLayout", createListLayoutDemo, nil},
+ {"GridLayout", createGridLayoutDemo, nil},
+ {"ColumnLayout", createColumnLayoutDemo, nil},
+ {"StackLayout", createStackLayoutDemo, nil},
+ {"AbsoluteLayout", createAbsoluteLayoutDemo, nil},
+ {"Resizable", createResizableDemo, nil},
+ {"ListView", createListViewDemo, nil},
+ {"Checkbox", createCheckboxDemo, nil},
+ {"Controls", createControlsDemo, nil},
+ {"TableView", createTableViewDemo, nil},
+ {"EditView", createEditDemo, nil},
+ {"ImageView", createImageViewDemo, nil},
+ {"Canvas", createCanvasDemo, nil},
+ {"VideoPlayer", createVideoPlayerDemo, nil},
+ {"AudioPlayer", createAudioPlayerDemo, nil},
+ {"Popups", createPopupDemo, nil},
+ {"Filter", createFilterDemo, nil},
+ {"Clip", createClipDemo, nil},
+ {"Transform", transformDemo, nil},
+ {"Transition", createTransitionDemo, nil},
+ {"Key events", createKeyEventsDemo, nil},
+ {"Mouse events", createMouseEventsDemo, nil},
+ {"Pointer events", createPointerEventsDemo, nil},
+ {"Touch events", createTouchEventsDemo, nil},
+ //{"Tabs", createTabsDemo, nil},
+ }
+
+ return sessionContent
+}
+
+func (demo *demoSession) CreateRootView(session rui.Session) rui.View {
+ demo.rootView = rui.CreateViewFromText(session, rootViewText)
+ if demo.rootView == nil {
+ return nil
+ }
+
+ rui.Set(demo.rootView, "rootTitleButton", rui.ClickEvent, demo.clickMenuButton)
+ demo.showPage(0)
+
+ return demo.rootView
+}
+
+func (demo *demoSession) clickMenuButton() {
+ items := make([]string, len(demo.pages))
+ for i, page := range demo.pages {
+ items[i] = page.title
+ }
+
+ rui.ShowMenu(demo.rootView.Session(), rui.Params{
+ rui.Items: items,
+ rui.OutsideClose: true,
+ rui.VerticalAlign: rui.TopAlign,
+ rui.HorizontalAlign: rui.LeftAlign,
+ rui.PopupMenuResult: func(n int) {
+ demo.showPage(n)
+ },
+ })
+}
+
+func (demo *demoSession) showPage(index int) {
+ if index < 0 || index >= len(demo.pages) {
+ return
+ }
+
+ if stackLayout := rui.StackLayoutByID(demo.rootView, "rootViews"); stackLayout != nil {
+ if demo.pages[index].view == nil {
+ demo.pages[index].view = demo.pages[index].creator(demo.rootView.Session())
+ stackLayout.Append(demo.pages[index].view)
+ } else {
+ stackLayout.MoveToFront(demo.pages[index].view)
+ }
+ rui.Set(demo.rootView, "rootTitleText", rui.Text, demo.pages[index].title)
+ }
+ // TODO
+}
+
+func main() {
+ rui.ProtocolInDebugLog = true
+ rui.AddEmbedResources(&resources)
+ app := rui.NewApplication("RUI demo", "icon.svg", createDemo)
+
+ //addr := rui.GetLocalIP() + ":8080"
+ addr := "localhost:8000"
+ fmt.Print(addr)
+ rui.OpenBrowser("http://" + addr)
+ app.Start(addr)
+}
diff --git a/demo/mouseEventsDemo.go b/demo/mouseEventsDemo.go
new file mode 100644
index 0000000..43103b7
--- /dev/null
+++ b/demo/mouseEventsDemo.go
@@ -0,0 +1,111 @@
+package main
+
+import (
+ "fmt"
+ "strconv"
+ "strings"
+
+ "github.com/anoshenko/rui"
+)
+
+const mouseEventsDemoText = `
+GridLayout {
+ width = 100%, height = 100%, cell-height = "1fr, auto",
+ content = [
+ GridLayout {
+ padding = 12px,
+ content = [
+ GridLayout {
+ id = mouseEventsTest, cell-horizontal-align = center, cell-vertical-align = center,
+ height = 150%,
+ border = _{ style = solid, width = 1px, color = gray},
+ content = [
+ TextView {
+ id = mouseEventsText, text = "Test box",
+ }
+ ]
+ }
+ ],
+ },
+ Resizable {
+ row = 1, side = top, background-color = lightgrey, height = 200px,
+ content = EditView {
+ id = mouseEventsLog, type = multiline, read-only = true, wrap = true,
+ }
+ },
+ ]
+}
+`
+
+func createMouseEventsDemo(session rui.Session) rui.View {
+ view := rui.CreateViewFromText(session, mouseEventsDemoText)
+ if view == nil {
+ return nil
+ }
+
+ addToLog := func(tag string, event rui.MouseEvent) {
+ var buffer strings.Builder
+
+ appendBool := func(name string, value bool) {
+ buffer.WriteString(`, `)
+ buffer.WriteString(name)
+ if value {
+ buffer.WriteString(` = true`)
+ } else {
+ buffer.WriteString(` = false`)
+ }
+ }
+
+ appendInt := func(name string, value int) {
+ buffer.WriteString(`, `)
+ buffer.WriteString(name)
+ buffer.WriteString(` = `)
+ buffer.WriteString(strconv.Itoa(value))
+ }
+
+ appendPoint := func(name string, x, y float64) {
+ buffer.WriteString(fmt.Sprintf(`, %s = (%g:%g)`, name, x, y))
+ }
+
+ buffer.WriteString(tag)
+ buffer.WriteString(`: TimeStamp = `)
+ buffer.WriteString(strconv.FormatUint(event.TimeStamp, 10))
+
+ appendInt("Button", event.Button)
+ appendInt("Buttons", event.Buttons)
+ appendPoint("(X:Y)", event.X, event.Y)
+ appendPoint("Client (X:Y)", event.ClientX, event.ClientY)
+ appendPoint("Screen (X:Y)", event.ScreenX, event.ScreenY)
+ appendBool("CtrlKey", event.CtrlKey)
+ appendBool("ShiftKey", event.ShiftKey)
+ appendBool("AltKey", event.AltKey)
+ appendBool("MetaKey", event.MetaKey)
+ buffer.WriteString(";\n\n")
+
+ rui.AppendEditText(view, "mouseEventsLog", buffer.String())
+ rui.ScrollViewToEnd(view, "mouseEventsLog")
+ }
+
+ rui.SetParams(view, "mouseEventsTest", rui.Params{
+ rui.MouseDown: func(v rui.View, event rui.MouseEvent) {
+ addToLog("mouse-down", event)
+ },
+ rui.MouseUp: func(v rui.View, event rui.MouseEvent) {
+ addToLog("mouse-up", event)
+ },
+ rui.MouseOut: func(v rui.View, event rui.MouseEvent) {
+ addToLog("mouse-out", event)
+ rui.Set(view, "mouseEventsText", rui.Text, "Mouse out")
+ },
+ rui.MouseOver: func(v rui.View, event rui.MouseEvent) {
+ addToLog("mouse-over", event)
+ },
+ rui.MouseMove: func(v rui.View, event rui.MouseEvent) {
+ rui.Set(view, "mouseEventsText", rui.Text,
+ fmt.Sprintf("(X:Y): (%g : %g)
Client (X:Y): (%g : %g)
Screen (X:Y): (%g : %g)",
+ event.X, event.Y, event.ClientX, event.ClientY, event.ScreenX, event.ScreenY))
+ },
+ })
+
+ return view
+}
diff --git a/demo/pointerEventsDemo.go b/demo/pointerEventsDemo.go
new file mode 100644
index 0000000..2d09cc5
--- /dev/null
+++ b/demo/pointerEventsDemo.go
@@ -0,0 +1,129 @@
+package main
+
+import (
+ "fmt"
+ "strconv"
+ "strings"
+
+ "github.com/anoshenko/rui"
+)
+
+const pointerEventsDemoText = `
+GridLayout {
+ width = 100%, height = 100%, cell-height = "1fr, auto",
+ content = [
+ GridLayout {
+ padding = 12px,
+ content = [
+ GridLayout {
+ id = pointerEventsTest, cell-horizontal-align = center, cell-vertical-align = center,
+ border = _{ style = solid, width = 1px, color = gray},
+ content = [
+ TextView {
+ id = pointerEventsText, text = "Test box",
+ }
+ ]
+ }
+ ],
+ },
+ Resizable {
+ row = 1, side = top, background-color = lightgrey, height = 200px,
+ content = EditView {
+ id = pointerEventsLog, type = multiline, read-only = true, wrap = true,
+ }
+ },
+ ]
+}
+`
+
+func createPointerEventsDemo(session rui.Session) rui.View {
+ view := rui.CreateViewFromText(session, pointerEventsDemoText)
+ if view == nil {
+ return nil
+ }
+
+ addToLog := func(tag string, event rui.PointerEvent) {
+ var buffer strings.Builder
+
+ appendBool := func(name string, value bool) {
+ buffer.WriteString(`, `)
+ buffer.WriteString(name)
+ if value {
+ buffer.WriteString(` = true`)
+ } else {
+ buffer.WriteString(` = false`)
+ }
+ }
+
+ appendInt := func(name string, value int) {
+ buffer.WriteString(`, `)
+ buffer.WriteString(name)
+ buffer.WriteString(` = `)
+ buffer.WriteString(strconv.Itoa(value))
+ }
+
+ appendFloat := func(name string, value float64) {
+ buffer.WriteString(fmt.Sprintf(`, %s = %g`, name, value))
+ }
+
+ appendPoint := func(name string, x, y float64) {
+ buffer.WriteString(fmt.Sprintf(`, %s = (%g:%g)`, name, x, y))
+ }
+
+ buffer.WriteString(tag)
+ buffer.WriteString(`: TimeStamp = `)
+ buffer.WriteString(strconv.FormatUint(event.TimeStamp, 10))
+
+ appendInt("Button", event.Button)
+ appendInt("Buttons", event.Buttons)
+ appendPoint("(X:Y)", event.X, event.Y)
+ appendPoint("Client (X:Y)", event.ClientX, event.ClientY)
+ appendPoint("Screen (X:Y)", event.ScreenX, event.ScreenY)
+ appendFloat("Width", event.Width)
+ appendFloat("Height", event.Height)
+ appendFloat("Pressure", event.Pressure)
+ appendFloat("TangentialPressure", event.TangentialPressure)
+ appendFloat("TiltX", event.TiltX)
+ appendFloat("TiltY", event.TiltY)
+ appendFloat("Twist", event.Twist)
+
+ buffer.WriteString(`, PointerType = `)
+ buffer.WriteString(event.PointerType)
+
+ appendBool("IsPrimary", event.IsPrimary)
+ appendBool("CtrlKey", event.CtrlKey)
+ appendBool("ShiftKey", event.ShiftKey)
+ appendBool("AltKey", event.AltKey)
+ appendBool("MetaKey", event.MetaKey)
+ buffer.WriteString(";\n\n")
+
+ rui.AppendEditText(view, "pointerEventsLog", buffer.String())
+ rui.ScrollViewToEnd(view, "pointerEventsLog")
+ }
+
+ rui.SetParams(view, "pointerEventsTest", rui.Params{
+ rui.PointerDown: func(v rui.View, event rui.PointerEvent) {
+ addToLog("pointer-down", event)
+ },
+ rui.PointerUp: func(v rui.View, event rui.PointerEvent) {
+ addToLog("pointer-up", event)
+ },
+ rui.PointerOut: func(v rui.View, event rui.PointerEvent) {
+ addToLog("pointer-out", event)
+ rui.Set(view, "pointerEventsText", rui.Text, "Pointer out")
+ },
+ rui.PointerOver: func(v rui.View, event rui.PointerEvent) {
+ addToLog("pointer-over", event)
+ },
+ rui.PointerCancel: func(v rui.View, event rui.PointerEvent) {
+ addToLog("pointer-cancel", event)
+ },
+ rui.PointerMove: func(v rui.View, event rui.PointerEvent) {
+ rui.Set(view, "pointerEventsText", rui.Text,
+ fmt.Sprintf("(X:Y): (%g : %g)
Client (X:Y): (%g : %g)
Screen (X:Y): (%g : %g)",
+ event.X, event.Y, event.ClientX, event.ClientY, event.ScreenX, event.ScreenY))
+ },
+ })
+
+ return view
+}
diff --git a/demo/popupDemo.go b/demo/popupDemo.go
new file mode 100644
index 0000000..9529caa
--- /dev/null
+++ b/demo/popupDemo.go
@@ -0,0 +1,86 @@
+package main
+
+import (
+ "fmt"
+
+ "github.com/anoshenko/rui"
+)
+
+const popupDemoText = `
+GridLayout {
+ width = 100%, height = 100%, cell-height = "auto, 1fr",
+ content = GridLayout {
+ width = 100%, cell-width = "auto, 1fr",
+ cell-vertical-align = center, gap = 8px,
+ content = [
+ Button {
+ id = popupShowMessage, margin = 4px, content = "Show message",
+ },
+ Button {
+ id = popupShowQuestion, row = 1, margin = 4px, content = "Show question",
+ },
+ TextView {
+ id = popupShowQuestionResult, row = 1, column = 1,
+ },
+ Button {
+ id = popupShowCancellableQuestion, row = 2, margin = 4px, content = "Show cancellable question",
+ },
+ TextView {
+ id = popupShowCancellableQuestionResult, row = 2, column = 1,
+ },
+ Button {
+ id = popupShowMenu, row = 3, margin = 4px, content = "Show menu",
+ },
+ TextView {
+ id = popupShowMenuResult, row = 3, column = 1,
+ },
+ ]
+ }
+}
+`
+
+func createPopupDemo(session rui.Session) rui.View {
+ view := rui.CreateViewFromText(session, popupDemoText)
+ if view == nil {
+ return nil
+ }
+
+ rui.Set(view, "popupShowMessage", rui.ClickEvent, func() {
+ rui.ShowMessage("Hello", "Hello world!!!", session)
+ })
+
+ rui.Set(view, "popupShowQuestion", rui.ClickEvent, func() {
+ rui.ShowQuestion("Hello", "Are you alright?", session,
+ func() {
+ rui.Set(view, "popupShowQuestionResult", rui.Text, "Answer: Yes")
+ },
+ func() {
+ rui.Set(view, "popupShowQuestionResult", rui.Text, "Answer: No")
+ })
+ })
+
+ rui.Set(view, "popupShowCancellableQuestion", rui.ClickEvent, func() {
+ rui.ShowCancellableQuestion("Hello", "Are you alright?", session,
+ func() {
+ rui.Set(view, "popupShowCancellableQuestionResult", rui.Text, "Answer: Yes")
+ },
+ func() {
+ rui.Set(view, "popupShowCancellableQuestionResult", rui.Text, "Answer: No")
+ },
+ func() {
+ rui.Set(view, "popupShowCancellableQuestionResult", rui.Text, "Answer: Cancel")
+ })
+ })
+
+ rui.Set(view, "popupShowMenu", rui.ClickEvent, func() {
+ rui.ShowMenu(session, rui.Params{
+ rui.Items: []string{"Item 1", "Item 2", "Item 3", "Item 4"},
+ rui.Title: "Menu",
+ rui.PopupMenuResult: func(n int) {
+ rui.Set(view, "popupShowMenuResult", rui.Text, fmt.Sprintf("Item %d selected", n+1))
+ },
+ })
+ })
+
+ return view
+}
diff --git a/demo/resizableDemo.go b/demo/resizableDemo.go
new file mode 100644
index 0000000..26051fe
--- /dev/null
+++ b/demo/resizableDemo.go
@@ -0,0 +1,79 @@
+package main
+
+import "github.com/anoshenko/rui"
+
+const resizableDemoText = `
+GridLayout {
+ cell-width = "auto, 1fr, auto", cell-height = "auto, 1fr, auto",
+ content = [
+ Resizable {
+ id = resizableTop, column = 0:2, row = 0, side = bottom,
+ background-color = lightgrey,
+ content = GridLayout {
+ cell-vertical-align = center, cell-horizontal-align = center,
+ background-color = yellow, padding = 8px, content = "Top",
+ }
+ },
+ Resizable {
+ id = resizableBottom, column = 0:2, row = 2, side = top,
+ background-color = lightgrey,
+ content = GridLayout {
+ cell-vertical-align = center, cell-horizontal-align = center,
+ background-color = lightcoral, padding = 8px, content = "Bottom",
+ }
+ },
+ Resizable {
+ id = resizableLeft, column = 0, row = 0:2, side = right,
+ background-color = lightgrey,
+ content = GridLayout {
+ cell-vertical-align = center, cell-horizontal-align = center,
+ background-color = lightskyblue, padding = 8px, content = "Left",
+ }
+ },
+ Resizable {
+ id = resizableRight, column = 2, row = 0:2, side = left,
+ background-color = lightgrey,
+ content = GridLayout {
+ cell-vertical-align = center, cell-horizontal-align = center,
+ background-color = lightpink, padding = 8px, content = "Right",
+ }
+ }
+ GridLayout {
+ column = 1, row = 1, cell-vertical-align = center, cell-horizontal-align = center,
+ content = Resizable {
+ id = resizableRight, side = all,
+ background-color = lightgrey,
+ content = GridLayout {
+ cell-vertical-align = center, cell-horizontal-align = center,
+ background-color = lightseagreen, padding = 8px, content = "Center",
+ }
+ }
+ }
+ ]
+}
+`
+
+func createResizableDemo(session rui.Session) rui.View {
+ return rui.CreateViewFromText(session, resizableDemoText)
+ /*
+ return rui.NewGridLayout(session, rui.Params{
+ rui.CellWidth: []rui.SizeUnit{rui.AutoSize(), rui.Fr(1), rui.AutoSize()},
+ rui.CellHeight: []rui.SizeUnit{rui.AutoSize(), rui.Fr(1), rui.AutoSize()},
+ rui.Content: []rui.View{
+ rui.NewResizable(session, rui.Params{
+ rui.ID: "resizableTop",
+ rui.Column: rui.Range{First: 0, Last: 2},
+ rui.Row: 0,
+ rui.Side: rui.BottomSide,
+ rui.BackgroundColor: rui.LightGray,
+ rui.Content: rui.NewGridLayout(session, rui.Params{
+ rui.BackgroundColor: rui.Yellow,
+ rui.CellHorizontalAlign: rui.CenterAlign,
+ rui.CellVerticalAlign: rui.CenterAlign,
+ rui.Content: "Top",
+ }),
+ }),
+ },
+ })
+ */
+}
diff --git a/demo/resources/images/A.png b/demo/resources/images/A.png
new file mode 100644
index 0000000..03a4703
Binary files /dev/null and b/demo/resources/images/A.png differ
diff --git a/demo/resources/images/A@2x.png b/demo/resources/images/A@2x.png
new file mode 100644
index 0000000..0cab01a
Binary files /dev/null and b/demo/resources/images/A@2x.png differ
diff --git a/demo/resources/images/cat.jpg b/demo/resources/images/cat.jpg
new file mode 100644
index 0000000..47dce70
Binary files /dev/null and b/demo/resources/images/cat.jpg differ
diff --git a/demo/resources/images/cat@2x.jpg b/demo/resources/images/cat@2x.jpg
new file mode 100644
index 0000000..47dce70
Binary files /dev/null and b/demo/resources/images/cat@2x.jpg differ
diff --git a/demo/resources/images/gifsInEmail.gif b/demo/resources/images/gifsInEmail.gif
new file mode 100644
index 0000000..2123df8
Binary files /dev/null and b/demo/resources/images/gifsInEmail.gif differ
diff --git a/demo/resources/images/icon.svg b/demo/resources/images/icon.svg
new file mode 100644
index 0000000..90eddd9
--- /dev/null
+++ b/demo/resources/images/icon.svg
@@ -0,0 +1,73 @@
+
+
+
+
diff --git a/demo/resources/images/image_sample.png b/demo/resources/images/image_sample.png
new file mode 100644
index 0000000..a3ac4f9
Binary files /dev/null and b/demo/resources/images/image_sample.png differ
diff --git a/demo/resources/images/image_sample@2x.png b/demo/resources/images/image_sample@2x.png
new file mode 100644
index 0000000..a58d1d9
Binary files /dev/null and b/demo/resources/images/image_sample@2x.png differ
diff --git a/demo/resources/images/image_sample@3x.png b/demo/resources/images/image_sample@3x.png
new file mode 100644
index 0000000..c5a6004
Binary files /dev/null and b/demo/resources/images/image_sample@3x.png differ
diff --git a/demo/resources/images/menu_icon.svg b/demo/resources/images/menu_icon.svg
new file mode 100644
index 0000000..c53badd
--- /dev/null
+++ b/demo/resources/images/menu_icon.svg
@@ -0,0 +1,64 @@
+
+
+
+
diff --git a/demo/resources/images/mountain.svg b/demo/resources/images/mountain.svg
new file mode 100644
index 0000000..0f907f5
--- /dev/null
+++ b/demo/resources/images/mountain.svg
@@ -0,0 +1,94 @@
+
+
diff --git a/demo/resources/images/tile00.svg b/demo/resources/images/tile00.svg
new file mode 100644
index 0000000..05cfd17
--- /dev/null
+++ b/demo/resources/images/tile00.svg
@@ -0,0 +1,65 @@
+
+
+
+
diff --git a/demo/resources/images/tile00_50.png b/demo/resources/images/tile00_50.png
new file mode 100644
index 0000000..a8c4ab1
Binary files /dev/null and b/demo/resources/images/tile00_50.png differ
diff --git a/demo/resources/images/tile00_50@2x.png b/demo/resources/images/tile00_50@2x.png
new file mode 100644
index 0000000..972cc72
Binary files /dev/null and b/demo/resources/images/tile00_50@2x.png differ
diff --git a/demo/resources/images/tile00_50@3x.png b/demo/resources/images/tile00_50@3x.png
new file mode 100644
index 0000000..c9be91e
Binary files /dev/null and b/demo/resources/images/tile00_50@3x.png differ
diff --git a/demo/resources/images/tile01.svg b/demo/resources/images/tile01.svg
new file mode 100644
index 0000000..2cbfa58
--- /dev/null
+++ b/demo/resources/images/tile01.svg
@@ -0,0 +1,65 @@
+
+
+
+
diff --git a/demo/resources/images/tile01_50.png b/demo/resources/images/tile01_50.png
new file mode 100644
index 0000000..41a082d
Binary files /dev/null and b/demo/resources/images/tile01_50.png differ
diff --git a/demo/resources/images/tile01_50@2x.png b/demo/resources/images/tile01_50@2x.png
new file mode 100644
index 0000000..85883bd
Binary files /dev/null and b/demo/resources/images/tile01_50@2x.png differ
diff --git a/demo/resources/images/tile01_50@3x.png b/demo/resources/images/tile01_50@3x.png
new file mode 100644
index 0000000..bff513d
Binary files /dev/null and b/demo/resources/images/tile01_50@3x.png differ
diff --git a/demo/resources/images/tile02.svg b/demo/resources/images/tile02.svg
new file mode 100644
index 0000000..adeab52
--- /dev/null
+++ b/demo/resources/images/tile02.svg
@@ -0,0 +1,65 @@
+
+
+
+
diff --git a/demo/resources/images/tile02_50.png b/demo/resources/images/tile02_50.png
new file mode 100644
index 0000000..f732632
Binary files /dev/null and b/demo/resources/images/tile02_50.png differ
diff --git a/demo/resources/images/tile02_50@2x.png b/demo/resources/images/tile02_50@2x.png
new file mode 100644
index 0000000..e0bfced
Binary files /dev/null and b/demo/resources/images/tile02_50@2x.png differ
diff --git a/demo/resources/images/tile02_50@3x.png b/demo/resources/images/tile02_50@3x.png
new file mode 100644
index 0000000..6ba1aae
Binary files /dev/null and b/demo/resources/images/tile02_50@3x.png differ
diff --git a/demo/resources/images/tile03.svg b/demo/resources/images/tile03.svg
new file mode 100644
index 0000000..b61ee3d
--- /dev/null
+++ b/demo/resources/images/tile03.svg
@@ -0,0 +1,65 @@
+
+
+
+
diff --git a/demo/resources/images/tile03_50.png b/demo/resources/images/tile03_50.png
new file mode 100644
index 0000000..5f50334
Binary files /dev/null and b/demo/resources/images/tile03_50.png differ
diff --git a/demo/resources/images/tile03_50@2x.png b/demo/resources/images/tile03_50@2x.png
new file mode 100644
index 0000000..6093d9a
Binary files /dev/null and b/demo/resources/images/tile03_50@2x.png differ
diff --git a/demo/resources/images/tile03_50@3x.png b/demo/resources/images/tile03_50@3x.png
new file mode 100644
index 0000000..0b82637
Binary files /dev/null and b/demo/resources/images/tile03_50@3x.png differ
diff --git a/demo/resources/images/winds.png b/demo/resources/images/winds.png
new file mode 100644
index 0000000..0854fdd
Binary files /dev/null and b/demo/resources/images/winds.png differ
diff --git a/demo/resources/strings/ru.rui b/demo/resources/strings/ru.rui
new file mode 100644
index 0000000..42ebcda
--- /dev/null
+++ b/demo/resources/strings/ru.rui
@@ -0,0 +1,34 @@
+strings:ru {
+ "Text style" = "Стиль текста",
+ "View border" = "Рамка",
+ "Background image" = "Фоновое изображение",
+ "Controls" = "Контролы",
+ "Popups" = "Всплывающие окна",
+ "Filter" = "Фильтр",
+ "Clip" = "Обрезка",
+ "Transform" = "Трансформация",
+ "Key events" = "События клавиатуры",
+ "Mouse events" = "События мыши",
+ "Pointer events" = "События указателя",
+ "Touch events" = "События касания",
+ "Font name" = "Название шрифта",
+ "Text size" = "Размер текста",
+ "Text color" = "Цвет текста",
+ "Italic" = "Курсив",
+ "Strikethrough" = "Зачеркнутый",
+ "Overline" = "Подчеркнутый сверху",
+ "Underline" = "Подчеркнутый",
+ "Line style" = "Стиль линии",
+ "Line thickness" = "Толщина линии",
+ "Line color" = "Цвет линии",
+ "Twenty years from now you will be more disappointed by the things that you didn't do than by the ones you did do. So throw off the bowlines. Sail away from the safe harbor. Catch the trade winds in your sails. Explore. Dream. Discover." =
+ "Через 20 лет вы будете больше разочарованы теми вещами, которые вы не делали, чем теми, которые вы сделали. Так отчальте от тихой пристани. Почувствуйте попутный ветер в вашем парусе. Двигайтесь вперед, действуйте, открывайте!",
+ "Shadow" = "Тень",
+ "default" = "по умолчанию",
+ "Hello" = "Привет",
+ "Hello world!!!" = "Привет мир!!!",
+ "Yes" = "Да",
+ "No" = "Нет",
+ "Cancel" = "Отмена",
+
+}
\ No newline at end of file
diff --git a/demo/resources/themes/default.rui b/demo/resources/themes/default.rui
new file mode 100644
index 0000000..963b85b
--- /dev/null
+++ b/demo/resources/themes/default.rui
@@ -0,0 +1,88 @@
+theme {
+ colors = _{
+ optionsBackground = #FFDDDDDD,
+ optionsTextColor = #FF000000,
+ },
+ colors:dark = _{
+ optionsBackground = #FF404040,
+ optionsTextColor = #FFDDDDDD,
+ },
+ constants = _{
+ optionsFont = sans-serif,
+ optionsTextSize = 10pt,
+ },
+ styles = [
+ demoPage {
+ width = 100%,
+ height = 100%,
+ cell-width = "1fr, auto",
+ },
+ demoPanel {
+ width = 100%,
+ height = 100%,
+ orientation = horizontal,
+ },
+ optionsPanel {
+ column = 1,
+ height = 100%,
+ width = auto,
+ background-color = @optionsBackground,
+ text-color = @optionsTextColor,
+ font = @optionsFont,
+ text-size = @optionsTextSize,
+ padding = 8px,
+ orientation = vertical,
+ },
+ optionsTable {
+ grid-column-gap = 8px,
+ grid-row-gap = 8px,
+ cell-vertical-align = center,
+ },
+ optionsLine {
+ padding = 8px,
+ orientation = horizontal,
+ vertical-align = center,
+ },
+ transitionBar {
+ height = 24px,
+ background-color = #FF00DD00,
+ margin-top = 4px,
+ margin-bottom = 16px,
+ },
+ header1 {
+ semantics = h1,
+ text-align = center,
+ margin-bottom = 0.5em,
+ },
+ header2 {
+ semantics = h2,
+ text-align = center,
+ margin-bottom = 0.5em,
+ },
+ paragraph {
+ semantics = p,
+ text-indent = 2em,
+ margin-bottom = 0.5em,
+ },
+ tableHead1 {
+ background-color = #FFDDDDDD,
+ text-align = left,
+ table-vertical-align = top,
+ text-weight = normal,
+ italic = true,
+ border = _{ top = _{style = solid, color = black, width = 4px }, bottom = _{style = solid, color = black, width = 4px } },
+ cell-border = _{ style = dashed, color = gray, width = 1px },
+ cell-padding = 8px,
+ },
+ tableHead2 {
+
+ },
+ tableFoot1 {
+ background-color = #FFfefbd8,
+ text-align = center,
+ text-weight = bold,
+ border = _{ top = _{style = solid, color = black, width = 2px }, bottom = _{style = solid, color = black, width = 4px } },
+ cell-padding = 8px,
+ }
+ ],
+}
diff --git a/demo/splitViewDemo.go b/demo/splitViewDemo.go
new file mode 100644
index 0000000..54f8981
--- /dev/null
+++ b/demo/splitViewDemo.go
@@ -0,0 +1,26 @@
+package main
+
+/*
+import (
+ "github.com/anoshenko/rui"
+)
+
+const splitViewDemoText = `
+SplitView {
+ width = 100%, height = 100%, orientation = vertical, anchor = bottom, padding = 2px,
+ view1 = GridLayout { width = 100%, height = 75%, content = ["View 1"], cell-vertical-align = center, cell-horizontal-align = center,
+ border = _{ width = 1px, style = solid, color = #FF000000 }, radius = 8px,},
+ view2 = GridLayout { width = 100%, height = 25%, content = ["View 2"], cell-align = center,
+ border = _{ width = 1px, style = solid, color = #FF000000 }, radius = 8px,},
+}
+`
+
+func createSplitViewDemo(session rui.Session) rui.View {
+ view := rui.CreateViewFromText(session, splitViewDemoText)
+ if view == nil {
+ return nil
+ }
+
+ return view
+}
+*/
diff --git a/demo/stackLayoutDemo.go b/demo/stackLayoutDemo.go
new file mode 100644
index 0000000..e05d7e1
--- /dev/null
+++ b/demo/stackLayoutDemo.go
@@ -0,0 +1,95 @@
+package main
+
+import "github.com/anoshenko/rui"
+
+const stackLayoutDemoText = `
+GridLayout {
+ style = demoPage,
+ content = [
+ StackLayout {
+ id = stackLayout, width = 100%, height = 100%
+ },
+ ListLayout {
+ style = optionsPanel,
+ content = [
+ GridLayout {
+ style = optionsTable,
+ content = [
+ Button { row = 0, column = 0:1, id = pushRed, content = "Push red view" },
+ Button { row = 1, column = 0:1, id = pushGreen, content = "Push green view" },
+ Button { row = 2, column = 0:1, id = pushBlue, content = "Push blue view" },
+ Button { row = 3, column = 0:1, id = popView, content = "Pop view" },
+ TextView { row = 4, text = "Animation" },
+ DropDownList { row = 4, column = 1, id = pushAnimation, current = 0, items = ["default", "start-to-end", "end-to-start", "top-down", "bottom-up"]},
+ TextView { row = 5, text = "Timing" },
+ DropDownList { row = 5, column = 1, id = pushTiming, current = 0, items = ["ease", "linear"]},
+ TextView { row = 6, text = "Duration" },
+ DropDownList { row = 6, column = 1, id = pushDuration, current = 0, items = ["0.5s", "1s", "2s"]},
+ ]
+ }
+ ]
+ }
+ ]
+}
+`
+
+func createStackLayoutDemo(session rui.Session) rui.View {
+ view := rui.CreateViewFromText(session, stackLayoutDemoText)
+ if view == nil {
+ return nil
+ }
+
+ animation := func() int {
+ return rui.GetDropDownCurrent(view, "pushAnimation")
+ }
+
+ /*
+ transition := func() rui.ViewTransition {
+ timing := rui.EaseTiming
+ timings := []string{rui.EaseTiming, rui.LinearTiming}
+ if n := rui.GetDropDownCurrent(view, "pushTiming"); n >= 0 && n < len(timings) {
+ timing = timings[n]
+ }
+
+ duration := float64(0.5)
+ durations := []float64{0.5, 1, 2}
+ if n := rui.GetDropDownCurrent(view, "pushDuration"); n >= 0 && n < len(durations) {
+ duration = durations[n]
+ }
+
+ return rui.NewTransition(duration, timing, session)
+ }
+ */
+
+ rui.Set(view, "pushRed", rui.ClickEvent, func(_ rui.View) {
+ if stackLayout := rui.StackLayoutByID(view, "stackLayout"); stackLayout != nil {
+ if v := rui.CreateViewFromText(session, `View { background-color = red }`); v != nil {
+ stackLayout.Push(v, animation(), nil)
+ }
+ }
+ })
+
+ rui.Set(view, "pushGreen", rui.ClickEvent, func(_ rui.View) {
+ if stackLayout := rui.StackLayoutByID(view, "stackLayout"); stackLayout != nil {
+ if v := rui.CreateViewFromText(session, `View { background-color = green }`); v != nil {
+ stackLayout.Push(v, animation(), nil)
+ }
+ }
+ })
+
+ rui.Set(view, "pushBlue", rui.ClickEvent, func(_ rui.View) {
+ if stackLayout := rui.StackLayoutByID(view, "stackLayout"); stackLayout != nil {
+ if v := rui.CreateViewFromText(session, `View { background-color = blue }`); v != nil {
+ stackLayout.Push(v, animation(), nil)
+ }
+ }
+ })
+
+ rui.Set(view, "popView", rui.ClickEvent, func(_ rui.View) {
+ if stackLayout := rui.StackLayoutByID(view, "stackLayout"); stackLayout != nil {
+ stackLayout.Pop(animation(), nil)
+ }
+ })
+
+ return view
+}
diff --git a/demo/tableDemo.go b/demo/tableDemo.go
new file mode 100644
index 0000000..188280f
--- /dev/null
+++ b/demo/tableDemo.go
@@ -0,0 +1,206 @@
+package main
+
+import "github.com/anoshenko/rui"
+
+const tableViewDemoText = `
+GridLayout {
+ style = demoPage,
+ content = [
+ ColumnLayout {
+ width = 100%, height = 100%,
+ content = TableView {
+ id = demoTableView1, margin = 24px,
+ }
+ },
+ ListLayout {
+ style = optionsPanel,
+ content = [
+ GridLayout {
+ style = optionsTable,
+ content = [
+ TextView { row = 0, text = "Cell gap" },
+ DropDownList { row = 0, column = 1, id = tableCellGap, current = 0, items = ["0", "2px"]},
+ TextView { row = 1, text = "Table border" },
+ DropDownList { row = 1, column = 1, id = tableBorder, current = 0, items = ["none", "solid black 1px", "4 colors"]},
+ TextView { row = 2, text = "Cell border" },
+ DropDownList { row = 2, column = 1, id = tableCellBorder, current = 0, items = ["none", "solid black 1px", "4 colors"]},
+ TextView { row = 3, text = "Cell padding" },
+ DropDownList { row = 3, column = 1, id = tableCellPadding, current = 0, items = ["default", "4px", "8px, 16px, 8px, 16px"]},
+ TextView { row = 4, text = "Head style" },
+ DropDownList { row = 4, column = 1, id = tableHeadStyle, current = 0, items = ["none", "tableHead1", "rui.Params"]},
+ TextView { row = 5, text = "Foot style" },
+ DropDownList { row = 5, column = 1, id = tableFootStyle, current = 0, items = ["none", "tableFoot1", "rui.Params"]},
+ Checkbox { row = 6, column = 0:1, id = tableRowStyle, content = "Row style" },
+ Checkbox { row = 7, column = 0:1, id = tableColumnStyle, content = "Column style" },
+ ]
+ }
+ ]
+ }
+ ]
+}
+`
+
+func createTableViewDemo(session rui.Session) rui.View {
+ view := rui.CreateViewFromText(session, tableViewDemoText)
+ if view == nil {
+ return nil
+ }
+
+ content := [][]interface{}{
+ {"Cell content", "Cell value", rui.HorizontalTableJoin{}},
+ {rui.VerticalTableJoin{}, "Type", "Value"},
+ {"Text", "string", "Text"},
+ {"Number", "int", 10},
+ {rui.VerticalTableJoin{}, "float", 10.95},
+ {"Boolean", "true", true},
+ {rui.VerticalTableJoin{}, "false", false},
+ {"Color", "red", rui.Red},
+ {rui.VerticalTableJoin{}, "green", rui.Green},
+ {rui.VerticalTableJoin{}, "yellow", rui.Yellow},
+ {"View", "Button", rui.NewButton(session, rui.Params{
+ rui.Content: "OK",
+ })},
+ {"Foot line", rui.HorizontalTableJoin{}, rui.HorizontalTableJoin{}},
+ }
+
+ rui.SetParams(view, "demoTableView1", rui.Params{
+ rui.Content: content,
+ rui.HeadHeight: 2,
+ rui.FootHeight: 1,
+ })
+
+ setBorder := func(borderTag string, number int) {
+ switch number {
+ case 1:
+ rui.Set(view, "demoTableView1", borderTag, rui.NewBorder(rui.Params{
+ rui.Style: rui.SolidLine,
+ rui.ColorProperty: rui.Black,
+ rui.Width: rui.Px(1),
+ }))
+
+ case 2:
+ rui.Set(view, "demoTableView1", borderTag, rui.NewBorder(rui.Params{
+ rui.Style: rui.SolidLine,
+ rui.LeftColor: rui.Blue,
+ rui.RightColor: rui.Magenta,
+ rui.TopColor: rui.Red,
+ rui.BottomColor: rui.Green,
+ rui.Width: rui.Px(2),
+ }))
+
+ default:
+ rui.Set(view, "demoTableView1", borderTag, nil)
+ }
+ }
+
+ rui.Set(view, "tableCellGap", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ if number == 0 {
+ rui.Set(view, "demoTableView1", rui.Gap, rui.Px(0))
+ } else {
+ rui.Set(view, "demoTableView1", rui.Gap, rui.Px(2))
+ }
+ })
+
+ rui.Set(view, "tableBorder", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ setBorder(rui.Border, number)
+ })
+
+ rui.Set(view, "tableCellBorder", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ setBorder(rui.CellBorder, number)
+ })
+
+ rui.Set(view, "tableHeadStyle", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ switch number {
+ case 1:
+ rui.Set(view, "demoTableView1", rui.HeadStyle, "tableHead1")
+
+ case 2:
+ rui.Set(view, "demoTableView1", rui.HeadStyle, rui.Params{
+ rui.CellBorder: rui.NewBorder(rui.Params{
+ rui.Style: rui.SolidLine,
+ rui.ColorProperty: rui.Green,
+ rui.Width: "2px",
+ }),
+ rui.CellPadding: "8px",
+ rui.BackgroundColor: rui.LightGrey,
+ })
+
+ default:
+ rui.Set(view, "demoTableView1", rui.HeadStyle, nil)
+ }
+ })
+
+ rui.Set(view, "tableFootStyle", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ switch number {
+ case 1:
+ rui.Set(view, "demoTableView1", rui.FootStyle, "tableFoot1")
+
+ case 2:
+ rui.Set(view, "demoTableView1", rui.FootStyle, rui.Params{
+ rui.Border: rui.NewBorder(rui.Params{
+ rui.Style: rui.SolidLine,
+ rui.ColorProperty: rui.Black,
+ rui.Width: "2px",
+ }),
+ rui.CellPadding: "4px",
+ rui.BackgroundColor: rui.LightYellow,
+ })
+
+ default:
+ rui.Set(view, "demoTableView1", rui.FootStyle, nil)
+ }
+ })
+
+ rui.Set(view, "tableCellPadding", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ switch number {
+ case 1:
+ rui.Set(view, "demoTableView1", rui.CellPadding, rui.Px(4))
+
+ case 2:
+ rui.Set(view, "demoTableView1", rui.CellPadding, rui.Bounds{
+ Left: rui.Px(16),
+ Right: rui.Px(16),
+ Top: rui.Px(8),
+ Bottom: rui.Px(8),
+ })
+
+ default:
+ rui.Set(view, "demoTableView1", rui.CellPadding, nil)
+ }
+ })
+
+ rui.Set(view, "tableRowStyle", rui.CheckboxChangedEvent, func(checked bool) {
+ if checked {
+ rui.Set(view, "demoTableView1", rui.RowStyle, []rui.Params{
+ {rui.BackgroundColor: 0xffeaece5},
+ {rui.BackgroundColor: 0xfff0efef},
+ {rui.BackgroundColor: 0xffe0e2e4},
+ {rui.BackgroundColor: 0xffbccad6},
+ {rui.BackgroundColor: 0xffcfe0e8},
+ {rui.BackgroundColor: 0xffb7d7e8},
+ {rui.BackgroundColor: 0xffdaebe8},
+ {rui.BackgroundColor: 0xfff1e3dd},
+ {rui.BackgroundColor: 0xfffbefcc},
+ {rui.BackgroundColor: 0xfffff2df},
+ {rui.BackgroundColor: 0xffffeead},
+ {rui.BackgroundColor: 0xfff2e394},
+ })
+ } else {
+ rui.Set(view, "demoTableView1", rui.RowStyle, nil)
+ }
+ })
+
+ rui.Set(view, "tableColumnStyle", rui.CheckboxChangedEvent, func(checked bool) {
+ if checked {
+ rui.Set(view, "demoTableView1", rui.ColumnStyle, []rui.Params{
+ {rui.BackgroundColor: 0xffeaece5},
+ {rui.BackgroundColor: 0xffdaebe8},
+ {rui.BackgroundColor: 0xfff2e394},
+ })
+ } else {
+ rui.Set(view, "demoTableView1", rui.RowStyle, nil)
+ }
+ })
+
+ return view
+}
diff --git a/demo/tabsDemo.go b/demo/tabsDemo.go
new file mode 100644
index 0000000..ce05659
--- /dev/null
+++ b/demo/tabsDemo.go
@@ -0,0 +1,48 @@
+package main
+
+import (
+ "github.com/anoshenko/rui"
+)
+
+const tabsDemoText = `
+GridLayout {
+ style = demoPage,
+ content = [
+ TabsLayout { id = tabsLayout, width = 100%, height = 100%, tabs = top,
+ content = [
+ View { width = 300px, height = 200px, background-color = #FFFF0000, title = "Red tab"},
+ View { width = 400px, height = 250px, background-color = #FF00FF00, title = "Green tab"},
+ View { width = 100px, height = 400px, background-color = #FF0000FF, title = "Blue tab"},
+ View { width = 300px, height = 200px, background-color = #FF000000, title = "Black tab"},
+ ]
+ },
+ ListLayout {
+ style = optionsPanel,
+ content = [
+ GridLayout {
+ style = optionsTable,
+ content = [
+ TextView { row = 0, text = "Tabs location" },
+ DropDownList { row = 0, column = 1, id = tabsTypeList, current = 1,
+ items = ["hidden", "top", "bottom", "left", "right", "left list", "right list"]
+ }
+ ]
+ }
+ ]
+ }
+ ]
+}
+`
+
+func createTabsDemo(session rui.Session) rui.View {
+ view := rui.CreateViewFromText(session, tabsDemoText)
+ if view == nil {
+ return nil
+ }
+
+ rui.Set(view, "tabsTypeList", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ rui.Set(view, "tabsLayout", rui.Tabs, number)
+ })
+
+ return view
+}
diff --git a/demo/textStyle.go b/demo/textStyle.go
new file mode 100644
index 0000000..1666381
--- /dev/null
+++ b/demo/textStyle.go
@@ -0,0 +1,143 @@
+package main
+
+import "github.com/anoshenko/rui"
+
+const textStyleDemoText = `
+GridLayout {
+ style = demoPage,
+ content = [
+ GridLayout {
+ width = 100%, height = 100%, cell-vertical-align = center, cell-horizontal-align = center,
+ content = [
+ TextView {
+ id = textStyleText, padding = 16px, max-width = 80%,
+ border = _{ style = solid, width = 1px, color = darkgray },
+ text = "Twenty years from now you will be more disappointed by the things that you didn't do than by the ones you did do. So throw off the bowlines. Sail away from the safe harbor. Catch the trade winds in your sails. Explore. Dream. Discover."
+ }
+ ]
+ },
+ ListLayout {
+ style = optionsPanel,
+ content = [
+ GridLayout {
+ style = optionsTable,
+ content = [
+ TextView { row = 0, text = "Font name" },
+ DropDownList { row = 0, column = 1, id = textStyleFont, current = 0, items = ["default", "serif", "sans-serif", "\"Courier new\", monospace", "cursive", "fantasy"]},
+ TextView { row = 1, text = "Text size" },
+ DropDownList { row = 1, column = 1, id = textStyleSize, current = 0, items = ["1em", "14pt", "12px", "1.5em"]},
+ TextView { row = 2, text = "Text color" },
+ ColorPicker { row = 2, column = 1, id = textStyleColor },
+ TextView { row = 3, text = "Text weight" },
+ DropDownList { row = 3, column = 1, id = textStyleWeight, current = 0, items = ["default", "thin", "extra-light", "light", "normal", "medium", "semi-bold", "bold", "extra-bold", "black"]},
+ Checkbox { row = 4, column = 0:1, id = textStyleItalic, content = "Italic" },
+ Checkbox { row = 5, column = 0:1, id = textStyleSmallCaps, content = "Small-caps" },
+ Checkbox { row = 6, column = 0:1, id = textStyleStrikethrough, content = "Strikethrough" },
+ Checkbox { row = 7, column = 0:1, id = textStyleOverline, content = "Overline" },
+ Checkbox { row = 8, column = 0:1, id = textStyleUnderline, content = "Underline" },
+ TextView { row = 9, text = "Line style" },
+ DropDownList { row = 9, column = 1, id = textStyleLineStyle, current = 0, items = ["default", "solid", "dashed", "dotted", "double", "wavy"]},
+ TextView { row = 10, text = "Line thickness" },
+ DropDownList { row = 10, column = 1, id = textStyleLineThickness, current = 0, items = ["default", "1px", "1.5px", "2px", "3px", "4px"]},
+ TextView { row = 11, text = "Line color" },
+ ColorPicker { row = 11, column = 1, id = textStyleLineColor },
+ TextView { row = 12, text = "Shadow" },
+ DropDownList { row = 12, column = 1, id = textStyleShadow, current = 0, items = ["none", "gray, (x, y)=(1px, 1px), blur=0", "blue, (x, y)=(-2px, -2px), blur=1", "green, (x, y)=(0px, 0px), blur=3px"]},
+ ]
+ }
+ ]
+ }
+ ]
+}
+`
+
+func createTextStyleDemo(session rui.Session) rui.View {
+ view := rui.CreateViewFromText(session, textStyleDemoText)
+ if view == nil {
+ return nil
+ }
+
+ rui.Set(view, "textStyleFont", rui.DropDownEvent, func(number int) {
+ fonts := []string{"", "serif", "sans-serif", "\"Courier new\", monospace", "cursive", "fantasy"}
+ if number > 0 && number < len(fonts) {
+ rui.Set(view, "textStyleText", rui.FontName, fonts[number])
+ } else {
+ rui.Set(view, "textStyleText", rui.FontName, nil)
+ }
+ })
+
+ rui.Set(view, "textStyleSize", rui.DropDownEvent, func(number int) {
+ sizes := []string{"1em", "14pt", "12px", "1.5em"}
+ if number >= 0 && number < len(sizes) {
+ rui.Set(view, "textStyleText", rui.TextSize, sizes[number])
+ }
+ })
+
+ rui.Set(view, "textStyleColor", rui.ColorChangedEvent, func(color rui.Color) {
+ rui.Set(view, "textStyleText", rui.TextColor, color)
+ })
+
+ rui.Set(view, "textStyleWeight", rui.DropDownEvent, func(number int) {
+ rui.Set(view, "textStyleText", rui.TextWeight, number)
+ })
+
+ rui.Set(view, "textStyleItalic", rui.CheckboxChangedEvent, func(state bool) {
+ rui.Set(view, "textStyleText", rui.Italic, state)
+ })
+
+ rui.Set(view, "textStyleSmallCaps", rui.CheckboxChangedEvent, func(state bool) {
+ rui.Set(view, "textStyleText", rui.SmallCaps, state)
+ })
+
+ rui.Set(view, "textStyleStrikethrough", rui.CheckboxChangedEvent, func(state bool) {
+ rui.Set(view, "textStyleText", rui.Strikethrough, state)
+ })
+
+ rui.Set(view, "textStyleOverline", rui.CheckboxChangedEvent, func(state bool) {
+ rui.Set(view, "textStyleText", rui.Overline, state)
+ })
+
+ rui.Set(view, "textStyleUnderline", rui.CheckboxChangedEvent, func(state bool) {
+ rui.Set(view, "textStyleText", rui.Underline, state)
+ })
+
+ rui.Set(view, "textStyleLineStyle", rui.DropDownEvent, func(number int) {
+ styles := []string{"inherit", "solid", "dashed", "dotted", "double", "wavy"}
+ if number > 0 && number < len(styles) {
+ rui.Set(view, "textStyleText", rui.TextLineStyle, styles[number])
+ } else {
+ rui.Set(view, "textStyleText", rui.TextLineStyle, nil)
+ }
+ })
+
+ rui.Set(view, "textStyleLineThickness", rui.DropDownEvent, func(number int) {
+ sizes := []string{"", "1px", "1.5px", "2px", "3px", "4px"}
+ if number > 0 && number < len(sizes) {
+ rui.Set(view, "textStyleText", rui.TextLineThickness, sizes[number])
+ } else {
+ rui.Set(view, "textStyleText", rui.TextLineThickness, nil)
+ }
+ })
+
+ rui.Set(view, "textStyleLineColor", rui.ColorChangedEvent, func(color rui.Color) {
+ rui.Set(view, "textStyleText", rui.TextLineColor, color)
+ })
+
+ rui.Set(view, "textStyleShadow", rui.DropDownEvent, func(number int) {
+ switch number {
+ case 0:
+ rui.Set(view, "textStyleText", rui.TextShadow, nil)
+
+ case 1:
+ rui.Set(view, "textStyleText", rui.TextShadow, rui.NewTextShadow(rui.Px(1), rui.Px(1), rui.Px(0), rui.Gray))
+
+ case 2:
+ rui.Set(view, "textStyleText", rui.TextShadow, rui.NewTextShadow(rui.Px(-2), rui.Px(-2), rui.Px(1), rui.Blue))
+
+ case 3:
+ rui.Set(view, "textStyleText", rui.TextShadow, rui.NewTextShadow(rui.Px(0), rui.Px(0), rui.Px(3), rui.Green))
+ }
+ })
+
+ return view
+}
diff --git a/demo/touchEventsDemo.go b/demo/touchEventsDemo.go
new file mode 100644
index 0000000..0fec7c3
--- /dev/null
+++ b/demo/touchEventsDemo.go
@@ -0,0 +1,122 @@
+package main
+
+import (
+ "fmt"
+ "strconv"
+ "strings"
+
+ "github.com/anoshenko/rui"
+)
+
+const touchEventsDemoText = `
+GridLayout {
+ width = 100%, height = 100%, cell-height = "1fr, auto",
+ content = [
+ GridLayout {
+ padding = 12px,
+ content = [
+ GridLayout {
+ id = touchEventsTest, cell-horizontal-align = center, cell-vertical-align = center,
+ height = 150%,
+ border = _{ style = solid, width = 1px, color = gray},
+ content = [
+ TextView {
+ id = touchEventsText, text = "Test box",
+ }
+ ]
+ }
+ ],
+ },
+ Resizable {
+ row = 1, side = top, background-color = lightgrey, height = 300px,
+ content = EditView {
+ id = touchEventsLog, type = multiline, read-only = true, wrap = true,
+ }
+ },
+ ]
+}
+`
+
+func createTouchEventsDemo(session rui.Session) rui.View {
+ view := rui.CreateViewFromText(session, touchEventsDemoText)
+ if view == nil {
+ return nil
+ }
+
+ addToLog := func(tag string, event rui.TouchEvent) {
+ var buffer strings.Builder
+
+ appendBool := func(name string, value bool) {
+ buffer.WriteString(`, `)
+ buffer.WriteString(name)
+ if value {
+ buffer.WriteString(` = true`)
+ } else {
+ buffer.WriteString(` = false`)
+ }
+ }
+
+ /*
+ appendInt := func(name string, value int) {
+ buffer.WriteString(`, `)
+ buffer.WriteString(name)
+ buffer.WriteString(` = `)
+ buffer.WriteString(strconv.Itoa(value))
+ }*/
+
+ appendFloat := func(name string, value float64) {
+ buffer.WriteString(fmt.Sprintf(`, %s = %g`, name, value))
+ }
+
+ appendPoint := func(name string, x, y float64) {
+ buffer.WriteString(fmt.Sprintf(`, %s = (%g:%g)`, name, x, y))
+ }
+
+ buffer.WriteString(tag)
+ buffer.WriteString(`: TimeStamp = `)
+ buffer.WriteString(strconv.FormatUint(event.TimeStamp, 10))
+
+ buffer.WriteString(`, touches = [`)
+ for i, touch := range event.Touches {
+ if i > 0 {
+ buffer.WriteString(`, `)
+ }
+ buffer.WriteString(`{ Identifier = `)
+ buffer.WriteString(strconv.Itoa(touch.Identifier))
+ appendPoint("(X:Y)", touch.X, touch.Y)
+ appendPoint("Client (X:Y)", touch.ClientX, touch.ClientY)
+ appendPoint("Screen (X:Y)", touch.ScreenX, touch.ScreenY)
+ appendPoint("Radius (X:Y)", touch.RadiusX, touch.RadiusY)
+ appendFloat("RotationAngle", touch.RotationAngle)
+ appendFloat("Force", touch.Force)
+ buffer.WriteString(`}`)
+ }
+ buffer.WriteString(`]`)
+
+ appendBool("CtrlKey", event.CtrlKey)
+ appendBool("ShiftKey", event.ShiftKey)
+ appendBool("AltKey", event.AltKey)
+ appendBool("MetaKey", event.MetaKey)
+ buffer.WriteString(";\n\n")
+
+ rui.AppendEditText(view, "touchEventsLog", buffer.String())
+ rui.ScrollViewToEnd(view, "touchEventsLog")
+ }
+
+ rui.SetParams(view, "touchEventsTest", rui.Params{
+ rui.TouchStart: func(v rui.View, event rui.TouchEvent) {
+ addToLog("touch-start", event)
+ },
+ rui.TouchEnd: func(v rui.View, event rui.TouchEvent) {
+ addToLog("touch-end", event)
+ },
+ rui.TouchCancel: func(v rui.View, event rui.TouchEvent) {
+ addToLog("touch-cancel", event)
+ },
+ rui.TouchMove: func(v rui.View, event rui.TouchEvent) {
+ addToLog("touch-move", event)
+ },
+ })
+
+ return view
+}
diff --git a/demo/transformDemo.go b/demo/transformDemo.go
new file mode 100644
index 0000000..8c92495
--- /dev/null
+++ b/demo/transformDemo.go
@@ -0,0 +1,361 @@
+package main
+
+import (
+ "fmt"
+
+ "github.com/anoshenko/rui"
+)
+
+const transformDemoText = `
+GridLayout {
+ style = demoPage,
+ content = [
+ GridLayout {
+ id = listLayout, width = 100%, height = 100%, cell-horizontal-align = center, cell-vertical-align = center,
+ content = [
+ TextView { id = transformView, width = 200px, height = 100px,
+ text = "View", text-align = center, text-size = 32pt,
+ background-color = #FFBBBBBB, radius = 8px, padding = 8px, margin = 4px,
+ border = _{ style = solid, width = 1px, color = #FF000080 },
+ shadow = _{ spread-radius = 1px, blur = 16px, color = #80000000},
+ },
+ ]
+ },
+ ListLayout {
+ style = optionsPanel,
+ content = [
+ "Perspective",
+ ListLayout {
+ margin-bottom = 12px, orientation = horizontal, vertical-align = center,
+ content = [
+ NumberPicker { id = PerspectiveEditor, type = slider, width = 120px,
+ min = -500, max = 500, step = 10, value = 0
+ },
+ TextView {
+ id = PerspectiveValue, text = "0px", margin-left = 12px, width = 32px
+ }
+ ]
+ },
+ "Perspective origin X (pixels)",
+ ListLayout {
+ margin-bottom = 12px, orientation = horizontal, vertical-align = center,
+ content = [
+ NumberPicker { id = xPerspectiveOriginEditor, type = slider, width = 120px,
+ min = -1000, max = 1000, step = 10, value = 0
+ },
+ TextView {
+ id = xPerspectiveOriginValue, text = "0px", margin-left = 12px, width = 32px
+ }
+ ]
+ },
+ "Perspective origin Y (pixels)",
+ ListLayout {
+ margin-bottom = 12px, orientation = horizontal, vertical-align = center,
+ content = [
+ NumberPicker { id = yPerspectiveOriginEditor, type = slider, width = 120px,
+ min = -1000, max = 1000, step = 10, value = 0
+ },
+ TextView {
+ id = yPerspectiveOriginValue, text = "0px", margin-left = 12px, width = 32px
+ }
+ ]
+ },
+ "Origin X (pixels)",
+ ListLayout {
+ margin-bottom = 12px, orientation = horizontal, vertical-align = center,
+ content = [
+ NumberPicker { id = xOriginEditor, type = slider, width = 120px,
+ min = -1000, max = 1000, step = 10, value = 0
+ },
+ TextView {
+ id = xOriginValue, text = "0px", margin-left = 12px, width = 32px
+ }
+ ]
+ },
+ "Origin Y (pixels)",
+ ListLayout {
+ margin-bottom = 12px, orientation = horizontal, vertical-align = center,
+ content = [
+ NumberPicker { id = yOriginEditor, type = slider, width = 120px,
+ min = -1000, max = 1000, step = 10, value = 0
+ },
+ TextView {
+ id = yOriginValue, text = "0px", margin-left = 12px, width = 32px
+ }
+ ]
+ },
+ "Origin Z (pixels)",
+ ListLayout {
+ margin-bottom = 12px, orientation = horizontal, vertical-align = center,
+ content = [
+ NumberPicker { id = zOriginEditor, type = slider, width = 120px,
+ min = -1000, max = 1000, step = 10, value = 0
+ },
+ TextView {
+ id = zOriginValue, text = "0px", margin-left = 12px, width = 32px
+ }
+ ]
+ },
+ "Translate X (pixels)",
+ ListLayout {
+ margin-bottom = 12px, orientation = horizontal, vertical-align = center,
+ content = [
+ NumberPicker { id = xTranslateEditor, type = slider, width = 120px,
+ min = -100, max = 100, step = 1, value = 0
+ },
+ TextView {
+ id = xTranslateValue, text = "0px", margin-left = 12px, width = 32px
+ }
+ ]
+ },
+ "Translate Y (pixels)",
+ ListLayout {
+ margin-bottom = 12px, orientation = horizontal, vertical-align = center,
+ content = [
+ NumberPicker { id = yTranslateEditor, type = slider, width = 120px,
+ min = -100, max = 100, step = 1, value = 0
+ },
+ TextView {
+ id = yTranslateValue, text = "0px", margin-left = 12px, width = 32px
+ }
+ ]
+ },
+ "Translate Z (pixels)",
+ ListLayout {
+ margin-bottom = 12px, orientation = horizontal, vertical-align = center,
+ content = [
+ NumberPicker { id = zTranslateEditor, type = slider, width = 120px,
+ min = -100, max = 100, step = 1, value = 0
+ },
+ TextView {
+ id = zTranslateValue, text = "0px", margin-left = 12px, width = 32px
+ }
+ ]
+ },
+ "Scale X",
+ ListLayout {
+ margin-bottom = 12px, orientation = horizontal, vertical-align = center,
+ content = [
+ NumberPicker { id = xScaleEditor, type = slider, width = 120px,
+ min = -5, max = 5, step = 0.1, value = 1
+ },
+ TextView {
+ id = xScaleValue, text = "1", margin-left = 12px, width = 32px
+ }
+ ]
+ },
+ "Scale Y",
+ ListLayout {
+ margin-bottom = 12px, orientation = horizontal, vertical-align = center,
+ content = [
+ NumberPicker { id = yScaleEditor, type = slider, width = 120px,
+ min = -5, max = 5, step = 0.1, value = 1
+ },
+ TextView {
+ id = yScaleValue, text = "1", margin-left = 12px, width = 32px
+ }
+ ]
+ },
+ "Scale Z",
+ ListLayout {
+ margin-bottom = 12px, orientation = horizontal, vertical-align = center,
+ content = [
+ NumberPicker { id = zScaleEditor, type = slider, width = 120px,
+ min = -5, max = 5, step = 0.1, value = 1
+ },
+ TextView {
+ id = zScaleValue, text = "1", margin-left = 12px, width = 32px
+ }
+ ]
+ },
+ "Skew X (degree)",
+ ListLayout {
+ margin-bottom = 12px, orientation = horizontal, vertical-align = center,
+ content = [
+ NumberPicker { id = xSkewEditor, type = slider, width = 120px,
+ min = -90, max = 90, step = 1, value = 0
+ },
+ TextView {
+ id = xSkewValue, text = "0°", margin-left = 12px, width = 32px
+ }
+ ]
+ },
+ "Skew Y (degree)",
+ ListLayout {
+ margin-bottom = 12px, orientation = horizontal, vertical-align = center,
+ content = [
+ NumberPicker { id = ySkewEditor, type = slider, width = 120px,
+ min = -90, max = 90, step = 1, value = 0
+ },
+ TextView {
+ id = ySkewValue, text = "0°", margin-left = 12px, width = 32px
+ }
+ ]
+ },
+ "Rotate (degree)",
+ ListLayout {
+ margin-bottom = 12px, orientation = horizontal, vertical-align = center,
+ content = [
+ NumberPicker { id = RotateEditor, type = slider, width = 120px,
+ min = -180, max = 180, step = 1, value = 0
+ },
+ TextView {
+ id = RotateValue, text = "0°", margin-left = 12px, width = 32px
+ }
+ ]
+ },
+ "Rotate X",
+ ListLayout {
+ margin-bottom = 12px, orientation = horizontal, vertical-align = center,
+ content = [
+ NumberPicker { id = xRotateEditor, type = slider, width = 120px,
+ min = 0, max = 1, step = 0.01, value = 1
+ },
+ TextView {
+ id = xRotateValue, text = "1", margin-left = 12px, width = 32px
+ }
+ ]
+ },
+ "Rotate Y",
+ ListLayout {
+ margin-bottom = 12px, orientation = horizontal, vertical-align = center,
+ content = [
+ NumberPicker { id = yRotateEditor, type = slider, width = 120px,
+ min = 0, max = 1, step = 0.01, value = 1
+ },
+ TextView {
+ id = yRotateValue, text = "1", margin-left = 12px, width = 32px
+ }
+ ]
+ },
+ "Rotate Z",
+ ListLayout {
+ margin-bottom = 12px, orientation = horizontal, vertical-align = center,
+ content = [
+ NumberPicker { id = zRotateEditor, type = slider, width = 120px,
+ min = 0, max = 1, step = 0.01, value = 1
+ },
+ TextView {
+ id = zRotateValue, text = "1", margin-left = 12px, width = 32px
+ }
+ ]
+ },
+ Checkbox { id = backfaceVisibility, content = "backface-visibility", checked = true }
+ ]
+ }
+ ]
+}`
+
+func transformDemo(session rui.Session) rui.View {
+ view := rui.CreateViewFromText(session, transformDemoText)
+ if view == nil {
+ return nil
+ }
+
+ // transform := rui.NewTransform(view.Session())
+
+ transformView := rui.ViewByID(view, "transformView")
+ if transformView == nil {
+ return view
+ }
+
+ updateSliderText := func(tag string, value float64, unit string) {
+ rui.Set(view, tag, rui.Text, fmt.Sprintf("%g%s", value, unit))
+ }
+
+ rui.Set(view, "PerspectiveEditor", rui.NumberChangedEvent, func(v rui.NumberPicker, newValue float64) {
+ transformView.Set(rui.Perspective, rui.Px(newValue))
+ updateSliderText("PerspectiveValue", newValue, "px")
+ })
+
+ rui.Set(view, "xPerspectiveOriginEditor", rui.NumberChangedEvent, func(v rui.NumberPicker, newValue float64) {
+ transformView.Set(rui.PerspectiveOriginX, rui.Px(newValue))
+ updateSliderText("xPerspectiveOriginValue", newValue, "px")
+ })
+
+ rui.Set(view, "yPerspectiveOriginEditor", rui.NumberChangedEvent, func(v rui.NumberPicker, newValue float64) {
+ transformView.Set(rui.PerspectiveOriginY, rui.Px(newValue))
+ updateSliderText("yPerspectiveOriginValue", newValue, "px")
+ })
+
+ rui.Set(view, "xOriginEditor", rui.NumberChangedEvent, func(v rui.NumberPicker, newValue float64) {
+ transformView.Set(rui.OriginX, rui.Px(newValue))
+ updateSliderText("xOriginValue", newValue, "px")
+ })
+
+ rui.Set(view, "yOriginEditor", rui.NumberChangedEvent, func(v rui.NumberPicker, newValue float64) {
+ transformView.Set(rui.OriginY, rui.Px(newValue))
+ updateSliderText("yOriginValue", newValue, "px")
+ })
+
+ rui.Set(view, "zOriginEditor", rui.NumberChangedEvent, func(v rui.NumberPicker, newValue float64) {
+ transformView.Set(rui.OriginZ, rui.Px(newValue))
+ updateSliderText("zOriginValue", newValue, "px")
+ })
+
+ rui.Set(view, "xTranslateEditor", rui.NumberChangedEvent, func(v rui.NumberPicker, newValue float64) {
+ transformView.Set(rui.TranslateX, rui.Px(newValue))
+ updateSliderText("xTranslateValue", newValue, "px")
+ })
+
+ rui.Set(view, "yTranslateEditor", rui.NumberChangedEvent, func(v rui.NumberPicker, newValue float64) {
+ transformView.Set(rui.TranslateY, rui.Px(newValue))
+ updateSliderText("yTranslateValue", newValue, "px")
+ })
+
+ rui.Set(view, "zTranslateEditor", rui.NumberChangedEvent, func(v rui.NumberPicker, newValue float64) {
+ transformView.Set(rui.TranslateZ, rui.Px(newValue))
+ updateSliderText("zTranslateValue", newValue, "px")
+ })
+
+ rui.Set(view, "xScaleEditor", rui.NumberChangedEvent, func(v rui.NumberPicker, newValue float64) {
+ transformView.Set(rui.ScaleX, newValue)
+ updateSliderText("xScaleValue", newValue, "")
+ })
+
+ rui.Set(view, "yScaleEditor", rui.NumberChangedEvent, func(v rui.NumberPicker, newValue float64) {
+ transformView.Set(rui.ScaleY, newValue)
+ updateSliderText("yScaleValue", newValue, "")
+ })
+
+ rui.Set(view, "zScaleEditor", rui.NumberChangedEvent, func(v rui.NumberPicker, newValue float64) {
+ transformView.Set(rui.ScaleZ, newValue)
+ updateSliderText("zScaleValue", newValue, "")
+ })
+
+ rui.Set(view, "RotateEditor", rui.NumberChangedEvent, func(v rui.NumberPicker, newValue float64) {
+ transformView.Set(rui.Rotate, rui.Deg(newValue))
+ updateSliderText("RotateValue", newValue, "°")
+ })
+
+ rui.Set(view, "xRotateEditor", rui.NumberChangedEvent, func(v rui.NumberPicker, newValue float64) {
+ transformView.Set(rui.RotateX, newValue)
+ updateSliderText("xRotateValue", newValue, "")
+ })
+
+ rui.Set(view, "yRotateEditor", rui.NumberChangedEvent, func(v rui.NumberPicker, newValue float64) {
+ transformView.Set(rui.RotateY, newValue)
+ updateSliderText("yRotateValue", newValue, "")
+ })
+
+ rui.Set(view, "zRotateEditor", rui.NumberChangedEvent, func(v rui.NumberPicker, newValue float64) {
+ transformView.Set(rui.RotateZ, newValue)
+ updateSliderText("zRotateValue", newValue, "")
+ })
+
+ rui.Set(view, "xSkewEditor", rui.NumberChangedEvent, func(v rui.NumberPicker, newValue float64) {
+ transformView.Set(rui.SkewX, rui.Deg(newValue))
+ updateSliderText("xSkewValue", newValue, "°")
+ })
+
+ rui.Set(view, "ySkewEditor", rui.NumberChangedEvent, func(v rui.NumberPicker, newValue float64) {
+ transformView.Set(rui.SkewY, rui.Deg(newValue))
+ updateSliderText("ySkewValue", newValue, "°")
+ })
+
+ rui.Set(view, "backfaceVisibility", rui.CheckboxChangedEvent, func(checkbox rui.Checkbox, checked bool) {
+ transformView.Set(rui.BackfaceVisible, checked)
+ })
+
+ return view
+}
diff --git a/demo/transitionDemo.go b/demo/transitionDemo.go
new file mode 100644
index 0000000..5ac91fc
--- /dev/null
+++ b/demo/transitionDemo.go
@@ -0,0 +1,70 @@
+package main
+
+import (
+ "github.com/anoshenko/rui"
+)
+
+const transitionDemoText = `
+ListLayout {
+ width = 100%, height = 100%, orientation = vertical, padding = 12px,
+ content = [
+ "ease",
+ View { id = bar1, width = 20%, style = transitionBar },
+ "ease-in",
+ View { id = bar2, width = 20%, style = transitionBar },
+ "ease-out",
+ View { id = bar3, width = 20%, style = transitionBar },
+ "ease-in-out",
+ View { id = bar4, width = 20%, style = transitionBar },
+ "linear",
+ View { id = bar5, width = 20%, style = transitionBar },
+ "steps(5)",
+ View { id = bar6, width = 20%, style = transitionBar },
+ "cubic-bezier(0.1, -0.6, 0.2, 0)",
+ View { id = bar7, width = 20%, style = transitionBar },
+ Button { id = startTransition, content = "Start" }
+ ]
+}`
+
+func createTransitionDemo(session rui.Session) rui.View {
+ view := rui.CreateViewFromText(session, transitionDemoText)
+ if view == nil {
+ return nil
+ }
+
+ bars := map[string]string{
+ "bar1": rui.EaseTiming,
+ "bar2": rui.EaseInTiming,
+ "bar3": rui.EaseOutTiming,
+ "bar4": rui.EaseInOutTiming,
+ "bar5": rui.LinearTiming,
+ "bar6": rui.StepsTiming(5),
+ "bar7": rui.CubicBezierTiming(0.1, -0.6, 0.2, 0),
+ }
+
+ rui.Set(view, "startTransition", rui.ClickEvent, func(button rui.View) {
+ for id, timing := range bars {
+ if bar := rui.ViewByID(view, id); bar != nil {
+ if rui.GetWidth(bar, "").Value == 100 {
+ bar.SetAnimated(rui.Width, rui.Percent(20), rui.Animation{
+ Duration: 2,
+ TimingFunction: timing,
+ })
+ } else {
+ bar.SetAnimated(rui.Width, rui.Percent(100), rui.Animation{
+ Duration: 2,
+ TimingFunction: timing,
+ FinishListener: rui.AnimationFinishedFunc(func(v rui.View, tag string) {
+ bar.SetAnimated(rui.Width, rui.Percent(20), rui.Animation{
+ Duration: 2,
+ TimingFunction: bars[v.ID()],
+ })
+ }),
+ })
+ }
+ }
+ }
+ })
+
+ return view
+}
diff --git a/demo/videoPlayerDemo.go b/demo/videoPlayerDemo.go
new file mode 100644
index 0000000..d85a319
--- /dev/null
+++ b/demo/videoPlayerDemo.go
@@ -0,0 +1,152 @@
+package main
+
+import (
+ "fmt"
+
+ "github.com/anoshenko/rui"
+)
+
+const videoPlayerDemoText = `
+GridLayout {
+ cell-height = "auto, 1fr, auto, auto", width = 100%, height = 100%,
+ content = [
+ ListLayout {
+ row = 0, orientation = start-to-end, padding = 4px,
+ content = [
+ Checkbox {
+ id = showVideoPlayerControls, content = "Controls"
+ },
+ Checkbox {
+ id = showVideoPlayerLoop, content = "Loop"
+ },
+ Checkbox {
+ id = showVideoPlayerMuted, content = "Muted"
+ },
+ ],
+ },
+ GridLayout {
+ row = 1, id = videoPlayerContainer,
+ content = VideoPlayer {
+ id = videoPlayer, src = "https://alxanosoft.com/testVideo.mp4", video-width = 320,
+ },
+ },
+ ListLayout {
+ row = 2, orientation = start-to-end, vertical-align = top, padding = 8px,
+ content = [
+ NumberPicker {
+ id = videoPlayerSlider, width = 200px, type = slider
+ }
+ Button {
+ id = videoPlayerPlay, content = "Play", margin-left = 16px
+ }
+ ]
+ },
+ Resizable {
+ row = 3, side = top, background-color = lightgrey, height = 200px,
+ content = EditView {
+ id = videoPlayerEventsLog, type = multiline, read-only = true, wrap = true,
+ }
+ },
+ ]
+}`
+
+var videoPlayerPause = true
+
+func createVideoPlayerDemo(session rui.Session) rui.View {
+ view := rui.CreateViewFromText(session, videoPlayerDemoText)
+ if view == nil {
+ return nil
+ }
+
+ createListener := func(event string) func() {
+ return func() {
+ rui.AppendEditText(view, "videoPlayerEventsLog", event+"\n")
+ rui.ScrollViewToEnd(view, "videoPlayerEventsLog")
+ }
+ }
+ createListener2 := func(event string) func(value float64) {
+ return func(value float64) {
+ rui.AppendEditText(view, "videoPlayerEventsLog", fmt.Sprintf("%s: %g\n", event, value))
+ rui.ScrollViewToEnd(view, "videoPlayerEventsLog")
+ }
+ }
+
+ rui.Set(view, "videoPlayerContainer", rui.ResizeEvent, func(frame rui.Frame) {
+ rui.Set(view, "videoPlayer", rui.VideoWidth, frame.Width)
+ rui.Set(view, "videoPlayer", rui.VideoHeight, frame.Height)
+ })
+
+ rui.Set(view, "showVideoPlayerControls", rui.CheckboxChangedEvent, func(state bool) {
+ rui.Set(view, "videoPlayer", rui.Controls, state)
+ })
+
+ rui.Set(view, "showVideoPlayerLoop", rui.CheckboxChangedEvent, func(state bool) {
+ rui.Set(view, "videoPlayer", rui.Loop, state)
+ })
+
+ rui.Set(view, "showVideoPlayerMuted", rui.CheckboxChangedEvent, func(state bool) {
+ rui.Set(view, "videoPlayer", rui.Muted, state)
+ })
+
+ for _, event := range []string{rui.AbortEvent, rui.CanPlayEvent, rui.CanPlayThroughEvent,
+ rui.CompleteEvent, rui.EmptiedEvent, rui.EndedEvent, rui.LoadStartEvent,
+ rui.LoadedMetadataEvent, rui.PlayingEvent, rui.SeekedEvent, rui.SeekingEvent,
+ rui.StalledEvent, rui.SuspendEvent, rui.WaitingEvent} {
+
+ rui.Set(view, "videoPlayer", event, createListener(event))
+ }
+
+ for _, event := range []string{rui.DurationChangedEvent, rui.RateChangedEvent, rui.VolumeChangedEvent} {
+
+ rui.Set(view, "videoPlayer", event, createListener2(event))
+ }
+
+ rui.Set(view, "videoPlayer", rui.PlayEvent, func() {
+ rui.AppendEditText(view, "videoPlayerEventsLog", "play-event\n")
+ rui.ScrollViewToEnd(view, "videoPlayerEventsLog")
+ rui.Set(view, "videoPlayerPlay", rui.Content, "Pause")
+ videoPlayerPause = false
+ })
+
+ rui.Set(view, "videoPlayer", rui.PauseEvent, func() {
+ rui.AppendEditText(view, "videoPlayerEventsLog", "pause-event\n")
+ rui.ScrollViewToEnd(view, "videoPlayerEventsLog")
+ rui.Set(view, "videoPlayerPlay", rui.Content, "Play")
+ videoPlayerPause = true
+ })
+
+ rui.Set(view, "videoPlayer", rui.LoadedDataEvent, func() {
+ rui.AppendEditText(view, "videoPlayerEventsLog", "loaded-data-event\n")
+ rui.ScrollViewToEnd(view, "videoPlayerEventsLog")
+ rui.Set(view, "videoPlayerSlider", rui.Max, rui.MediaPlayerDuration(view, "videoPlayer"))
+ })
+
+ rui.Set(view, "videoPlayer", rui.TimeUpdateEvent, func(time float64) {
+ rui.AppendEditText(view, "videoPlayerEventsLog", fmt.Sprintf("time-update-event %gs\n", time))
+ rui.ScrollViewToEnd(view, "videoPlayerEventsLog")
+ rui.Set(view, "videoPlayerSlider", rui.Value, time)
+ })
+
+ rui.Set(view, "vodeoPlayer", rui.PlayerErrorEvent, func(code int, message string) {
+ rui.AppendEditText(view, "vodeoPlayerEventsLog", fmt.Sprintf("player-error-event: code = %d, message = '%s'\n", code, message))
+ rui.ScrollViewToEnd(view, "vodeoPlayerEventsLog")
+ })
+
+ rui.Set(view, "videoPlayerPlay", rui.ClickEvent, func() {
+ if videoPlayerPause {
+ rui.MediaPlayerPlay(view, "videoPlayer")
+ } else {
+ rui.MediaPlayerPause(view, "videoPlayer")
+ }
+ })
+
+ rui.Set(view, "videoPlayerSlider", rui.NumberChangedEvent, func(value float64) {
+ if videoPlayerPause {
+ rui.SetMediaPlayerCurrentTime(view, "videoPlayer", value)
+ }
+ })
+
+ return view
+}
+
+//MAH00054.MP4
diff --git a/demo/viewDemo.go b/demo/viewDemo.go
new file mode 100644
index 0000000..16cf070
--- /dev/null
+++ b/demo/viewDemo.go
@@ -0,0 +1,116 @@
+package main
+
+import (
+ "github.com/anoshenko/rui"
+)
+
+const viewDemoText = `
+GridLayout {
+ style = demoPage,
+ content = [
+ GridLayout {
+ width = 100%, height = 100%, cell-vertical-align = center, cell-horizontal-align = center,
+ content = [
+ View {
+ id = demoView, width = 250px, height = 150px,
+ background-color = #FFFF0000, border-width = 1px
+ }
+ ]
+ },
+ ListLayout {
+ style = optionsPanel,
+ content = [
+ GridLayout {
+ style = optionsTable,
+ content = [
+ TextView { row = 0, text = "Border style" },
+ DropDownList { row = 0, column = 1, id = viewBorderStyle, current = 0,
+ items = ["none", "solid", "dashed", "dotted", "double", "4 styles"]
+ },
+ TextView { row = 1, text = "Border width" },
+ DropDownList { row = 1, column = 1, id = viewBorderWidth, current = 0,
+ items = ["1px", "2px", "3.5px", "5px", "1px,2px,3px,4px"]
+ },
+ TextView { row = 2, text = "Border color" },
+ DropDownList { row = 2, column = 1, id = viewBorderColor, current = 0,
+ items = ["black", "blue", "4 colors"]
+ },
+ TextView { row = 3, text = "Radius" },
+ DropDownList { row = 3, column = 1, id = viewRadius, current = 0,
+ items = ["0", "8px", "12px/24px", "0 48px/24px 0 48px/24px"]
+ },
+
+ ]
+ }
+ ]
+ }
+ ]
+}
+`
+
+func viewDemo(session rui.Session) rui.View {
+ view := rui.CreateViewFromText(session, viewDemoText)
+ if view == nil {
+ return nil
+ }
+
+ rui.Set(view, "viewBorderStyle", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ if number < 5 {
+ rui.Set(view, "demoView", rui.BorderStyle, number)
+ } else {
+ rui.Set(view, "demoView", rui.BorderTopStyle, 1)
+ rui.Set(view, "demoView", rui.BorderRightStyle, 2)
+ rui.Set(view, "demoView", rui.BorderBottomStyle, 3)
+ rui.Set(view, "demoView", rui.BorderLeftStyle, 4)
+ }
+ })
+
+ rui.Set(view, "viewBorderWidth", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ widths := []rui.SizeUnit{rui.Px(1), rui.Px(2), rui.Px(3.5), rui.Px(5)}
+ if number < len(widths) {
+ rui.Set(view, "demoView", rui.BorderWidth, widths[number])
+ } else {
+ rui.SetParams(view, "demoView", rui.Params{
+ rui.BorderTopWidth: rui.Px(1),
+ rui.BorderRightWidth: rui.Px(2),
+ rui.BorderBottomWidth: rui.Px(3),
+ rui.BorderLeftWidth: rui.Px(4)})
+ }
+ })
+
+ rui.Set(view, "viewBorderColor", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ colors := []rui.Color{rui.Black, rui.Blue}
+ if number < len(colors) {
+ rui.Set(view, "demoView", rui.BorderColor, colors[number])
+ } else {
+ rui.SetParams(view, "demoView", rui.Params{
+ rui.BorderTopColor: rui.Blue,
+ rui.BorderRightColor: rui.Green,
+ rui.BorderBottomColor: rui.Magenta,
+ rui.BorderLeftColor: rui.Aqua})
+ }
+ })
+
+ rui.Set(view, "viewRadius", rui.DropDownEvent, func(list rui.DropDownList, number int) {
+ switch number {
+ case 0:
+ rui.Set(view, "demoView", rui.Radius, nil)
+
+ case 1:
+ rui.Set(view, "demoView", rui.Radius, rui.Px(8))
+
+ case 2:
+ rui.Set(view, "demoView", rui.RadiusX, rui.Px(12))
+ rui.Set(view, "demoView", rui.RadiusY, rui.Px(24))
+
+ case 3:
+ rui.Set(view, "demoView", rui.Radius, nil)
+ rui.Set(view, "demoView", rui.RadiusTopRightX, rui.Px(48))
+ rui.Set(view, "demoView", rui.RadiusTopRightY, rui.Px(24))
+ rui.Set(view, "demoView", rui.RadiusBottomLeftX, rui.Px(48))
+ rui.Set(view, "demoView", rui.RadiusBottomLeftY, rui.Px(24))
+ }
+ })
+
+ return view
+}