gocui: more spacing logic

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-04-26 00:07:09 -05:00
parent 97079e936b
commit d8a1c53757
8 changed files with 31 additions and 28 deletions

View File

@ -27,8 +27,8 @@ func (n *Node) NewGrid(name string, w int, h int) *Node {
a.Text = name a.Text = name
a.X = w a.X = w
a.Y = h a.Y = h
a.Width = w // a.Width = w
a.Height = h // a.Height = h
newNode.X = w newNode.X = w
newNode.Y = h newNode.Y = h
newNode.NextX = 1 newNode.NextX = 1

View File

@ -32,8 +32,8 @@ func (n *Node) redo(plug *aplug) {
a.WidgetId = n.id a.WidgetId = n.id
// used for new Windows // used for new Windows
a.Width = n.Width // a.Width = n.Width
a.Height = n.Height // a.Height = n.Height
// used for anything that needs a range // used for anything that needs a range
a.X = n.X a.X = n.X

View File

@ -23,7 +23,7 @@ func newWindow(a toolkit.Action) {
newt.wId = a.WidgetId newt.wId = a.WidgetId
// menubar bool is if the OS defined border on the window should be used // menubar bool is if the OS defined border on the window should be used
win := ui.NewWindow(a.Name, a.Width, a.Height, menubar) win := ui.NewWindow(a.Name, a.X, a.Y, menubar)
win.SetBorderless(canvas) win.SetBorderless(canvas)
win.SetMargined(margin) win.SetMargined(margin)
win.OnClosing(func(*ui.Window) bool { win.OnClosing(func(*ui.Window) bool {

View File

@ -17,26 +17,26 @@ func makeWidget(a *toolkit.Action) *cuiWidget {
w.s = a.S w.s = a.S
w.x = a.X w.x = a.X
w.y = a.Y w.y = a.Y
w.width = a.Width
w.height = a.Height
t := len(w.text) t := len(w.text)
w.realWidth = t + me.buttonPadding w.gocuiSize.width = t + me.PadW
w.realHeight = me.DefaultHeight w.gocuiSize.height = me.DefaultHeight + me.PadH
w.gocuiSize.width = t + me.buttonPadding
w.gocuiSize.height = me.DefaultHeight w.realWidth = w.gocuiSize.width
w.realHeight = w.gocuiSize.height
// set the gocui view.Frame = true by default
w.frame = true
if (w.frame) {
w.realHeight += me.FramePadH
w.gocuiSize.height += me.FramePadH
}
w.widgetType = a.WidgetType w.widgetType = a.WidgetType
w.id = a.WidgetId w.id = a.WidgetId
// set the name used by gocui to the id // set the name used by gocui to the id
w.cuiName = strconv.Itoa(w.id) w.cuiName = strconv.Itoa(w.id)
// set the gocui view.Frame = true by default
w.frame = true
if (w.frame) {
w.realHeight += me.FramePadH
w.gocuiSize.height += me.FramePadH
}
if w.widgetType == toolkit.Root { if w.widgetType == toolkit.Root {
log(logInfo, "setupWidget() FOUND ROOT w.id =", w.id, "w.parent", w.parent, "ParentId =", a.ParentId) log(logInfo, "setupWidget() FOUND ROOT w.id =", w.id, "w.parent", w.parent, "ParentId =", a.ParentId)

View File

@ -48,13 +48,13 @@ func (w *cuiWidget) placeBox() {
w.showWidgetPlacement(logNow, "boxE()") w.showWidgetPlacement(logNow, "boxE()")
} }
/*
func (w *cuiWidget) getGroupWH() { func (w *cuiWidget) getGroupWH() {
p := w.parent // the parent must be a group widget p := w.parent // the parent must be a group widget
// update parent gocuiSize // update parent gocuiSize
p.realWidth = 0 // p.realWidth =
p.realHeight = 0 // p.realHeight += me.DefaultHeight + me.PadH + me.FramePadH
p.realHeight += me.buttonPadding // pad height for the group label
for _, child := range p.children { for _, child := range p.children {
p.realWidth += child.realWidth p.realWidth += child.realWidth
p.realHeight += child.realHeight p.realHeight += child.realHeight
@ -71,6 +71,7 @@ func (w *cuiWidget) getGroupWH() {
} }
return return
} }
*/
func (w *cuiWidget) placeWidgets() { func (w *cuiWidget) placeWidgets() {
if (w == nil) { if (w == nil) {

View File

@ -69,7 +69,7 @@ type config struct {
// horizontalPadding int // horizontalPadding int
// groupPadding int `default:"6" dense:"2"` // this is supposed to be how far to indent to the left // groupPadding int `default:"6" dense:"2"` // this is supposed to be how far to indent to the left
buttonPadding int `default:"4" dense:"3"` // if 3, buttons slightly overlap // buttonPadding int `default:"4" dense:"3"` // if 3, buttons slightly overlap
} }
var ( var (

View File

@ -34,14 +34,16 @@ type Action struct {
A any // switch to this or deprecate this? pros/cons? A any // switch to this or deprecate this? pros/cons?
// This GUI is intended for simple things
// We are not laying out PDF's here
// This is used for things like a slider(0,100) // This is used for things like a slider(0,100)
Width int
Height int
X int X int
Y int Y int
// This GUI is intended for simple things
// Is having an option like 640x480 really a good idea?
// TODO: remove Width & Height measured in pixels?
// Width int
// Height int
// Put space around elements to improve look & feel // Put space around elements to improve look & feel
Margin bool Margin bool

View File

@ -17,8 +17,8 @@ func (n *Node) NewWindow(title string) *Node {
var a toolkit.Action var a toolkit.Action
a.ActionType = toolkit.Add a.ActionType = toolkit.Add
a.Width = Config.Width a.X = Config.Width
a.Height = Config.Height a.Y = Config.Height
a.Name = title a.Name = title
a.Text = title a.Text = title
newaction(&a, newNode, n) newaction(&a, newNode, n)