From 5716be9c4d1f105486f342476887eb8b372c3273 Mon Sep 17 00:00:00 2001 From: Arda Atci Date: Sun, 29 Oct 2023 20:43:09 +0300 Subject: [PATCH] gtk settings app, first commit --- .gitignore | 2 + animations.go | 51 +++++++++++++++++++++++ go.mod | 5 +++ main.go | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 168 insertions(+) create mode 100644 .gitignore create mode 100644 animations.go create mode 100644 go.mod create mode 100644 main.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c7cb5c4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +go.sum +physettings diff --git a/animations.go b/animations.go new file mode 100644 index 0000000..a8af9de --- /dev/null +++ b/animations.go @@ -0,0 +1,51 @@ +package main + +import ( + "github.com/gotk3/gotk3/gtk" +) + +// Setup the TextView, put it in a ScrolledWindow, and add both to box. +func setupTextView(box *gtk.Box) *gtk.TextView { + sw, _ := gtk.ScrolledWindowNew(nil, nil) + tv, _ := gtk.TextViewNew() + sw.Add(tv) + box.PackStart(sw, true, true, 0) + return tv +} + +// func setupPropertyCheckboxes(tv *gtk.TextView, outer *gtk.Box, props []*BoolProperty) { +// box, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0) +// for _, prop := range props { +// chk, _ := gtk.CheckButtonNewWithLabel(prop.Name) +// // initialize the checkbox with the property's current value +// chk.SetActive(prop.Get()) +// p := prop // w/o this all the checkboxes will toggle the last property in props +// chk.Connect("toggled", func() { +// p.Set(chk.GetActive()) +// }) +// box.PackStart(chk, true, true, 0) +// } +// outer.PackStart(box, false, false, 0) +// } + +func setupAnimationsTab() *gtk.Box{ + box := boxNew(gtk.ORIENTATION_VERTICAL, 0) + + // tv := setupTextView(box) + + chkGlx, _ := gtk.CheckButtonNewWithLabel("Use GLX:") + chkVsync, _ := gtk.CheckButtonNewWithLabel("Enable VSync:") + chkAnimations, _ := gtk.CheckButtonNewWithLabel("Enable Animations:") + chkFading, _ := gtk.CheckButtonNewWithLabel("Enable Fading:") + chkNextTagFading, _ := gtk.CheckButtonNewWithLabel("Next Tag Fading:") + chkPrevTagFading, _ := gtk.CheckButtonNewWithLabel("Prev Tag Fading:") + + box.Add(chkGlx) + box.Add(chkVsync) + box.Add(chkAnimations) + box.Add(chkFading) + box.Add(chkNextTagFading) + box.Add(chkPrevTagFading) + + return box +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..dce6a5c --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module physettings + +go 1.21.3 + +require github.com/gotk3/gotk3 v0.6.2 diff --git a/main.go b/main.go new file mode 100644 index 0000000..1503123 --- /dev/null +++ b/main.go @@ -0,0 +1,110 @@ +package main + + +import ( + "github.com/gotk3/gotk3/gtk" + "log" +) + +const ( + width = 800 + height = 600 + spacing = 25 + logo_path = "/usr/share/pixmaps/phyOS-logo-128x128.png" +) + +func boxNew(o gtk.Orientation, spc int) *gtk.Box { + + box, err := gtk.BoxNew(o, spc) + + if err != nil { + log.Fatal("Error: Can not create box", err) + } + + return box +} + + +func imageNew(path string) *gtk.Image { + + img, err := gtk.ImageNewFromFile(path) + + if err != nil { + log.Fatal("Error: can not load image file", err) + } + + return img +} + +func labelNew(text string) *gtk.Label { + + label, err := gtk.LabelNew(text) + + if err != nil { + log.Fatal("Error: Can not create label", text) + } + + return label +} + +func windowNew(title string) *gtk.Window { + + win, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL) + + if err != nil { + log.Fatal("Error: Can not create window", err) + } + + win.SetTitle(title) + win.Connect("destroy", func() { + gtk.MainQuit() + }) + + win.SetSizeRequest(width, height) + win.SetDefaultSize(width, height) + win.SetPosition(gtk.WIN_POS_CENTER) + + return win +} + + +func main() { + + gtk.Init(nil) + + nb, err := gtk.NotebookNew() + if err != nil { + log.Fatal("Unable to create notebook:", err) + } + win := windowNew("phy") + win.Add(nb) + nb.SetHExpand(true) + nb.SetVExpand(true) + + logo := imageNew(logo_path) + box := boxNew(gtk.ORIENTATION_VERTICAL, 15) + logo.SetHAlign(gtk.ALIGN_CENTER) + box.SetMarginStart(spacing) + box.SetMarginTop(spacing) + box.Add(logo) + + + // Add a child widget and tab label to the notebook so it renders. + nbChild, err := gtk.LabelNew("Notebook content") + if err != nil { + log.Fatal("Unable to create button:", err) + } + nbInfo := labelNew("INFO") + nbOptions := labelNew("OPTIONS") + nbAnimations := labelNew("ANIMATIONS") + nb.SetTabPos(gtk.POS_BOTTOM) + nb.AppendPage(box, nbInfo) + nb.AppendPage(nbChild, nbOptions) + + animationsBox := setupAnimationsTab() + nb.AppendPage(animationsBox, nbAnimations) + + win.ShowAll() + + gtk.Main() +}