cogentcore / core

A free and open source framework for building powerful, fast, and elegant 2D and 3D apps that run on macOS, Windows, Linux, iOS, Android, and the Web with a single pure Go codebase, allowing you to Code Once, Run Everywhere.
http://cogentcore.org/core
BSD 3-Clause "New" or "Revised" License
1.32k stars 71 forks source link

SizeDownGrowCells error: sub alloc > total to alloc: #885

Closed ddkwork closed 4 months ago

ddkwork commented 4 months ago

Describe the bug

toolbar not show

How to reproduce

run demo

Example code

package main

import (
    "cogentcore.org/core/colors"
    "cogentcore.org/core/events"
    "cogentcore.org/core/gi"
    "cogentcore.org/core/giv"
    "cogentcore.org/core/icons"
    "cogentcore.org/core/ki"
    "cogentcore.org/core/styles"
)

func main() {
    b := gi.NewBody("toolbar BUg")
    hSplits := gi.NewSplits(b)
    leftFrame := gi.NewFrame(hSplits)

    tableView := giv.NewTableView(leftFrame, "tableView")
    tableView.SetReadOnly(true)
    tableView.SetSlice(&packets)

    b.AddAppBar(func(tb *gi.Toolbar) {
        gi.NewTextField(tb).SetPlaceholder("filter content").AddClearButton().SetLeadingIcon(icons.Search)
        gi.NewButton(tb).SetTooltip("Cleaner").SetIcon("cleaner").OnClick(func(e events.Event) {
            restPackets()
            update(tableView)
        })
        gi.NewButton(tb).SetTooltip("Replay").SetIcon("replay")
        gi.NewButton(tb).SetTooltip("Edit").SetIcon("edit")
        gi.NewButton(tb).SetTooltip("Submit").SetIcon("submit")
        gi.NewButton(tb).SetTooltip("Rec").SetIcon("rec")
        gi.NewButton(tb).SetTooltip("Vpn").SetIcon("vpn")
        gi.NewButton(tb).SetTooltip("Rootca").SetIcon("rootca")
        gi.NewButton(tb).SetTooltip("Ssl").SetIcon("ssl3")
        gi.NewButton(tb).SetTooltip("Setting").SetIcon("setting")
        gi.NewButton(tb).SetTooltip("logView").SetIcon("Charles") //todo
        gi.NewButton(tb).SetTooltip("script").SetIcon("Charles")  //todo
        gi.NewButton(tb).SetTooltip("About").SetIcon("about")
    })

    tableView.AddContextMenu(func(m *gi.Scene) {
        gi.NewButton(m).SetText("copy row")
        gi.NewButton(m).SetText("copy Column")
        gi.NewButton(m).SetText("new packet")
        gi.NewButton(m).SetText("new packet container")
        gi.NewButton(m).SetText("save to json")
        gi.NewButton(m).SetText("load from json")
    })
    rightFrame := gi.NewFrame(hSplits)
    vSplits := NewVSplits(rightFrame)

    gi.NewTabs(vSplits)

    gi.NewTabs(vSplits)

    hSplits.SetSplits(.6, .4)

    b.RunMainWindow()
}

func restPackets() { packets = packets[:0] }

type Packet struct {
}

var packets = make([]*Packet, 0, 80000)

func update(tableView *giv.TableView) {
    updt := tableView.UpdateStartAsync()
    tableView.UpdateWidgets()
    //tableView.UpdateEndAsync(updt)
    tableView.UpdateEndAsyncRender(updt)
}

func NewVSplits(parent ki.Ki) *gi.Splits { // Horizontal and vertical
    splits := gi.NewSplits(parent)
    splits.Style(func(s *styles.Style) {
        s.Direction = styles.Column
        s.Background = colors.C(colors.Scheme.SurfaceContainerLow)
    })
    return splits
}

Relevant output

/mitmproxy scene/top-bar/toolbar-0 SizeDownGrowCells error: sub alloc > total to alloc: 5479 5267
ma: X mi: 2 ci: 0 mx: 287 gsum: 1 gr: 1 ex: 5192 par act: 75
col: 0  max X: 75       sum Y: 63       max grX: 0      sum grY: 0
col: 1  max X: 234      sum Y: 65       max grX: 0      sum grY: 0

Platform

Windows

ddkwork commented 4 months ago

core/gi/layimpl.go in line 1296

kkoreilly commented 4 months ago

I have gotten this issue before and will work on fixing it.

kkoreilly commented 4 months ago

You should not add your own search textfield to the toolbar; rather, you should use the app chooser that already exists. You can add items to it using this code in your AddAppBar function:

        ch := tb.AppChooser()
        ch.AddItemsFunc(func() {
            ch.Items = append(ch.Items, gi.ChooserItem{
                Value: "my search result",
                // etc
            })
        })
kkoreilly commented 4 months ago

Also note that we will work on improving searching support, especially for tables and trees, in #28, #770, and #675.

ddkwork commented 4 months ago

Also note that we will work on improving searching support, especially for tables and trees, in #28, #770, and #675.

Thanks