mirror of https://github.com/anoshenko/rui.git
Added PopupDefault, PopupDefaultsSeq, and SetPopupDefaults methods to Session interface
This commit is contained in:
parent
4c3bcf4427
commit
84c8c1e3d7
|
|
@ -3,7 +3,7 @@
|
||||||
* Removed "style-disabled" property and GetDisabledStyle function
|
* Removed "style-disabled" property and GetDisabledStyle function
|
||||||
* Added GoogleFonts field to AppParams
|
* Added GoogleFonts field to AppParams
|
||||||
* Added functions: GetWhiteSpace, GetWordBreak, ScrollIntoViewIfNeeded
|
* Added functions: GetWhiteSpace, GetWordBreak, ScrollIntoViewIfNeeded
|
||||||
* Added Popups, PopupShowAnimation, and SetPopupShowAnimation methods to Session interface
|
* Added Popups, PopupDefault, PopupDefaultsSeq, and SetPopupDefaults methods to Session interface
|
||||||
* Added DismissWithoutAnimation add SetHotKey methods to Popup interface
|
* Added DismissWithoutAnimation add SetHotKey methods to Popup interface
|
||||||
* Added ViewSeq add ViewCount methods to ParentView interface
|
* Added ViewSeq add ViewCount methods to ParentView interface
|
||||||
* Added ToBoundsProperty method to Bounds struct
|
* Added ToBoundsProperty method to Bounds struct
|
||||||
|
|
|
||||||
74
popup.go
74
popup.go
|
|
@ -798,14 +798,34 @@ func (popup *popupData) propertyChanged(tag PropertyName) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (popup *popupData) animationProperty() AnimationProperty {
|
func (popup *popupData) defaultPopupFloat(tag PropertyName, defaultValue float64) float64 {
|
||||||
_, _, defaultDuration, defaultTiming := popup.session.PopupShowAnimation()
|
if value := popup.session.PopupDefault(tag); value != nil {
|
||||||
|
if f, ok := valueToFloat(value, popup.session, defaultValue); ok {
|
||||||
duration, _ := floatProperty(popup, ShowDuration, popup.session, defaultDuration)
|
return f
|
||||||
timing, ok := stringProperty(popup, ShowTiming, popup.session)
|
} else {
|
||||||
if !ok {
|
DebugLogF(`"%v" is an invalid float64 value`, value)
|
||||||
timing = defaultTiming
|
}
|
||||||
}
|
}
|
||||||
|
return defaultValue
|
||||||
|
}
|
||||||
|
|
||||||
|
func (popup *popupData) animationProperty() AnimationProperty {
|
||||||
|
timing, ok := stringProperty(popup, ShowTiming, popup.session)
|
||||||
|
if ok && !isTimingFunctionValid(timing) {
|
||||||
|
DebugLog(`"` + timing + `" is an invalid timing function`)
|
||||||
|
ok = false
|
||||||
|
}
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
timing = EaseTiming
|
||||||
|
if value := popup.session.PopupDefault(ShowTiming); value != nil {
|
||||||
|
if text, ok := value.(string); ok && text != "" && isTimingFunctionValid(text) {
|
||||||
|
timing = text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
duration, _ := floatProperty(popup, ShowDuration, popup.session, popup.defaultPopupFloat(ShowDuration, 1))
|
||||||
|
|
||||||
return NewAnimationProperty(Params{
|
return NewAnimationProperty(Params{
|
||||||
Duration: duration,
|
Duration: duration,
|
||||||
TimingFunction: timing,
|
TimingFunction: timing,
|
||||||
|
|
@ -967,12 +987,15 @@ func (popup *popupData) Show() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (popup *popupData) showTransformAndOpacity() (TransformProperty, float64) {
|
func (popup *popupData) showTransformAndOpacity() (TransformProperty, float64) {
|
||||||
defaultTransform, defaultOpacity, _, _ := popup.session.PopupShowAnimation()
|
|
||||||
|
|
||||||
opacity, _ := floatProperty(popup, ShowOpacity, popup.session, defaultOpacity)
|
opacity, _ := floatProperty(popup, ShowOpacity, popup.session, popup.defaultPopupFloat(ShowOpacity, 1))
|
||||||
transform := getTransformProperty(popup, ShowTransform)
|
transform := getTransformProperty(popup, ShowTransform)
|
||||||
if transform == nil {
|
if transform == nil {
|
||||||
transform = defaultTransform
|
if value := popup.session.PopupDefault(ShowTransform); value != nil {
|
||||||
|
if t, ok := value.(TransformProperty); ok {
|
||||||
|
transform = t
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform, opacity
|
return transform, opacity
|
||||||
|
|
@ -1387,34 +1410,9 @@ func NewPopup(view View, param Params) Popup {
|
||||||
popup.properties = map[PropertyName]any{}
|
popup.properties = map[PropertyName]any{}
|
||||||
popup.hotkeys = map[string]func(Popup){}
|
popup.hotkeys = map[string]func(Popup){}
|
||||||
|
|
||||||
defaultTransform, defaultOpacity, duration, timing := popup.session.PopupShowAnimation()
|
for tag, value := range popup.session.PopupDefaultsSeq() {
|
||||||
|
if _, ok := param[tag]; !ok && value != nil {
|
||||||
if value, ok := param[ShowTransform]; ok {
|
param[tag] = value
|
||||||
if transform := valueToTransformProperty(value); transform != nil {
|
|
||||||
defaultTransform = transform
|
|
||||||
} else {
|
|
||||||
param[ShowTransform] = defaultTransform
|
|
||||||
}
|
|
||||||
} else if defaultTransform != nil {
|
|
||||||
param[ShowTransform] = defaultTransform
|
|
||||||
}
|
|
||||||
|
|
||||||
if value, ok := param[ShowOpacity]; ok {
|
|
||||||
if opacity, _ := valueToFloat(value, popup.session, 1); opacity >= 0 && opacity < 1 {
|
|
||||||
defaultOpacity = opacity
|
|
||||||
} else {
|
|
||||||
param[ShowOpacity] = defaultOpacity
|
|
||||||
}
|
|
||||||
} else if defaultOpacity != 1 {
|
|
||||||
param[ShowOpacity] = defaultOpacity
|
|
||||||
}
|
|
||||||
|
|
||||||
if defaultTransform != nil || defaultOpacity != 1 {
|
|
||||||
if _, ok := param[ShowDuration]; !ok {
|
|
||||||
param[ShowDuration] = duration
|
|
||||||
}
|
|
||||||
if _, ok := param[ShowTiming]; !ok {
|
|
||||||
param[ShowTiming] = timing
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
55
session.go
55
session.go
|
|
@ -2,6 +2,8 @@ package rui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"iter"
|
||||||
|
"maps"
|
||||||
"net/url"
|
"net/url"
|
||||||
"slices"
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
@ -112,16 +114,17 @@ type Session interface {
|
||||||
// a description of the error is written to the log
|
// a description of the error is written to the log
|
||||||
Set(viewID string, tag PropertyName, value any) bool
|
Set(viewID string, tag PropertyName, value any) bool
|
||||||
|
|
||||||
// PopupShowAnimation returns default popup animation parameters.
|
|
||||||
// Returns the default value for the properties: "show-transform", "show-opacity", "show-duration" and "show-timing".
|
|
||||||
PopupShowAnimation() (transform TransformProperty, opacity, duration float64, timing string)
|
|
||||||
|
|
||||||
// PopupShowAnimation returns a list of displayed popups or nil if there are no displayed popups.
|
// PopupShowAnimation returns a list of displayed popups or nil if there are no displayed popups.
|
||||||
Popups() []Popup
|
Popups() []Popup
|
||||||
|
|
||||||
// SetPopupShowAnimation sets default popup animation parameters.
|
// PopupDefault returns default values for the Popup property
|
||||||
// Sets the default value for the properties: "show-transform", "show-opacity", "show-duration" and "show-timing".
|
PopupDefault(tag PropertyName) any
|
||||||
SetPopupShowAnimation(transform TransformProperty, opacity, duration float64, timing string)
|
|
||||||
|
// PopupDefaultsSeq returns an iterator over all default values for Popup properties
|
||||||
|
PopupDefaultsSeq() iter.Seq2[PropertyName, any]
|
||||||
|
|
||||||
|
// SetPopupDefaults sets default values for Popup properties
|
||||||
|
SetPopupDefaults(params Params)
|
||||||
|
|
||||||
// DownloadFile downloads (saves) on the client side the file located at the specified path on the server.
|
// DownloadFile downloads (saves) on the client side the file located at the specified path on the server.
|
||||||
DownloadFile(path string)
|
DownloadFile(path string)
|
||||||
|
|
@ -250,10 +253,7 @@ type sessionData struct {
|
||||||
timers map[int]func(Session)
|
timers map[int]func(Session)
|
||||||
nextTimerID int
|
nextTimerID int
|
||||||
pauseTime int64
|
pauseTime int64
|
||||||
popupTransform TransformProperty
|
popupDefaults Params
|
||||||
popupOpacity float64
|
|
||||||
popupDuration float64
|
|
||||||
popupTiming string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newSession(app Application, id int, customTheme string, params DataObject) Session {
|
func newSession(app Application, id int, customTheme string, params DataObject) Session {
|
||||||
|
|
@ -274,9 +274,6 @@ func newSession(app Application, id int, customTheme string, params DataObject)
|
||||||
session.hotkeys = map[string]func(Session){}
|
session.hotkeys = map[string]func(Session){}
|
||||||
session.timers = map[int]func(Session){}
|
session.timers = map[int]func(Session){}
|
||||||
session.nextTimerID = 1
|
session.nextTimerID = 1
|
||||||
session.popupOpacity = 1
|
|
||||||
session.popupDuration = 1
|
|
||||||
session.popupTiming = EaseTiming
|
|
||||||
|
|
||||||
if customTheme != "" {
|
if customTheme != "" {
|
||||||
if theme, ok := CreateThemeFromText(customTheme); ok {
|
if theme, ok := CreateThemeFromText(customTheme); ok {
|
||||||
|
|
@ -977,19 +974,27 @@ func (session *sessionData) StopTimer(timerID int) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (session *sessionData) SetPopupShowAnimation(transform TransformProperty, opacity, duration float64, timing string) {
|
func (session *sessionData) PopupDefault(tag PropertyName) any {
|
||||||
session.popupTransform = transform
|
if value, ok := session.popupDefaults[tag]; ok {
|
||||||
if opacity >= 0 && opacity <= 1 {
|
return value
|
||||||
session.popupOpacity = opacity
|
|
||||||
}
|
}
|
||||||
if duration > 0 {
|
return nil
|
||||||
session.popupDuration = duration
|
}
|
||||||
}
|
|
||||||
if isTimingFunctionValid(timing) {
|
func (session *sessionData) PopupDefaultsSeq() iter.Seq2[PropertyName, any] {
|
||||||
session.popupTiming = timing
|
return func(yield func(PropertyName, any) bool) {
|
||||||
|
for tag, value := range session.popupDefaults {
|
||||||
|
if !yield(tag, value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (session *sessionData) PopupShowAnimation() (transform TransformProperty, opacity, duration float64, timing string) {
|
func (session *sessionData) SetPopupDefaults(params Params) {
|
||||||
return session.popupTransform, session.popupOpacity, session.popupDuration, session.popupTiming
|
if len(params) > 0 {
|
||||||
|
session.popupDefaults = maps.Clone(params)
|
||||||
|
} else {
|
||||||
|
session.popupDefaults = nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue