forked from mbk-lab/rui_orig
2
0
Fork 0
rui/customView.go

286 lines
8.3 KiB
Go
Raw Normal View History

2021-09-07 17:36:50 +03:00
package rui
import "strings"
// CustomView defines a custom view interface
type CustomView interface {
ViewsContainer
CreateSuperView(session Session) View
SuperView() View
setSuperView(view View)
setTag(tag string)
}
// CustomViewData defines a data of a basic custom view
type CustomViewData struct {
tag string
superView View
}
// InitCustomView initializes fields of CustomView by default values
func InitCustomView(customView CustomView, tag string, session Session, params Params) bool {
customView.setTag(tag)
if view := customView.CreateSuperView(session); view != nil {
customView.setSuperView(view)
setInitParams(customView, params)
} else {
ErrorLog(`nil SuperView of "` + tag + `" view`)
return false
}
return true
}
// SuperView returns a super view
func (customView *CustomViewData) SuperView() View {
return customView.superView
}
func (customView *CustomViewData) setSuperView(view View) {
customView.superView = view
}
func (customView *CustomViewData) setTag(tag string) {
customView.tag = tag
}
// Get returns a value of the property with name defined by the argument.
// The type of return value depends on the property. If the property is not set then nil is returned.
2022-07-26 18:36:00 +03:00
func (customView *CustomViewData) Get(tag string) any {
2021-09-07 17:36:50 +03:00
return customView.superView.Get(tag)
}
2022-07-26 18:36:00 +03:00
func (customView *CustomViewData) getRaw(tag string) any {
2021-09-07 17:36:50 +03:00
return customView.superView.getRaw(tag)
}
2022-07-26 18:36:00 +03:00
func (customView *CustomViewData) setRaw(tag string, value any) {
2021-09-07 17:36:50 +03:00
customView.superView.setRaw(tag, value)
}
// Set sets the value (second argument) of the property with name defined by the first argument.
// Return "true" if the value has been set, in the opposite case "false" are returned and
// a description of the error is written to the log
2022-07-26 18:36:00 +03:00
func (customView *CustomViewData) Set(tag string, value any) bool {
2021-09-07 17:36:50 +03:00
return customView.superView.Set(tag, value)
}
2022-07-26 18:36:00 +03:00
func (customView *CustomViewData) SetAnimated(tag string, value any, animation Animation) bool {
2021-09-07 17:36:50 +03:00
return customView.superView.SetAnimated(tag, value, animation)
}
func (customView *CustomViewData) SetChangeListener(tag string, listener func(View, string)) {
customView.superView.SetChangeListener(tag, listener)
}
2021-09-07 17:36:50 +03:00
// Remove removes the property with name defined by the argument
func (customView *CustomViewData) Remove(tag string) {
customView.superView.Remove(tag)
}
// AllTags returns an array of the set properties
func (customView *CustomViewData) AllTags() []string {
return customView.superView.AllTags()
}
// Clear removes all properties
func (customView *CustomViewData) Clear() {
customView.superView.Clear()
}
// Init initializes fields of View by default values
func (customView *CustomViewData) Init(session Session) {
}
2022-05-22 12:54:02 +03:00
func (customView *CustomViewData) cssViewStyle(buffer cssBuilder, session Session) {
customView.superView.cssViewStyle(buffer, session)
}
2021-09-07 17:36:50 +03:00
// Session returns a current Session interface
func (customView *CustomViewData) Session() Session {
return customView.superView.Session()
}
// Parent returns a parent view
func (customView *CustomViewData) Parent() View {
return customView.superView.Parent()
}
func (customView *CustomViewData) parentHTMLID() string {
return customView.superView.parentHTMLID()
}
func (customView *CustomViewData) setParentID(parentID string) {
customView.superView.setParentID(parentID)
}
// Tag returns a tag of View interface
func (customView *CustomViewData) Tag() string {
if customView.tag != "" {
return customView.tag
}
return customView.superView.Tag()
}
// ID returns a id of the view
func (customView *CustomViewData) ID() string {
return customView.superView.ID()
}
// Focusable returns true if the view receives the focus
func (customView *CustomViewData) Focusable() bool {
return customView.superView.Focusable()
}
/*
// SetTransitionEndListener sets the new listener of the transition end event
func (customView *CustomViewData) SetTransitionEndListener(property string, listener TransitionEndListener) {
customView.superView.SetTransitionEndListener(property, listener)
}
// SetTransitionEndFunc sets the new listener function of the transition end event
func (customView *CustomViewData) SetTransitionEndFunc(property string, listenerFunc func(View, string)) {
customView.superView.SetTransitionEndFunc(property, listenerFunc)
}
*/
// Frame returns a location and size of the view in pixels
func (customView *CustomViewData) Frame() Frame {
return customView.superView.Frame()
}
func (customView *CustomViewData) Scroll() Frame {
return customView.superView.Scroll()
}
func (customView *CustomViewData) HasFocus() bool {
return customView.superView.HasFocus()
}
2021-09-07 17:36:50 +03:00
func (customView *CustomViewData) onResize(self View, x, y, width, height float64) {
customView.superView.onResize(customView.superView, x, y, width, height)
}
func (customView *CustomViewData) onItemResize(self View, index string, x, y, width, height float64) {
2021-09-07 17:36:50 +03:00
customView.superView.onItemResize(customView.superView, index, x, y, width, height)
}
func (customView *CustomViewData) handleCommand(self View, command string, data DataObject) bool {
return customView.superView.handleCommand(customView.superView, command, data)
}
func (customView *CustomViewData) htmlClass(disabled bool) string {
return customView.superView.htmlClass(disabled)
}
func (customView *CustomViewData) htmlTag() string {
return customView.superView.htmlTag()
}
func (customView *CustomViewData) closeHTMLTag() bool {
return customView.superView.closeHTMLTag()
}
func (customView *CustomViewData) htmlID() string {
return customView.superView.htmlID()
}
func (customView *CustomViewData) htmlSubviews(self View, buffer *strings.Builder) {
customView.superView.htmlSubviews(customView.superView, buffer)
}
func (customView *CustomViewData) htmlProperties(self View, buffer *strings.Builder) {
customView.superView.htmlProperties(customView.superView, buffer)
}
func (customView *CustomViewData) htmlDisabledProperties(self View, buffer *strings.Builder) {
customView.superView.htmlDisabledProperties(customView.superView, buffer)
}
func (customView *CustomViewData) cssStyle(self View, builder cssBuilder) {
customView.superView.cssStyle(customView.superView, builder)
}
func (customView *CustomViewData) addToCSSStyle(addCSS map[string]string) {
customView.superView.addToCSSStyle(addCSS)
}
func (customView *CustomViewData) setNoResizeEvent() {
customView.superView.setNoResizeEvent()
}
func (customView *CustomViewData) isNoResizeEvent() bool {
return customView.superView.isNoResizeEvent()
}
// Views return a list of child views
func (customView *CustomViewData) Views() []View {
if customView.superView != nil {
if container, ok := customView.superView.(ViewsContainer); ok {
return container.Views()
}
}
return []View{}
}
// Append appends a view to the end of the list of a view children
func (customView *CustomViewData) Append(view View) {
if customView.superView != nil {
if container, ok := customView.superView.(ViewsContainer); ok {
container.Append(view)
}
}
}
// Insert inserts a view to the "index" position in the list of a view children
func (customView *CustomViewData) Insert(view View, index int) {
2021-09-07 17:36:50 +03:00
if customView.superView != nil {
if container, ok := customView.superView.(ViewsContainer); ok {
container.Insert(view, index)
}
}
}
// Remove removes a view from the list of a view children and return it
func (customView *CustomViewData) RemoveView(index int) View {
2021-09-07 17:36:50 +03:00
if customView.superView != nil {
if container, ok := customView.superView.(ViewsContainer); ok {
return container.RemoveView(index)
}
}
return nil
}
func (customView *CustomViewData) String() string {
if customView.superView != nil {
2022-05-22 12:54:02 +03:00
return getViewString(customView)
2021-09-07 17:36:50 +03:00
}
return customView.tag + " { }"
}
func (customView *CustomViewData) setScroll(x, y, width, height float64) {
if customView.superView != nil {
customView.superView.setScroll(x, y, width, height)
}
}
2022-08-10 15:36:38 +03:00
func (customView *CustomViewData) Transition(tag string) Animation {
if customView.superView != nil {
2022-08-10 15:36:38 +03:00
return customView.superView.Transition(tag)
}
return nil
}
func (customView *CustomViewData) Transitions() map[string]Animation {
if customView.superView != nil {
return customView.superView.Transitions()
}
return map[string]Animation{}
}
func (customView *CustomViewData) SetTransition(tag string, animation Animation) {
if customView.superView != nil {
customView.superView.SetTransition(tag, animation)
}
}