diff --git a/CHANGELOG.md b/CHANGELOG.md index 590d2e0..0181114 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,10 @@ * Requires go 1.18 or higher * The "interface{}" type replaced by "any" -* Added "accent-color", "overflow", "arrow", "arrow-align", "arrow-size", "arrow-width", and "arrow-offset" properties +* Added "accent-color", "tab-size", "overflow", "arrow", "arrow-align", "arrow-size", "arrow-width", and "arrow-offset" properties * Added "@ruiArrowSize" and "@ruiArrowWidth" constants to the default theme * Added Transition, Transitions, and SetTransition functions to the ViewStyle interface -* Added GetAccentColor, GetOverflow, IsTimingFunctionValid, and GetTransitions functions +* Added GetAccentColor, GetTabSize, GetOverflow, IsTimingFunctionValid, and GetTransitions functions * Changed GetTransition functions * Added the OpenURL function to the Session interface diff --git a/README-ru.md b/README-ru.md index baf4141..f6335e1 100644 --- a/README-ru.md +++ b/README-ru.md @@ -1408,6 +1408,11 @@ radius необходимо передать nil | WhiteSpacePreLine | Сохраняются как в источнике | Объединяются в один пробел | Переносится | Удаляются | | WhiteSpaceBreakSpaces | Сохраняются как в источнике | Сохраняются как в источнике | Переносится | Переносятся | +#### Свойство "tab-size" + +Свойство "tab-size" (константа TabSize) типа int задает размер символа табуляции (U+0009) в пробелах. +Значение свойства "tab-size" должно быть больше 0. + #### Свойство "word-break" Свойство "word-break" (константа WordBreak) типа int определяет, где будет установлен перевод diff --git a/README.md b/README.md index af4bc78..173ed91 100644 --- a/README.md +++ b/README.md @@ -1391,20 +1391,25 @@ The table below shows the behavior of various values of the "white-space" proper | WhiteSpacePreLine | Preserve | Collapse | Wrap | Remove | Hang | | WhiteSpaceBreakSpaces | Preserve | Preserve | Wrap | Wrap | Wrap | +#### "tab-size" property + +The "tab-size" int property (TabSize constant) specifies the size of the tab character (U+0009) in spaces. +The value of the "tab-size" property must be greater than 0. The default value is 8 + #### "word-break" property The "word-break" int property (WordBreak constant) determines where the newline will be set if the text exceeds the block boundaries. The "white-space" property can take the following values: -0 (constant WordBreak, name "normal) - default behavior for linefeed placement. +0 (WordBreak constant, "normal" name) - default behavior for linefeed placement. -1 (constant WordBreakAll, name "break-all) - if the block boundaries are exceeded, +1 (WordBreakAll constant, "break-all" name) - if the block boundaries are exceeded, a line break will be inserted between any two characters (except for Chinese/Japanese/Korean text). -2 (constant WordBreakKeepAll, name "keep-all) - Line break will not be used in Chinese/Japanese/ Korean text. +2 (WordBreakKeepAll constant, "keep-all" name) - Line break will not be used in Chinese/Japanese/ Korean text. For text in other languages, the default behavior (normal) will be applied. -3 (constant WordBreakWord, name "break-word) - when the block boundaries are exceeded, +3 (WordBreakWord constant, "break-word" name) - when the block boundaries are exceeded, the remaining whole words can be broken in an arbitrary place, if a more suitable place for line break is not found. #### "strikethrough", "overline", "underline" properties diff --git a/propertyGet.go b/propertyGet.go index f800ce8..e0ef75a 100644 --- a/propertyGet.go +++ b/propertyGet.go @@ -42,6 +42,16 @@ func valueToSizeUnit(value any, session Session) (SizeUnit, bool) { if text, ok := session.resolveConstants(value); ok { return StringToSizeUnit(text) } + + case float64: + return Px(value), true + + case float32: + return Px(float64(value)), true + } + + if n, ok := isInt(value); ok { + return Px(float64(n)), true } } diff --git a/propertyNames.go b/propertyNames.go index d810039..ea80288 100644 --- a/propertyNames.go +++ b/propertyNames.go @@ -359,6 +359,11 @@ const ( // This is an inherited property, i.e. if it is not defined, then the value of the parent view is used. TextShadow = "text-shadow" + // TabSize is the constant for the "tab-size" property tag. + // The "tab-size" int property sets the width of tab characters (U+0009) in spaces. + // This is an inherited property, i.e. if it is not defined, then the value of the parent view is used. + TabSize = "tab-size" + // LetterSpacing is the constant for the "letter-spacing" property tag. // The "letter-spacing" SizeUnit property sets the horizontal spacing behavior between text characters. // This value is added to the natural spacing between characters while rendering the text. diff --git a/propertySet.go b/propertySet.go index f16ce05..6d54615 100644 --- a/propertySet.go +++ b/propertySet.go @@ -67,6 +67,7 @@ var boolProperties = []string{ var intProperties = []string{ ZIndex, + TabSize, HeadHeight, FootHeight, RowSpan, diff --git a/view.go b/view.go index 54cb833..f2f0bd3 100644 --- a/view.go +++ b/view.go @@ -591,9 +591,9 @@ func viewPropertyChanged(view *viewData, tag string) { } return - case ZIndex: - if i, ok := intProperty(view, ZIndex, session, 0); ok { - updateCSSProperty(htmlID, ZIndex, strconv.Itoa(i), session) + case ZIndex, TabSize: + if i, ok := intProperty(view, tag, session, 0); ok { + updateCSSProperty(htmlID, tag, strconv.Itoa(i), session) } return diff --git a/viewStyle.go b/viewStyle.go index 608680c..ea295a6 100644 --- a/viewStyle.go +++ b/viewStyle.go @@ -279,6 +279,10 @@ 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 a37b490..10cf27f 100644 --- a/viewUtils.go +++ b/viewUtils.go @@ -156,7 +156,7 @@ func GetOverflow(view View, subviewID string) int { // 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 { - return intStyledProperty(view, subviewID, Visibility, 0) + return intStyledProperty(view, subviewID, ZIndex, 0) } // GetWidth returns the subview width. @@ -366,6 +366,12 @@ func GetTextSize(view View, subviewID string) SizeUnit { return sizeStyledProperty(view, subviewID, TextSize, true) } +// GetTabSize returns the subview width of tab characters (U+0009) in spaces. +// If the second argument (subviewID) is "" then a width of the first argument (view) is returned +func GetTabSize(view View, subviewID string) int { + return intStyledProperty(view, subviewID, TabSize, 8) +} + // 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.