rui_orig/viewUtils.go

884 lines
32 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.
2022-07-26 18:36:00 +03:00
func Get(rootView View, viewID, tag string) 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).
2022-07-26 18:36:00 +03:00
func Set(rootView View, viewID, tag string, 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 "" then a listener for the first argument (view) is set
func SetChangeListener(view View, viewID, tag string, listener func(View, string)) {
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
for tag, value := range params {
2022-07-22 13:10:55 +03:00
result = rootView.Set(tag, value) && result
2021-09-07 17:36:50 +03:00
}
2022-07-22 13:10:55 +03:00
session.finishUpdateScript(rootView.htmlID())
2021-09-07 17:36:50 +03:00
return result
}
// IsDisabled returns "true" if the subview is disabled
// If the second argument (subviewID) is "" then a state of the first argument (view) is returned
func IsDisabled(view View, subviewID string) bool {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
2022-07-01 18:01:25 +03:00
if view != nil {
if disabled, _ := boolProperty(view, Disabled, view.Session()); disabled {
return true
}
if parent := view.Parent(); parent != nil {
return IsDisabled(parent, "")
}
}
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 "" 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 "" 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 "" then a style of the first argument (view) is returned
func GetStyle(view View, subviewID string) string {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if view != nil {
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 "" then a style of the first argument (view) is returned
func GetDisabledStyle(view View, subviewID string) string {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if view != nil {
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 "" 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 "" then a value of the first argument (view) is returned
func GetOverflow(view View, subviewID string) int {
2022-07-28 12:41:50 +03:00
defaultOverflow := OverflowHidden
view2 := view
2022-07-27 13:26:36 +03:00
if subviewID != "" {
2022-07-28 12:41:50 +03:00
view2 = ViewByID(view, subviewID)
2022-07-27 13:26:36 +03:00
}
2022-07-28 12:41:50 +03:00
if view2 != nil {
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
}
2022-07-27 13:26:36 +03:00
}
2022-07-28 12:41:50 +03:00
return enumStyledProperty(view, subviewID, Overflow, defaultOverflow, false)
2022-07-27 13:26:36 +03:00
}
2021-09-07 17:36:50 +03:00
// GetZIndex returns the subview z-order.
// If the second argument (subviewID) is "" then a z-order of the first argument (view) is returned
func GetZIndex(view View, subviewID string) int {
2022-07-28 12:11:27 +03:00
return intStyledProperty(view, subviewID, Visibility, 0)
2021-09-07 17:36:50 +03:00
}
// GetWidth returns the subview width.
// If the second argument (subviewID) 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 "" 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 "" 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 "" 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 "" 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 "" 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 "" 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 "" 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 "" 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 "" 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 "" 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 "" then a margin of the first argument (view) is returned
func GetMargin(view View, subviewID string) Bounds {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
var bounds Bounds
if view != nil {
bounds.setFromProperties(Margin, MarginTop, MarginRight, MarginBottom, MarginLeft, view, view.Session())
}
return bounds
}
// GetPadding returns the subview padding.
// If the second argument (subviewID) is "" then a padding of the first argument (view) is returned
func GetPadding(view View, subviewID string) Bounds {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
var bounds Bounds
if view != nil {
bounds.setFromProperties(Padding, PaddingTop, PaddingRight, PaddingBottom, PaddingLeft, view, view.Session())
}
return bounds
}
// GetBorder returns ViewBorders of the subview.
// If the second argument (subviewID) is "" then a ViewBorders of the first argument (view) is returned.
func GetBorder(view View, subviewID string) ViewBorders {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if view != nil {
if border := getBorder(view, Border); border != nil {
return border.ViewBorders(view.Session())
}
}
return ViewBorders{}
}
// Radius returns the BoxRadius structure of the subview.
// If the second argument (subviewID) is "" then a BoxRadius of the first argument (view) is returned.
func GetRadius(view View, subviewID string) BoxRadius {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if view == nil {
return BoxRadius{}
}
return getRadius(view, view.Session())
}
// GetOutline returns ViewOutline of the subview.
// If the second argument (subviewID) is "" then a ViewOutline of the first argument (view) is returned.
func GetOutline(view View, subviewID string) ViewOutline {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if view != nil {
if outline := getOutline(view); outline != nil {
return outline.ViewOutline(view.Session())
}
}
return ViewOutline{Style: NoneLine, Width: AutoSize(), Color: 0}
}
// GetViewShadows returns shadows of the subview.
// If the second argument (subviewID) is "" then shadows of the first argument (view) is returned.
func GetViewShadows(view View, subviewID string) []ViewShadow {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if view == nil {
return []ViewShadow{}
}
return getShadows(view, Shadow)
}
// GetTextShadows returns text shadows of the subview.
// If the second argument (subviewID) is "" then shadows of the first argument (view) is returned.
func GetTextShadows(view View, subviewID string) []ViewShadow {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if view == nil {
return []ViewShadow{}
}
return getShadows(view, TextShadow)
}
// GetBackgroundColor returns a background color of the subview.
// If the second argument (subviewID) 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 "" then a value from the first argument (view) is returned.
func GetAccentColor(view View, subviewID string) Color {
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 "" then a value from the first argument (view) is returned.
func GetFontName(view View, subviewID string) string {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if view != nil {
if font, ok := stringProperty(view, FontName, view.Session()); ok {
return font
}
2022-05-23 15:22:14 +03:00
if value := valueFromStyle(view, FontName); value != nil {
if font, ok := value.(string); ok {
return font
}
2021-09-07 17:36:50 +03:00
}
if parent := view.Parent(); parent != nil {
return GetFontName(parent, "")
}
}
return ""
}
// GetTextColor returns a text color of the subview.
// If the second argument (subviewID) 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 "" 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
}
// 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 "" 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
//
2021-09-07 17:36:50 +03:00
// If the second argument (subviewID) 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)
2021-09-07 17:36:50 +03:00
}
// GetTextIndent returns a text indent of the subview.
// If the second argument (subviewID) 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 "" 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 "" 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 "" 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 "" 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 "" 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 "" 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 "" 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 "" 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 "" 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 "" 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 "" 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 "" 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)
2021-09-07 17:36:50 +03:00
// If the second argument (subviewID) 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).
2021-09-07 17:36:50 +03:00
// If the second argument (subviewID) 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).
2021-09-07 17:36:50 +03:00
// If the second argument (subviewID) 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 "" then a values from the first argument (view) is returned.
func GetRow(view View, subviewID string) Range {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if view != nil {
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 "" then a values from the first argument (view) is returned.
func GetColumn(view View, subviewID string) Range {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if view != nil {
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{}
}
// 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 "" 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 "" then a value from the first argument (view) is returned.
func GetPerspectiveOrigin(view View, subviewID string) (SizeUnit, SizeUnit) {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
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.
2021-09-07 17:36:50 +03:00
// If the second argument (subviewID) 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
}
// GetOrigin returns a x-, y-, and z-coordinate of the point around which a view transformation is applied.
// The default value is (50%, 50%, 50%).
// If the second argument (subviewID) is "" then a value from the first argument (view) is returned.
func GetOrigin(view View, subviewID string) (SizeUnit, SizeUnit, SizeUnit) {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if view == nil {
return AutoSize(), AutoSize(), AutoSize()
}
return getOrigin(view, view.Session())
}
// GetTranslate returns a x-, y-, and z-axis translation value of a 2D/3D translation
// If the second argument (subviewID) is "" then a value from the first argument (view) is returned.
func GetTranslate(view View, subviewID string) (SizeUnit, SizeUnit, SizeUnit) {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if view == nil {
return AutoSize(), AutoSize(), AutoSize()
}
return getTranslate(view, view.Session())
}
// 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 "" then a value from the first argument (view) is returned.
func GetSkew(view View, subviewID string) (AngleUnit, AngleUnit) {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if view == nil {
return AngleUnit{Value: 0, Type: Radian}, AngleUnit{Value: 0, Type: Radian}
}
x, y, _ := getSkew(view, 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 "" then a value from the first argument (view) is returned.
func GetScale(view View, subviewID string) (float64, float64, float64) {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
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 "" then a value from the first argument (view) is returned.
func GetRotate(view View, subviewID string) (float64, float64, float64, AngleUnit) {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
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 "" 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
}
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
}
2022-07-26 18:36:00 +03:00
func valueFromStyle(view View, tag string) any {
2021-09-07 17:36:50 +03:00
session := view.Session()
2022-07-26 18:36:00 +03:00
getValue := func(styleTag string) 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)
}
2022-07-28 12:53:50 +03:00
func sizeStyledProperty(view View, subviewID string, tag string, inherit bool) SizeUnit {
if subviewID != "" {
view = ViewByID(view, subviewID)
2021-09-07 17:36:50 +03:00
}
2022-07-28 12:53:50 +03:00
if view != nil {
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, "", tag, true)
}
}
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
}
2022-07-28 12:41:50 +03:00
func enumStyledProperty(view View, subviewID string, tag string, defaultValue int, inherit bool) int {
if subviewID != "" {
view = ViewByID(view, subviewID)
2021-09-07 17:36:50 +03:00
}
2022-07-28 12:41:50 +03:00
if view != nil {
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, "", tag, defaultValue, true)
}
}
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
}
2022-07-28 12:11:27 +03:00
func boolStyledProperty(view View, subviewID string, tag string, inherit bool) bool {
if subviewID != "" {
view = ViewByID(view, subviewID)
2021-09-07 17:36:50 +03:00
}
2022-07-28 12:11:27 +03:00
if view != nil {
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, "", tag, inherit)
}
}
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
}
2022-07-28 12:11:27 +03:00
func intStyledProperty(view View, subviewID string, tag string, defaultValue int) int {
if subviewID != "" {
view = ViewByID(view, subviewID)
2021-09-07 17:36:50 +03:00
}
2022-07-28 12:11:27 +03:00
if view != nil {
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
}
2022-07-28 12:11:27 +03:00
func floatStyledProperty(view View, subviewID string, tag string, defaultValue float64) float64 {
if subviewID != "" {
view = ViewByID(view, subviewID)
2021-09-07 17:36:50 +03:00
}
2022-07-28 12:11:27 +03:00
if view != nil {
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
}
2022-07-28 12:11:27 +03:00
func colorStyledProperty(view View, subviewID, tag string, inherit bool) Color {
if subviewID != "" {
view = ViewByID(view, subviewID)
2021-09-07 17:36:50 +03:00
}
2022-07-28 12:11:27 +03:00
if view != nil {
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, "", tag, true)
}
}
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
}
// FocusView sets focus on the specified View, 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 FocusView(view View) {
if view != nil {
view.Session().runScript("focus('" + view.htmlID() + "')")
}
}
// 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 != "" {
session.runScript("focus('" + viewID + "')")
}
}
// BlurView removes keyboard focus from the specified View.
func BlurView(view View) {
if view != nil {
view.Session().runScript("blur('" + view.htmlID() + "')")
}
}
// BlurViewByID removes keyboard focus from the View with the specified viewID.
func BlurViewByID(viewID string, session Session) {
if viewID != "" {
session.runScript("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 "" then a value from the first argument (view) is returned.
func GetCurrent(view View, subviewID string) int {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
defaultValue := -1
if 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 "" then a value from the first argument (view) is returned.
func IsUserSelect(view View, subviewID string) bool {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if 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
}
}
2022-07-28 12:11:27 +03:00
switch GetSemantics(view, "") {
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
}