From 848606a3be98bb239a5f463fd50c360ea00700e4 Mon Sep 17 00:00:00 2001 From: Alexei Anoshenko <2277098+anoshenko@users.noreply.github.com> Date: Sat, 7 Dec 2024 19:24:54 +0300 Subject: [PATCH] Added "hide-summary-marker" DetailsView property --- CHANGELOG.md | 4 +++- README-ru.md | 9 +++++---- README.md | 9 +++++---- app_styles.css | 8 ++++++++ detailsView.go | 46 +++++++++++++++++++++++++++++++++++++++++++--- propertySet.go | 1 + 6 files changed, 65 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f5c1c6..f4c2a5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,7 +33,7 @@ * Added functions: NewBounds, NewEllipticRadius, NewRadii, NewLinearGradient, NewCircleRadialGradient, NewEllipseRadialGradient, GetPushTransform, GetPushDuration, GetPushTiming, IsMoveToFrontAnimation, GetBackground, GetMask, GetBackgroundClip,GetBackgroundOrigin, GetMaskClip, GetMaskOrigin, NewColumnSeparator, -NewClipShapeProperty, NewTransitionAnimation, NewAnimation. +NewClipShapeProperty, NewTransitionAnimation, NewAnimation, IsSummaryMarkerHidden. * Added SetConicGradientFillStyle and SetConicGradientStrokeStyle methods to Canvas interface. @@ -49,6 +49,8 @@ NewClipShapeProperty, NewTransitionAnimation, NewAnimation. * Added "mask", "mask-clip", "mask-origin", and "background-origin" properties. +* Added "hide-summary-marker" DetailsView property. + * Added LineJoin type. Type of constants MiterJoin, RoundJoin, and BevelJoin changed to LineJoin. Type of Canvas.SetLineJoin function argument changed to LineJoin. * Added LineCap type. Type of constants ButtCap, RoundCap, and SquareCap changed to LineCap. Type of Canvas.SetLineCap function argument changed to LineCap. diff --git a/README-ru.md b/README-ru.md index ad9b748..973dd32 100644 --- a/README-ru.md +++ b/README-ru.md @@ -2980,13 +2980,14 @@ DetailsView переключается между состояниями по к "expanded" (константа Expanded). Соответственно значение "true" показывает дочерние View, "false" - скрывает. -Получить значение свойства "expanded" можно с помощью функции +По умолчанию в начале элемента "summary" отображается маркер ▶︎/▼. Его можно спрятать. +Для этого используется свойство "hide-summary-marker" (константа DetailsView) типа bool. - func IsDetailsExpanded(view View, subviewID ...string) bool - -а значение свойства "summary" можно получить с помощью функции +Получить значение свойств "summary", "expanded" и "hide-summary-marker" можно с помощью функций func GetDetailsSummary(view View, subviewID ...string) View + func IsDetailsExpanded(view View, subviewID ...string) bool + func IsSummaryMarkerHidden(view View, subviewID ...string) bool ## Resizable diff --git a/README.md b/README.md index fb4c579..908d7f8 100644 --- a/README.md +++ b/README.md @@ -2963,13 +2963,14 @@ DetailsView switches between states by clicking on "summary" view. For forced switching of the DetailsView states, the bool property "expanded" (Expanded constant) is used. Accordingly, the value "true" shows child Views, "false" - hides. -You can get the value of the "expanded" property using the function +By default, a ▶︎/▼ marker is displayed at the beginning of the "summary" element. It can be hidden. +For this, the "hide-summary-marker" bool property (DetailsView constant) is used. - func IsDetailsExpanded(view View, subviewID ...string) bool - -and the value of the "summary" property can be obtained using the function +The value of the "summary", "expanded" and "hide-summary-marker" properties can be obtained using the functions func GetDetailsSummary(view View, subviewID ...string) View + func IsDetailsExpanded(view View, subviewID ...string) bool + func IsSummaryMarkerHidden(view View, subviewID ...string) bool ## Resizable diff --git a/app_styles.css b/app_styles.css index ba496a7..30fd215 100644 --- a/app_styles.css +++ b/app_styles.css @@ -181,6 +181,14 @@ ul:focus { overflow: auto; } +.hiddenMarker { + list-style: none; +} + +.hiddenMarker::-webkit-details-marker { + display: none; +} + /* @media (prefers-color-scheme: light) { body { diff --git a/detailsView.go b/detailsView.go index 90c4ecc..c4b9401 100644 --- a/detailsView.go +++ b/detailsView.go @@ -25,6 +25,18 @@ const ( // - true, 1, "true", "yes", "on", or "1" - Content is visible. // - false, 0, "false", "no", "off", or "0" - Content is collapsed (hidden). Expanded PropertyName = "expanded" + + // HideSummaryMarker is the constant for "hide-summary-marker" property tag. + // + // Used by DetailsView. + // Allows you to hide the summary marker (▶︎). Default value is false. + // + // Supported types: bool, int, string. + // + // Values: + // - true, 1, "true", "yes", "on", or "1" - The summary marker is hidden. + // - false, 0, "false", "no", "off", or "0" - The summary marker is displayed (default value). + HideSummaryMarker PropertyName = "hide-summary-marker" ) // DetailsView represent a DetailsView view, which is a collapsible container of views @@ -99,7 +111,7 @@ func (detailsView *detailsViewData) setFunc(tag PropertyName, value any) []Prope func (detailsView *detailsViewData) propertyChanged(tag PropertyName) { switch tag { - case Summary: + case Summary, HideSummaryMarker: updateInnerHTML(detailsView.htmlID(), detailsView.Session()) case Expanded: @@ -130,24 +142,46 @@ func (detailsView *detailsViewData) htmlProperties(self View, buffer *strings.Bu } func (detailsView *detailsViewData) htmlSubviews(self View, buffer *strings.Builder) { + summary := false + hidden := IsSummaryMarkerHidden(detailsView) + if value, ok := detailsView.properties[Summary]; ok { + switch value := value.(type) { case string: if !GetNotTranslate(detailsView) { value, _ = detailsView.session.GetString(value) } - buffer.WriteString("") + if hidden { + buffer.WriteString(``) + } else { + buffer.WriteString("") + } buffer.WriteString(value) buffer.WriteString("") + summary = true case View: - if value.htmlTag() == "div" { + if hidden { + buffer.WriteString(``) + viewHTML(value, buffer, "") + buffer.WriteString("") + } else if value.htmlTag() == "div" { viewHTML(value, buffer, "summary") } else { buffer.WriteString(`
`) viewHTML(value, buffer, "") buffer.WriteString("
") } + summary = true + } + } + + if !summary { + if hidden { + buffer.WriteString(``) + } else { + buffer.WriteString("") } } @@ -189,3 +223,9 @@ func GetDetailsSummary(view View, subviewID ...string) View { func IsDetailsExpanded(view View, subviewID ...string) bool { return boolStyledProperty(view, subviewID, Expanded, false) } + +// IsDetailsExpanded returns a value of the HideSummaryMarker property of DetailsView. +// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned. +func IsSummaryMarkerHidden(view View, subviewID ...string) bool { + return boolStyledProperty(view, subviewID, HideSummaryMarker, false) +} diff --git a/propertySet.go b/propertySet.go index 41d43b3..6cac614 100644 --- a/propertySet.go +++ b/propertySet.go @@ -63,6 +63,7 @@ var boolProperties = []PropertyName{ UserSelect, ColumnSpanAll, MoveToFrontAnimation, + HideSummaryMarker, } var intProperties = []PropertyName{