From fe8be202146c8ccdea2048fbce7330b1e6f3b5f0 Mon Sep 17 00:00:00 2001 From: rafern Date: Thu, 21 Nov 2024 12:35:10 +0000 Subject: [PATCH] 0.10.12: Allow settable ThemeScope scopeTheme, add options object to it --- package.json | 2 +- src/widgets/ThemeScope.ts | 27 ++++++++++++++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 01cb57a..d1e2016 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lazy-widgets", - "version": "0.10.11", + "version": "0.10.12", "description": "Typescript retained mode GUI for the HTML canvas API", "main": "dist/index.js", "module": "dist/index.js", diff --git a/src/widgets/ThemeScope.ts b/src/widgets/ThemeScope.ts index 78cdd03..fd83314 100644 --- a/src/widgets/ThemeScope.ts +++ b/src/widgets/ThemeScope.ts @@ -1,6 +1,6 @@ import { PassthroughWidget } from './PassthroughWidget.js'; import type { Theme } from '../theme/Theme.js'; -import type { Widget } from './Widget.js'; +import type { Widget, WidgetProperties } from './Widget.js'; import type { WidgetAutoXML } from '../xml/WidgetAutoXML.js'; /** * A {@link PassthroughWidget} which changes the theme of its child and @@ -31,18 +31,31 @@ export class ThemeScope extends PassthroughWidget }; /** The theme used for the child. */ - private scopeTheme: Theme; + private _scopeTheme: Theme | undefined; - constructor(child: W, theme: Theme) { - super(child); - this.scopeTheme = theme; + constructor(child: W, theme?: Theme, properties?: Readonly) { + super(child, properties); + this._scopeTheme = theme; } override set inheritedTheme(_theme: Theme | undefined) { - super.inheritedTheme = this.scopeTheme; + super.inheritedTheme = this._scopeTheme; } override get inheritedTheme(): Theme | undefined { - return this.scopeTheme; + return this._scopeTheme; + } + + set scopeTheme(scopeTheme: Theme | undefined) { + if (this._scopeTheme === scopeTheme) { + return; + } + + this._scopeTheme = scopeTheme; + super.inheritedTheme = this._scopeTheme; + } + + get scopeTheme(): Theme | undefined { + return this._scopeTheme; } }