2021-09-07 17:36:50 +03:00
|
|
|
package rui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Frame - the location and size of a rectangle area
|
|
|
|
type Frame struct {
|
|
|
|
// Left - the left border
|
|
|
|
Left float64
|
|
|
|
// Top - the top border
|
|
|
|
Top float64
|
|
|
|
// Width - the width of a rectangle area
|
|
|
|
Width float64
|
|
|
|
// Height - the height of a rectangle area
|
|
|
|
Height float64
|
|
|
|
}
|
|
|
|
|
|
|
|
// Right returns the right border
|
|
|
|
func (frame Frame) Right() float64 {
|
|
|
|
return frame.Left + frame.Width
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bottom returns the bottom border
|
|
|
|
func (frame Frame) Bottom() float64 {
|
|
|
|
return frame.Top + frame.Height
|
|
|
|
}
|
|
|
|
|
2024-09-12 14:05:11 +03:00
|
|
|
// View represents a base view interface
|
2021-09-07 17:36:50 +03:00
|
|
|
type View interface {
|
2022-05-22 12:54:02 +03:00
|
|
|
ViewStyle
|
2021-09-07 17:36:50 +03:00
|
|
|
fmt.Stringer
|
|
|
|
|
|
|
|
// Session returns the current Session interface
|
|
|
|
Session() Session
|
2024-04-23 19:34:36 +03:00
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
// Parent returns the parent view
|
|
|
|
Parent() View
|
2024-04-23 19:34:36 +03:00
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
// Tag returns the tag of View interface
|
|
|
|
Tag() string
|
2024-04-23 19:34:36 +03:00
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
// ID returns the id of the view
|
|
|
|
ID() string
|
2024-04-23 19:34:36 +03:00
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
// Focusable returns true if the view receives the focus
|
|
|
|
Focusable() bool
|
2024-04-23 19:34:36 +03:00
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
// Frame returns the location and size of the view in pixels
|
|
|
|
Frame() Frame
|
2024-04-23 19:34:36 +03:00
|
|
|
|
2022-11-23 15:10:29 +03:00
|
|
|
// Scroll returns the location size of the scrollable view in pixels
|
2021-09-07 17:36:50 +03:00
|
|
|
Scroll() Frame
|
2024-04-23 19:34:36 +03:00
|
|
|
|
2024-09-25 13:45:47 +03:00
|
|
|
// 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
|
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
// 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
|
2022-07-26 18:36:00 +03:00
|
|
|
SetAnimated(tag string, value any, animation Animation) bool
|
2024-04-23 19:34:36 +03:00
|
|
|
|
2021-11-21 18:30:46 +03:00
|
|
|
// SetChangeListener set the function to track the change of the View property
|
2021-11-20 11:15:28 +03:00
|
|
|
SetChangeListener(tag string, listener func(View, string))
|
2024-04-23 19:34:36 +03:00
|
|
|
|
2022-01-15 01:20:04 +03:00
|
|
|
// HasFocus returns 'true' if the view has focus
|
|
|
|
HasFocus() bool
|
2021-11-20 11:15:28 +03:00
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
handleCommand(self View, command string, data DataObject) bool
|
|
|
|
htmlClass(disabled bool) string
|
|
|
|
htmlTag() string
|
|
|
|
closeHTMLTag() bool
|
|
|
|
htmlID() string
|
2022-09-01 11:04:50 +03:00
|
|
|
parentHTMLID() string
|
|
|
|
setParentID(parentID string)
|
2021-09-07 17:36:50 +03:00
|
|
|
htmlSubviews(self View, buffer *strings.Builder)
|
|
|
|
htmlProperties(self View, buffer *strings.Builder)
|
|
|
|
cssStyle(self View, builder cssBuilder)
|
|
|
|
addToCSSStyle(addCSS map[string]string)
|
2024-05-02 15:07:57 +03:00
|
|
|
exscludeTags() []string
|
2021-09-07 17:36:50 +03:00
|
|
|
|
|
|
|
onResize(self View, x, y, width, height float64)
|
2022-01-15 01:20:04 +03:00
|
|
|
onItemResize(self View, index string, x, y, width, height float64)
|
2021-09-07 17:36:50 +03:00
|
|
|
setNoResizeEvent()
|
|
|
|
isNoResizeEvent() bool
|
|
|
|
setScroll(x, y, width, height float64)
|
|
|
|
}
|
|
|
|
|
|
|
|
// viewData - base implementation of View interface
|
|
|
|
type viewData struct {
|
|
|
|
viewStyle
|
2021-10-04 17:58:17 +03:00
|
|
|
session Session
|
|
|
|
tag string
|
|
|
|
viewID string
|
|
|
|
_htmlID string
|
|
|
|
parentID string
|
|
|
|
systemClass string
|
2021-11-20 11:15:28 +03:00
|
|
|
changeListener map[string]func(View, string)
|
2021-10-04 17:58:17 +03:00
|
|
|
singleTransition map[string]Animation
|
|
|
|
addCSS map[string]string
|
|
|
|
frame Frame
|
|
|
|
scroll Frame
|
|
|
|
noResizeEvent bool
|
|
|
|
created bool
|
2022-01-15 01:20:04 +03:00
|
|
|
hasFocus bool
|
2024-04-23 18:24:51 +03:00
|
|
|
hasHtmlDisabled bool
|
2021-09-07 17:36:50 +03:00
|
|
|
//animation map[string]AnimationEndListener
|
|
|
|
}
|
|
|
|
|
|
|
|
func newView(session Session) View {
|
|
|
|
view := new(viewData)
|
2022-09-01 11:04:50 +03:00
|
|
|
view.init(session)
|
2021-09-07 17:36:50 +03:00
|
|
|
return view
|
|
|
|
}
|
|
|
|
|
|
|
|
func setInitParams(view View, params Params) {
|
|
|
|
if params != nil {
|
|
|
|
session := view.Session()
|
|
|
|
if !session.ignoreViewUpdates() {
|
|
|
|
session.setIgnoreViewUpdates(true)
|
|
|
|
defer session.setIgnoreViewUpdates(false)
|
|
|
|
}
|
|
|
|
for _, tag := range params.AllTags() {
|
|
|
|
if value, ok := params[tag]; ok {
|
|
|
|
view.Set(tag, value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewView create new View object and return it
|
|
|
|
func NewView(session Session, params Params) View {
|
|
|
|
view := new(viewData)
|
2022-09-01 11:04:50 +03:00
|
|
|
view.init(session)
|
2021-09-07 17:36:50 +03:00
|
|
|
setInitParams(view, params)
|
|
|
|
return view
|
|
|
|
}
|
|
|
|
|
2022-09-01 11:04:50 +03:00
|
|
|
func (view *viewData) init(session Session) {
|
2021-09-07 17:36:50 +03:00
|
|
|
view.viewStyle.init()
|
|
|
|
view.tag = "View"
|
|
|
|
view.session = session
|
2021-11-20 11:15:28 +03:00
|
|
|
view.changeListener = map[string]func(View, string){}
|
2021-09-07 17:36:50 +03:00
|
|
|
view.addCSS = map[string]string{}
|
|
|
|
//view.animation = map[string]AnimationEndListener{}
|
2021-10-04 17:58:17 +03:00
|
|
|
view.singleTransition = map[string]Animation{}
|
2021-09-07 17:36:50 +03:00
|
|
|
view.noResizeEvent = false
|
|
|
|
view.created = false
|
2024-04-23 18:24:51 +03:00
|
|
|
view.hasHtmlDisabled = false
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (view *viewData) Session() Session {
|
|
|
|
return view.session
|
|
|
|
}
|
|
|
|
|
|
|
|
func (view *viewData) Parent() View {
|
|
|
|
return view.session.viewByHTMLID(view.parentID)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (view *viewData) parentHTMLID() string {
|
|
|
|
return view.parentID
|
|
|
|
}
|
|
|
|
|
|
|
|
func (view *viewData) setParentID(parentID string) {
|
|
|
|
view.parentID = parentID
|
|
|
|
}
|
|
|
|
|
|
|
|
func (view *viewData) Tag() string {
|
|
|
|
return view.tag
|
|
|
|
}
|
|
|
|
|
|
|
|
func (view *viewData) ID() string {
|
|
|
|
return view.viewID
|
|
|
|
}
|
|
|
|
|
|
|
|
func (view *viewData) ViewByID(id string) View {
|
|
|
|
if id == view.ID() {
|
|
|
|
if v := view.session.viewByHTMLID(view.htmlID()); v != nil {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
return view
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (view *viewData) Focusable() bool {
|
2022-04-14 12:05:45 +03:00
|
|
|
if focus, ok := boolProperty(view, Focusable, view.session); ok {
|
|
|
|
return focus
|
|
|
|
}
|
2023-05-02 14:49:35 +03:00
|
|
|
|
|
|
|
if style, ok := stringProperty(view, Style, view.session); ok {
|
|
|
|
if style, ok := view.session.resolveConstants(style); ok {
|
|
|
|
if value := view.session.styleProperty(style, Focusable); ok {
|
|
|
|
if focus, ok := valueToBool(value, view.Session()); ok {
|
|
|
|
return focus
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (view *viewData) Remove(tag string) {
|
|
|
|
view.remove(strings.ToLower(tag))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (view *viewData) remove(tag string) {
|
|
|
|
switch tag {
|
|
|
|
case ID:
|
|
|
|
view.viewID = ""
|
|
|
|
|
2022-12-20 18:38:39 +03:00
|
|
|
case TabIndex, "tab-index":
|
|
|
|
delete(view.properties, tag)
|
|
|
|
if view.Focusable() {
|
|
|
|
view.session.updateProperty(view.htmlID(), "tabindex", "0")
|
|
|
|
} else {
|
|
|
|
view.session.updateProperty(view.htmlID(), "tabindex", "-1")
|
|
|
|
}
|
|
|
|
|
2022-04-14 12:05:45 +03:00
|
|
|
case UserData:
|
|
|
|
delete(view.properties, tag)
|
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
case Style, StyleDisabled:
|
|
|
|
if _, ok := view.properties[tag]; ok {
|
|
|
|
delete(view.properties, tag)
|
2022-10-30 17:22:33 +03:00
|
|
|
view.session.updateProperty(view.htmlID(), "class", view.htmlClass(IsDisabled(view)))
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
case FocusEvent, LostFocusEvent:
|
|
|
|
view.removeFocusListener(tag)
|
|
|
|
|
|
|
|
case KeyDownEvent, KeyUpEvent:
|
|
|
|
view.removeKeyListener(tag)
|
|
|
|
|
|
|
|
case ClickEvent, DoubleClickEvent, MouseDown, MouseUp, MouseMove, MouseOut, MouseOver, ContextMenuEvent:
|
|
|
|
view.removeMouseListener(tag)
|
|
|
|
|
|
|
|
case PointerDown, PointerUp, PointerMove, PointerOut, PointerOver, PointerCancel:
|
|
|
|
view.removePointerListener(tag)
|
|
|
|
|
|
|
|
case TouchStart, TouchEnd, TouchMove, TouchCancel:
|
|
|
|
view.removeTouchListener(tag)
|
|
|
|
|
2021-10-04 17:58:17 +03:00
|
|
|
case TransitionRunEvent, TransitionStartEvent, TransitionEndEvent, TransitionCancelEvent:
|
|
|
|
view.removeTransitionListener(tag)
|
|
|
|
|
|
|
|
case AnimationStartEvent, AnimationEndEvent, AnimationIterationEvent, AnimationCancelEvent:
|
|
|
|
view.removeAnimationListener(tag)
|
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
case ResizeEvent, ScrollEvent:
|
|
|
|
delete(view.properties, tag)
|
|
|
|
|
|
|
|
case Content:
|
|
|
|
if _, ok := view.properties[Content]; ok {
|
|
|
|
delete(view.properties, Content)
|
|
|
|
updateInnerHTML(view.htmlID(), view.session)
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
view.viewStyle.remove(tag)
|
2021-11-20 11:15:28 +03:00
|
|
|
viewPropertyChanged(view, tag)
|
|
|
|
}
|
|
|
|
|
|
|
|
view.propertyChangedEvent(tag)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (view *viewData) propertyChangedEvent(tag string) {
|
|
|
|
if listener, ok := view.changeListener[tag]; ok {
|
|
|
|
listener(view, tag)
|
|
|
|
}
|
|
|
|
|
|
|
|
switch tag {
|
|
|
|
case BorderLeft, BorderRight, BorderTop, BorderBottom,
|
|
|
|
BorderStyle, BorderLeftStyle, BorderRightStyle, BorderTopStyle, BorderBottomStyle,
|
|
|
|
BorderColor, BorderLeftColor, BorderRightColor, BorderTopColor, BorderBottomColor,
|
|
|
|
BorderWidth, BorderLeftWidth, BorderRightWidth, BorderTopWidth, BorderBottomWidth:
|
|
|
|
tag = Border
|
|
|
|
|
|
|
|
case CellBorderStyle, CellBorderColor, CellBorderWidth,
|
|
|
|
CellBorderLeft, CellBorderLeftStyle, CellBorderLeftColor, CellBorderLeftWidth,
|
|
|
|
CellBorderRight, CellBorderRightStyle, CellBorderRightColor, CellBorderRightWidth,
|
|
|
|
CellBorderTop, CellBorderTopStyle, CellBorderTopColor, CellBorderTopWidth,
|
|
|
|
CellBorderBottom, CellBorderBottomStyle, CellBorderBottomColor, CellBorderBottomWidth:
|
|
|
|
tag = CellBorder
|
|
|
|
|
|
|
|
case OutlineColor, OutlineStyle, OutlineWidth:
|
|
|
|
tag = Outline
|
|
|
|
|
|
|
|
case RadiusX, RadiusY, RadiusTopLeft, RadiusTopLeftX, RadiusTopLeftY,
|
|
|
|
RadiusTopRight, RadiusTopRightX, RadiusTopRightY,
|
|
|
|
RadiusBottomLeft, RadiusBottomLeftX, RadiusBottomLeftY,
|
|
|
|
RadiusBottomRight, RadiusBottomRightX, RadiusBottomRightY:
|
|
|
|
tag = Radius
|
|
|
|
|
|
|
|
case MarginTop, MarginRight, MarginBottom, MarginLeft,
|
|
|
|
"top-margin", "right-margin", "bottom-margin", "left-margin":
|
|
|
|
tag = Margin
|
|
|
|
|
|
|
|
case PaddingTop, PaddingRight, PaddingBottom, PaddingLeft,
|
|
|
|
"top-padding", "right-padding", "bottom-padding", "left-padding":
|
|
|
|
tag = Padding
|
|
|
|
|
|
|
|
case CellPaddingTop, CellPaddingRight, CellPaddingBottom, CellPaddingLeft:
|
|
|
|
tag = CellPadding
|
|
|
|
|
|
|
|
case ColumnSeparatorStyle, ColumnSeparatorWidth, ColumnSeparatorColor:
|
|
|
|
tag = ColumnSeparator
|
|
|
|
|
|
|
|
default:
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if listener, ok := view.changeListener[tag]; ok {
|
|
|
|
listener(view, tag)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-26 18:36:00 +03:00
|
|
|
func (view *viewData) Set(tag string, value any) bool {
|
2021-09-07 17:36:50 +03:00
|
|
|
return view.set(strings.ToLower(tag), value)
|
|
|
|
}
|
|
|
|
|
2022-07-26 18:36:00 +03:00
|
|
|
func (view *viewData) set(tag string, value any) bool {
|
2021-09-07 17:36:50 +03:00
|
|
|
if value == nil {
|
|
|
|
view.remove(tag)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-11-20 11:15:28 +03:00
|
|
|
result := func(res bool) bool {
|
|
|
|
if res {
|
|
|
|
view.propertyChangedEvent(tag)
|
|
|
|
}
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
switch tag {
|
|
|
|
case ID:
|
2021-11-20 11:15:28 +03:00
|
|
|
text, ok := value.(string)
|
|
|
|
if !ok {
|
|
|
|
notCompatibleType(ID, value)
|
|
|
|
return false
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
2021-11-20 11:15:28 +03:00
|
|
|
view.viewID = text
|
2021-09-07 17:36:50 +03:00
|
|
|
|
2024-07-01 19:17:03 +03:00
|
|
|
case AnimationTag:
|
|
|
|
oldAnimations := []Animation{}
|
|
|
|
if val, ok := view.properties[AnimationTag]; ok && val != nil {
|
|
|
|
if animation, ok := val.([]Animation); ok {
|
|
|
|
oldAnimations = animation
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !view.setAnimation(tag, value) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, animation := range oldAnimations {
|
|
|
|
animation.unused(view.session)
|
|
|
|
}
|
|
|
|
if view.created {
|
|
|
|
viewPropertyChanged(view, tag)
|
|
|
|
}
|
|
|
|
|
2022-12-20 18:38:39 +03:00
|
|
|
case TabIndex, "tab-index":
|
|
|
|
if !view.setIntProperty(tag, value) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if value, ok := intProperty(view, TabIndex, view.Session(), 0); ok {
|
|
|
|
view.session.updateProperty(view.htmlID(), "tabindex", strconv.Itoa(value))
|
|
|
|
} else if view.Focusable() {
|
|
|
|
view.session.updateProperty(view.htmlID(), "tabindex", "0")
|
|
|
|
} else {
|
|
|
|
view.session.updateProperty(view.htmlID(), "tabindex", "-1")
|
|
|
|
}
|
|
|
|
|
2022-04-14 12:05:45 +03:00
|
|
|
case UserData:
|
|
|
|
view.properties[tag] = value
|
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
case Style, StyleDisabled:
|
2021-11-20 11:15:28 +03:00
|
|
|
text, ok := value.(string)
|
|
|
|
if !ok {
|
|
|
|
notCompatibleType(ID, value)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
view.properties[tag] = text
|
|
|
|
if view.created {
|
2022-10-30 17:22:33 +03:00
|
|
|
view.session.updateProperty(view.htmlID(), "class", view.htmlClass(IsDisabled(view)))
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
case FocusEvent, LostFocusEvent:
|
2021-11-20 11:15:28 +03:00
|
|
|
return result(view.setFocusListener(tag, value))
|
2021-09-07 17:36:50 +03:00
|
|
|
|
|
|
|
case KeyDownEvent, KeyUpEvent:
|
2021-11-20 11:15:28 +03:00
|
|
|
return result(view.setKeyListener(tag, value))
|
2021-09-07 17:36:50 +03:00
|
|
|
|
|
|
|
case ClickEvent, DoubleClickEvent, MouseDown, MouseUp, MouseMove, MouseOut, MouseOver, ContextMenuEvent:
|
2021-11-20 11:15:28 +03:00
|
|
|
return result(view.setMouseListener(tag, value))
|
2021-09-07 17:36:50 +03:00
|
|
|
|
|
|
|
case PointerDown, PointerUp, PointerMove, PointerOut, PointerOver, PointerCancel:
|
2021-11-20 11:15:28 +03:00
|
|
|
return result(view.setPointerListener(tag, value))
|
2021-09-07 17:36:50 +03:00
|
|
|
|
|
|
|
case TouchStart, TouchEnd, TouchMove, TouchCancel:
|
2021-11-20 11:15:28 +03:00
|
|
|
return result(view.setTouchListener(tag, value))
|
2021-09-07 17:36:50 +03:00
|
|
|
|
2021-10-04 17:58:17 +03:00
|
|
|
case TransitionRunEvent, TransitionStartEvent, TransitionEndEvent, TransitionCancelEvent:
|
2021-11-20 11:15:28 +03:00
|
|
|
return result(view.setTransitionListener(tag, value))
|
2021-10-04 17:58:17 +03:00
|
|
|
|
|
|
|
case AnimationStartEvent, AnimationEndEvent, AnimationIterationEvent, AnimationCancelEvent:
|
2021-11-20 11:15:28 +03:00
|
|
|
return result(view.setAnimationListener(tag, value))
|
2021-10-04 17:58:17 +03:00
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
case ResizeEvent, ScrollEvent:
|
2021-11-20 11:15:28 +03:00
|
|
|
return result(view.setFrameListener(tag, value))
|
2021-09-07 17:36:50 +03:00
|
|
|
|
2021-11-20 11:15:28 +03:00
|
|
|
default:
|
|
|
|
if !view.viewStyle.set(tag, value) {
|
|
|
|
return false
|
|
|
|
}
|
2021-09-07 17:36:50 +03:00
|
|
|
if view.created {
|
2021-11-20 11:15:28 +03:00
|
|
|
viewPropertyChanged(view, tag)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-20 11:15:28 +03:00
|
|
|
view.propertyChangedEvent(tag)
|
|
|
|
return true
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
2024-09-25 13:45:47 +03:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2021-11-20 11:15:28 +03:00
|
|
|
func viewPropertyChanged(view *viewData, tag string) {
|
2021-09-07 17:36:50 +03:00
|
|
|
if view.updateTransformProperty(tag) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
htmlID := view.htmlID()
|
|
|
|
session := view.session
|
|
|
|
|
|
|
|
switch tag {
|
|
|
|
case Disabled:
|
2024-04-23 18:24:51 +03:00
|
|
|
tabIndex := GetTabIndex(view, htmlID)
|
|
|
|
enabledClass := view.htmlClass(false)
|
|
|
|
disabledClass := view.htmlClass(true)
|
|
|
|
session.startUpdateScript(htmlID)
|
|
|
|
if IsDisabled(view) {
|
|
|
|
session.updateProperty(htmlID, "data-disabled", "1")
|
|
|
|
if view.hasHtmlDisabled {
|
|
|
|
session.updateProperty(htmlID, "disabled", true)
|
|
|
|
}
|
|
|
|
if tabIndex >= 0 {
|
|
|
|
session.updateProperty(htmlID, "tabindex", -1)
|
|
|
|
}
|
|
|
|
if enabledClass != disabledClass {
|
|
|
|
session.updateProperty(htmlID, "class", disabledClass)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
session.updateProperty(htmlID, "data-disabled", "0")
|
|
|
|
if view.hasHtmlDisabled {
|
|
|
|
session.removeProperty(htmlID, "disabled")
|
|
|
|
}
|
|
|
|
if tabIndex >= 0 {
|
|
|
|
session.updateProperty(htmlID, "tabindex", tabIndex)
|
|
|
|
}
|
|
|
|
if enabledClass != disabledClass {
|
|
|
|
session.updateProperty(htmlID, "class", enabledClass)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
session.finishUpdateScript(htmlID)
|
|
|
|
updateInnerHTML(htmlID, session)
|
2022-03-31 19:59:10 +03:00
|
|
|
return
|
|
|
|
|
|
|
|
case Visibility:
|
2022-08-31 22:17:46 +03:00
|
|
|
switch GetVisibility(view) {
|
2022-03-31 19:59:10 +03:00
|
|
|
case Invisible:
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, Visibility, "hidden")
|
|
|
|
session.updateCSSProperty(htmlID, "display", "")
|
2023-05-07 20:58:51 +03:00
|
|
|
session.callFunc("hideTooltip")
|
2022-03-31 19:59:10 +03:00
|
|
|
|
|
|
|
case Gone:
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, Visibility, "hidden")
|
|
|
|
session.updateCSSProperty(htmlID, "display", "none")
|
2023-05-07 20:58:51 +03:00
|
|
|
session.callFunc("hideTooltip")
|
2022-03-31 19:59:10 +03:00
|
|
|
|
|
|
|
default:
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, Visibility, "visible")
|
|
|
|
session.updateCSSProperty(htmlID, "display", "")
|
2022-03-31 19:59:10 +03:00
|
|
|
}
|
|
|
|
return
|
2021-09-07 17:36:50 +03:00
|
|
|
|
|
|
|
case Background:
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, Background, view.backgroundCSS(session))
|
2021-09-07 17:36:50 +03:00
|
|
|
return
|
|
|
|
|
|
|
|
case Border:
|
|
|
|
if getBorder(view, Border) == nil {
|
2022-10-31 16:07:59 +03:00
|
|
|
if session.startUpdateScript(htmlID) {
|
|
|
|
defer session.finishUpdateScript(htmlID)
|
2022-07-22 13:10:55 +03:00
|
|
|
}
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, BorderWidth, "")
|
|
|
|
session.updateCSSProperty(htmlID, BorderColor, "")
|
|
|
|
session.updateCSSProperty(htmlID, BorderStyle, "none")
|
2021-09-07 17:36:50 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
|
|
|
|
case BorderLeft, BorderRight, BorderTop, BorderBottom:
|
|
|
|
if border := getBorder(view, Border); border != nil {
|
2022-10-31 16:07:59 +03:00
|
|
|
if session.startUpdateScript(htmlID) {
|
|
|
|
defer session.finishUpdateScript(htmlID)
|
2022-07-22 13:10:55 +03:00
|
|
|
}
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, BorderWidth, border.cssWidthValue(session))
|
|
|
|
session.updateCSSProperty(htmlID, BorderColor, border.cssColorValue(session))
|
|
|
|
session.updateCSSProperty(htmlID, BorderStyle, border.cssStyleValue(session))
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
return
|
|
|
|
|
|
|
|
case BorderStyle, BorderLeftStyle, BorderRightStyle, BorderTopStyle, BorderBottomStyle:
|
|
|
|
if border := getBorder(view, Border); border != nil {
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, BorderStyle, border.cssStyleValue(session))
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
return
|
|
|
|
|
|
|
|
case BorderColor, BorderLeftColor, BorderRightColor, BorderTopColor, BorderBottomColor:
|
|
|
|
if border := getBorder(view, Border); border != nil {
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, BorderColor, border.cssColorValue(session))
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
return
|
|
|
|
|
|
|
|
case BorderWidth, BorderLeftWidth, BorderRightWidth, BorderTopWidth, BorderBottomWidth:
|
|
|
|
if border := getBorder(view, Border); border != nil {
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, BorderWidth, border.cssWidthValue(session))
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
return
|
|
|
|
|
|
|
|
case Outline, OutlineColor, OutlineStyle, OutlineWidth:
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, Outline, GetOutline(view).cssString(session))
|
2021-09-07 17:36:50 +03:00
|
|
|
return
|
|
|
|
|
|
|
|
case Shadow:
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, "box-shadow", shadowCSS(view, Shadow, session))
|
2021-09-07 17:36:50 +03:00
|
|
|
return
|
|
|
|
|
|
|
|
case TextShadow:
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, "text-shadow", shadowCSS(view, TextShadow, session))
|
2021-09-07 17:36:50 +03:00
|
|
|
return
|
|
|
|
|
|
|
|
case Radius, RadiusX, RadiusY, RadiusTopLeft, RadiusTopLeftX, RadiusTopLeftY,
|
|
|
|
RadiusTopRight, RadiusTopRightX, RadiusTopRightY,
|
|
|
|
RadiusBottomLeft, RadiusBottomLeftX, RadiusBottomLeftY,
|
|
|
|
RadiusBottomRight, RadiusBottomRightX, RadiusBottomRightY:
|
2022-08-31 22:17:46 +03:00
|
|
|
radius := GetRadius(view)
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, "border-radius", radius.cssString(session))
|
2021-09-07 17:36:50 +03:00
|
|
|
return
|
|
|
|
|
|
|
|
case Margin, MarginTop, MarginRight, MarginBottom, MarginLeft,
|
|
|
|
"top-margin", "right-margin", "bottom-margin", "left-margin":
|
2022-08-31 22:17:46 +03:00
|
|
|
margin := GetMargin(view)
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, Margin, margin.cssString(session))
|
2021-09-07 17:36:50 +03:00
|
|
|
return
|
|
|
|
|
|
|
|
case Padding, PaddingTop, PaddingRight, PaddingBottom, PaddingLeft,
|
|
|
|
"top-padding", "right-padding", "bottom-padding", "left-padding":
|
2022-08-31 22:17:46 +03:00
|
|
|
padding := GetPadding(view)
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, Padding, padding.cssString(session))
|
2021-09-07 17:36:50 +03:00
|
|
|
return
|
|
|
|
|
|
|
|
case AvoidBreak:
|
|
|
|
if avoid, ok := boolProperty(view, AvoidBreak, session); ok {
|
|
|
|
if avoid {
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, "break-inside", "avoid")
|
2021-09-07 17:36:50 +03:00
|
|
|
} else {
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, "break-inside", "auto")
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
|
|
|
|
case Clip:
|
|
|
|
if clip := getClipShape(view, Clip, session); clip != nil && clip.valid(session) {
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, `clip-path`, clip.cssStyle(session))
|
2021-09-07 17:36:50 +03:00
|
|
|
} else {
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, `clip-path`, "none")
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
return
|
|
|
|
|
|
|
|
case ShapeOutside:
|
|
|
|
if clip := getClipShape(view, ShapeOutside, session); clip != nil && clip.valid(session) {
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, ShapeOutside, clip.cssStyle(session))
|
2021-09-07 17:36:50 +03:00
|
|
|
} else {
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, ShapeOutside, "none")
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
return
|
|
|
|
|
|
|
|
case Filter:
|
|
|
|
text := ""
|
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
|
|
|
if value := view.getRaw(tag); value != nil {
|
2021-09-07 17:36:50 +03:00
|
|
|
if filter, ok := value.(ViewFilter); ok {
|
|
|
|
text = filter.cssStyle(session)
|
|
|
|
}
|
|
|
|
}
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, tag, text)
|
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
|
|
|
return
|
|
|
|
|
|
|
|
case BackdropFilter:
|
|
|
|
text := ""
|
|
|
|
if value := view.getRaw(tag); value != nil {
|
|
|
|
if filter, ok := value.(ViewFilter); ok {
|
|
|
|
text = filter.cssStyle(session)
|
|
|
|
}
|
|
|
|
}
|
2022-10-31 16:07:59 +03:00
|
|
|
if session.startUpdateScript(htmlID) {
|
|
|
|
defer session.finishUpdateScript(htmlID)
|
2022-07-22 13:10:55 +03:00
|
|
|
}
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, "-webkit-backdrop-filter", text)
|
|
|
|
session.updateCSSProperty(htmlID, tag, text)
|
2021-09-07 17:36:50 +03:00
|
|
|
return
|
|
|
|
|
|
|
|
case FontName:
|
|
|
|
if font, ok := stringProperty(view, FontName, session); ok {
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, "font-family", font)
|
2021-09-07 17:36:50 +03:00
|
|
|
} else {
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, "font-family", "")
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
return
|
|
|
|
|
|
|
|
case Italic:
|
|
|
|
if state, ok := boolProperty(view, tag, session); ok {
|
|
|
|
if state {
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, "font-style", "italic")
|
2021-09-07 17:36:50 +03:00
|
|
|
} else {
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, "font-style", "normal")
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
} else {
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, "font-style", "")
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
2021-10-04 17:58:17 +03:00
|
|
|
return
|
2021-09-07 17:36:50 +03:00
|
|
|
|
|
|
|
case SmallCaps:
|
|
|
|
if state, ok := boolProperty(view, tag, session); ok {
|
|
|
|
if state {
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, "font-variant", "small-caps")
|
2021-09-07 17:36:50 +03:00
|
|
|
} else {
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, "font-variant", "normal")
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
} else {
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, "font-variant", "")
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
2021-10-04 17:58:17 +03:00
|
|
|
return
|
2021-09-07 17:36:50 +03:00
|
|
|
|
|
|
|
case Strikethrough, Overline, Underline:
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, "text-decoration", view.cssTextDecoration(session))
|
2021-09-07 17:36:50 +03:00
|
|
|
for _, tag2 := range []string{TextLineColor, TextLineStyle, TextLineThickness} {
|
2021-11-20 11:15:28 +03:00
|
|
|
viewPropertyChanged(view, tag2)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
2021-10-04 17:58:17 +03:00
|
|
|
return
|
2021-09-07 17:36:50 +03:00
|
|
|
|
2021-10-04 17:58:17 +03:00
|
|
|
case Transition:
|
|
|
|
view.updateTransitionCSS()
|
|
|
|
return
|
|
|
|
|
|
|
|
case AnimationTag:
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, AnimationTag, view.animationCSS(session))
|
2021-10-04 17:58:17 +03:00
|
|
|
return
|
|
|
|
|
|
|
|
case AnimationPaused:
|
|
|
|
paused, ok := boolProperty(view, AnimationPaused, session)
|
|
|
|
if !ok {
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, `animation-play-state`, ``)
|
2021-10-04 17:58:17 +03:00
|
|
|
} else if paused {
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, `animation-play-state`, `paused`)
|
2021-10-04 17:58:17 +03:00
|
|
|
} else {
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, `animation-play-state`, `running`)
|
2021-10-04 17:58:17 +03:00
|
|
|
}
|
|
|
|
return
|
2022-04-21 18:22:17 +03:00
|
|
|
|
2022-12-18 18:37:36 +03:00
|
|
|
case ZIndex, Order, TabSize:
|
2022-08-20 20:05:56 +03:00
|
|
|
if i, ok := intProperty(view, tag, session, 0); ok {
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, tag, strconv.Itoa(i))
|
2024-04-24 19:26:57 +03:00
|
|
|
} else {
|
|
|
|
session.updateCSSProperty(htmlID, tag, "")
|
2022-04-21 18:22:17 +03:00
|
|
|
}
|
|
|
|
return
|
2022-05-03 12:12:57 +03:00
|
|
|
|
|
|
|
case Row, Column:
|
2022-10-30 17:22:33 +03:00
|
|
|
if parentID := view.parentHTMLID(); parentID != "" {
|
|
|
|
updateInnerHTML(parentID, session)
|
2022-05-03 12:12:57 +03:00
|
|
|
}
|
|
|
|
return
|
2022-07-08 13:16:42 +03:00
|
|
|
|
|
|
|
case UserSelect:
|
2022-10-31 16:07:59 +03:00
|
|
|
if session.startUpdateScript(htmlID) {
|
|
|
|
defer session.finishUpdateScript(htmlID)
|
2022-07-22 13:10:55 +03:00
|
|
|
}
|
2022-07-08 13:16:42 +03:00
|
|
|
if userSelect, ok := boolProperty(view, UserSelect, session); ok {
|
|
|
|
if userSelect {
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, "-webkit-user-select", "auto")
|
|
|
|
session.updateCSSProperty(htmlID, "user-select", "auto")
|
2022-07-08 13:16:42 +03:00
|
|
|
} else {
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, "-webkit-user-select", "none")
|
|
|
|
session.updateCSSProperty(htmlID, "user-select", "none")
|
2022-07-08 13:16:42 +03:00
|
|
|
}
|
|
|
|
} else {
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, "-webkit-user-select", "")
|
|
|
|
session.updateCSSProperty(htmlID, "user-select", "")
|
2022-07-08 13:16:42 +03:00
|
|
|
}
|
|
|
|
return
|
2023-01-03 14:56:57 +03:00
|
|
|
|
|
|
|
case ColumnSpanAll:
|
|
|
|
if spanAll, ok := boolProperty(view, ColumnSpanAll, session); ok && spanAll {
|
|
|
|
session.updateCSSProperty(htmlID, `column-span`, `all`)
|
|
|
|
} else {
|
|
|
|
session.updateCSSProperty(htmlID, `column-span`, `none`)
|
|
|
|
}
|
|
|
|
return
|
2023-04-25 17:20:47 +03:00
|
|
|
|
|
|
|
case Tooltip:
|
|
|
|
if tooltip := GetTooltip(view); tooltip == "" {
|
|
|
|
session.removeProperty(htmlID, "data-tooltip")
|
|
|
|
} else {
|
|
|
|
session.updateProperty(htmlID, "data-tooltip", tooltip)
|
|
|
|
session.updateProperty(htmlID, "onmouseenter", "mouseEnterEvent(this, event)")
|
|
|
|
session.updateProperty(htmlID, "onmouseleave", "mouseLeaveEvent(this, event)")
|
|
|
|
}
|
|
|
|
return
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if cssTag, ok := sizeProperties[tag]; ok {
|
2024-04-24 19:26:57 +03:00
|
|
|
if size, ok := sizeProperty(view, tag, session); ok {
|
|
|
|
session.updateCSSProperty(htmlID, cssTag, size.cssString("", session))
|
|
|
|
} else {
|
|
|
|
session.updateCSSProperty(htmlID, cssTag, "")
|
|
|
|
}
|
2021-09-07 17:36:50 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
colorTags := map[string]string{
|
|
|
|
BackgroundColor: BackgroundColor,
|
|
|
|
TextColor: "color",
|
|
|
|
TextLineColor: "text-decoration-color",
|
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
|
|
|
CaretColor: CaretColor,
|
2022-08-20 19:13:51 +03:00
|
|
|
AccentColor: AccentColor,
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
if cssTag, ok := colorTags[tag]; ok {
|
|
|
|
if color, ok := colorProperty(view, tag, session); ok {
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, cssTag, color.cssString())
|
2021-09-07 17:36:50 +03:00
|
|
|
} else {
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, cssTag, "")
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if valuesData, ok := enumProperties[tag]; ok && valuesData.cssTag != "" {
|
2024-04-24 19:26:57 +03:00
|
|
|
if n, ok := enumProperty(view, tag, session, 0); ok {
|
|
|
|
session.updateCSSProperty(htmlID, valuesData.cssTag, valuesData.cssValues[n])
|
|
|
|
} else {
|
|
|
|
session.updateCSSProperty(htmlID, valuesData.cssTag, "")
|
|
|
|
}
|
2021-09-07 17:36:50 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-04-21 18:22:17 +03:00
|
|
|
for _, floatTag := range []string{Opacity, ScaleX, ScaleY, ScaleZ, RotateX, RotateY, RotateZ} {
|
2021-09-07 17:36:50 +03:00
|
|
|
if tag == floatTag {
|
2022-08-18 18:18:36 +03:00
|
|
|
if f, ok := floatTextProperty(view, floatTag, session, 0); ok {
|
2022-10-30 17:22:33 +03:00
|
|
|
session.updateCSSProperty(htmlID, floatTag, f)
|
2024-04-24 19:26:57 +03:00
|
|
|
} else {
|
|
|
|
session.updateCSSProperty(htmlID, floatTag, "")
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-26 18:36:00 +03:00
|
|
|
func (view *viewData) Get(tag string) any {
|
2021-09-07 17:36:50 +03:00
|
|
|
return view.get(strings.ToLower(tag))
|
|
|
|
}
|
|
|
|
|
2022-07-26 18:36:00 +03:00
|
|
|
func (view *viewData) get(tag string) any {
|
2022-05-22 12:54:02 +03:00
|
|
|
if tag == ID {
|
|
|
|
if view.viewID != "" {
|
|
|
|
return view.viewID
|
|
|
|
} else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
2021-09-07 17:36:50 +03:00
|
|
|
return view.viewStyle.get(tag)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (view *viewData) htmlTag() string {
|
2022-08-31 22:17:46 +03:00
|
|
|
if semantics := GetSemantics(view); semantics > DefaultSemantics {
|
2021-09-07 17:36:50 +03:00
|
|
|
values := enumProperties[Semantics].cssValues
|
|
|
|
if semantics < len(values) {
|
|
|
|
return values[semantics]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "div"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (view *viewData) closeHTMLTag() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (view *viewData) htmlID() string {
|
|
|
|
if view._htmlID == "" {
|
|
|
|
view._htmlID = view.session.nextViewID()
|
|
|
|
}
|
|
|
|
return view._htmlID
|
|
|
|
}
|
|
|
|
|
|
|
|
func (view *viewData) htmlSubviews(self View, buffer *strings.Builder) {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (view *viewData) addToCSSStyle(addCSS map[string]string) {
|
|
|
|
view.addCSS = addCSS
|
|
|
|
}
|
|
|
|
|
|
|
|
func (view *viewData) cssStyle(self View, builder cssBuilder) {
|
2021-10-04 17:58:17 +03:00
|
|
|
view.viewStyle.cssViewStyle(builder, view.session)
|
2024-06-19 16:36:50 +03:00
|
|
|
/*
|
|
|
|
switch GetVisibility(view) {
|
|
|
|
case Invisible:
|
|
|
|
builder.add(`visibility`, `hidden`)
|
2021-09-07 17:36:50 +03:00
|
|
|
|
2024-06-19 16:36:50 +03:00
|
|
|
case Gone:
|
|
|
|
builder.add(`display`, `none`)
|
|
|
|
}
|
|
|
|
*/
|
2021-09-07 17:36:50 +03:00
|
|
|
if view.addCSS != nil {
|
|
|
|
for tag, value := range view.addCSS {
|
|
|
|
builder.add(tag, value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (view *viewData) htmlProperties(self View, buffer *strings.Builder) {
|
|
|
|
view.created = true
|
|
|
|
|
2022-08-31 22:17:46 +03:00
|
|
|
if IsDisabled(self) {
|
2021-09-07 17:36:50 +03:00
|
|
|
buffer.WriteString(` data-disabled="1"`)
|
2024-04-23 18:24:51 +03:00
|
|
|
if view.hasHtmlDisabled {
|
|
|
|
buffer.WriteString(` disabled`)
|
|
|
|
}
|
2021-09-07 17:36:50 +03:00
|
|
|
} else {
|
|
|
|
buffer.WriteString(` data-disabled="0"`)
|
|
|
|
}
|
2024-04-23 18:24:51 +03:00
|
|
|
|
|
|
|
if view.frame.Left != 0 || view.frame.Top != 0 || view.frame.Width != 0 || view.frame.Height != 0 {
|
|
|
|
buffer.WriteString(fmt.Sprintf(` data-left="%g" data-top="%g" data-width="%g" data-height="%g"`,
|
|
|
|
view.frame.Left, view.frame.Top, view.frame.Width, view.frame.Height))
|
|
|
|
}
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func viewHTML(view View, buffer *strings.Builder) {
|
|
|
|
viewHTMLTag := view.htmlTag()
|
|
|
|
buffer.WriteRune('<')
|
|
|
|
buffer.WriteString(viewHTMLTag)
|
|
|
|
buffer.WriteString(` id="`)
|
|
|
|
buffer.WriteString(view.htmlID())
|
|
|
|
buffer.WriteRune('"')
|
|
|
|
|
2022-08-31 22:17:46 +03:00
|
|
|
disabled := IsDisabled(view)
|
2021-09-07 17:36:50 +03:00
|
|
|
|
|
|
|
if cls := view.htmlClass(disabled); cls != "" {
|
|
|
|
buffer.WriteString(` class="`)
|
|
|
|
buffer.WriteString(cls)
|
|
|
|
buffer.WriteRune('"')
|
|
|
|
}
|
|
|
|
|
2022-10-29 20:16:40 +03:00
|
|
|
cssBuilder := viewCSSBuilder{buffer: allocStringBuilder()}
|
2021-09-07 17:36:50 +03:00
|
|
|
view.cssStyle(view, &cssBuilder)
|
|
|
|
|
|
|
|
if style := cssBuilder.finish(); style != "" {
|
|
|
|
buffer.WriteString(` style="`)
|
|
|
|
buffer.WriteString(style)
|
|
|
|
buffer.WriteRune('"')
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer.WriteRune(' ')
|
|
|
|
view.htmlProperties(view, buffer)
|
|
|
|
|
|
|
|
if view.isNoResizeEvent() {
|
|
|
|
buffer.WriteString(` data-noresize="1" `)
|
|
|
|
} else {
|
|
|
|
buffer.WriteRune(' ')
|
|
|
|
}
|
|
|
|
|
2022-12-20 18:38:39 +03:00
|
|
|
if !disabled {
|
2024-04-23 18:24:51 +03:00
|
|
|
if tabIndex := GetTabIndex(view); tabIndex >= 0 {
|
2022-12-20 18:38:39 +03:00
|
|
|
buffer.WriteString(`tabindex="`)
|
2024-04-23 18:24:51 +03:00
|
|
|
buffer.WriteString(strconv.Itoa(tabIndex))
|
2022-12-20 18:38:39 +03:00
|
|
|
buffer.WriteString(`" `)
|
|
|
|
}
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
2023-04-25 17:20:47 +03:00
|
|
|
hasTooltip := false
|
|
|
|
if tooltip := GetTooltip(view); tooltip != "" {
|
|
|
|
buffer.WriteString(`data-tooltip=" `)
|
|
|
|
buffer.WriteString(tooltip)
|
|
|
|
buffer.WriteString(`" `)
|
|
|
|
hasTooltip = true
|
|
|
|
}
|
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
buffer.WriteString(`onscroll="scrollEvent(this, event)" `)
|
|
|
|
|
|
|
|
keyEventsHtml(view, buffer)
|
2023-04-25 17:20:47 +03:00
|
|
|
mouseEventsHtml(view, buffer, hasTooltip)
|
2021-09-07 17:36:50 +03:00
|
|
|
pointerEventsHtml(view, buffer)
|
|
|
|
touchEventsHtml(view, buffer)
|
|
|
|
focusEventsHtml(view, buffer)
|
2021-10-04 17:58:17 +03:00
|
|
|
transitionEventsHtml(view, buffer)
|
|
|
|
animationEventsHtml(view, buffer)
|
2021-09-07 17:36:50 +03:00
|
|
|
|
|
|
|
buffer.WriteRune('>')
|
|
|
|
view.htmlSubviews(view, buffer)
|
|
|
|
if view.closeHTMLTag() {
|
|
|
|
buffer.WriteString(`</`)
|
|
|
|
buffer.WriteString(viewHTMLTag)
|
|
|
|
buffer.WriteRune('>')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (view *viewData) htmlClass(disabled bool) string {
|
|
|
|
cls := "ruiView"
|
|
|
|
disabledStyle := false
|
|
|
|
if disabled {
|
|
|
|
if value, ok := stringProperty(view, StyleDisabled, view.Session()); ok && value != "" {
|
|
|
|
cls += " " + value
|
|
|
|
disabledStyle = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !disabledStyle {
|
|
|
|
if value, ok := stringProperty(view, Style, view.Session()); ok {
|
|
|
|
cls += " " + value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if view.systemClass != "" {
|
|
|
|
cls = view.systemClass + " " + cls
|
|
|
|
}
|
|
|
|
|
|
|
|
return cls
|
|
|
|
}
|
|
|
|
|
|
|
|
func (view *viewData) handleCommand(self View, command string, data DataObject) bool {
|
|
|
|
switch command {
|
|
|
|
|
|
|
|
case KeyDownEvent, KeyUpEvent:
|
2022-08-31 22:17:46 +03:00
|
|
|
if !IsDisabled(self) {
|
2021-09-07 17:36:50 +03:00
|
|
|
handleKeyEvents(self, command, data)
|
|
|
|
}
|
|
|
|
|
|
|
|
case ClickEvent, DoubleClickEvent, MouseDown, MouseUp, MouseMove, MouseOut, MouseOver, ContextMenuEvent:
|
|
|
|
handleMouseEvents(self, command, data)
|
|
|
|
|
|
|
|
case PointerDown, PointerUp, PointerMove, PointerOut, PointerOver, PointerCancel:
|
|
|
|
handlePointerEvents(self, command, data)
|
|
|
|
|
|
|
|
case TouchStart, TouchEnd, TouchMove, TouchCancel:
|
|
|
|
handleTouchEvents(self, command, data)
|
|
|
|
|
2022-01-15 01:20:04 +03:00
|
|
|
case FocusEvent:
|
|
|
|
view.hasFocus = true
|
2022-08-31 22:17:46 +03:00
|
|
|
for _, listener := range getFocusListeners(view, nil, command) {
|
2022-01-15 01:20:04 +03:00
|
|
|
listener(self)
|
|
|
|
}
|
|
|
|
|
|
|
|
case LostFocusEvent:
|
|
|
|
view.hasFocus = false
|
2022-08-31 22:17:46 +03:00
|
|
|
for _, listener := range getFocusListeners(view, nil, command) {
|
2021-09-07 17:36:50 +03:00
|
|
|
listener(self)
|
|
|
|
}
|
|
|
|
|
2021-10-04 17:58:17 +03:00
|
|
|
case TransitionRunEvent, TransitionStartEvent, TransitionEndEvent, TransitionCancelEvent:
|
|
|
|
view.handleTransitionEvents(command, data)
|
|
|
|
|
|
|
|
case AnimationStartEvent, AnimationEndEvent, AnimationIterationEvent, AnimationCancelEvent:
|
|
|
|
view.handleAnimationEvents(command, data)
|
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
case "scroll":
|
|
|
|
view.onScroll(view, dataFloatProperty(data, "x"), dataFloatProperty(data, "y"), dataFloatProperty(data, "width"), dataFloatProperty(data, "height"))
|
|
|
|
|
|
|
|
case "widthChanged":
|
|
|
|
if value, ok := data.PropertyValue("width"); ok {
|
|
|
|
if width, ok := StringToSizeUnit(value); ok {
|
|
|
|
self.setRaw(Width, width)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
case "heightChanged":
|
|
|
|
if value, ok := data.PropertyValue("height"); ok {
|
|
|
|
if height, ok := StringToSizeUnit(value); ok {
|
|
|
|
self.setRaw(Height, height)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
case "resize":
|
|
|
|
floatProperty := func(tag string) float64 {
|
|
|
|
if value, ok := data.PropertyValue(tag); ok {
|
|
|
|
if result, err := strconv.ParseFloat(value, 64); err == nil {
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
self.onResize(self, floatProperty("x"), floatProperty("y"), floatProperty("width"), floatProperty("height"))
|
|
|
|
return true
|
|
|
|
*/
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-11-20 11:15:28 +03:00
|
|
|
func (view *viewData) SetChangeListener(tag string, listener func(View, string)) {
|
|
|
|
if listener == nil {
|
|
|
|
delete(view.changeListener, tag)
|
|
|
|
} else {
|
|
|
|
view.changeListener[tag] = listener
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
}
|
2022-01-15 01:20:04 +03:00
|
|
|
|
|
|
|
func (view *viewData) HasFocus() bool {
|
|
|
|
return view.hasFocus
|
|
|
|
}
|
2022-05-22 12:54:02 +03:00
|
|
|
|
|
|
|
func (view *viewData) String() string {
|
2024-05-02 15:07:57 +03:00
|
|
|
return getViewString(view, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (view *viewData) exscludeTags() []string {
|
|
|
|
return nil
|
2022-05-22 12:54:02 +03:00
|
|
|
}
|