From 3097f89f5a65d02296fd95702f93acfb2da11369 Mon Sep 17 00:00:00 2001 From: Alexei Anoshenko Date: Mon, 16 May 2022 17:43:06 +0300 Subject: [PATCH] Added Append function to Theme & bug fixing --- defaultTheme.rui | 4 ++-- editView.go | 2 +- go.mod | 2 +- go.sum | 2 ++ resources.go | 8 ++++---- session.go | 6 ------ sessionTheme.go | 16 ++-------------- tableView.go | 14 +++++++++++++- theme.go | 4 ++-- 9 files changed, 27 insertions(+), 31 deletions(-) diff --git a/defaultTheme.rui b/defaultTheme.rui index 6b8acbd..968204b 100644 --- a/defaultTheme.rui +++ b/defaultTheme.rui @@ -46,7 +46,7 @@ theme { }, constants = _{ ruiButtonHorizontalPadding = 16px, - ruiButtonVerticalPadding = 8px, + ruiButtonVerticalPadding = 6px, ruiButtonMargin = 4px, ruiButtonRadius = 4px, ruiButtonHighlightDilation = 1.5px, @@ -64,7 +64,7 @@ theme { }, constants:touch = _{ ruiButtonHorizontalPadding = 20px, - ruiButtonVerticalPadding = 16px + ruiButtonVerticalPadding = 10px }, styles = [ ruiApp { diff --git a/editView.go b/editView.go index 63b15d9..33074a2 100644 --- a/editView.go +++ b/editView.go @@ -278,7 +278,7 @@ func (edit *editViewData) set(tag string, value interface{}) bool { case EditViewPattern: oldText := GetEditViewPattern(edit, "") if text, ok := value.(string); ok { - edit.properties[Pattern] = text + edit.properties[EditViewPattern] = text if text = GetEditViewPattern(edit, ""); oldText != text { if edit.created { if text != "" { diff --git a/go.mod b/go.mod index 944bf12..ff93f55 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,4 @@ module github.com/anoshenko/rui go 1.17 -require github.com/gorilla/websocket v1.4.2 +require github.com/gorilla/websocket v1.5.0 diff --git a/go.sum b/go.sum index 85efffd..fe2ee7f 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,4 @@ github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= +github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= diff --git a/resources.go b/resources.go index 468db00..97b828a 100644 --- a/resources.go +++ b/resources.go @@ -231,9 +231,9 @@ func registerThemeText(text string) bool { name := theme.Name() if name == "" { - defaultTheme.concat(theme) + defaultTheme.Append(theme) } else if t, ok := resources.themes[name]; ok { - t.concat(theme) + t.Append(theme) } else { resources.themes[name] = theme } @@ -418,9 +418,9 @@ func AddTheme(theme Theme) { if theme != nil { name := theme.Name() if name == "" { - defaultTheme.concat(theme) + defaultTheme.Append(theme) } else if t, ok := resources.themes[name]; ok { - t.concat(theme) + t.Append(theme) } else { resources.themes[name] = theme } diff --git a/session.go b/session.go index b3c5013..28b8774 100644 --- a/session.go +++ b/session.go @@ -29,16 +29,10 @@ type Session interface { TextDirection() int // Constant returns the constant with "tag" name or "" if it is not exists Constant(tag string) (string, bool) - // ConstantTags returns the list of all available constants - ConstantTags() []string // Color returns the color with "tag" name or 0 if it is not exists Color(tag string) (Color, bool) - // ColorTags returns the list of all available color constants - ColorTags() []string // ImageConstant returns the image constant with "tag" name or "" if it is not exists ImageConstant(tag string) (string, bool) - // ImageConstantTags returns the list of all available image constants - ImageConstantTags() []string // SetCustomTheme set the custom theme SetCustomTheme(name string) bool // UserAgent returns the "user-agent" text of the client browser diff --git a/sessionTheme.go b/sessionTheme.go index ef99e6a..27ee820 100644 --- a/sessionTheme.go +++ b/sessionTheme.go @@ -119,8 +119,8 @@ func (session *sessionData) getCurrentTheme() Theme { if session.customTheme != nil { session.currentTheme = NewTheme("") - session.currentTheme.concat(defaultTheme) - session.currentTheme.concat(session.customTheme) + session.currentTheme.Append(defaultTheme) + session.currentTheme.Append(session.customTheme) return session.currentTheme } @@ -337,15 +337,3 @@ func (session *sessionData) SetLanguage(lang string) { } } } - -func (session *sessionData) ConstantTags() []string { - return session.getCurrentTheme().ConstantTags() -} - -func (session *sessionData) ColorTags() []string { - return session.getCurrentTheme().ColorTags() -} - -func (session *sessionData) ImageConstantTags() []string { - return session.getCurrentTheme().ImageConstantTags() -} diff --git a/tableView.go b/tableView.go index 03f368b..929c496 100644 --- a/tableView.go +++ b/tableView.go @@ -895,8 +895,9 @@ func (table *tableViewData) htmlSubviews(self View, buffer *strings.Builder) { vAlign := vAlignCss[vAlignValue] tableCSS := func(startRow, endRow int, cellTag string, cellBorder BorderProperty, cellPadding BoundsProperty) { - for row := startRow; row < endRow; row++ { + var namedColors []NamedColor = nil + for row := startRow; row < endRow; row++ { cssBuilder.buffer.Reset() if rowStyle != nil { if styles := rowStyle.RowStyle(row); styles != nil { @@ -1069,6 +1070,17 @@ func (table *tableViewData) htmlSubviews(self View, buffer *strings.Builder) { buffer.WriteString(value.cssString()) buffer.WriteString(`">     `) buffer.WriteString(value.String()) + if namedColors == nil { + namedColors = NamedColors() + } + for _, namedColor := range namedColors { + if namedColor.Color == value { + buffer.WriteString(" (") + buffer.WriteString(namedColor.Name) + buffer.WriteRune(')') + break + } + } case fmt.Stringer: buffer.WriteString(textToJS(value.String())) diff --git a/theme.go b/theme.go index 705b284..a051731 100644 --- a/theme.go +++ b/theme.go @@ -45,12 +45,12 @@ type Theme interface { SetImage(tag, image, darkUIImage string) // ImageConstantTags returns the list of all available image constants ImageConstantTags() []string + Append(anotherTheme Theme) constant(tag string, touchUI bool) string color(tag string, darkUI bool) string image(tag string, darkUI bool) string style(tag string) Params - concat(anotherTheme Theme) cssText(session Session) string data() *theme } @@ -290,7 +290,7 @@ func (theme *theme) data() *theme { return theme } -func (theme *theme) concat(anotherTheme Theme) { +func (theme *theme) Append(anotherTheme Theme) { if theme.constants == nil { theme.init() }