Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/_build-ios-port.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
id: src_hash
run: |
set -euo pipefail
SRC_HASH=$(find CodenameOne/src Ports/iOSPort vm/JavaAPI vm/ByteCodeTranslator Themes \
SRC_HASH=$(find CodenameOne/src Ports/iOSPort vm/JavaAPI vm/ByteCodeTranslator Themes native-themes \
-type f \( -name '*.java' -o -name '*.m' -o -name '*.h' -o -name '*.xml' -o -name '*.properties' -o -name '*.css' \) 2>/dev/null \
| sort | xargs shasum -a 256 | shasum -a 256 | awk '{print $1}')
POM_HASH=$(find . -name 'pom.xml' -not -path './scripts/*' 2>/dev/null \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ios-packaging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
id: src_hash
run: |
set -euo pipefail
SRC_HASH=$(find CodenameOne/src Ports/iOSPort vm/JavaAPI vm/ByteCodeTranslator Themes \
SRC_HASH=$(find CodenameOne/src Ports/iOSPort vm/JavaAPI vm/ByteCodeTranslator Themes native-themes \
-type f \( -name '*.java' -o -name '*.m' -o -name '*.h' -o -name '*.xml' -o -name '*.properties' -o -name '*.css' \) 2>/dev/null \
| sort | xargs shasum -a 256 | shasum -a 256 | awk '{print $1}')
POM_HASH=$(find . -name 'pom.xml' -not -path './scripts/*' 2>/dev/null \
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/scripts-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ name: Test Android build scripts
- '!CodenameOne/src/**/*.md'
- 'Ports/Android/**'
- '!Ports/Android/**/*.md'
- 'native-themes/android-material/**'
- '!native-themes/android-material/**/*.md'
- 'maven/**'
- '!maven/core-unittests/**'
- 'tests/**'
Expand Down Expand Up @@ -49,6 +51,8 @@ name: Test Android build scripts
- '!CodenameOne/src/**/*.md'
- 'Ports/Android/**'
- '!Ports/Android/**/*.md'
- 'native-themes/android-material/**'
- '!native-themes/android-material/**/*.md'
- 'maven/**'
- '!maven/core-unittests/**'
- 'tests/**'
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/scripts-ios-native.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ on:
- '!CodenameOne/src/**/*.md'
- 'Ports/iOSPort/**'
- '!Ports/iOSPort/**/*.md'
- 'native-themes/ios-modern/**'
- '!native-themes/ios-modern/**/*.md'
- 'vm/**'
- '!vm/**/*.md'
- 'tests/**'
Expand Down Expand Up @@ -47,6 +49,8 @@ on:
- '!CodenameOne/src/**/*.md'
- 'Ports/iOSPort/**'
- '!Ports/iOSPort/**/*.md'
- 'native-themes/ios-modern/**'
- '!native-themes/ios-modern/**/*.md'
- 'vm/**'
- '!vm/**/*.md'
- 'tests/**'
Expand Down Expand Up @@ -108,7 +112,7 @@ jobs:
id: src_hash
run: |
set -euo pipefail
SRC_HASH=$(find CodenameOne/src Ports/iOSPort vm/JavaAPI vm/ByteCodeTranslator Themes \
SRC_HASH=$(find CodenameOne/src Ports/iOSPort vm/JavaAPI vm/ByteCodeTranslator Themes native-themes \
-type f \( -name '*.java' -o -name '*.m' -o -name '*.h' -o -name '*.xml' -o -name '*.properties' -o -name '*.css' \) 2>/dev/null \
| sort | xargs shasum -a 256 | shasum -a 256 | awk '{print $1}')
POM_HASH=$(find . -name 'pom.xml' -not -path './scripts/*' 2>/dev/null \
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/scripts-ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ on:
- '!CodenameOne/src/**/*.md'
- 'Ports/iOSPort/**'
- '!Ports/iOSPort/**/*.md'
- 'native-themes/ios-modern/**'
- '!native-themes/ios-modern/**/*.md'
- 'vm/**'
- '!vm/**/*.md'
- 'tests/**'
Expand Down Expand Up @@ -53,6 +55,8 @@ on:
- '!CodenameOne/src/**/*.md'
- 'Ports/iOSPort/**'
- '!Ports/iOSPort/**/*.md'
- 'native-themes/ios-modern/**'
- '!native-themes/ios-modern/**/*.md'
- 'vm/**'
- '!vm/**/*.md'
- 'tests/**'
Expand Down Expand Up @@ -120,7 +124,7 @@ jobs:
id: src_hash
run: |
set -euo pipefail
SRC_HASH=$(find CodenameOne/src Ports/iOSPort vm/JavaAPI vm/ByteCodeTranslator Themes \
SRC_HASH=$(find CodenameOne/src Ports/iOSPort vm/JavaAPI vm/ByteCodeTranslator Themes native-themes \
-type f \( -name '*.java' -o -name '*.m' -o -name '*.h' -o -name '*.xml' -o -name '*.properties' -o -name '*.css' \) 2>/dev/null \
| sort | xargs shasum -a 256 | shasum -a 256 | awk '{print $1}')
POM_HASH=$(find . -name 'pom.xml' -not -path './scripts/*' 2>/dev/null \
Expand Down Expand Up @@ -269,7 +273,7 @@ jobs:
id: src_hash
run: |
set -euo pipefail
SRC_HASH=$(find CodenameOne/src Ports/iOSPort vm/JavaAPI vm/ByteCodeTranslator Themes \
SRC_HASH=$(find CodenameOne/src Ports/iOSPort vm/JavaAPI vm/ByteCodeTranslator Themes native-themes \
-type f \( -name '*.java' -o -name '*.m' -o -name '*.h' -o -name '*.xml' -o -name '*.properties' -o -name '*.css' \) 2>/dev/null \
| sort | xargs shasum -a 256 | shasum -a 256 | awk '{print $1}')
POM_HASH=$(find . -name 'pom.xml' -not -path './scripts/*' 2>/dev/null \
Expand Down
95 changes: 95 additions & 0 deletions CodenameOne/src/com/codename1/ui/plaf/UIManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1802,6 +1802,8 @@ private void buildTheme(Hashtable themeProps) {
this.themeProps.put(key, themeProps.get(key));
}

applyThemeBindings();

updateLargerTextScaleSettingFromTheme();

if (!this.themeProps.containsKey("PickerButtonBar.derive")) {
Expand Down Expand Up @@ -1863,6 +1865,99 @@ private void buildTheme(Hashtable themeProps) {

}

/// Theme entries can be bound to a named theme constant via a
/// `@cn1-bind:<themeKey>=<varName>` pseudo-constant emitted by the CSS
/// compiler when it expands a `var(--name, fallback)` reference. The
/// compiler still inlines `fallback` as the baked-in default (so themes
/// load correctly with no override), but additionally records that the
/// resolved style property tracks `--name`.
///
/// At runtime, callers tune the palette by injecting an `@<varName>`
/// constant via [#addThemeProps]. This method walks the binding entries
/// and overlays the override value onto every bound style key, so a
/// single `addThemeProps({"@accent-color": "ff2d95"})` call retunes
/// every UIID whose CSS rule referenced `var(--accent-color, ...)`.
/// Bindings without a matching override are left at their baked-in
/// default (whatever was already in themeProps from the initial load).
private void applyThemeBindings() {
if (themeConstants == null || themeConstants.isEmpty() || themeProps == null) {
return;
}
final String prefix = "cn1-bind:";
for (Map.Entry<String, Object> entry : themeConstants.entrySet()) {
String constantKey = entry.getKey();
if (constantKey == null || !constantKey.startsWith(prefix)) {
continue;
}
Object varNameObj = entry.getValue();
if (!(varNameObj instanceof String)) {
continue;
}
String varName = ((String) varNameObj).trim();
if (varName.length() == 0) {
continue;
}
Object override = themeConstants.get(varName);
if (!(override instanceof String)) {
continue;
}
String themeKey = constantKey.substring(prefix.length());
if (themeKey.length() == 0) {
continue;
}
// Only retune keys that are already present in themeProps so a
// stale binding entry (left over after the bound rule was
// dropped from the source CSS) can't materialize a phantom
// style key from the user's override value.
if (!themeProps.containsKey(themeKey)) {
continue;
}
String overrideValue = (String) override;
if (themeKey.endsWith("Color")) {
overrideValue = normalizeBoundColorValue(overrideValue);
if (overrideValue == null) {
continue;
}
}
themeProps.put(themeKey, overrideValue);
}
}

/// `loadTheme` stores color theme entries as plain hex strings (no `#`,
/// lowercase). User-supplied overrides may use either form, so trim a
/// leading `#` and lowercase the value before assigning it to a bound
/// color key. Returns null when the value can't be parsed as a 3- or
/// 6-digit hex color so the binding falls through to its default.
private static String normalizeBoundColorValue(String raw) {
if (raw == null) {
return null;
}
String value = raw.trim();
if (value.length() == 0) {
return null;
}
if (value.charAt(0) == '#') {
value = value.substring(1);
}
if (value.length() == 3) {
char r = value.charAt(0);
char g = value.charAt(1);
char b = value.charAt(2);
value = "" + r + r + g + g + b + b;
}
if (value.length() != 6) {
return null;
}
for (int i = 0; i < 6; i++) {
char c = value.charAt(i);
boolean hex = (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
if (!hex) {
return null;
}
}
return value.toLowerCase();
}

private Map<String, String> parseCache() {
if (parseCache == null) {
parseCache = new HashMap<String, String>();
Expand Down
Loading
Loading