Skip to content

Commit

Permalink
slave window docking
Browse files Browse the repository at this point in the history
  • Loading branch information
aarzilli committed Sep 28, 2017
1 parent a225bb4 commit 358b5ea
Show file tree
Hide file tree
Showing 8 changed files with 772 additions and 123 deletions.
62 changes: 59 additions & 3 deletions _demo/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ func id(fn func (*nucular.Window)) func () func(*nucular.Window) {
}
}

func saveFnFor(i byte) func() []byte {
return func() []byte {
return []byte{ i }
}
}

type Demo struct {
Name string
Title string
Expand Down Expand Up @@ -70,6 +76,16 @@ var demos = []Demo{
} },
{ "nestedmenu", "Nested menu demo", 0, id(nestedMenu) },
{ "list", "List", nucular.WindowNoScrollbar, id(listDemo) },
{ "saverestore", "Save / Restore", nucular.WindowNoScrollbar, nil },
}

func init() {
for i := range demos {
if demos[i].Name == "saverestore" {
demos[i].UpdateFn = saveRestoreDemo
return
}
}
}

var Wnd nucular.MasterWindow
Expand Down Expand Up @@ -98,11 +114,11 @@ func main() {
switch whichdemo {
case "multi", "":
Wnd = nucular.NewMasterWindow(0, "Multiwindow Demo", func(w *nucular.Window) {})
Wnd.PopupOpen("Multiwindow Demo", nucular.WindowTitle|nucular.WindowBorder | nucular.WindowMovable | nucular.WindowScalable|nucular.WindowNonmodal, rect.Rect{ 0, 0, 400, 300 }, true, multiDemo)
Wnd.PopupOpenPersistent("Multiwindow Demo", nucular.WindowTitle|nucular.WindowBorder | nucular.WindowMovable | nucular.WindowScalable|nucular.WindowNonmodal, rect.Rect{ 0, 0, 400, 300 }, true, multiDemo, saveFnFor('m'))
default:
for i := range demos {
if demos[i].Name == whichdemo {
Wnd = nucular.NewMasterWindow(demos[i].Flags, demos[i].Title, demos[i].UpdateFn())
Wnd = nucular.NewMasterWindow(demos[i].Flags, demos[i].Title, demos[i].UpdateFn())
break
}
}
Expand Down Expand Up @@ -337,7 +353,47 @@ func multiDemo(w *nucular.Window) {
w.Row(30).Static(100, 100, 100)
for i := range demos {
if w.ButtonText(demos[i].Name) {
w.Master().PopupOpen(demos[i].Title, nucular.WindowDefaultFlags|nucular.WindowNonmodal | demos[i].Flags, rect.Rect{0, 0, 200, 200}, true, demos[i].UpdateFn())
w.Master().PopupOpenPersistent(demos[i].Title, nucular.WindowDefaultFlags|nucular.WindowNonmodal | demos[i].Flags, rect.Rect{0, 0, 200, 200}, true, demos[i].UpdateFn(), saveFnFor(byte(i)))
}
}
}

func restoreFn(data []byte, openWndFn nucular.OpenWindowFn) error {
if data[0] == 'm' {
openWndFn("Multiwindow Demo", nucular.WindowTitle|nucular.WindowBorder | nucular.WindowMovable | nucular.WindowScalable|nucular.WindowNonmodal, multiDemo, saveFnFor('m'))
return nil
}
i := data[0]
openWndFn(demos[i].Title, nucular.WindowDefaultFlags|nucular.WindowNonmodal | demos[i].Flags, demos[i].UpdateFn(), saveFnFor(byte(i)))
return nil
}

func saveRestoreDemo() func(w *nucular.Window) {
var saveed nucular.TextEditor
saveed.Flags = nucular.EditSelectable | nucular.EditClipboard
wd, _ := os.Getwd()
saveed.Buffer = []rune(fmt.Sprintf("%s/save.sav", wd))
return func(w *nucular.Window) {
w.Row(30).Static(0)
saveed.Edit(w)
w.Row(30).Static(0, 100, 100)
w.Spacing(1)
if w.ButtonText("Save") {
s, err := w.Master().Save()
if err != nil {
fmt.Fprintf(os.Stderr, "Error saving layout: %v", err)
}
ioutil.WriteFile(string(saveed.Buffer), s, 0666)
w.Close()
}
if w.ButtonText("Restore") {
data, err := ioutil.ReadFile(string(saveed.Buffer))
if err != nil {
fmt.Fprintf(os.Stderr, "Error loading save file: %v", err)
} else {
w.Master().Restore(data, restoreFn)
}
w.Close()
}
}
}
Loading

0 comments on commit 358b5ea

Please sign in to comment.