Add menu navigation to net remaining in browseable render
This commit is contained in:
parent
ca4e9e963a
commit
68fef90684
@ -158,6 +158,7 @@ func(pg *Page) RenderTemplate(sym string, values map[string]string, idx uint16)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// render menu and all syms except sink, split sink into display chunks
|
// render menu and all syms except sink, split sink into display chunks
|
||||||
|
// TODO: Function too long, split up
|
||||||
func(pg *Page) prepare(sym string, values map[string]string, idx uint16) (map[string]string, error) {
|
func(pg *Page) prepare(sym string, values map[string]string, idx uint16) (map[string]string, error) {
|
||||||
var sink string
|
var sink string
|
||||||
|
|
||||||
@ -191,32 +192,51 @@ func(pg *Page) prepare(sym string, values map[string]string, idx uint16) (map[st
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
// remaining includes core menu
|
||||||
if pg.menu != nil {
|
|
||||||
r, err := pg.menu.Render(idx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
log.Printf("appending %s for menu", r)
|
|
||||||
s += r
|
|
||||||
}
|
|
||||||
|
|
||||||
remaining, ok := pg.sizer.Check(s)
|
remaining, ok := pg.sizer.Check(s)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("capacity exceeded")
|
return nil, fmt.Errorf("capacity exceeded")
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("%v bytes available for sink split", remaining)
|
var menuSizes [4]uint32 // mainSize, prevsize, nextsize, nextsize+prevsize
|
||||||
|
if pg.menu != nil {
|
||||||
|
cfg := pg.menu.GetBrowseConfig()
|
||||||
|
tmpm := NewMenu().WithBrowseConfig(cfg)
|
||||||
|
v, err := tmpm.Render(0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
menuSizes[0] = uint32(len(v))
|
||||||
|
tmpm = tmpm.WithPageCount(2)
|
||||||
|
v, err = tmpm.Render(0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
menuSizes[1] = uint32(len(v)) - menuSizes[0]
|
||||||
|
v, err = tmpm.Render(1)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
menuSizes[2] = uint32(len(v)) - menuSizes[0]
|
||||||
|
menuSizes[3] = menuSizes[1] + menuSizes[2]
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("%v bytes available for sink split before navigation", remaining)
|
||||||
|
|
||||||
l := 0
|
l := 0
|
||||||
var count uint16
|
var count uint16
|
||||||
tb := strings.Builder{}
|
tb := strings.Builder{}
|
||||||
rb := strings.Builder{}
|
rb := strings.Builder{}
|
||||||
|
|
||||||
|
netRemaining := remaining
|
||||||
|
if len(sinkValues) > 1 {
|
||||||
|
netRemaining -= menuSizes[1]
|
||||||
|
}
|
||||||
|
|
||||||
for i, v := range sinkValues {
|
for i, v := range sinkValues {
|
||||||
log.Printf("processing sinkvalue %v: %s", i, v)
|
log.Printf("processing sinkvalue %v: %s", i, v)
|
||||||
l += len(v)
|
l += len(v)
|
||||||
if uint32(l) > remaining {
|
if uint32(l) > netRemaining {
|
||||||
if tb.Len() == 0 {
|
if tb.Len() == 0 {
|
||||||
return nil, fmt.Errorf("capacity insufficient for sink field %v", i)
|
return nil, fmt.Errorf("capacity insufficient for sink field %v", i)
|
||||||
}
|
}
|
||||||
@ -226,6 +246,9 @@ func(pg *Page) prepare(sym string, values map[string]string, idx uint16) (map[st
|
|||||||
pg.sizer.AddCursor(c)
|
pg.sizer.AddCursor(c)
|
||||||
tb.Reset()
|
tb.Reset()
|
||||||
l = 0
|
l = 0
|
||||||
|
if count == 0 {
|
||||||
|
netRemaining -= menuSizes[2]
|
||||||
|
}
|
||||||
count += 1
|
count += 1
|
||||||
}
|
}
|
||||||
if tb.Len() > 0 {
|
if tb.Len() > 0 {
|
||||||
@ -264,6 +287,8 @@ func(pg *Page) render(sym string, values map[string]string, idx uint16) (string,
|
|||||||
}
|
}
|
||||||
log.Printf("rendered %v bytes for template", len(s))
|
log.Printf("rendered %v bytes for template", len(s))
|
||||||
r += s
|
r += s
|
||||||
|
|
||||||
|
if pg.menu != nil {
|
||||||
s, err = pg.menu.Render(idx)
|
s, err = pg.menu.Render(idx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@ -272,6 +297,8 @@ func(pg *Page) render(sym string, values map[string]string, idx uint16) (string,
|
|||||||
if len(s) > 0 {
|
if len(s) > 0 {
|
||||||
r += "\n" + s
|
r += "\n" + s
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if pg.sizer != nil {
|
if pg.sizer != nil {
|
||||||
_, ok = pg.sizer.Check(r)
|
_, ok = pg.sizer.Check(r)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -65,6 +65,10 @@ func(szr *Sizer) Size(s string) (uint16, error) {
|
|||||||
return r, nil
|
return r, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func(szr *Sizer) MenuSize() uint16 {
|
||||||
|
return szr.menuSize
|
||||||
|
}
|
||||||
|
|
||||||
func(szr *Sizer) AddCursor(c uint32) {
|
func(szr *Sizer) AddCursor(c uint32) {
|
||||||
log.Printf("added cursor: %v", c)
|
log.Printf("added cursor: %v", c)
|
||||||
szr.crsrs = append(szr.crsrs, c)
|
szr.crsrs = append(szr.crsrs, c)
|
||||||
|
@ -166,7 +166,7 @@ lala poo
|
|||||||
|
|
||||||
|
|
||||||
if r != expect {
|
if r != expect {
|
||||||
t.Fatalf("expected:\n\t%s\ngot:\n\t%s\n", expect, r)
|
t.Fatalf("expected:\n\t%x\ngot:\n\t%x\n", expect, r)
|
||||||
}
|
}
|
||||||
r, err = pg.Render("pages", 1)
|
r, err = pg.Render("pages", 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
2
go/testdata/testdata.go
vendored
2
go/testdata/testdata.go
vendored
@ -112,7 +112,7 @@ func long() error {
|
|||||||
b := []byte{}
|
b := []byte{}
|
||||||
b = vm.NewLine(b, vm.MOUT, []string{"0", "back"}, nil, nil)
|
b = vm.NewLine(b, vm.MOUT, []string{"0", "back"}, nil, nil)
|
||||||
b = vm.NewLine(b, vm.MNEXT, []string{"00", "nexxt"}, nil, nil)
|
b = vm.NewLine(b, vm.MNEXT, []string{"00", "nexxt"}, nil, nil)
|
||||||
b = vm.NewLine(b, vm.MPREV, []string{"11", "prevv"}, nil, nil)
|
b = vm.NewLine(b, vm.MPREV, []string{"11", "prevvv"}, nil, nil)
|
||||||
b = vm.NewLine(b, vm.LOAD, []string{"longdata"}, []byte{0x00}, nil)
|
b = vm.NewLine(b, vm.LOAD, []string{"longdata"}, []byte{0x00}, nil)
|
||||||
b = vm.NewLine(b, vm.MAP, []string{"longdata"}, nil, nil)
|
b = vm.NewLine(b, vm.MAP, []string{"longdata"}, nil, nil)
|
||||||
b = vm.NewLine(b, vm.HALT, nil, nil, nil)
|
b = vm.NewLine(b, vm.HALT, nil, nil, nil)
|
||||||
|
Loading…
Reference in New Issue
Block a user