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
|
// Append appends view to the end of view list
|
||||||
func (tabsLayout *tabsLayoutData) Append(view View) {
|
func (tabsLayout *tabsLayoutData) Append(view View) {
|
||||||
if tabsLayout.views == nil {
|
if tabsLayout.append(view) {
|
||||||
tabsLayout.views = []View{}
|
|
||||||
}
|
|
||||||
if view != nil {
|
|
||||||
tabsLayout.viewsContainerData.Append(view)
|
|
||||||
view.SetChangeListener(Title, tabsLayout.updateTitle)
|
view.SetChangeListener(Title, tabsLayout.updateTitle)
|
||||||
view.SetChangeListener(Icon, tabsLayout.updateIcon)
|
view.SetChangeListener(Icon, tabsLayout.updateIcon)
|
||||||
view.SetChangeListener(TabCloseButton, tabsLayout.updateTabCloseButton)
|
view.SetChangeListener(TabCloseButton, tabsLayout.updateTabCloseButton)
|
||||||
if len(tabsLayout.views) == 1 {
|
if tabsLayout.created {
|
||||||
tabsLayout.setRaw(Current, nil)
|
updateInnerHTML(tabsLayout.htmlID(), tabsLayout.Session())
|
||||||
tabsLayout.Set(Current, 0)
|
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
|
// Insert inserts view to the "index" position in view list
|
||||||
func (tabsLayout *tabsLayoutData) Insert(view View, index int) {
|
func (tabsLayout *tabsLayoutData) Insert(view View, index int) {
|
||||||
if tabsLayout.views == nil {
|
|
||||||
tabsLayout.views = []View{}
|
|
||||||
}
|
|
||||||
if view != nil {
|
if view != nil {
|
||||||
if current := GetCurrent(tabsLayout); current >= index {
|
if current := GetCurrent(tabsLayout); current >= index {
|
||||||
tabsLayout.setRaw(Current, current+1)
|
tabsLayout.setRaw(Current, current+1)
|
||||||
|
@ -600,14 +596,21 @@ func (tabsLayout *tabsLayoutData) RemoveView(index int) View {
|
||||||
newCurrent--
|
newCurrent--
|
||||||
}
|
}
|
||||||
|
|
||||||
if view := tabsLayout.viewsContainerData.RemoveView(index); view != nil {
|
if view := tabsLayout.viewsContainerData.removeView(index); view != nil {
|
||||||
view.SetChangeListener(Title, nil)
|
view.SetChangeListener(Title, nil)
|
||||||
view.SetChangeListener(Icon, nil)
|
view.SetChangeListener(Icon, nil)
|
||||||
view.SetChangeListener(TabCloseButton, 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.setRaw(Current, newCurrent)
|
||||||
tabsLayout.currentChanged(newCurrent, oldCurrent)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -64,58 +64,62 @@ func (container *viewsContainerData) Views() []View {
|
||||||
return []View{}
|
return []View{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append appends a view to the end of the list of a view children
|
func (container *viewsContainerData) append(view View) bool {
|
||||||
func (container *viewsContainerData) Append(view View) {
|
|
||||||
if view != nil {
|
if view != nil {
|
||||||
htmlID := container.htmlID()
|
view.setParentID(container.htmlID())
|
||||||
view.setParentID(htmlID)
|
|
||||||
if len(container.views) == 0 {
|
if len(container.views) == 0 {
|
||||||
container.views = []View{view}
|
container.views = []View{view}
|
||||||
} else {
|
} else {
|
||||||
container.views = append(container.views, view)
|
container.views = append(container.views, view)
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
if container.created {
|
// Append appends a view to the end of the list of a view children
|
||||||
buffer := allocStringBuilder()
|
func (container *viewsContainerData) Append(view View) {
|
||||||
defer freeStringBuilder(buffer)
|
if container.append(view) && container.created {
|
||||||
|
buffer := allocStringBuilder()
|
||||||
|
defer freeStringBuilder(buffer)
|
||||||
|
|
||||||
viewHTML(view, buffer, "")
|
viewHTML(view, buffer, "")
|
||||||
container.Session().appendToInnerHTML(htmlID, buffer.String())
|
container.Session().appendToInnerHTML(container.htmlID(), buffer.String())
|
||||||
|
|
||||||
if listener, ok := container.changeListener[Content]; ok {
|
if listener, ok := container.changeListener[Content]; ok {
|
||||||
listener(container, Content)
|
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) bool {
|
||||||
func (container *viewsContainerData) Insert(view View, index int) {
|
|
||||||
if view != nil {
|
if view != nil {
|
||||||
if container.views == nil || index < 0 || index >= len(container.views) {
|
if container.views == nil || index < 0 || index >= len(container.views) {
|
||||||
container.Append(view)
|
return container.append(view)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
htmlID := container.htmlID()
|
view.setParentID(container.htmlID())
|
||||||
view.setParentID(htmlID)
|
|
||||||
if index > 0 {
|
if index > 0 {
|
||||||
container.views = append(container.views[:index], append([]View{view}, container.views[index:]...)...)
|
container.views = append(container.views[:index], append([]View{view}, container.views[index:]...)...)
|
||||||
} else {
|
} else {
|
||||||
container.views = append([]View{view}, container.views...)
|
container.views = append([]View{view}, container.views...)
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
if container.created {
|
// Insert inserts a view to the "index" position in the list of a view children
|
||||||
updateInnerHTML(htmlID, container.Session())
|
func (container *viewsContainerData) Insert(view View, index int) {
|
||||||
if listener, ok := container.changeListener[Content]; ok {
|
if container.insert(view, index) && container.created {
|
||||||
listener(container, Content)
|
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 {
|
if container.views == nil {
|
||||||
container.views = []View{}
|
container.views = []View{}
|
||||||
return nil
|
return nil
|
||||||
|
@ -136,8 +140,13 @@ func (container *viewsContainerData) RemoveView(index int) View {
|
||||||
}
|
}
|
||||||
|
|
||||||
view.setParentID("")
|
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())
|
container.Session().callFunc("removeView", view.htmlID())
|
||||||
if listener, ok := container.changeListener[Content]; ok {
|
if listener, ok := container.changeListener[Content]; ok {
|
||||||
listener(container, Content)
|
listener(container, Content)
|
||||||
|
|
Loading…
Reference in New Issue