mirror of https://github.com/anoshenko/rui.git
Fixed TabsLayout
This commit is contained in:
parent
0c4aa9bfc6
commit
c06214f4ae
|
@ -546,26 +546,22 @@ func (tabsLayout *tabsLayoutData) updateTabCloseButton(view View, tag PropertyNa
|
|||
|
||||
// Append appends view to the end of view list
|
||||
func (tabsLayout *tabsLayoutData) Append(view View) {
|
||||
if tabsLayout.views == nil {
|
||||
tabsLayout.views = []View{}
|
||||
}
|
||||
if view != nil {
|
||||
tabsLayout.viewsContainerData.Append(view)
|
||||
if tabsLayout.append(view) {
|
||||
view.SetChangeListener(Title, tabsLayout.updateTitle)
|
||||
view.SetChangeListener(Icon, tabsLayout.updateIcon)
|
||||
view.SetChangeListener(TabCloseButton, tabsLayout.updateTabCloseButton)
|
||||
if len(tabsLayout.views) == 1 {
|
||||
tabsLayout.setRaw(Current, nil)
|
||||
tabsLayout.Set(Current, 0)
|
||||
if tabsLayout.created {
|
||||
updateInnerHTML(tabsLayout.htmlID(), tabsLayout.Session())
|
||||
if listener, ok := tabsLayout.changeListener[Content]; ok {
|
||||
listener(tabsLayout, Content)
|
||||
}
|
||||
tabsLayout.Set(Current, len(tabsLayout.views)-1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Insert inserts view to the "index" position in view list
|
||||
func (tabsLayout *tabsLayoutData) Insert(view View, index int) {
|
||||
if tabsLayout.views == nil {
|
||||
tabsLayout.views = []View{}
|
||||
}
|
||||
if view != nil {
|
||||
if current := GetCurrent(tabsLayout); current >= index {
|
||||
tabsLayout.setRaw(Current, current+1)
|
||||
|
@ -600,14 +596,21 @@ func (tabsLayout *tabsLayoutData) RemoveView(index int) View {
|
|||
newCurrent--
|
||||
}
|
||||
|
||||
if view := tabsLayout.viewsContainerData.RemoveView(index); view != nil {
|
||||
if view := tabsLayout.viewsContainerData.removeView(index); view != nil {
|
||||
view.SetChangeListener(Title, nil)
|
||||
view.SetChangeListener(Icon, nil)
|
||||
view.SetChangeListener(TabCloseButton, nil)
|
||||
|
||||
if newCurrent != oldCurrent {
|
||||
if tabsLayout.created {
|
||||
if newCurrent != oldCurrent {
|
||||
tabsLayout.Set(Current, newCurrent)
|
||||
}
|
||||
updateInnerHTML(tabsLayout.htmlID(), tabsLayout.Session())
|
||||
if listener, ok := tabsLayout.changeListener[Content]; ok {
|
||||
listener(tabsLayout, Content)
|
||||
}
|
||||
} else if newCurrent != oldCurrent {
|
||||
tabsLayout.setRaw(Current, newCurrent)
|
||||
tabsLayout.currentChanged(newCurrent, oldCurrent)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -64,58 +64,62 @@ func (container *viewsContainerData) Views() []View {
|
|||
return []View{}
|
||||
}
|
||||
|
||||
// Append appends a view to the end of the list of a view children
|
||||
func (container *viewsContainerData) Append(view View) {
|
||||
func (container *viewsContainerData) append(view View) bool {
|
||||
if view != nil {
|
||||
htmlID := container.htmlID()
|
||||
view.setParentID(htmlID)
|
||||
view.setParentID(container.htmlID())
|
||||
if len(container.views) == 0 {
|
||||
container.views = []View{view}
|
||||
} else {
|
||||
container.views = append(container.views, view)
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
if container.created {
|
||||
buffer := allocStringBuilder()
|
||||
defer freeStringBuilder(buffer)
|
||||
// Append appends a view to the end of the list of a view children
|
||||
func (container *viewsContainerData) Append(view View) {
|
||||
if container.append(view) && container.created {
|
||||
buffer := allocStringBuilder()
|
||||
defer freeStringBuilder(buffer)
|
||||
|
||||
viewHTML(view, buffer, "")
|
||||
container.Session().appendToInnerHTML(htmlID, buffer.String())
|
||||
viewHTML(view, buffer, "")
|
||||
container.Session().appendToInnerHTML(container.htmlID(), buffer.String())
|
||||
|
||||
if listener, ok := container.changeListener[Content]; ok {
|
||||
listener(container, Content)
|
||||
}
|
||||
if listener, ok := container.changeListener[Content]; ok {
|
||||
listener(container, Content)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Insert inserts a view to the "index" position in the list of a view children
|
||||
func (container *viewsContainerData) Insert(view View, index int) {
|
||||
func (container *viewsContainerData) insert(view View, index int) bool {
|
||||
if view != nil {
|
||||
if container.views == nil || index < 0 || index >= len(container.views) {
|
||||
container.Append(view)
|
||||
return
|
||||
return container.append(view)
|
||||
}
|
||||
|
||||
htmlID := container.htmlID()
|
||||
view.setParentID(htmlID)
|
||||
view.setParentID(container.htmlID())
|
||||
if index > 0 {
|
||||
container.views = append(container.views[:index], append([]View{view}, container.views[index:]...)...)
|
||||
} else {
|
||||
container.views = append([]View{view}, container.views...)
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
if container.created {
|
||||
updateInnerHTML(htmlID, container.Session())
|
||||
if listener, ok := container.changeListener[Content]; ok {
|
||||
listener(container, Content)
|
||||
}
|
||||
// Insert inserts a view to the "index" position in the list of a view children
|
||||
func (container *viewsContainerData) Insert(view View, index int) {
|
||||
if container.insert(view, index) && container.created {
|
||||
updateInnerHTML(container.htmlID(), container.Session())
|
||||
if listener, ok := container.changeListener[Content]; ok {
|
||||
listener(container, Content)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove removes view from list and return it
|
||||
func (container *viewsContainerData) RemoveView(index int) View {
|
||||
func (container *viewsContainerData) removeView(index int) View {
|
||||
if container.views == nil {
|
||||
container.views = []View{}
|
||||
return nil
|
||||
|
@ -136,8 +140,13 @@ func (container *viewsContainerData) RemoveView(index int) View {
|
|||
}
|
||||
|
||||
view.setParentID("")
|
||||
return view
|
||||
}
|
||||
|
||||
if container.created {
|
||||
// Remove removes view from list and return it
|
||||
func (container *viewsContainerData) RemoveView(index int) View {
|
||||
view := container.removeView(index)
|
||||
if view != nil && container.created {
|
||||
container.Session().callFunc("removeView", view.htmlID())
|
||||
if listener, ok := container.changeListener[Content]; ok {
|
||||
listener(container, Content)
|
||||
|
|
Loading…
Reference in New Issue