Skip to content

Commit

Permalink
0.10.12: Allow settable ThemeScope scopeTheme, add options object to it
Browse files Browse the repository at this point in the history
  • Loading branch information
rafern committed Nov 21, 2024
1 parent 0e593f6 commit fe8be20
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
27 changes: 20 additions & 7 deletions src/widgets/ThemeScope.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -31,18 +31,31 @@ export class ThemeScope<W extends Widget = Widget> extends PassthroughWidget<W>
};

/** 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<WidgetProperties>) {
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;
}
}

0 comments on commit fe8be20

Please sign in to comment.