forked from mbk-lab/rui_orig
2
0
Fork 0

Update viewByID.go

This commit is contained in:
Alexei Anoshenko 2022-05-26 10:18:11 +03:00
parent 9c236ae102
commit eed42fd295
1 changed files with 14 additions and 0 deletions

View File

@ -1,5 +1,7 @@
package rui package rui
import "strings"
// ViewByID return a View with id equal to the argument of the function or nil if there is no such View // ViewByID return a View with id equal to the argument of the function or nil if there is no such View
func ViewByID(rootView View, id string) View { func ViewByID(rootView View, id string) View {
if rootView == nil { if rootView == nil {
@ -9,11 +11,23 @@ func ViewByID(rootView View, id string) View {
if rootView.ID() == id { if rootView.ID() == id {
return rootView return rootView
} }
if container, ok := rootView.(ParanetView); ok { if container, ok := rootView.(ParanetView); ok {
if view := viewByID(container, id); view != nil { if view := viewByID(container, id); view != nil {
return view return view
} }
} }
if index := strings.IndexRune(id, '/'); index > 0 {
if view2 := ViewByID(rootView, id[:index]); view2 != nil {
if view := ViewByID(view2, id[index+1:]); view != nil {
return view
}
return nil
}
return nil
}
ErrorLog(`ViewByID(_, "` + id + `"): View not found`) ErrorLog(`ViewByID(_, "` + id + `"): View not found`)
return nil return nil
} }