rui_orig/columnLayout.go

239 lines
9.1 KiB
Go
Raw Normal View History

2021-09-07 17:36:50 +03:00
package rui
import (
"strconv"
"strings"
)
const (
// ColumnCount is the constant for the "column-count" property tag.
// The "column-count" int property specifies number of columns into which the content is break
// Values less than zero are not valid. if the "column-count" property value is 0 then
// the number of columns is calculated based on the "column-width" property
ColumnCount = "column-count"
2022-12-23 17:27:14 +03:00
2021-09-07 17:36:50 +03:00
// ColumnWidth is the constant for the "column-width" property tag.
// The "column-width" SizeUnit property specifies the width of each column.
ColumnWidth = "column-width"
2022-12-23 17:27:14 +03:00
2021-09-07 17:36:50 +03:00
// ColumnGap is the constant for the "column-gap" property tag.
// The "column-width" SizeUnit property sets the size of the gap (gutter) between columns.
ColumnGap = "column-gap"
2022-12-23 17:27:14 +03:00
2021-09-07 17:36:50 +03:00
// ColumnSeparator is the constant for the "column-separator" property tag.
// The "column-separator" property specifies the line drawn between columns in a multi-column layout.
ColumnSeparator = "column-separator"
2022-12-23 17:27:14 +03:00
2021-09-07 17:36:50 +03:00
// ColumnSeparatorStyle is the constant for the "column-separator-style" property tag.
// The "column-separator-style" int property sets the style of the line drawn between
// columns in a multi-column layout.
// Valid values are NoneLine (0), SolidLine (1), DashedLine (2), DottedLine (3), and DoubleLine (4).
ColumnSeparatorStyle = "column-separator-style"
2022-12-23 17:27:14 +03:00
2021-09-07 17:36:50 +03:00
// ColumnSeparatorWidth is the constant for the "column-separator-width" property tag.
// The "column-separator-width" SizeUnit property sets the width of the line drawn between
// columns in a multi-column layout.
ColumnSeparatorWidth = "column-separator-width"
2022-12-23 17:27:14 +03:00
2021-09-07 17:36:50 +03:00
// ColumnSeparatorColor is the constant for the "column-separator-color" property tag.
// The "column-separator-color" Color property sets the color of the line drawn between
// columns in a multi-column layout.
ColumnSeparatorColor = "column-separator-color"
2022-12-23 17:27:14 +03:00
// ColumnFill is the constant for the "column-fill" property tag.
// The "column-fill" int property controls how an ColumnLayout's contents are balanced when broken into columns.
// Valid values are
// * ColumnFillBalance (0) - Content is equally divided between columns (default value);
// * ColumnFillAuto (1) - Columns are filled sequentially. Content takes up only the room it needs, possibly resulting in some columns remaining empty.
ColumnFill = "column-fill"
2023-01-03 14:56:57 +03:00
// ColumnSpanAll is the constant for the "column-span-all" property tag.
// The "column-span-all" bool property makes it possible for a view to span across all columns when its value is set to true.
ColumnSpanAll = "column-span-all"
2021-09-07 17:36:50 +03:00
)
// ColumnLayout - grid-container of View
type ColumnLayout interface {
ViewsContainer
}
type columnLayoutData struct {
viewsContainerData
}
// NewColumnLayout create new ColumnLayout object and return it
func NewColumnLayout(session Session, params Params) ColumnLayout {
view := new(columnLayoutData)
view.init(session)
2021-09-07 17:36:50 +03:00
setInitParams(view, params)
return view
}
func newColumnLayout(session Session) View {
return NewColumnLayout(session, nil)
}
// Init initialize fields of ColumnLayout by default values
func (ColumnLayout *columnLayoutData) init(session Session) {
ColumnLayout.viewsContainerData.init(session)
2021-09-07 17:36:50 +03:00
ColumnLayout.tag = "ColumnLayout"
//ColumnLayout.systemClass = "ruiColumnLayout"
}
2022-05-22 12:54:02 +03:00
func (columnLayout *columnLayoutData) String() string {
return getViewString(columnLayout, nil)
2022-05-22 12:54:02 +03:00
}
2021-09-07 17:36:50 +03:00
func (columnLayout *columnLayoutData) normalizeTag(tag string) string {
tag = strings.ToLower(tag)
switch tag {
case Gap:
return ColumnGap
}
return tag
}
2022-07-26 18:36:00 +03:00
func (columnLayout *columnLayoutData) Get(tag string) any {
2021-09-07 17:36:50 +03:00
return columnLayout.get(columnLayout.normalizeTag(tag))
}
func (columnLayout *columnLayoutData) Remove(tag string) {
columnLayout.remove(columnLayout.normalizeTag(tag))
}
func (columnLayout *columnLayoutData) remove(tag string) {
columnLayout.viewsContainerData.remove(tag)
if columnLayout.created {
switch tag {
case ColumnCount, ColumnWidth, ColumnGap:
2022-10-30 17:22:33 +03:00
columnLayout.session.updateCSSProperty(columnLayout.htmlID(), tag, "")
2021-09-07 17:36:50 +03:00
case ColumnSeparator:
2022-10-30 17:22:33 +03:00
columnLayout.session.updateCSSProperty(columnLayout.htmlID(), "column-rule", "")
}
2021-09-07 17:36:50 +03:00
}
}
2022-07-26 18:36:00 +03:00
func (columnLayout *columnLayoutData) Set(tag string, value any) bool {
2021-09-07 17:36:50 +03:00
return columnLayout.set(columnLayout.normalizeTag(tag), value)
}
2022-07-26 18:36:00 +03:00
func (columnLayout *columnLayoutData) set(tag string, value any) bool {
2021-09-07 17:36:50 +03:00
if value == nil {
columnLayout.remove(tag)
return true
}
if !columnLayout.viewsContainerData.set(tag, value) {
2021-09-07 17:36:50 +03:00
return false
}
if columnLayout.created {
2021-09-07 17:36:50 +03:00
switch tag {
case ColumnSeparator:
css := ""
session := columnLayout.Session()
if val, ok := columnLayout.properties[ColumnSeparator]; ok {
separator := val.(ColumnSeparatorProperty)
css = separator.cssValue(columnLayout.Session())
}
2022-10-30 17:22:33 +03:00
session.updateCSSProperty(columnLayout.htmlID(), "column-rule", css)
case ColumnCount:
session := columnLayout.Session()
if count, ok := intProperty(columnLayout, tag, session, 0); ok && count > 0 {
2022-10-30 17:22:33 +03:00
session.updateCSSProperty(columnLayout.htmlID(), tag, strconv.Itoa(count))
} else {
2022-10-30 17:22:33 +03:00
session.updateCSSProperty(columnLayout.htmlID(), tag, "auto")
}
2021-09-07 17:36:50 +03:00
}
}
return true
2021-09-07 17:36:50 +03:00
}
// GetColumnCount returns int value which specifies number of columns into which the content of
// ColumnLayout is break. If the return value is 0 then the number of columns is calculated
// based on the "column-width" property.
// If the second argument (subviewID) is not specified or it is "" then a top position of the first argument (view) is returned
func GetColumnCount(view View, subviewID ...string) int {
2022-07-28 12:11:27 +03:00
return intStyledProperty(view, subviewID, ColumnCount, 0)
2021-09-07 17:36:50 +03:00
}
// GetColumnWidth returns SizeUnit value which specifies the width of each column of ColumnLayout.
// If the second argument (subviewID) is not specified or it is "" then a top position of the first argument (view) is returned
func GetColumnWidth(view View, subviewID ...string) SizeUnit {
2022-07-28 12:53:50 +03:00
return sizeStyledProperty(view, subviewID, ColumnWidth, false)
2021-09-07 17:36:50 +03:00
}
// GetColumnGap returns SizeUnit property which specifies the size of the gap (gutter) between columns of ColumnLayout.
// If the second argument (subviewID) is not specified or it is "" then a top position of the first argument (view) is returned
func GetColumnGap(view View, subviewID ...string) SizeUnit {
2022-07-28 12:53:50 +03:00
return sizeStyledProperty(view, subviewID, ColumnGap, false)
2021-09-07 17:36:50 +03:00
}
func getColumnSeparator(view View, subviewID []string) ViewBorder {
if len(subviewID) > 0 && subviewID[0] != "" {
view = ViewByID(view, subviewID[0])
2021-09-07 17:36:50 +03:00
}
if view != nil {
value := view.Get(ColumnSeparator)
if value == nil {
2022-05-23 15:22:14 +03:00
value = valueFromStyle(view, ColumnSeparator)
2021-09-07 17:36:50 +03:00
}
if value != nil {
if separator, ok := value.(ColumnSeparatorProperty); ok {
return separator.ViewBorder(view.Session())
}
}
}
return ViewBorder{}
}
// GetColumnSeparator returns ViewBorder struct which specifies the line drawn between
// columns in a multi-column ColumnLayout.
// If the second argument (subviewID) is not specified or it is "" then a top position of the first argument (view) is returned
func GetColumnSeparator(view View, subviewID ...string) ViewBorder {
return getColumnSeparator(view, subviewID)
}
2021-09-07 17:36:50 +03:00
// ColumnSeparatorStyle returns int value which specifies the style of the line drawn between
// columns in a multi-column layout.
// Valid values are NoneLine (0), SolidLine (1), DashedLine (2), DottedLine (3), and DoubleLine (4).
// If the second argument (subviewID) is not specified or it is "" then a top position of the first argument (view) is returned
func GetColumnSeparatorStyle(view View, subviewID ...string) int {
border := getColumnSeparator(view, subviewID)
2021-09-07 17:36:50 +03:00
return border.Style
}
// ColumnSeparatorWidth returns SizeUnit value which specifies the width of the line drawn between
// columns in a multi-column layout.
// If the second argument (subviewID) is not specified or it is "" then a top position of the first argument (view) is returned
func GetColumnSeparatorWidth(view View, subviewID ...string) SizeUnit {
border := getColumnSeparator(view, subviewID)
2021-09-07 17:36:50 +03:00
return border.Width
}
// ColumnSeparatorColor returns Color value which specifies the color of the line drawn between
// columns in a multi-column layout.
// If the second argument (subviewID) is not specified or it is "" then a top position of the first argument (view) is returned
func GetColumnSeparatorColor(view View, subviewID ...string) Color {
border := getColumnSeparator(view, subviewID)
2021-09-07 17:36:50 +03:00
return border.Color
}
2022-12-23 17:27:14 +03:00
// GetColumnFill returns a "column-fill" property value of the subview.
// Returns one of next values: ColumnFillBalance (0) or ColumnFillAuto (1)
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetColumnFill(view View, subviewID ...string) int {
return enumStyledProperty(view, subviewID, ColumnFill, ColumnFillBalance, true)
}
2023-01-03 14:56:57 +03:00
// IsColumnSpanAll returns a "column-span-all" property value 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 IsColumnSpanAll(view View, subviewID ...string) bool {
return boolStyledProperty(view, subviewID, ColumnSpanAll, false)
}