rui_orig/viewUtils.go

958 lines
38 KiB
Go
Raw Normal View History

2021-09-07 17:36:50 +03:00
package rui
// Get returns a value of the property with name "tag" of the "rootView" subview with "viewID" id value.
// The type of return value depends on the property.
// If the subview don't exists or the property is not set then nil is returned.
2024-11-13 12:56:39 +03:00
func Get(rootView View, viewID string, tag PropertyName) any {
var view View
if viewID != "" {
view = ViewByID(rootView, viewID)
} else {
view = rootView
}
if view != nil {
2021-09-07 17:36:50 +03:00
return view.Get(tag)
}
return nil
}
// Set sets the property with name "tag" of the "rootView" subview with "viewID" id by value. Result:
2021-11-04 14:59:25 +03:00
// true - success,
// false - error (incompatible type or invalid format of a string value, see AppLog).
2024-11-13 12:56:39 +03:00
func Set(rootView View, viewID string, tag PropertyName, value any) bool {
var view View
if viewID != "" {
view = ViewByID(rootView, viewID)
} else {
view = rootView
}
if view != nil {
2021-09-07 17:36:50 +03:00
return view.Set(tag, value)
}
return false
}
// SetChangeListener sets a listener for changing a subview property value.
// If the second argument (subviewID) is not specified or it is "" then a listener for the first argument (view) is set
2024-11-13 12:56:39 +03:00
func SetChangeListener(view View, viewID string, tag PropertyName, listener func(View, PropertyName)) {
if viewID != "" {
view = ViewByID(view, viewID)
}
if view != nil {
view.SetChangeListener(tag, listener)
}
}
2021-09-07 17:36:50 +03:00
// SetParams sets properties with name "tag" of the "rootView" subview. Result:
2021-11-04 14:59:25 +03:00
// true - all properties were set successful,
// false - error (incompatible type or invalid format of a string value, see AppLog).
2021-09-07 17:36:50 +03:00
func SetParams(rootView View, viewID string, params Params) bool {
2022-06-17 19:26:24 +03:00
if viewID != "" {
2022-07-22 13:10:55 +03:00
rootView = ViewByID(rootView, viewID)
2022-06-17 19:26:24 +03:00
}
2022-07-22 13:10:55 +03:00
if rootView == nil {
2021-09-07 17:36:50 +03:00
return false
}
2022-07-22 13:10:55 +03:00
session := rootView.Session()
session.startUpdateScript(rootView.htmlID())
2021-09-07 17:36:50 +03:00
result := true
2024-09-25 13:45:47 +03:00
//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
}
2021-09-07 17:36:50 +03:00
}
2024-09-25 13:45:47 +03:00
2022-07-22 13:10:55 +03:00
session.finishUpdateScript(rootView.htmlID())
2021-09-07 17:36:50 +03:00
return result
}
2024-11-24 16:43:31 +03:00
func getSubview(view View, subviewID []string) View {
switch len(subviewID) {
case 0:
// do nothing
case 1:
if subviewID[0] != "" {
view = ViewByID(view, subviewID[0])
}
default:
buffer := allocStringBuilder()
defer freeStringBuilder(buffer)
for _, id := range subviewID {
if id != "" {
if buffer.Len() > 0 {
buffer.WriteRune('/')
}
buffer.WriteString(id)
}
}
view = ViewByID(view, buffer.String())
}
return view
}
// IsDisabled returns "true" if the subview is disabled
// If the second argument (subviewID) is not specified or it is "" then a state of the first argument (view) is returned
func IsDisabled(view View, subviewID ...string) bool {
2024-11-24 16:43:31 +03:00
if view = getSubview(view, subviewID); view != nil {
2022-07-01 18:01:25 +03:00
if disabled, _ := boolProperty(view, Disabled, view.Session()); disabled {
return true
}
if parent := view.Parent(); parent != nil {
return IsDisabled(parent)
2022-07-01 18:01:25 +03:00
}
}
return false
}
2021-09-07 17:36:50 +03:00
// GetSemantics returns the subview semantics. Valid semantics values are
// DefaultSemantics (0), ArticleSemantics (1), SectionSemantics (2), AsideSemantics (3),
// HeaderSemantics (4), MainSemantics (5), FooterSemantics (6), NavigationSemantics (7),
// FigureSemantics (8), FigureCaptionSemantics (9), ButtonSemantics (10), ParagraphSemantics (11),
// H1Semantics (12) - H6Semantics (17), BlockquoteSemantics (18), and CodeSemantics (19).
// If the second argument (subviewID) is not specified or it is "" then a semantics of the first argument (view) is returned
func GetSemantics(view View, subviewID ...string) int {
2022-07-28 12:41:50 +03:00
return enumStyledProperty(view, subviewID, Semantics, DefaultSemantics, false)
2021-09-07 17:36:50 +03:00
}
// GetOpacity returns the subview opacity.
// If the second argument (subviewID) is not specified or it is "" then an opacity of the first argument (view) is returned
func GetOpacity(view View, subviewID ...string) float64 {
2022-07-28 12:11:27 +03:00
return floatStyledProperty(view, subviewID, Opacity, 1)
2021-09-07 17:36:50 +03:00
}
// GetStyle returns the subview style id.
// If the second argument (subviewID) is not specified or it is "" then a style of the first argument (view) is returned
func GetStyle(view View, subviewID ...string) string {
2024-11-24 16:43:31 +03:00
if view = getSubview(view, subviewID); view != nil {
2021-09-07 17:36:50 +03:00
if style, ok := stringProperty(view, Style, view.Session()); ok {
return style
}
}
return ""
}
// GetDisabledStyle returns the disabled subview style id.
// If the second argument (subviewID) is not specified or it is "" then a style of the first argument (view) is returned
func GetDisabledStyle(view View, subviewID ...string) string {
2024-11-24 16:43:31 +03:00
if view = getSubview(view, subviewID); view != nil {
2021-09-07 17:36:50 +03:00
if style, ok := stringProperty(view, StyleDisabled, view.Session()); ok {
return style
}
}
return ""
}
// GetVisibility returns the subview visibility. One of the following values is returned:
// Visible (0), Invisible (1), or Gone (2)
// If the second argument (subviewID) is not specified or it is "" then a visibility of the first argument (view) is returned
func GetVisibility(view View, subviewID ...string) int {
2022-07-28 12:41:50 +03:00
return enumStyledProperty(view, subviewID, Visibility, Visible, false)
2021-09-07 17:36:50 +03:00
}
2022-07-27 13:26:36 +03:00
// GetOverflow returns a value of the subview "overflow" property. Returns one of next values:
// OverflowHidden (0), OverflowVisible (1), OverflowScroll (2), OverflowAuto (3)
// If the second argument (subviewID) is not specified or it is "" then a value of the first argument (view) is returned
func GetOverflow(view View, subviewID ...string) int {
2024-11-24 16:43:31 +03:00
if view = getSubview(view, subviewID); view != nil {
defaultOverflow := OverflowHidden
2022-07-28 12:41:50 +03:00
switch view.(type) {
case EditView:
defaultOverflow = OverflowAuto
2022-07-27 13:26:36 +03:00
2022-07-28 12:41:50 +03:00
case ListView:
defaultOverflow = OverflowAuto
}
2024-11-24 16:43:31 +03:00
return enumStyledProperty(view, nil, Overflow, defaultOverflow, false)
2022-07-27 13:26:36 +03:00
}
2024-11-24 16:43:31 +03:00
return OverflowHidden
2022-07-27 13:26:36 +03:00
}
2022-12-20 18:38:39 +03:00
// GetTabIndex returns the subview tab-index.
// If the second argument (subviewID) is not specified or it is "" then a tab-index of the first argument (view) is returned
func GetTabIndex(view View, subviewID ...string) int {
2024-11-24 16:43:31 +03:00
view = getSubview(view, subviewID)
2022-12-20 18:38:39 +03:00
defaultValue := -1
if view != nil {
if view.Focusable() {
defaultValue = 0
}
if value, ok := intProperty(view, TabIndex, view.Session(), defaultValue); ok {
return value
}
}
return defaultValue
}
2021-09-07 17:36:50 +03:00
// GetZIndex returns the subview z-order.
// If the second argument (subviewID) is not specified or it is "" then a z-order of the first argument (view) is returned
func GetZIndex(view View, subviewID ...string) int {
2022-08-20 20:05:56 +03:00
return intStyledProperty(view, subviewID, ZIndex, 0)
2021-09-07 17:36:50 +03:00
}
2022-12-18 18:37:36 +03:00
// GetOrder returns the subview order to layout an item in a ListLayout or GridLayout container.
// If the second argument (subviewID) is not specified or it is "" then an order of the first argument (view) is returned
func GetOrder(view View, subviewID ...string) int {
return intStyledProperty(view, subviewID, Order, 0)
}
2021-09-07 17:36:50 +03:00
// GetWidth returns the subview width.
// If the second argument (subviewID) is not specified or it is "" then a width of the first argument (view) is returned
func GetWidth(view View, subviewID ...string) SizeUnit {
2022-07-28 12:53:50 +03:00
return sizeStyledProperty(view, subviewID, Width, false)
2021-09-07 17:36:50 +03:00
}
// GetHeight returns the subview height.
// If the second argument (subviewID) is not specified or it is "" then a height of the first argument (view) is returned
func GetHeight(view View, subviewID ...string) SizeUnit {
2022-07-28 12:53:50 +03:00
return sizeStyledProperty(view, subviewID, Height, false)
2021-09-07 17:36:50 +03:00
}
// GetMinWidth returns a minimal subview width.
// If the second argument (subviewID) is not specified or it is "" then a minimal width of the first argument (view) is returned
func GetMinWidth(view View, subviewID ...string) SizeUnit {
2022-07-28 12:53:50 +03:00
return sizeStyledProperty(view, subviewID, MinWidth, false)
2021-09-07 17:36:50 +03:00
}
// GetMinHeight returns a minimal subview height.
// If the second argument (subviewID) is not specified or it is "" then a minimal height of the first argument (view) is returned
func GetMinHeight(view View, subviewID ...string) SizeUnit {
2022-07-28 12:53:50 +03:00
return sizeStyledProperty(view, subviewID, MinHeight, false)
2021-09-07 17:36:50 +03:00
}
// GetMaxWidth returns a maximal subview width.
// If the second argument (subviewID) is not specified or it is "" then a maximal width of the first argument (view) is returned
func GetMaxWidth(view View, subviewID ...string) SizeUnit {
2022-07-28 12:53:50 +03:00
return sizeStyledProperty(view, subviewID, MaxWidth, false)
2021-09-07 17:36:50 +03:00
}
// GetMaxHeight returns a maximal subview height.
// If the second argument (subviewID) is not specified or it is "" then a maximal height of the first argument (view) is returned
func GetMaxHeight(view View, subviewID ...string) SizeUnit {
2022-07-28 12:53:50 +03:00
return sizeStyledProperty(view, subviewID, MaxHeight, false)
2021-09-07 17:36:50 +03:00
}
// GetResize returns the "resize" property value if the subview. One of the following values is returned:
// NoneResize (0), BothResize (1), HorizontalResize (2), or VerticalResize (3)
// If the second argument (subviewID) is not specified or it is "" then a value of the first argument (view) is returned
func GetResize(view View, subviewID ...string) int {
2022-07-28 12:41:50 +03:00
return enumStyledProperty(view, subviewID, Resize, NoneResize, false)
}
2021-09-07 17:36:50 +03:00
// GetLeft returns a left position of the subview in an AbsoluteLayout container.
// If a parent view is not an AbsoluteLayout container then this value is ignored.
// If the second argument (subviewID) is not specified or it is "" then a left position of the first argument (view) is returned
func GetLeft(view View, subviewID ...string) SizeUnit {
2022-07-28 12:53:50 +03:00
return sizeStyledProperty(view, subviewID, Left, false)
2021-09-07 17:36:50 +03:00
}
// GetRight returns a right position of the subview in an AbsoluteLayout container.
// If a parent view is not an AbsoluteLayout container then this value is ignored.
// If the second argument (subviewID) is not specified or it is "" then a right position of the first argument (view) is returned
func GetRight(view View, subviewID ...string) SizeUnit {
2022-07-28 12:53:50 +03:00
return sizeStyledProperty(view, subviewID, Right, false)
2021-09-07 17:36:50 +03:00
}
// GetTop returns a top position of the subview in an AbsoluteLayout container.
// If a parent view is not an AbsoluteLayout container then this value is ignored.
// If the second argument (subviewID) is not specified or it is "" then a top position of the first argument (view) is returned
func GetTop(view View, subviewID ...string) SizeUnit {
2022-07-28 12:53:50 +03:00
return sizeStyledProperty(view, subviewID, Top, false)
2021-09-07 17:36:50 +03:00
}
// GetBottom returns a top position of the subview in an AbsoluteLayout container.
// If a parent view is not an AbsoluteLayout container then this value is ignored.
// If the second argument (subviewID) is not specified or it is "" then a bottom position of the first argument (view) is returned
func GetBottom(view View, subviewID ...string) SizeUnit {
2022-07-28 12:53:50 +03:00
return sizeStyledProperty(view, subviewID, Bottom, false)
2021-09-07 17:36:50 +03:00
}
// Margin returns the subview margin.
// If the second argument (subviewID) is not specified or it is "" then a margin of the first argument (view) is returned
func GetMargin(view View, subviewID ...string) Bounds {
2021-09-07 17:36:50 +03:00
var bounds Bounds
2024-11-24 16:43:31 +03:00
if view = getSubview(view, subviewID); view != nil {
2021-09-07 17:36:50 +03:00
bounds.setFromProperties(Margin, MarginTop, MarginRight, MarginBottom, MarginLeft, view, view.Session())
}
return bounds
}
// GetPadding returns the subview padding.
// If the second argument (subviewID) is not specified or it is "" then a padding of the first argument (view) is returned
func GetPadding(view View, subviewID ...string) Bounds {
2021-09-07 17:36:50 +03:00
var bounds Bounds
2024-11-24 16:43:31 +03:00
if view = getSubview(view, subviewID); view != nil {
2021-09-07 17:36:50 +03:00
bounds.setFromProperties(Padding, PaddingTop, PaddingRight, PaddingBottom, PaddingLeft, view, view.Session())
}
return bounds
}
// GetBorder returns ViewBorders of the subview.
// If the second argument (subviewID) is not specified or it is "" then a ViewBorders of the first argument (view) is returned.
func GetBorder(view View, subviewID ...string) ViewBorders {
2024-11-24 16:43:31 +03:00
if view = getSubview(view, subviewID); view != nil {
2024-11-13 12:56:39 +03:00
if border := getBorderProperty(view, Border); border != nil {
2021-09-07 17:36:50 +03:00
return border.ViewBorders(view.Session())
}
}
return ViewBorders{}
}
// Radius returns the BoxRadius structure of the subview.
// If the second argument (subviewID) is not specified or it is "" then a BoxRadius of the first argument (view) is returned.
func GetRadius(view View, subviewID ...string) BoxRadius {
2024-11-24 16:43:31 +03:00
view = getSubview(view, subviewID)
2021-09-07 17:36:50 +03:00
if view == nil {
return BoxRadius{}
}
return getRadius(view, view.Session())
}
// GetOutline returns ViewOutline of the subview.
// If the second argument (subviewID) is not specified or it is "" then a ViewOutline of the first argument (view) is returned.
func GetOutline(view View, subviewID ...string) ViewOutline {
2024-11-24 16:43:31 +03:00
if view = getSubview(view, subviewID); view != nil {
2024-11-13 12:56:39 +03:00
if outline := getOutlineProperty(view); outline != nil {
2021-09-07 17:36:50 +03:00
return outline.ViewOutline(view.Session())
}
}
return ViewOutline{Style: NoneLine, Width: AutoSize(), Color: 0}
}
2023-04-23 13:41:26 +03:00
// GetOutlineOffset returns the subview outline offset.
// If the second argument (subviewID) is not specified or it is "" then a offset of the first argument (view) is returned
func GetOutlineOffset(view View, subviewID ...string) SizeUnit {
return sizeStyledProperty(view, subviewID, OutlineOffset, false)
}
2021-09-07 17:36:50 +03:00
// GetViewShadows returns shadows of the subview.
// If the second argument (subviewID) is not specified or it is "" then shadows of the first argument (view) is returned.
func GetViewShadows(view View, subviewID ...string) []ViewShadow {
2024-11-24 16:43:31 +03:00
view = getSubview(view, subviewID)
2021-09-07 17:36:50 +03:00
if view == nil {
return []ViewShadow{}
}
return getShadows(view, Shadow)
}
// GetTextShadows returns text shadows of the subview.
// If the second argument (subviewID) is not specified or it is "" then shadows of the first argument (view) is returned.
func GetTextShadows(view View, subviewID ...string) []ViewShadow {
2024-11-24 16:43:31 +03:00
view = getSubview(view, subviewID)
2021-09-07 17:36:50 +03:00
if view == nil {
return []ViewShadow{}
}
return getShadows(view, TextShadow)
}
// GetBackgroundColor returns a background color of the subview.
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetBackgroundColor(view View, subviewID ...string) Color {
2022-07-28 12:11:27 +03:00
return colorStyledProperty(view, subviewID, BackgroundColor, false)
2021-09-07 17:36:50 +03:00
}
2022-08-20 19:13:51 +03:00
// GetAccentColor returns the accent color for UI controls generated by some elements.
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetAccentColor(view View, subviewID ...string) Color {
2022-08-20 19:13:51 +03:00
return colorStyledProperty(view, subviewID, AccentColor, false)
}
2021-09-07 17:36:50 +03:00
// GetFontName returns the subview font.
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetFontName(view View, subviewID ...string) string {
2024-11-21 09:25:46 +03:00
return stringStyledProperty(view, nil, FontName, true)
2021-09-07 17:36:50 +03:00
}
// GetTextColor returns a text color of the subview.
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetTextColor(view View, subviewID ...string) Color {
2022-07-28 12:11:27 +03:00
return colorStyledProperty(view, subviewID, TextColor, true)
2021-09-07 17:36:50 +03:00
}
// GetTextSize returns a text size of the subview.
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetTextSize(view View, subviewID ...string) SizeUnit {
2022-07-28 12:53:50 +03:00
return sizeStyledProperty(view, subviewID, TextSize, true)
2021-09-07 17:36:50 +03:00
}
2022-08-20 20:05:56 +03:00
// GetTabSize returns the subview width of tab characters (U+0009) in spaces.
// If the second argument (subviewID) is not specified or it is "" then a width of the first argument (view) is returned
func GetTabSize(view View, subviewID ...string) int {
2022-08-20 20:05:56 +03:00
return intStyledProperty(view, subviewID, TabSize, 8)
}
2021-09-07 17:36:50 +03:00
// GetTextWeight returns a text weight of the subview. Returns one of next values:
// 1, 2, 3, 4 (normal text), 5, 6, 7 (bold text), 8 and 9
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetTextWeight(view View, subviewID ...string) int {
2022-07-28 12:41:50 +03:00
return enumStyledProperty(view, subviewID, TextWeight, NormalFont, true)
2021-09-07 17:36:50 +03:00
}
// GetTextAlign returns a text align of the subview. Returns one of next values:
2022-08-18 18:18:36 +03:00
//
// LeftAlign = 0, RightAlign = 1, CenterAlign = 2, JustifyAlign = 3
//
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetTextAlign(view View, subviewID ...string) int {
2022-07-28 12:41:50 +03:00
return enumStyledProperty(view, subviewID, TextAlign, LeftAlign, true)
2024-06-06 17:33:55 +03:00
}
// GetTextAlign returns how text inside of the subview is wrapped. Returns one of next values:
//
// TextWrapOn = 0, TextWrapOff = 1, TextWrapBalance = 3
//
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetTextWrap(view View, subviewID ...string) int {
return enumStyledProperty(view, subviewID, TextWrap, TextWrapOn, true)
2021-09-07 17:36:50 +03:00
}
// GetTextIndent returns a text indent of the subview.
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetTextIndent(view View, subviewID ...string) SizeUnit {
2022-07-28 12:53:50 +03:00
return sizeStyledProperty(view, subviewID, TextIndent, true)
2021-09-07 17:36:50 +03:00
}
// GetLetterSpacing returns a letter spacing of the subview.
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetLetterSpacing(view View, subviewID ...string) SizeUnit {
2022-07-28 12:53:50 +03:00
return sizeStyledProperty(view, subviewID, LetterSpacing, true)
2021-09-07 17:36:50 +03:00
}
// GetWordSpacing returns a word spacing of the subview.
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetWordSpacing(view View, subviewID ...string) SizeUnit {
2022-07-28 12:53:50 +03:00
return sizeStyledProperty(view, subviewID, WordSpacing, true)
2021-09-07 17:36:50 +03:00
}
// GetLineHeight returns a height of a text line of the subview.
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetLineHeight(view View, subviewID ...string) SizeUnit {
2022-07-28 12:53:50 +03:00
return sizeStyledProperty(view, subviewID, LineHeight, true)
2021-09-07 17:36:50 +03:00
}
// IsItalic returns "true" if a text font of the subview is displayed in italics, "false" otherwise.
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func IsItalic(view View, subviewID ...string) bool {
2022-07-28 12:11:27 +03:00
return boolStyledProperty(view, subviewID, Italic, true)
2021-09-07 17:36:50 +03:00
}
// IsSmallCaps returns "true" if a text font of the subview is displayed in small caps, "false" otherwise.
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func IsSmallCaps(view View, subviewID ...string) bool {
2022-07-28 12:11:27 +03:00
return boolStyledProperty(view, subviewID, SmallCaps, true)
2021-09-07 17:36:50 +03:00
}
// IsStrikethrough returns "true" if a text font of the subview is displayed strikethrough, "false" otherwise.
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func IsStrikethrough(view View, subviewID ...string) bool {
2022-07-28 12:11:27 +03:00
return boolStyledProperty(view, subviewID, Strikethrough, true)
2021-09-07 17:36:50 +03:00
}
// IsOverline returns "true" if a text font of the subview is displayed overlined, "false" otherwise.
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func IsOverline(view View, subviewID ...string) bool {
2022-07-28 12:11:27 +03:00
return boolStyledProperty(view, subviewID, Overline, true)
2021-09-07 17:36:50 +03:00
}
// IsUnderline returns "true" if a text font of the subview is displayed underlined, "false" otherwise.
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func IsUnderline(view View, subviewID ...string) bool {
2022-07-28 12:11:27 +03:00
return boolStyledProperty(view, subviewID, Underline, true)
2021-09-07 17:36:50 +03:00
}
// GetTextLineThickness returns the stroke thickness of the decoration line that
// is used on text in an element, such as a line-through, underline, or overline.
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetTextLineThickness(view View, subviewID ...string) SizeUnit {
2022-07-28 12:53:50 +03:00
return sizeStyledProperty(view, subviewID, TextLineThickness, true)
2021-09-07 17:36:50 +03:00
}
// GetTextLineStyle returns the stroke style of the decoration line that
// is used on text in an element, such as a line-through, underline, or overline.
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetTextLineStyle(view View, subviewID ...string) int {
2022-07-28 12:41:50 +03:00
return enumStyledProperty(view, subviewID, TextLineStyle, SolidLine, true)
2021-09-07 17:36:50 +03:00
}
// GetTextLineColor returns the stroke color of the decoration line that
// is used on text in an element, such as a line-through, underline, or overline.
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetTextLineColor(view View, subviewID ...string) Color {
2022-07-28 12:11:27 +03:00
return colorStyledProperty(view, subviewID, TextLineColor, true)
2021-09-07 17:36:50 +03:00
}
// GetTextTransform returns a text transform of the subview. Return one of next values:
// NoneTextTransform (0), CapitalizeTextTransform (1), LowerCaseTextTransform (2) or UpperCaseTextTransform (3)
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetTextTransform(view View, subviewID ...string) int {
2022-07-28 12:41:50 +03:00
return enumStyledProperty(view, subviewID, TextTransform, NoneTextTransform, true)
2021-09-07 17:36:50 +03:00
}
// GetWritingMode returns whether lines of text are laid out horizontally or vertically, as well as
2021-11-04 14:59:25 +03:00
// the direction in which blocks progress. Valid values are HorizontalTopToBottom (0),
// HorizontalBottomToTop (1), VerticalRightToLeft (2) and VerticalLeftToRight (3)
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetWritingMode(view View, subviewID ...string) int {
2022-07-28 12:41:50 +03:00
return enumStyledProperty(view, subviewID, WritingMode, HorizontalTopToBottom, true)
2021-09-07 17:36:50 +03:00
}
// GetTextDirection - returns a direction of text, table columns, and horizontal overflow.
2022-07-28 12:41:50 +03:00
// Valid values are SystemTextDirection (0), LeftToRightDirection (1), and RightToLeftDirection (2).
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetTextDirection(view View, subviewID ...string) int {
2022-07-28 12:41:50 +03:00
if view == nil {
return SystemTextDirection
2021-09-07 17:36:50 +03:00
}
2022-07-28 12:41:50 +03:00
defaultDirection := view.Session().TextDirection()
return enumStyledProperty(view, subviewID, TextDirection, defaultDirection, true)
2021-09-07 17:36:50 +03:00
}
// GetVerticalTextOrientation returns a orientation of the text characters in a line. It only affects text
2021-11-04 14:59:25 +03:00
// in vertical mode (when "writing-mode" is "vertical-right-to-left" or "vertical-left-to-right").
// Valid values are MixedTextOrientation (0), UprightTextOrientation (1), and SidewaysTextOrientation (2).
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetVerticalTextOrientation(view View, subviewID ...string) int {
2022-07-28 12:41:50 +03:00
return enumStyledProperty(view, subviewID, VerticalTextOrientation, MixedTextOrientation, true)
2021-09-07 17:36:50 +03:00
}
// GetRow returns the range of row numbers of a GridLayout in which the subview is placed.
// If the second argument (subviewID) is not specified or it is "" then a values from the first argument (view) is returned.
func GetRow(view View, subviewID ...string) Range {
2024-11-24 16:43:31 +03:00
if view = getSubview(view, subviewID); view != nil {
2021-09-07 17:36:50 +03:00
session := view.Session()
if result, ok := rangeProperty(view, Row, session); ok {
return result
}
2022-05-23 15:22:14 +03:00
if value := valueFromStyle(view, Row); value != nil {
2021-09-07 17:36:50 +03:00
if result, ok := valueToRange(value, session); ok {
return result
}
}
}
return Range{}
}
// GetColumn returns the range of column numbers of a GridLayout in which the subview is placed.
// If the second argument (subviewID) is not specified or it is "" then a values from the first argument (view) is returned.
func GetColumn(view View, subviewID ...string) Range {
2024-11-24 16:43:31 +03:00
if view = getSubview(view, subviewID); view != nil {
2021-09-07 17:36:50 +03:00
session := view.Session()
if result, ok := rangeProperty(view, Column, session); ok {
return result
}
2022-05-23 15:22:14 +03:00
if value := valueFromStyle(view, Column); value != nil {
2021-09-07 17:36:50 +03:00
if result, ok := valueToRange(value, session); ok {
return result
}
}
}
return Range{}
}
// GetTransform returns a view transform: translation, scale and rotation over x, y and z axes as well as a distortion of a view along x and y axes.
// The default value is nil (no transform)
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetTransform(view View, subviewID ...string) TransformProperty {
return transformStyledProperty(view, subviewID, Transform)
}
2021-09-07 17:36:50 +03:00
// GetPerspective returns a distance between the z = 0 plane and the user in order to give a 3D-positioned
// element some perspective. Each 3D element with z > 0 becomes larger; each 3D-element with z < 0 becomes smaller.
// The default value is 0 (no 3D effects).
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetPerspective(view View, subviewID ...string) SizeUnit {
2022-07-28 12:53:50 +03:00
return sizeStyledProperty(view, subviewID, Perspective, false)
2021-09-07 17:36:50 +03:00
}
// GetPerspectiveOrigin returns a x- and y-coordinate of the position at which the viewer is looking.
// It is used as the vanishing point by the Perspective property. The default value is (50%, 50%).
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetPerspectiveOrigin(view View, subviewID ...string) (SizeUnit, SizeUnit) {
2024-11-24 16:43:31 +03:00
view = getSubview(view, subviewID)
2021-09-07 17:36:50 +03:00
if view == nil {
return AutoSize(), AutoSize()
}
return getPerspectiveOrigin(view, view.Session())
}
// GetBackfaceVisible returns a bool property that sets whether the back face of an element is
// visible when turned towards the user. Values:
2021-11-04 14:59:25 +03:00
// true - the back face is visible when turned towards the user (default value).
// false - the back face is hidden, effectively making the element invisible when turned away from the user.
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetBackfaceVisible(view View, subviewID ...string) bool {
2022-07-28 12:11:27 +03:00
return boolStyledProperty(view, subviewID, BackfaceVisible, false)
2021-09-07 17:36:50 +03:00
}
// GetTransformOrigin returns a x-, y-, and z-coordinate of the point around which a view transformation is applied.
2021-09-07 17:36:50 +03:00
// The default value is (50%, 50%, 50%).
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetTransformOrigin(view View, subviewID ...string) (SizeUnit, SizeUnit, SizeUnit) {
2024-11-24 16:43:31 +03:00
view = getSubview(view, subviewID)
2021-09-07 17:36:50 +03:00
if view == nil {
return AutoSize(), AutoSize(), AutoSize()
}
return getTransformOrigin(view, view.Session())
2021-09-07 17:36:50 +03:00
}
// GetTranslate returns a x-, y-, and z-axis translation value of a 2D/3D translation
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetTranslate(view View, subviewID ...string) (SizeUnit, SizeUnit, SizeUnit) {
2024-11-24 16:43:31 +03:00
view = getSubview(view, subviewID)
2021-09-07 17:36:50 +03:00
if view == nil {
return AutoSize(), AutoSize(), AutoSize()
}
session := view.Session()
x, _ := sizeProperty(view, TranslateX, session)
y, _ := sizeProperty(view, TranslateY, session)
z, _ := sizeProperty(view, TranslateZ, session)
return x, y, z
2021-09-07 17:36:50 +03:00
}
// GetSkew returns a angles to use to distort the element along the abscissa (x-axis)
// and the ordinate (y-axis). The default value is 0.
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetSkew(view View, subviewID ...string) (AngleUnit, AngleUnit) {
2024-11-24 16:43:31 +03:00
view = getSubview(view, subviewID)
2021-09-07 17:36:50 +03:00
if view == nil {
return AngleUnit{Value: 0, Type: Radian}, AngleUnit{Value: 0, Type: Radian}
}
x, _ := angleProperty(view, SkewX, view.Session())
y, _ := angleProperty(view, SkewY, view.Session())
return x, y
2021-09-07 17:36:50 +03:00
}
// GetScale returns a x-, y-, and z-axis scaling value of a 2D/3D scale. The default value is 1.
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetScale(view View, subviewID ...string) (float64, float64, float64) {
2024-11-24 16:43:31 +03:00
view = getSubview(view, subviewID)
2021-09-07 17:36:50 +03:00
if view == nil {
return 1, 1, 1
}
2022-08-18 18:18:36 +03:00
session := view.Session()
x, _ := floatProperty(view, ScaleX, session, 1)
y, _ := floatProperty(view, ScaleY, session, 1)
z, _ := floatProperty(view, ScaleZ, session, 1)
return x, y, z
2021-09-07 17:36:50 +03:00
}
// GetRotate returns a x-, y, z-coordinate of the vector denoting the axis of rotation, and the angle of the view rotation
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetRotate(view View, subviewID ...string) (float64, float64, float64, AngleUnit) {
2024-11-24 16:43:31 +03:00
view = getSubview(view, subviewID)
2021-09-07 17:36:50 +03:00
if view == nil {
return 0, 0, 0, AngleUnit{Value: 0, Type: Radian}
}
2022-08-18 18:18:36 +03:00
session := view.Session()
angle, _ := angleProperty(view, Rotate, view.Session())
2022-08-18 18:18:36 +03:00
rotateX, _ := floatProperty(view, RotateX, session, 1)
rotateY, _ := floatProperty(view, RotateY, session, 1)
rotateZ, _ := floatProperty(view, RotateZ, session, 1)
return rotateX, rotateY, rotateZ, angle
2021-09-07 17:36:50 +03:00
}
// GetAvoidBreak returns "true" if avoids any break from being inserted within the principal box,
// and "false" if allows, but does not force, any break to be inserted within the principal box.
// If the second argument (subviewID) is not specified or it is "" then a top position of the first argument (view) is returned
func GetAvoidBreak(view View, subviewID ...string) bool {
2022-07-28 12:11:27 +03:00
return boolStyledProperty(view, subviewID, AvoidBreak, true)
2021-09-07 17:36:50 +03:00
}
// GetNotTranslate returns value of "not-translate" property of the subview. If the second argument (subviewID) is not
// specified or is an empty string then a value from the first argument (view) is returned.
func GetNotTranslate(view View, subviewID ...string) bool {
2022-07-28 12:11:27 +03:00
return boolStyledProperty(view, subviewID, NotTranslate, true)
2021-09-07 17:36:50 +03:00
}
2024-11-13 12:56:39 +03:00
func valueFromStyle(view View, tag PropertyName) any {
2021-09-07 17:36:50 +03:00
session := view.Session()
2024-11-13 12:56:39 +03:00
getValue := func(styleTag PropertyName) any {
2021-09-07 17:36:50 +03:00
if style, ok := stringProperty(view, styleTag, session); ok {
if style, ok := session.resolveConstants(style); ok {
return session.styleProperty(style, tag)
}
}
2022-05-23 15:22:14 +03:00
return nil
2021-09-07 17:36:50 +03:00
}
if IsDisabled(view) {
2022-05-23 15:22:14 +03:00
if value := getValue(StyleDisabled); value != nil {
return value
2021-09-07 17:36:50 +03:00
}
}
return getValue(Style)
}
2024-11-21 09:25:46 +03:00
func stringStyledProperty(view View, subviewID []string, tag PropertyName, inherit bool) string {
2024-11-24 16:43:31 +03:00
if view = getSubview(view, subviewID); view != nil {
2024-11-21 09:25:46 +03:00
if text, ok := stringProperty(view, tag, view.Session()); ok {
return text
}
if value := valueFromStyle(view, tag); value != nil {
if text, ok := value.(string); ok {
return text
}
}
if inherit {
if parent := view.Parent(); parent != nil {
return stringStyledProperty(parent, nil, tag, true)
}
}
}
return ""
}
2024-11-13 12:56:39 +03:00
func sizeStyledProperty(view View, subviewID []string, tag PropertyName, inherit bool) SizeUnit {
2024-11-24 16:43:31 +03:00
if view = getSubview(view, subviewID); view != nil {
2022-07-28 12:53:50 +03:00
if value, ok := sizeProperty(view, tag, view.Session()); ok {
return value
}
if value := valueFromStyle(view, tag); value != nil {
if result, ok := valueToSizeUnit(value, view.Session()); ok {
return result
}
}
if inherit {
if parent := view.Parent(); parent != nil {
return sizeStyledProperty(parent, []string{}, tag, true)
2022-07-28 12:53:50 +03:00
}
}
2021-09-07 17:36:50 +03:00
}
2022-07-28 12:53:50 +03:00
return AutoSize()
2021-09-07 17:36:50 +03:00
}
2024-11-13 12:56:39 +03:00
func enumStyledProperty(view View, subviewID []string, tag PropertyName, defaultValue int, inherit bool) int {
2024-11-24 16:43:31 +03:00
if view = getSubview(view, subviewID); view != nil {
2022-07-28 12:41:50 +03:00
if value, ok := enumProperty(view, tag, view.Session(), defaultValue); ok {
return value
}
if value := valueFromStyle(view, tag); value != nil {
if result, ok := valueToEnum(value, tag, view.Session(), defaultValue); ok {
return result
}
}
if inherit {
if parent := view.Parent(); parent != nil {
return enumStyledProperty(parent, []string{}, tag, defaultValue, true)
2022-07-28 12:41:50 +03:00
}
}
2021-09-07 17:36:50 +03:00
}
2022-07-28 12:41:50 +03:00
return defaultValue
2021-09-07 17:36:50 +03:00
}
2024-11-13 12:56:39 +03:00
func boolStyledProperty(view View, subviewID []string, tag PropertyName, inherit bool) bool {
2024-11-24 16:43:31 +03:00
if view = getSubview(view, subviewID); view != nil {
2022-07-28 12:11:27 +03:00
if value, ok := boolProperty(view, tag, view.Session()); ok {
return value
}
if value := valueFromStyle(view, tag); value != nil {
if b, ok := valueToBool(value, view.Session()); ok {
return b
}
}
if inherit {
if parent := view.Parent(); parent != nil {
return boolStyledProperty(parent, []string{}, tag, inherit)
2022-07-28 12:11:27 +03:00
}
}
2021-09-07 17:36:50 +03:00
}
2022-07-28 12:11:27 +03:00
return false
2021-09-07 17:36:50 +03:00
}
2024-11-13 12:56:39 +03:00
func intStyledProperty(view View, subviewID []string, tag PropertyName, defaultValue int) int {
2024-11-24 16:43:31 +03:00
if view = getSubview(view, subviewID); view != nil {
2022-07-28 12:11:27 +03:00
if value, ok := intProperty(view, tag, view.Session(), defaultValue); ok {
return value
}
if value := valueFromStyle(view, tag); value != nil {
n, _ := valueToInt(value, view.Session(), defaultValue)
return n
}
2021-09-07 17:36:50 +03:00
}
2022-07-28 12:11:27 +03:00
return defaultValue
2021-09-07 17:36:50 +03:00
}
2024-11-13 12:56:39 +03:00
func floatStyledProperty(view View, subviewID []string, tag PropertyName, defaultValue float64) float64 {
2024-11-24 16:43:31 +03:00
if view = getSubview(view, subviewID); view != nil {
2022-07-28 12:11:27 +03:00
if value, ok := floatProperty(view, tag, view.Session(), defaultValue); ok {
return value
}
if value := valueFromStyle(view, tag); value != nil {
f, _ := valueToFloat(value, view.Session(), defaultValue)
return f
}
2021-09-07 17:36:50 +03:00
}
2022-07-28 12:11:27 +03:00
return defaultValue
2021-09-07 17:36:50 +03:00
}
2024-11-13 12:56:39 +03:00
func colorStyledProperty(view View, subviewID []string, tag PropertyName, inherit bool) Color {
2024-11-24 16:43:31 +03:00
if view = getSubview(view, subviewID); view != nil {
2022-07-28 12:11:27 +03:00
if value, ok := colorProperty(view, tag, view.Session()); ok {
return value
}
if value := valueFromStyle(view, tag); value != nil {
if color, ok := valueToColor(value, view.Session()); ok {
return color
}
}
if inherit {
if parent := view.Parent(); parent != nil {
return colorStyledProperty(parent, []string{}, tag, true)
2022-07-28 12:11:27 +03:00
}
}
2021-09-07 17:36:50 +03:00
}
2022-07-28 12:11:27 +03:00
return Color(0)
2021-09-07 17:36:50 +03:00
}
func transformStyledProperty(view View, subviewID []string, tag PropertyName) TransformProperty {
2024-11-24 16:43:31 +03:00
if view = getSubview(view, subviewID); view != nil {
if transform := getTransformProperty(view, tag); transform != nil {
return transform
}
if value := valueFromStyle(view, tag); value != nil {
return valueToTransformProperty(value)
}
}
return nil
}
2023-05-07 19:44:28 +03:00
// FocusView sets focus on the specified subview, if it can be focused.
// The focused View is the View which will receive keyboard events by default.
2023-05-07 19:44:28 +03:00
// If the second argument (subviewID) is not specified or it is "" then focus is set on the first argument (view)
func FocusView(view View, subviewID ...string) {
2024-11-24 16:43:31 +03:00
if view = getSubview(view, subviewID); view != nil {
2022-11-02 20:10:19 +03:00
view.Session().callFunc("focus", view.htmlID())
2021-09-07 17:36:50 +03:00
}
}
// FocusView sets focus on the View with the specified viewID, if it can be focused.
// The focused View is the View which will receive keyboard events by default.
2021-09-07 17:36:50 +03:00
func FocusViewByID(viewID string, session Session) {
if viewID != "" {
2022-11-02 20:10:19 +03:00
session.callFunc("focus", viewID)
2021-09-07 17:36:50 +03:00
}
}
// BlurView removes keyboard focus from the specified View.
func BlurView(view View) {
if view != nil {
2022-11-02 20:10:19 +03:00
view.Session().callFunc("blur", view.htmlID())
}
}
// BlurViewByID removes keyboard focus from the View with the specified viewID.
func BlurViewByID(viewID string, session Session) {
if viewID != "" {
2022-11-02 20:10:19 +03:00
session.callFunc("blur", viewID)
}
}
// GetCurrent returns the index of the selected item (<0 if there is no a selected item) or the current view index (StackLayout, TabsLayout).
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetCurrent(view View, subviewID ...string) int {
defaultValue := -1
2024-11-24 16:43:31 +03:00
if view = getSubview(view, subviewID); view != nil {
if result, ok := intProperty(view, Current, view.Session(), defaultValue); ok {
return result
} else if view.Tag() != "ListView" {
defaultValue = 0
}
}
return defaultValue
}
// IsUserSelect returns "true" if the user can select text, "false" otherwise.
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func IsUserSelect(view View, subviewID ...string) bool {
2024-11-24 16:43:31 +03:00
if view = getSubview(view, subviewID); view != nil {
value, _ := isUserSelect(view)
return value
}
return false
}
func isUserSelect(view View) (bool, bool) {
2022-07-28 12:11:27 +03:00
if value, ok := boolProperty(view, UserSelect, view.Session()); ok {
return value, true
}
if value := valueFromStyle(view, UserSelect); value != nil {
if b, ok := valueToBool(value, view.Session()); ok {
return b, true
}
}
if parent := view.Parent(); parent != nil {
2022-07-28 12:11:27 +03:00
if result, ok := isUserSelect(parent); ok {
return result, true
}
}
switch GetSemantics(view) {
2022-07-28 12:11:27 +03:00
case ParagraphSemantics, H1Semantics, H2Semantics, H3Semantics, H4Semantics, H5Semantics,
H6Semantics, BlockquoteSemantics, CodeSemantics:
return true, false
}
2022-07-28 12:11:27 +03:00
if _, ok := view.(TableView); ok {
return true, false
}
2022-07-28 12:11:27 +03:00
return false, false
}
// GetMixBlendMode returns a "mix-blend-mode" of the subview. Returns one of next values:
//
// BlendNormal (0), BlendMultiply (1), BlendScreen (2), BlendOverlay (3), BlendDarken (4),
// BlendLighten (5), BlendColorDodge (6), BlendColorBurn (7), BlendHardLight (8),
// BlendSoftLight (9), BlendDifference (10), BlendExclusion (11), BlendHue (12),
// BlendSaturation (13), BlendColor (14), BlendLuminosity (15)
//
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetMixBlendMode(view View, subviewID ...string) int {
return enumStyledProperty(view, subviewID, MixBlendMode, BlendNormal, true)
}
// GetBackgroundBlendMode returns a "background-blend-mode" of the subview. Returns one of next values:
//
// BlendNormal (0), BlendMultiply (1), BlendScreen (2), BlendOverlay (3), BlendDarken (4),
// BlendLighten (5), BlendColorDodge (6), BlendColorBurn (7), BlendHardLight (8),
// BlendSoftLight (9), BlendDifference (10), BlendExclusion (11), BlendHue (12),
// BlendSaturation (13), BlendColor (14), BlendLuminosity (15)
//
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetBackgroundBlendMode(view View, subviewID ...string) int {
return enumStyledProperty(view, subviewID, BackgroundBlendMode, BlendNormal, true)
}
2023-04-25 17:20:47 +03:00
// GetTooltip returns a tooltip text of the subview.
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetTooltip(view View, subviewID ...string) string {
2024-11-24 16:43:31 +03:00
if view = getSubview(view, subviewID); view != nil {
2023-04-25 17:20:47 +03:00
if value := view.Get(Tooltip); value != nil {
if text, ok := value.(string); ok {
return text
}
}
}
return ""
}