2021-09-07 17:36:50 +03:00
|
|
|
package rui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2024-09-12 14:05:11 +03:00
|
|
|
// Constants which represent values of the "orientation" property of the [ListLayout]
|
2021-09-07 17:36:50 +03:00
|
|
|
const (
|
|
|
|
// TopDownOrientation - subviews are arranged from top to bottom. Synonym of VerticalOrientation
|
|
|
|
TopDownOrientation = 0
|
2024-04-23 19:34:36 +03:00
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
// StartToEndOrientation - subviews are arranged from left to right. Synonym of HorizontalOrientation
|
|
|
|
StartToEndOrientation = 1
|
2024-04-23 19:34:36 +03:00
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
// BottomUpOrientation - subviews are arranged from bottom to top
|
|
|
|
BottomUpOrientation = 2
|
2024-04-23 19:34:36 +03:00
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
// EndToStartOrientation - subviews are arranged from right to left
|
|
|
|
EndToStartOrientation = 3
|
2024-09-12 14:05:11 +03:00
|
|
|
)
|
2024-04-23 19:34:36 +03:00
|
|
|
|
2024-09-12 14:05:11 +03:00
|
|
|
// Constants which represent values of the "list-wrap" property of the [ListLayout]
|
|
|
|
const (
|
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
|
|
|
// ListWrapOff - subviews are scrolled and "true" if a new row/column starts
|
|
|
|
ListWrapOff = 0
|
2024-04-23 19:34:36 +03:00
|
|
|
|
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
|
|
|
// ListWrapOn - the new row/column starts at bottom/right
|
|
|
|
ListWrapOn = 1
|
2024-04-23 19:34:36 +03:00
|
|
|
|
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
|
|
|
// ListWrapReverse - the new row/column starts at top/left
|
|
|
|
ListWrapReverse = 2
|
2021-09-07 17:36:50 +03:00
|
|
|
)
|
|
|
|
|
2024-09-12 14:05:11 +03:00
|
|
|
// ListLayout represents a ListLayout view
|
2021-09-07 17:36:50 +03:00
|
|
|
type ListLayout interface {
|
|
|
|
ViewsContainer
|
2024-06-03 18:31:25 +03:00
|
|
|
// UpdateContent updates child Views if the "content" property value is set to ListAdapter,
|
|
|
|
// otherwise does nothing
|
|
|
|
UpdateContent()
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type listLayoutData struct {
|
|
|
|
viewsContainerData
|
2024-06-03 18:31:25 +03:00
|
|
|
adapter ListAdapter
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewListLayout create new ListLayout object and return it
|
|
|
|
func NewListLayout(session Session, params Params) ListLayout {
|
|
|
|
view := new(listLayoutData)
|
2022-09-01 11:04:50 +03:00
|
|
|
view.init(session)
|
2021-09-07 17:36:50 +03:00
|
|
|
setInitParams(view, params)
|
|
|
|
return view
|
|
|
|
}
|
|
|
|
|
|
|
|
func newListLayout(session Session) View {
|
|
|
|
return NewListLayout(session, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Init initialize fields of ViewsAlignContainer by default values
|
2022-09-01 11:04:50 +03:00
|
|
|
func (listLayout *listLayoutData) init(session Session) {
|
|
|
|
listLayout.viewsContainerData.init(session)
|
2021-09-07 17:36:50 +03:00
|
|
|
listLayout.tag = "ListLayout"
|
|
|
|
listLayout.systemClass = "ruiListLayout"
|
|
|
|
}
|
|
|
|
|
2022-05-22 12:54:02 +03:00
|
|
|
func (listLayout *listLayoutData) String() string {
|
2024-05-02 15:07:57 +03:00
|
|
|
return getViewString(listLayout, nil)
|
2022-05-22 12:54:02 +03:00
|
|
|
}
|
|
|
|
|
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
|
|
|
func (listLayout *listLayoutData) normalizeTag(tag string) string {
|
|
|
|
tag = strings.ToLower(tag)
|
|
|
|
switch tag {
|
|
|
|
case "wrap":
|
|
|
|
tag = ListWrap
|
2022-08-31 17:31:17 +03:00
|
|
|
|
|
|
|
case "row-gap":
|
|
|
|
return ListRowGap
|
|
|
|
|
|
|
|
case ColumnGap:
|
|
|
|
return ListColumnGap
|
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
|
|
|
}
|
|
|
|
return tag
|
|
|
|
}
|
|
|
|
|
2022-07-26 18:36:00 +03:00
|
|
|
func (listLayout *listLayoutData) Get(tag string) any {
|
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
|
|
|
return listLayout.get(listLayout.normalizeTag(tag))
|
|
|
|
}
|
|
|
|
|
2022-08-31 17:31:17 +03:00
|
|
|
func (listLayout *listLayoutData) get(tag string) any {
|
|
|
|
if tag == Gap {
|
2022-08-31 22:17:46 +03:00
|
|
|
if rowGap := GetListRowGap(listLayout); rowGap.Equal(GetListColumnGap(listLayout)) {
|
2022-08-31 17:31:17 +03:00
|
|
|
return rowGap
|
|
|
|
}
|
|
|
|
return AutoSize()
|
|
|
|
}
|
|
|
|
|
|
|
|
return listLayout.viewsContainerData.get(tag)
|
|
|
|
}
|
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
func (listLayout *listLayoutData) Remove(tag string) {
|
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
|
|
|
listLayout.remove(listLayout.normalizeTag(tag))
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (listLayout *listLayoutData) remove(tag string) {
|
2024-06-03 18:31:25 +03:00
|
|
|
switch tag {
|
|
|
|
case Gap:
|
2022-08-31 17:31:17 +03:00
|
|
|
listLayout.remove(ListRowGap)
|
|
|
|
listLayout.remove(ListColumnGap)
|
|
|
|
return
|
2024-06-03 18:31:25 +03:00
|
|
|
|
|
|
|
case Content:
|
|
|
|
listLayout.adapter = nil
|
2022-08-31 17:31:17 +03:00
|
|
|
}
|
2024-06-03 18:31:25 +03:00
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
listLayout.viewsContainerData.remove(tag)
|
2021-11-20 11:15:28 +03:00
|
|
|
if listLayout.created {
|
|
|
|
switch tag {
|
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
|
|
|
case Orientation, ListWrap, HorizontalAlign, VerticalAlign:
|
2021-11-20 11:15:28 +03:00
|
|
|
updateCSSStyle(listLayout.htmlID(), listLayout.session)
|
|
|
|
}
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-26 18:36:00 +03:00
|
|
|
func (listLayout *listLayoutData) Set(tag string, value any) bool {
|
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
|
|
|
return listLayout.set(listLayout.normalizeTag(tag), value)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
2022-07-26 18:36:00 +03:00
|
|
|
func (listLayout *listLayoutData) set(tag string, value any) bool {
|
2021-09-07 17:36:50 +03:00
|
|
|
if value == nil {
|
|
|
|
listLayout.remove(tag)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2024-06-03 18:31:25 +03:00
|
|
|
switch tag {
|
|
|
|
case Gap:
|
2022-08-31 17:31:17 +03:00
|
|
|
return listLayout.set(ListRowGap, value) && listLayout.set(ListColumnGap, value)
|
2024-06-03 18:31:25 +03:00
|
|
|
|
|
|
|
case Content:
|
|
|
|
if adapter, ok := value.(ListAdapter); ok {
|
|
|
|
listLayout.adapter = adapter
|
|
|
|
listLayout.UpdateContent()
|
|
|
|
// TODO
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
listLayout.adapter = nil
|
2022-08-31 17:31:17 +03:00
|
|
|
}
|
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
if listLayout.viewsContainerData.set(tag, value) {
|
2021-11-20 11:15:28 +03:00
|
|
|
if listLayout.created {
|
|
|
|
switch tag {
|
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
|
|
|
case Orientation, ListWrap, HorizontalAlign, VerticalAlign:
|
2021-11-20 11:15:28 +03:00
|
|
|
updateCSSStyle(listLayout.htmlID(), listLayout.session)
|
|
|
|
}
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (listLayout *listLayoutData) htmlSubviews(self View, buffer *strings.Builder) {
|
|
|
|
if listLayout.views != nil {
|
|
|
|
for _, view := range listLayout.views {
|
|
|
|
view.addToCSSStyle(map[string]string{`flex`: `0 0 auto`})
|
|
|
|
viewHTML(view, buffer)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-03 18:31:25 +03:00
|
|
|
func (listLayout *listLayoutData) UpdateContent() {
|
|
|
|
if adapter := listLayout.adapter; adapter != nil {
|
|
|
|
listLayout.views = []View{}
|
|
|
|
|
|
|
|
session := listLayout.session
|
|
|
|
htmlID := listLayout.htmlID()
|
|
|
|
isDisabled := IsDisabled(listLayout)
|
|
|
|
|
|
|
|
count := adapter.ListSize()
|
|
|
|
for i := 0; i < count; i++ {
|
|
|
|
if view := adapter.ListItem(i, session); view != nil {
|
|
|
|
view.setParentID(htmlID)
|
|
|
|
if isDisabled {
|
|
|
|
view.Set(Disabled, true)
|
|
|
|
}
|
|
|
|
listLayout.views = append(listLayout.views, view)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if listLayout.created {
|
|
|
|
updateInnerHTML(htmlID, session)
|
|
|
|
}
|
|
|
|
|
|
|
|
listLayout.propertyChangedEvent(Content)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
// GetListVerticalAlign returns the vertical align of a ListLayout or ListView sibview:
|
|
|
|
// TopAlign (0), BottomAlign (1), CenterAlign (2), or StretchAlign (3)
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
|
|
|
func GetListVerticalAlign(view View, subviewID ...string) int {
|
|
|
|
return enumStyledProperty(view, subviewID, VerticalAlign, TopAlign, false)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetListHorizontalAlign returns the vertical align of a ListLayout or ListView subview:
|
|
|
|
// LeftAlign (0), RightAlign (1), CenterAlign (2), or StretchAlign (3)
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
|
|
|
func GetListHorizontalAlign(view View, subviewID ...string) int {
|
|
|
|
return enumStyledProperty(view, subviewID, HorizontalAlign, LeftAlign, false)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetListOrientation returns the orientation of a ListLayout or ListView subview:
|
|
|
|
// TopDownOrientation (0), StartToEndOrientation (1), BottomUpOrientation (2), or EndToStartOrientation (3)
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
|
|
|
func GetListOrientation(view View, subviewID ...string) int {
|
|
|
|
if len(subviewID) > 0 && subviewID[0] != "" {
|
|
|
|
view = ViewByID(view, subviewID[0])
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
2021-11-11 13:23:41 +03:00
|
|
|
|
|
|
|
if view != nil {
|
|
|
|
if orientation, ok := valueToOrientation(view.Get(Orientation), view.Session()); ok {
|
|
|
|
return orientation
|
|
|
|
}
|
|
|
|
|
2022-05-23 15:22:14 +03:00
|
|
|
if value := valueFromStyle(view, Orientation); value != nil {
|
2021-11-11 13:23:41 +03:00
|
|
|
if orientation, ok := valueToOrientation(value, view.Session()); ok {
|
|
|
|
return orientation
|
|
|
|
}
|
|
|
|
}
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
2021-11-11 13:23:41 +03:00
|
|
|
|
|
|
|
return 0
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetListWrap returns the wrap type of a ListLayout or ListView subview:
|
2022-07-28 12:41:50 +03:00
|
|
|
// ListWrapOff (0), ListWrapOn (1), or ListWrapReverse (2)
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
|
|
|
func GetListWrap(view View, subviewID ...string) int {
|
2022-07-28 12:41:50 +03:00
|
|
|
return enumStyledProperty(view, subviewID, ListWrap, ListWrapOff, false)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
2022-08-31 17:31:17 +03:00
|
|
|
|
|
|
|
// GetListRowGap returns the gap between ListLayout or ListView rows.
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
|
|
|
func GetListRowGap(view View, subviewID ...string) SizeUnit {
|
2022-08-31 17:31:17 +03:00
|
|
|
return sizeStyledProperty(view, subviewID, ListRowGap, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetListColumnGap returns the gap between ListLayout or ListView columns.
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
|
|
|
func GetListColumnGap(view View, subviewID ...string) SizeUnit {
|
2022-08-31 17:31:17 +03:00
|
|
|
return sizeStyledProperty(view, subviewID, ListColumnGap, false)
|
|
|
|
}
|
2024-06-03 18:31:25 +03:00
|
|
|
|
2024-06-06 16:20:15 +03:00
|
|
|
// UpdateContent updates child Views of ListLayout/GridLayout subview if the "content" property value is set to ListAdapter/GridAdapter,
|
2024-06-03 18:31:25 +03:00
|
|
|
// otherwise does nothing.
|
|
|
|
// If the second argument (subviewID) is not specified or it is "" then the first argument (view) updates.
|
|
|
|
func UpdateContent(view View, subviewID ...string) {
|
|
|
|
if len(subviewID) > 0 && subviewID[0] != "" {
|
|
|
|
view = ViewByID(view, subviewID[0])
|
|
|
|
}
|
|
|
|
|
|
|
|
if view != nil {
|
|
|
|
switch view := view.(type) {
|
2024-06-06 16:20:15 +03:00
|
|
|
case GridLayout:
|
|
|
|
view.UpdateGridContent()
|
|
|
|
|
2024-06-03 18:31:25 +03:00
|
|
|
case ListLayout:
|
|
|
|
view.UpdateContent()
|
|
|
|
|
|
|
|
case ListView:
|
|
|
|
view.ReloadListViewData()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|