diff --git a/CHANGELOG.md b/CHANGELOG.md index fe90c94..fcc9d67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# v0.18.0 +Added SetParams method to View interface + # v0.17.0 * Added "mod", "rem", "round", "round-up", "round-down", and "round-to-zero" SizeFunc functions * Added ModSize, RemSize, RoundSize, RoundUpSize, RoundDownSize, and RoundToZeroSize functions diff --git a/app_scripts.js b/app_scripts.js index 5b91d49..0df4222 100644 --- a/app_scripts.js +++ b/app_scripts.js @@ -251,22 +251,22 @@ function activateTab(layoutId, tabNumber) { if (element) { const currentNumber = element.getAttribute("data-current"); if (currentNumber != tabNumber) { - function setTab(number, styleProperty, display) { + function setTab(number, styleProperty, visibility) { const tab = document.getElementById(layoutId + '-' + number); if (tab) { tab.className = element.getAttribute(styleProperty); const page = document.getElementById(tab.getAttribute("data-view")); if (page) { - page.style.display = display; + page.style.visibility = visibility } return } const page = document.getElementById(layoutId + "-page" + number); if (page) { - page.style.display = display; + page.style.visibility = visibility } } - setTab(currentNumber, "data-inactiveTabStyle", "none") + setTab(currentNumber, "data-inactiveTabStyle", "hidden") setTab(tabNumber, "data-activeTabStyle", ""); element.setAttribute("data-current", tabNumber); scanElementsSize() diff --git a/customView.go b/customView.go index 1c00e24..725406e 100644 --- a/customView.go +++ b/customView.go @@ -83,6 +83,10 @@ func (customView *CustomViewData) SetAnimated(tag string, value any, animation A return customView.superView.SetAnimated(tag, value, animation) } +func (customView *CustomViewData) SetParams(params Params) bool { + return customView.superView.SetParams(params) +} + // SetChangeListener set the function to track the change of the View property func (customView *CustomViewData) SetChangeListener(tag string, listener func(View, string)) { customView.superView.SetChangeListener(tag, listener) diff --git a/tabsLayout.go b/tabsLayout.go index e30f02d..9f99dea 100644 --- a/tabsLayout.go +++ b/tabsLayout.go @@ -38,8 +38,8 @@ const ( // TabCloseButton is the constant for "tab-close-button" property tag. // // Used by `TabsLayout`. - // Controls whether to add close button to a tab(s). This property can be set separately for each child view or for tabs - // layout itself. Property set for child view takes precedence over the value set for tabs layout. Default value is + // Controls whether to add close button to a tab(s). This property can be set separately for each child view or for tabs + // layout itself. Property set for child view takes precedence over the value set for tabs layout. Default value is // `false`. // // Supported types: `bool`, `int`, `string`. @@ -103,7 +103,7 @@ const ( // CurrentTabStyle is the constant for "current-tab-style" property tag. // // Used by `TabsLayout`. - // Set the style for the display of the current(selected) tab. The default value is "ruiCurrentTab" or + // Set the style for the display of the current(selected) tab. The default value is "ruiCurrentTab" or // "ruiCurrentVerticalTab". // // Supported types: `string`. @@ -925,24 +925,24 @@ func (tabsLayout *tabsLayoutData) htmlSubviews(self View, buffer *strings.Builde buffer.WriteString(`-page`) buffer.WriteString(strconv.Itoa(n)) + if current != n { + buffer.WriteString(`" style="display: grid; align-items: stretch; justify-items: stretch; visibility: hidden; `) + } else { + buffer.WriteString(`" style="display: grid; align-items: stretch; justify-items: stretch; `) + } + switch location { case LeftTabs, LeftListTabs: - buffer.WriteString(`" style="position: relative; grid-row-start: 1; grid-row-end: 2; grid-column-start: 2; grid-column-end: 3;`) + buffer.WriteString(`grid-row-start: 1; grid-row-end: 2; grid-column-start: 2; grid-column-end: 3;">`) case TopTabs: - buffer.WriteString(`" style="position: relative; grid-row-start: 2; grid-row-end: 3; grid-column-start: 1; grid-column-end: 2;`) + buffer.WriteString(`grid-row-start: 2; grid-row-end: 3; grid-column-start: 1; grid-column-end: 2;">`) default: - buffer.WriteString(`" style="position: relative; grid-row-start: 1; grid-row-end: 2; grid-column-start: 1; grid-column-end: 2;`) + buffer.WriteString(`grid-row-start: 1; grid-row-end: 2; grid-column-start: 1; grid-column-end: 2;">`) } - if current != n { - buffer.WriteString(` display: none;`) - } - buffer.WriteString(`">`) - - view.addToCSSStyle(map[string]string{`position`: `absolute`, `left`: `0`, `right`: `0`, `top`: `0`, `bottom`: `0`}) - viewHTML(tabsLayout.views[n], buffer) + viewHTML(view, buffer) buffer.WriteString(``) } } diff --git a/view.go b/view.go index f53c8d0..59673b9 100644 --- a/view.go +++ b/view.go @@ -54,6 +54,11 @@ type View interface { // Scroll returns the location size of the scrollable view in pixels Scroll() Frame + // SetParams sets properties with name "tag" of the "rootView" subview. Result: + // * true - all properties were set successful, + // * false - error (incompatible type or invalid format of a string value, see AppLog). + SetParams(params Params) bool + // SetAnimated 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 @@ -423,6 +428,24 @@ func (view *viewData) set(tag string, value any) bool { return true } +func (view *viewData) SetParams(params Params) bool { + if params == nil { + errorLog("Argument of function SetParams is nil") + return false + } + + session := view.Session() + session.startUpdateScript(view.htmlID()) + result := true + for _, tag := range params.AllTags() { + if value, ok := params[tag]; ok { + result = view.Set(tag, value) && result + } + } + session.finishUpdateScript(view.htmlID()) + return result +} + func viewPropertyChanged(view *viewData, tag string) { if view.updateTransformProperty(tag) { return diff --git a/viewUtils.go b/viewUtils.go index d327896..d8e942a 100644 --- a/viewUtils.go +++ b/viewUtils.go @@ -57,9 +57,15 @@ func SetParams(rootView View, viewID string, params Params) bool { session := rootView.Session() session.startUpdateScript(rootView.htmlID()) result := true - for tag, value := range params { - result = rootView.Set(tag, value) && result + //for tag, value := range params { + // result = rootView.Set(tag, value) && result + //} + for _, tag := range params.AllTags() { + if value, ok := params[tag]; ok { + result = rootView.Set(tag, value) && result + } } + session.finishUpdateScript(rootView.htmlID()) return result }