From 9fe570ec22fa48143ddfdea001c831ffe63be817 Mon Sep 17 00:00:00 2001 From: anoshenko Date: Sun, 18 Dec 2022 18:37:36 +0300 Subject: [PATCH] Added "order" property --- propertyNames.go | 5 +++++ propertySet.go | 1 + view.go | 2 +- viewStyle.go | 16 ++++++++-------- viewUtils.go | 6 ++++++ 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/propertyNames.go b/propertyNames.go index 2601fb7..df26607 100644 --- a/propertyNames.go +++ b/propertyNames.go @@ -669,4 +669,9 @@ const ( // The "user-select" bool property controls whether the user can select text. // This is an inherited property, i.e. if it is not defined, then the value of the parent view is used. UserSelect = "user-select" + + // Order is the constant for the "Order" property tag. + // The "Order" int property sets the order to layout an item in a ListLayout or GridLayout container. + // Items in a container are sorted by ascending order value and then by their source code order. + Order = "Order" ) diff --git a/propertySet.go b/propertySet.go index 34ead12..ab62187 100644 --- a/propertySet.go +++ b/propertySet.go @@ -73,6 +73,7 @@ var intProperties = []string{ RowSpan, ColumnSpan, ColumnCount, + Order, } var floatProperties = map[string]struct{ min, max float64 }{ diff --git a/view.go b/view.go index b81dae3..f7a62eb 100644 --- a/view.go +++ b/view.go @@ -577,7 +577,7 @@ func viewPropertyChanged(view *viewData, tag string) { } return - case ZIndex, TabSize: + case ZIndex, Order, TabSize: if i, ok := intProperty(view, tag, session, 0); ok { session.updateCSSProperty(htmlID, tag, strconv.Itoa(i)) } diff --git a/viewStyle.go b/viewStyle.go index 1abd273..1c505b6 100644 --- a/viewStyle.go +++ b/viewStyle.go @@ -193,16 +193,20 @@ func (style *viewStyle) cssViewStyle(builder cssBuilder, session Session) { outline.ViewOutline(session).cssValue(builder, session) } - if z, ok := intProperty(style, ZIndex, session, 0); ok { - builder.add(ZIndex, strconv.Itoa(z)) + for _, tag := range []string{ZIndex, Order} { + if value, ok := intProperty(style, tag, session, 0); ok { + builder.add(tag, strconv.Itoa(value)) + } } if opacity, ok := floatProperty(style, Opacity, session, 1.0); ok && opacity >= 0 && opacity <= 1 { builder.add(Opacity, strconv.FormatFloat(opacity, 'f', 3, 32)) } - if n, ok := intProperty(style, ColumnCount, session, 0); ok && n > 0 { - builder.add(ColumnCount, strconv.Itoa(n)) + for _, tag := range []string{ColumnCount, TabSize} { + if value, ok := intProperty(style, tag, session, 0); ok && value > 0 { + builder.add(tag, strconv.Itoa(value)) + } } for _, tag := range []string{ @@ -279,10 +283,6 @@ func (style *viewStyle) cssViewStyle(builder cssBuilder, session Session) { } } - if tabSize, ok := intProperty(style, TabSize, session, 8); ok && tabSize > 0 { - builder.add(TabSize, strconv.Itoa(tabSize)) - } - if text := style.cssTextDecoration(session); text != "" { builder.add("text-decoration", text) } diff --git a/viewUtils.go b/viewUtils.go index fd4765d..5e89dbe 100644 --- a/viewUtils.go +++ b/viewUtils.go @@ -159,6 +159,12 @@ func GetZIndex(view View, subviewID ...string) int { return intStyledProperty(view, subviewID, ZIndex, 0) } +// 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) +} + // 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 {