Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions core/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,8 @@ func (lb *ListBase) Init() {
})

lb.Maker(func(p *tree.Plan) {
svi := lb.This.(Lister)
svi.UpdateSliceSize()
ls := lb.This.(Lister)
ls.UpdateSliceSize()

scrollTo := -1
if lb.SelectedValue != nil {
Expand All @@ -360,12 +360,11 @@ func (lb *ListBase) Init() {

lb.Updater(func() {
lb.UpdateStartIndex()
svi.UpdateMaxWidths()
})

lb.MakeGrid(p, func(p *tree.Plan) {
for i := 0; i < lb.VisibleRows; i++ {
svi.MakeRow(p, i)
ls.MakeRow(p, i)
}
})
})
Expand Down Expand Up @@ -400,6 +399,7 @@ func (lb *ListBase) SetSliceBase() {
lb.SelectedIndex = -1
}
lb.ResetSelectedIndexes()
lb.This.(Lister).UpdateMaxWidths()
}

// SetSlice sets the source slice that we are viewing.
Expand All @@ -424,11 +424,11 @@ func (lb *ListBase) SetSlice(sl any) *ListBase {
return lb
}

lb.SetSliceBase()
lb.Slice = sl
lb.sliceUnderlying = reflectx.Underlying(reflect.ValueOf(lb.Slice))
lb.isArray = reflectx.NonPointerType(reflect.TypeOf(sl)).Kind() == reflect.Array
lb.elementValue = reflectx.SliceElementValue(sl)
lb.SetSliceBase()
return lb
}

Expand Down Expand Up @@ -553,7 +553,7 @@ func (lb *ListBase) MakeGrid(p *tree.Plan, maker func(p *tree.Plan)) {
}

func (lb *ListBase) MakeValue(w Value, i int) {
svi := lb.This.(Lister)
ls := lb.This.(Lister)
wb := w.AsWidget()
wb.SetProperty(ListRowProperty, i)
wb.Styler(func(s *styles.Style) {
Expand All @@ -564,9 +564,9 @@ func (lb *ListBase) MakeValue(w Value, i int) {
}
row, col := lb.widgetIndex(w)
row += lb.StartIndex
svi.StyleValue(w, s, row, col)
ls.StyleValue(w, s, row, col)
if row < lb.SliceSize {
svi.StyleRow(w, row, col)
ls.StyleRow(w, row, col)
}
})
wb.OnSelect(func(e events.Event) {
Expand All @@ -586,8 +586,8 @@ func (lb *ListBase) MakeValue(w Value, i int) {
}

func (lb *ListBase) MakeRow(p *tree.Plan, i int) {
svi := lb.This.(Lister)
si, vi, invis := svi.SliceIndex(i)
ls := lb.This.(Lister)
si, vi, invis := ls.SliceIndex(i)
itxt := strconv.Itoa(i)
val := lb.sliceElementValue(vi)

Expand All @@ -603,12 +603,13 @@ func (lb *ListBase) MakeRow(p *tree.Plan, i int) {
lb.MakeValue(w, i)
if !lb.IsReadOnly() {
wb.OnChange(func(e events.Event) {
lb.This.(Lister).UpdateMaxWidths()
lb.SendChange(e)
})
}
wb.Updater(func() {
wb := w.AsWidget()
_, vi, invis := svi.SliceIndex(i)
_, vi, invis := ls.SliceIndex(i)
val := lb.sliceElementValue(vi)
Bind(val.Addr().Interface(), w)
wb.SetReadOnly(lb.IsReadOnly())
Expand Down Expand Up @@ -1347,23 +1348,23 @@ func (lb *ListBase) pasteIndex(idx int) { //types:add

// makePasteMenu makes the menu of options for paste events
func (lb *ListBase) makePasteMenu(m *Scene, md mimedata.Mimes, idx int, mod events.DropMods, fun func()) {
svi := lb.This.(Lister)
ls := lb.This.(Lister)
if mod == events.DropCopy {
NewButton(m).SetText("Assign to").OnClick(func(e events.Event) {
svi.PasteAssign(md, idx)
ls.PasteAssign(md, idx)
if fun != nil {
fun()
}
})
}
NewButton(m).SetText("Insert before").OnClick(func(e events.Event) {
svi.PasteAtIndex(md, idx)
ls.PasteAtIndex(md, idx)
if fun != nil {
fun()
}
})
NewButton(m).SetText("Insert after").OnClick(func(e events.Event) {
svi.PasteAtIndex(md, idx+1)
ls.PasteAtIndex(md, idx+1)
if fun != nil {
fun()
}
Expand Down
4 changes: 2 additions & 2 deletions core/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ func (tb *Table) Init() {

tb.Updater(func() {
tb.UpdateStartIndex()
svi.UpdateMaxWidths()
})

tb.makeHeader(p)
Expand Down Expand Up @@ -146,10 +145,10 @@ func (tb *Table) SetSlice(sl any) *Table {
return tb
}

tb.SetSliceBase()
tb.Slice = sl
tb.sliceUnderlying = reflectx.Underlying(reflect.ValueOf(tb.Slice))
tb.elementValue = reflectx.Underlying(reflectx.SliceElementValue(sl))
tb.SetSliceBase()
tb.cacheVisibleFields()
return tb
}
Expand Down Expand Up @@ -316,6 +315,7 @@ func (tb *Table) MakeRow(p *tree.Plan, i int) {
w.AsTree().SetProperty(ListColProperty, fli)
if !tb.IsReadOnly() && !readOnlyTag {
wb.OnChange(func(e events.Event) {
tb.This.(Lister).UpdateMaxWidths()
tb.SendChange()
})
}
Expand Down
4 changes: 2 additions & 2 deletions tensor/tensorcore/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ func (tb *Table) Init() {

tb.Updater(func() {
tb.UpdateStartIndex()
tb.UpdateMaxWidths()
})

tb.MakeHeader(p)
Expand Down Expand Up @@ -138,9 +137,9 @@ func (tb *Table) SetTable(et *table.Table) *Table {
return nil
}

tb.SetSliceBase()
tb.Table = table.NewIndexView(et)
tb.This.(core.Lister).UpdateSliceSize()
tb.SetSliceBase()
tb.Update()
return tb
}
Expand Down Expand Up @@ -321,6 +320,7 @@ func (tb *Table) MakeRow(p *tree.Plan, i int) {
tb.Table.Table.SetFloatIndex(fli, tb.Table.Indexes[si], fval)
}
}
tb.This.(core.Lister).UpdateMaxWidths()
tb.SendChange()
})
}
Expand Down
4 changes: 2 additions & 2 deletions tensor/tensorcore/tensoreditor.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func (tb *TensorEditor) Init() {

tb.Updater(func() {
tb.UpdateStartIndex()
tb.UpdateMaxWidths()
})

tb.MakeHeader(p)
Expand Down Expand Up @@ -111,9 +110,9 @@ func (tb *TensorEditor) SetTensor(et tensor.Tensor) *TensorEditor {
return nil
}

tb.SetSliceBase()
tb.Tensor = et
tb.This.(core.Lister).UpdateSliceSize()
tb.SetSliceBase()
tb.Update()
return tb
}
Expand Down Expand Up @@ -247,6 +246,7 @@ func (tb *TensorEditor) MakeRow(p *tree.Plan, i int) {
tensor.Projection2DSet(tb.Tensor, tb.Layout.OddRow, vi, fli, fval)
}
}
tb.This.(core.Lister).UpdateMaxWidths()
tb.SendChange()
})
}
Expand Down
Loading