forked from mbk-lab/rui_orig
2
0
Fork 0

Optimisation

This commit is contained in:
Alexei Anoshenko 2022-07-28 12:41:50 +03:00
parent c5ca92de60
commit 3da4d660d5
10 changed files with 116 additions and 286 deletions

View File

@ -266,8 +266,8 @@ func (button *checkboxData) setChangedListener(value any) bool {
func (button *checkboxData) cssStyle(self View, builder cssBuilder) {
session := button.Session()
vAlign, _ := enumStyledProperty(button, CheckboxVerticalAlign, LeftAlign)
hAlign, _ := enumStyledProperty(button, CheckboxHorizontalAlign, TopAlign)
vAlign := GetCheckboxVerticalAlign(button, "")
hAlign := GetCheckboxHorizontalAlign(button, "")
switch hAlign {
case CenterAlign:
if vAlign == BottomAlign {
@ -294,8 +294,8 @@ func (button *checkboxData) cssStyle(self View, builder cssBuilder) {
}
func (button *checkboxData) htmlCheckbox(buffer *strings.Builder, checked bool) (int, int) {
vAlign, _ := enumStyledProperty(button, CheckboxVerticalAlign, LeftAlign)
hAlign, _ := enumStyledProperty(button, CheckboxHorizontalAlign, TopAlign)
vAlign := GetCheckboxVerticalAlign(button, "")
hAlign := GetCheckboxHorizontalAlign(button, "")
buffer.WriteString(`<div id="`)
buffer.WriteString(button.htmlID())
@ -370,7 +370,7 @@ func (button *checkboxData) htmlSubviews(self View, buffer *strings.Builder) {
}
func (button *checkboxData) cssHorizontalAlign() string {
align, _ := enumStyledProperty(button, HorizontalAlign, TopAlign)
align := GetCheckboxHorizontalAlign(button, "")
values := enumProperties[CellHorizontalAlign].cssValues
if align >= 0 && align < len(values) {
return values[align]
@ -379,7 +379,7 @@ func (button *checkboxData) cssHorizontalAlign() string {
}
func (button *checkboxData) cssVerticalAlign() string {
align, _ := enumStyledProperty(button, VerticalAlign, TopAlign)
align := GetCheckboxVerticalAlign(button, "")
values := enumProperties[CellVerticalAlign].cssValues
if align >= 0 && align < len(values) {
return values[align]
@ -402,3 +402,15 @@ func IsCheckboxChecked(view View, subviewID string) bool {
}
return false
}
// GetCheckboxVerticalAlign return the vertical align of a Checkbox subview: TopAlign (0), BottomAlign (1), CenterAlign (2)
// If the second argument (subviewID) is "" then a left position of the first argument (view) is returned
func GetCheckboxVerticalAlign(view View, subviewID string) int {
return enumStyledProperty(view, subviewID, VerticalAlign, LeftAlign, false)
}
// GetCheckboxHorizontalAlign return the vertical align of a Checkbox subview: LeftAlign (0), RightAlign (1), CenterAlign (2)
// If the second argument (subviewID) is "" then a left position of the first argument (view) is returned
func GetCheckboxHorizontalAlign(view View, subviewID string) int {
return enumStyledProperty(view, subviewID, VerticalAlign, TopAlign, false)
}

View File

@ -571,14 +571,7 @@ func GetTextChangedListeners(view View, subviewID string) []func(EditView, strin
// GetEditViewType returns a value of the Type property of EditView.
// If the second argument (subviewID) is "" then a value from the first argument (view) is returned.
func GetEditViewType(view View, subviewID string) int {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if view == nil {
return SingleLineText
}
t, _ := enumStyledProperty(view, EditViewType, SingleLineText)
return t
return enumStyledProperty(view, subviewID, EditViewType, SingleLineText, false)
}
// GetEditViewPattern returns a value of the Pattern property of EditView.

View File

@ -325,43 +325,19 @@ func (gridLayout *gridLayoutData) cssStyle(self View, builder cssBuilder) {
// GetCellVerticalAlign returns the vertical align of a GridLayout cell content: TopAlign (0), BottomAlign (1), CenterAlign (2), StretchAlign (3)
// If the second argument (subviewID) is "" then a value from the first argument (view) is returned.
func GetCellVerticalAlign(view View, subviewID string) int {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if view != nil {
if align, ok := enumStyledProperty(view, CellVerticalAlign, StretchAlign); ok {
return align
}
}
return StretchAlign
return enumStyledProperty(view, subviewID, CellVerticalAlign, StretchAlign, false)
}
// GetCellHorizontalAlign returns the vertical align of a GridLayout cell content: LeftAlign (0), RightAlign (1), CenterAlign (2), StretchAlign (3)
// If the second argument (subviewID) is "" then a value from the first argument (view) is returned.
func GetCellHorizontalAlign(view View, subviewID string) int {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if view != nil {
if align, ok := enumStyledProperty(view, CellHorizontalAlign, StretchAlign); ok {
return align
}
}
return StretchAlign
return enumStyledProperty(view, subviewID, CellHorizontalAlign, StretchAlign, false)
}
// GetGridAutoFlow returns the value of the "grid-auto-flow" property
// If the second argument (subviewID) is "" then a value from the first argument (view) is returned.
func GetGridAutoFlow(view View, subviewID string) int {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if view != nil {
if align, ok := enumStyledProperty(view, GridAutoFlow, 0); ok {
return align
}
}
return 0
return enumStyledProperty(view, subviewID, GridAutoFlow, 0, false)
}
// GetCellWidth returns the width of a GridLayout cell. If the result is an empty array, then the width is not set.

View File

@ -360,38 +360,17 @@ func GetImageViewAltText(view View, subviewID string) string {
// NoneFit (0), ContainFit (1), CoverFit (2), FillFit (3), or ScaleDownFit (4).
// If the second argument (subviewID) is "" then a left position of the first argument (view) is returned
func GetImageViewFit(view View, subviewID string) int {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if value, ok := enumStyledProperty(view, Fit, NoneFit); ok {
return value
}
return 0
return enumStyledProperty(view, subviewID, Fit, NoneFit, false)
}
// GetImageViewVerticalAlign return the vertical align of an ImageView subview: TopAlign (0), BottomAlign (1), CenterAlign (2)
// If the second argument (subviewID) is "" then a left position of the first argument (view) is returned
func GetImageViewVerticalAlign(view View, subviewID string) int {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if align, ok := enumStyledProperty(view, ImageVerticalAlign, LeftAlign); ok {
return align
}
return CenterAlign
return enumStyledProperty(view, subviewID, ImageVerticalAlign, LeftAlign, false)
}
// GetImageViewHorizontalAlign return the vertical align of an ImageView subview: LeftAlign (0), RightAlign (1), CenterAlign (2)
// If the second argument (subviewID) is "" then a left position of the first argument (view) is returned
func GetImageViewHorizontalAlign(view View, subviewID string) int {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if align, ok := enumStyledProperty(view, ImageHorizontalAlign, LeftAlign); ok {
return align
}
return CenterAlign
return enumStyledProperty(view, subviewID, ImageHorizontalAlign, LeftAlign, false)
}

View File

@ -163,16 +163,8 @@ func GetListOrientation(view View, subviewID string) int {
}
// GetListWrap returns the wrap type of a ListLayout or ListView subview:
// WrapOff (0), WrapOn (1), or WrapReverse (2)
// ListWrapOff (0), ListWrapOn (1), or ListWrapReverse (2)
// If the second argument (subviewID) is "" then a value from the first argument (view) is returned.
func GetListWrap(view View, subviewID string) int {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if view != nil {
if result, ok := enumStyledProperty(view, ListWrap, 0); ok {
return result
}
}
return ListWrapOff
return enumStyledProperty(view, subviewID, ListWrap, ListWrapOff, false)
}

View File

@ -917,8 +917,7 @@ func (listView *listViewData) htmlSubviews(self View, buffer *strings.Builder) {
}
value := ""
if align, ok := enumStyledProperty(listView, HorizontalAlign, LeftAlign); ok {
switch align {
switch enumStyledProperty(listView, "", HorizontalAlign, LeftAlign, false) {
case LeftAlign:
if (!rows && wrap == ListWrapReverse) || orientation == EndToStartOrientation {
value = `flex-end`
@ -941,7 +940,6 @@ func (listView *listViewData) htmlSubviews(self View, buffer *strings.Builder) {
value = `stretch`
}
}
}
if value != "" {
buffer.WriteRune(' ')
@ -952,8 +950,7 @@ func (listView *listViewData) htmlSubviews(self View, buffer *strings.Builder) {
}
value = ""
if align, ok := enumStyledProperty(listView, VerticalAlign, TopAlign); ok {
switch align {
switch enumStyledProperty(listView, "", VerticalAlign, TopAlign, false) {
case TopAlign:
if (rows && wrap == ListWrapReverse) || orientation == BottomUpOrientation {
value = `flex-end`
@ -976,7 +973,6 @@ func (listView *listViewData) htmlSubviews(self View, buffer *strings.Builder) {
value = `space-between`
}
}
}
if value != "" {
buffer.WriteRune(' ')

View File

@ -258,15 +258,7 @@ func (picker *numberPickerData) handleCommand(self View, command string, data Da
// NumberSlider (1) - NumberPicker is presented by slider.
// If the second argument (subviewID) is "" then a value from the first argument (view) is returned.
func GetNumberPickerType(view View, subviewID string) int {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if view == nil {
return 0
}
t, _ := enumStyledProperty(view, NumberPickerType, NumberEditor)
return t
return enumStyledProperty(view, subviewID, NumberPickerType, NumberEditor, false)
}
// GetNumberPickerMinMax returns the min and max value of NumberPicker subview.

View File

@ -91,30 +91,14 @@ func GetTableCellStyle(view View, subviewID string) TableCellStyle {
// Valid values are NoneSelection (0), CellSelection (1), and RowSelection (2).
// If the second argument (subviewID) is "" then a value from the first argument (view) is returned.
func GetTableSelectionMode(view View, subviewID string) int {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if view != nil {
if result, ok := enumStyledProperty(view, SelectionMode, NoneSelection); ok {
return result
}
}
return NoneSelection
return enumStyledProperty(view, subviewID, SelectionMode, NoneSelection, false)
}
// GetTableVerticalAlign returns a vertical align in a TavleView cell. Returns one of next values:
// TopAlign (0), BottomAlign (1), CenterAlign (2), and BaselineAlign (3)
// If the second argument (subviewID) is "" then a value from the first argument (view) is returned.
func GetTableVerticalAlign(view View, subviewID string) int {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if view != nil {
if result, ok := enumStyledProperty(view, TableVerticalAlign, TopAlign); ok {
return result
}
}
return TopAlign
return enumStyledProperty(view, subviewID, TableVerticalAlign, TopAlign, false)
}
// GetTableHeadHeight returns the number of rows in the table header.

View File

@ -167,12 +167,5 @@ func (textView *textViewData) htmlSubviews(self View, buffer *strings.Builder) {
// TextOverflowClip (0) or TextOverflowEllipsis (1).
// If the second argument (subviewID) is "" then a value from the first argument (view) is returned.
func GetTextOverflow(view View, subviewID string) int {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if view == nil {
return SingleLineText
}
t, _ := enumStyledProperty(view, TextOverflow, SingleLineText)
return t
return enumStyledProperty(view, subviewID, TextOverflow, SingleLineText, false)
}

View File

@ -88,16 +88,7 @@ func IsDisabled(view View, subviewID string) bool {
// 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 {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if view != nil {
if semantics, ok := enumStyledProperty(view, Semantics, DefaultSemantics); ok {
return semantics
}
}
return DefaultSemantics
return enumStyledProperty(view, subviewID, Semantics, DefaultSemantics, false)
}
// GetOpacity returns the subview opacity.
@ -138,28 +129,19 @@ func GetDisabledStyle(view View, subviewID string) string {
// 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 {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if view == nil {
return Visible
}
result, _ := enumStyledProperty(view, Visibility, Visible)
return result
return enumStyledProperty(view, subviewID, Visibility, Visible, false)
}
// 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 {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if view == nil {
return OverflowHidden
}
defaultOverflow := OverflowHidden
view2 := view
if subviewID != "" {
view2 = ViewByID(view, subviewID)
}
if view2 != nil {
switch view.(type) {
case EditView:
defaultOverflow = OverflowAuto
@ -167,9 +149,8 @@ func GetOverflow(view View, subviewID string) int {
case ListView:
defaultOverflow = OverflowAuto
}
result, _ := enumStyledProperty(view, Overflow, defaultOverflow)
return result
}
return enumStyledProperty(view, subviewID, Overflow, defaultOverflow, false)
}
// GetZIndex returns the subview z-order.
@ -260,14 +241,7 @@ func GetMaxHeight(view View, subviewID string) SizeUnit {
// 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 {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if view == nil {
return 0
}
result, _ := enumStyledProperty(view, Resize, 0)
return result
return enumStyledProperty(view, subviewID, Resize, NoneResize, false)
}
// GetLeft returns a left position of the subview in an AbsoluteLayout container.
@ -471,36 +445,14 @@ func GetTextSize(view View, subviewID string) SizeUnit {
// 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 {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if view != nil {
if weight, ok := enumStyledProperty(view, TextWeight, NormalFont); ok {
return weight
}
if parent := view.Parent(); parent != nil {
return GetTextWeight(parent, "")
}
}
return NormalFont
return enumStyledProperty(view, subviewID, TextWeight, NormalFont, true)
}
// GetTextAlign returns a text align of the subview. Returns one of next values:
// LeftAlign = 0, RightAlign = 1, CenterAlign = 2, JustifyAlign = 3
// If the second argument (subviewID) is "" then a value from the first argument (view) is returned.
func GetTextAlign(view View, subviewID string) int {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if view != nil {
if result, ok := enumStyledProperty(view, TextAlign, LeftAlign); ok {
return result
}
if parent := view.Parent(); parent != nil {
return GetTextAlign(parent, "")
}
}
return LeftAlign
return enumStyledProperty(view, subviewID, TextAlign, LeftAlign, true)
}
// GetTextIndent returns a text indent of the subview.
@ -623,18 +575,7 @@ func GetTextLineThickness(view View, subviewID string) SizeUnit {
// 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 {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if view != nil {
if result, ok := enumStyledProperty(view, TextLineStyle, SolidLine); ok {
return result
}
if parent := view.Parent(); parent != nil {
return GetTextLineStyle(parent, "")
}
}
return SolidLine
return enumStyledProperty(view, subviewID, TextLineStyle, SolidLine, true)
}
// GetTextLineColor returns the stroke color of the decoration line that
@ -648,18 +589,7 @@ func GetTextLineColor(view View, subviewID string) Color {
// 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 {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if view != nil {
if result, ok := enumStyledProperty(view, TextTransform, NoneTextTransform); ok {
return result
}
if parent := view.Parent(); parent != nil {
return GetTextTransform(parent, "")
}
}
return NoneTextTransform
return enumStyledProperty(view, subviewID, TextTransform, NoneTextTransform, true)
}
// GetWritingMode returns whether lines of text are laid out horizontally or vertically, as well as
@ -667,37 +597,18 @@ func GetTextTransform(view View, subviewID string) int {
// HorizontalBottomToTop (1), VerticalRightToLeft (2) and VerticalLeftToRight (3)
// If the second argument (subviewID) is "" then a value from the first argument (view) is returned.
func GetWritingMode(view View, subviewID string) int {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if view != nil {
if result, ok := enumStyledProperty(view, WritingMode, HorizontalTopToBottom); ok {
return result
}
if parent := view.Parent(); parent != nil {
return GetWritingMode(parent, "")
}
}
return HorizontalTopToBottom
return enumStyledProperty(view, subviewID, WritingMode, HorizontalTopToBottom, true)
}
// GetTextDirection - returns a direction of text, table columns, and horizontal overflow.
// Valid values are Inherit (0), LeftToRightDirection (1), and RightToLeftDirection (2).
// Valid values are SystemTextDirection (0), LeftToRightDirection (1), and RightToLeftDirection (2).
// If the second argument (subviewID) is "" then a value from the first argument (view) is returned.
func GetTextDirection(view View, subviewID string) int {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if view != nil {
if result, ok := enumStyledProperty(view, TextDirection, SystemTextDirection); ok {
return result
}
if parent := view.Parent(); parent != nil {
return GetTextDirection(parent, "")
}
}
if view == nil {
return SystemTextDirection
// TODO return system text direction
}
defaultDirection := view.Session().TextDirection()
return enumStyledProperty(view, subviewID, TextDirection, defaultDirection, true)
}
// GetVerticalTextOrientation returns a orientation of the text characters in a line. It only affects text
@ -705,18 +616,7 @@ func GetTextDirection(view View, subviewID string) int {
// Valid values are MixedTextOrientation (0), UprightTextOrientation (1), and SidewaysTextOrientation (2).
// If the second argument (subviewID) is "" then a value from the first argument (view) is returned.
func GetVerticalTextOrientation(view View, subviewID string) int {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if view != nil {
if result, ok := enumStyledProperty(view, VerticalTextOrientation, MixedTextOrientation); ok {
return result
}
if parent := view.Parent(); parent != nil {
return GetVerticalTextOrientation(parent, "")
}
}
return MixedTextOrientation
return enumStyledProperty(view, subviewID, VerticalTextOrientation, MixedTextOrientation, true)
}
// GetRow returns the range of row numbers of a GridLayout in which the subview is placed.
@ -903,14 +803,27 @@ func sizeStyledProperty(view View, tag string) (SizeUnit, bool) {
return AutoSize(), false
}
func enumStyledProperty(view View, tag string, defaultValue int) (int, bool) {
func enumStyledProperty(view View, subviewID string, tag string, defaultValue int, inherit bool) int {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if view != nil {
if value, ok := enumProperty(view, tag, view.Session(), defaultValue); ok {
return value, true
return value
}
if value := valueFromStyle(view, tag); value != nil {
return valueToEnum(value, tag, view.Session(), defaultValue)
if result, ok := valueToEnum(value, tag, view.Session(), defaultValue); ok {
return result
}
return defaultValue, false
}
if inherit {
if parent := view.Parent(); parent != nil {
return enumStyledProperty(parent, "", tag, defaultValue, true)
}
}
}
return defaultValue
}
func boolStyledProperty(view View, subviewID string, tag string, inherit bool) bool {