DOCS: try to start making correct go docs

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2021-10-28 04:58:54 -05:00
parent 6a477695ef
commit 57f95e9486
5 changed files with 119 additions and 74 deletions

View File

@ -6,78 +6,6 @@ import _ "github.com/andlabs/ui/winmanifest"
var mybox *ui.Box
/*
func (n *Node) AddDemoTab(title string) {
newNode := n.AddTab(title, makeDemoTab())
if (Config.DebugNode) {
newNode.Dump()
}
tabSetMargined(newNode.uiTab)
newNode.Dump()
newNode.ListChildren(false)
addDemoGroup(newNode, "new group 1")
addDemoGroup(newNode, "new group 2")
groupNode := newNode.AddGroup("new group 3")
groupNode.AddComboBox("testing", "foo", "man", "blah")
}
func makeDemoTab() *ui.Box {
hbox := ui.NewHorizontalBox()
hbox.SetPadded(true)
group := ui.NewGroup("DemoEditBox")
group.SetMargined(true)
hbox.Append(group, true)
vbox := ui.NewVerticalBox()
vbox.SetPadded(true)
group.SetChild(vbox)
ecbox := ui.NewEditableCombobox()
ecbox.Append("foo 1")
ecbox.Append("man 2")
ecbox.Append("bar 3")
ecbox.OnChanged(func(*ui.EditableCombobox) {
log.Println("test")
test := ecbox.Text()
log.Println("test=", test)
})
vbox.Append(ecbox, false)
return hbox
}
func addDemoGroup(n *Node, title string) {
hbox := n.uiBox
if (hbox == nil) {
return
}
group := ui.NewGroup(title)
group.SetMargined(true)
hbox.Append(group, true)
vbox := ui.NewVerticalBox()
vbox.SetPadded(true)
group.SetChild(vbox)
ecbox := ui.NewEditableCombobox()
ecbox.Append("foo 1")
ecbox.Append("man 2")
ecbox.Append("bar 3")
ecbox.OnChanged(func(*ui.EditableCombobox) {
log.Println("test")
test := ecbox.Text()
log.Println("test=", test)
})
vbox.Append(ecbox, false)
}
*/
func (n *Node) AddGroup(title string) *Node {
hbox := n.uiBox
if (hbox == nil) {

72
doc.go Normal file
View File

@ -0,0 +1,72 @@
/*
Package wit/gui implements a abstraction layer for Go visual elements in
a cross platform way. Right now, this abstraction is built on top of
the GUI toolkit 'andlabs/ui' which does the cross platform support.
A quick overview of the features, some general design guidelines
and principles for how this package should generally work:
* GUI elements are stored in a tree of nodes
* When in doubt, it's ok to guess. We will return something close.
* It tries to make your code simple
Quick Start
This section demonstrates how to quickly get started with spew. See the
sections below for further details on formatting and configuration options.
To dump a variable with full newlines, indentation, type, and pointer
information use Dump, Fdump, or Sdump:
package main
import (
"git.wit.org/wit/gui"
)
func main() {
gui.Main(initGUI)
}
// This initializes the first window
func initGUI() {
gui.Config.Title = "WIT GUI Window 1"
gui.Config.Width = 640
gui.Config.Height = 480
node1 := gui.NewWindow()
addDemoTab(node1, "A Simple Tab Demo")
}
func addDemoTab(n *gui.Node, title string) {
newNode := n.AddTab(title, nil)
groupNode1 := newNode.AddGroup("group 1")
groupNode1.AddComboBox("demoCombo2", "more 1", "more 2", "more 3")
}
Configuration Options
Configuration of the GUI is handled by fields in the ConfigType type. For
convenience, all of the top-level functions use a global state available
via the gui.Config global.
The following configuration options are available:
* Width
When creating a new window, this is the width
* Height
When creating a new window, this is the height
* Debug
When 'true' log more output
GUI Usage
Errors
Since it is possible for custom Stringer/error interfaces to panic, spew
detects them and handles them internally by printing the panic information
inline with the output. Since spew is intended to provide deep pretty printing
capabilities on structures, it intentionally does not return any errors.
*/
package gui

View File

@ -53,7 +53,7 @@ func SetText(box *GuiBox, name string, value string) error {
}
spew.Dump(box.Window.EntryMap)
if (box.Window.EntryMap[name] == nil) {
return fmt.Errorf("gui.SetText() ERROR box.Window.EntryMap[", name, "] == nil ")
return fmt.Errorf("gui.SetText() ERROR box.Window.EntryMap[" + name + "] == nil ")
}
e := box.Window.EntryMap[name]
log.Println("gui.SetText() box.Window.EntryMap[", name, "] = ", e.UiEntry.Text())

45
example_test.go Normal file
View File

@ -0,0 +1,45 @@
/*
* Copyright (c) 2013-2016 Dave Collins <dave@davec.name>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
package gui_test
import (
"git.wit.org/wit/gui"
)
// This example demonstrates how to create a NewWindow()
//
// Interacting with a GUI in a cross platform fashion adds some
// unusual problems. To obvuscate those, andlabs/ui starts a
// goroutine that interacts with the native gui toolkits
// on the Linux, MacOS, Windows, etc.
//
// Because of this oddity, to initialize a new window, the
// function is not passed any arguements and instead passes
// the information via the Config type.
//
func ExampleNewWindow() {
// Define the name and size
gui.Config.Title = "WIT GUI Window 1"
gui.Config.Width = 640
gui.Config.Height = 480
// Create the Window
gui.NewWindow()
// Output:
// You get a window
}

View File

@ -50,7 +50,7 @@ func FindWindow(s string) *GuiWindow {
return window
}
}
log.Printf("COULD NOT FIND WINDOW", s)
log.Printf("COULD NOT FIND WINDOW " + s)
return nil
}