forked from mbk-lab/rui_orig
2
0
Fork 0

bug fixing

This commit is contained in:
Alexei Anoshenko 2022-05-17 10:46:00 +03:00
parent 3097f89f5a
commit fcea1c89a3
7 changed files with 67 additions and 39 deletions

View File

@ -538,7 +538,7 @@ func (edit *editViewData) handleCommand(self View, command string, data DataObje
return edit.viewData.handleCommand(self, command, data)
}
// GetText returns a text of the subview.
// GetText returns a text of the EditView subview.
// If the second argument (subviewID) is "" then a text of the first argument (view) is returned.
func GetText(view View, subviewID string) string {
if subviewID != "" {

View File

@ -266,8 +266,17 @@ func GetImageViewSource(view View, subviewID string) string {
// GetImageViewAltText returns an alternative text description of an ImageView subview.
// If the second argument (subviewID) is "" then a left position of the first argument (view) is returned
func GetImageViewAltText(view View, subviewID string) string {
if text, ok := stringProperty(view, AltText, view.Session()); ok {
return text
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if view != nil {
if value := view.getRaw(AltText); value != nil {
if text, ok := value.(string); ok {
text, _ = view.Session().GetString(text)
return text
}
}
}
return ""
}

View File

@ -264,6 +264,7 @@ func (session *sessionData) setContent(content SessionContent, self Session) boo
session.content = content
session.rootView = content.CreateRootView(self)
if session.rootView != nil {
session.rootView.setParentID("ruiRootView")
return true
}
}

View File

@ -29,7 +29,13 @@ func updateCSSStyle(htmlID string, session Session) {
func updateInnerHTML(htmlID string, session Session) {
if !session.ignoreViewUpdates() {
if view := session.viewByHTMLID(htmlID); view != nil {
var view View
if htmlID == "ruiRootView" {
view = session.RootView()
} else {
view = session.viewByHTMLID(htmlID)
}
if view != nil {
script := allocStringBuilder()
defer freeStringBuilder(script)

View File

@ -214,6 +214,11 @@ func (tabsLayout *tabsLayoutData) set(tag string, value interface{}) bool {
tabsLayout.tabCloseListener = listeners
case Current:
if current, ok := value.(int); ok && current < 0 {
tabsLayout.remove(Current)
return true
}
oldCurrent := tabsLayout.currentItem()
if !tabsLayout.setIntProperty(Current, value) {
return false
@ -611,7 +616,6 @@ func (tabsLayout *tabsLayoutData) Append(view View) {
}
defer tabsLayout.propertyChangedEvent(Current)
}
updateInnerHTML(tabsLayout.htmlID(), tabsLayout.session)
}
}
@ -621,7 +625,7 @@ func (tabsLayout *tabsLayoutData) Insert(view View, index int) {
tabsLayout.views = []View{}
}
if view != nil {
if current := tabsLayout.currentItem(); current >= int(index) {
if current := tabsLayout.currentItem(); current >= index {
tabsLayout.properties[Current] = current + 1
defer tabsLayout.propertyChangedEvent(Current)
}
@ -638,40 +642,46 @@ func (tabsLayout *tabsLayoutData) RemoveView(index int) View {
tabsLayout.views = []View{}
return nil
}
i := int(index)
count := len(tabsLayout.views)
if i >= count {
if index < 0 || index >= count {
return nil
}
var view View
if count == 1 {
view = tabsLayout.views[0]
tabsLayout.views = []View{}
for _, listener := range tabsLayout.tabListener {
listener(tabsLayout, 0, 0)
}
tabsLayout.propertyChangedEvent(Current)
} else {
current := tabsLayout.currentItem()
removeCurrent := (i == current)
if i < current || (removeCurrent && i == count-1) {
tabsLayout.properties[Current] = current - 1
for _, listener := range tabsLayout.tabListener {
listener(tabsLayout, current-1, current)
}
defer tabsLayout.propertyChangedEvent(Current)
}
view = tabsLayout.viewsContainerData.RemoveView(index)
}
view := tabsLayout.views[index]
view.setParentID("")
view.SetChangeListener(Title, nil)
view.SetChangeListener(Icon, nil)
view.SetChangeListener(TabCloseButton, nil)
current := tabsLayout.currentItem()
if index < current || (index == current && current > 0) {
current--
}
if len(tabsLayout.views) == 1 {
tabsLayout.views = []View{}
current = -1
} else if index == 0 {
tabsLayout.views = tabsLayout.views[1:]
} else if index == count-1 {
tabsLayout.views = tabsLayout.views[:index]
} else {
tabsLayout.views = append(tabsLayout.views[:index], tabsLayout.views[index+1:]...)
}
updateInnerHTML(tabsLayout.parentHTMLID(), tabsLayout.session)
tabsLayout.propertyChangedEvent(Content)
delete(tabsLayout.properties, Current)
tabsLayout.set(Current, current)
return view
}
func (tabsLayout *tabsLayoutData) currentID() string {
return fmt.Sprintf("%s-%d", tabsLayout.htmlID(), tabsLayout.currentItem())
}
func (tabsLayout *tabsLayoutData) htmlProperties(self View, buffer *strings.Builder) {
tabsLayout.viewsContainerData.htmlProperties(self, buffer)
buffer.WriteString(` data-inactiveTabStyle="`)
@ -679,9 +689,7 @@ func (tabsLayout *tabsLayoutData) htmlProperties(self View, buffer *strings.Buil
buffer.WriteString(`" data-activeTabStyle="`)
buffer.WriteString(tabsLayout.activeTabStyle())
buffer.WriteString(`" data-current="`)
buffer.WriteString(tabsLayout.htmlID())
buffer.WriteRune('-')
buffer.WriteString(strconv.Itoa(tabsLayout.currentItem()))
buffer.WriteString(tabsLayout.currentID())
buffer.WriteRune('"')
}

View File

@ -141,12 +141,11 @@ func textToJS(text string) string {
}
func (textView *textViewData) htmlSubviews(self View, buffer *strings.Builder) {
if value, ok := stringProperty(textView, Text, textView.Session()); ok {
if !GetNotTranslate(textView, "") {
value, _ = textView.session.GetString(value)
if value := textView.getRaw(Text); value != nil {
if text, ok := value.(string); ok {
text, _ = textView.session.GetString(text)
buffer.WriteString(textToJS(text))
}
buffer.WriteString(textToJS(value))
}
}

View File

@ -44,7 +44,12 @@ func (container *viewsContainerData) Views() []View {
if container.views == nil {
container.views = []View{}
}
return container.views
if count := len(container.views); count > 0 {
views := make([]View, count)
copy(views, container.views)
return views
}
return []View{}
}
// Append appends a view to the end of the list of a view children