Skip to content

Commit

Permalink
change the API for MathSymbolFont.createDerivedProperty so that a tan…
Browse files Browse the repository at this point in the history
…dem can be supplied, phetsims/fourier-making-waves#235
  • Loading branch information
pixelzoom committed Jun 5, 2023
1 parent 8bae983 commit 735784c
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions js/MathSymbolFont.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ import StrictOmit from '../../phet-core/js/types/StrictOmit.js';
import StringUtils from '../../phetcommon/js/util/StringUtils.js';
import { Font, FontOptions } from '../../scenery/js/imports.js';
import sceneryPhet from './sceneryPhet.js';
import PickOptional from '../../phet-core/js/types/PickOptional.js';
import { PhetioObjectOptions } from '../../tandem/js/PhetioObject.js';
import Tandem from '../../tandem/js/Tandem.js';
import StringIO from '../../tandem/js/types/StringIO.js';

const DEFAULT_STYLE = 'italic';

type SelfOptions = EmptySelfOptions;

export type MathSymbolFontOptions = SelfOptions & StrictOmit<FontOptions, 'family'>;

type CreateDerivedPropertyOptions = PickOptional<FontOptions, 'style'> & PickOptional<PhetioObjectOptions, 'tandem'>;

export default class MathSymbolFont extends Font {

public static readonly FAMILY = '"Times New Roman", Times, serif';
Expand Down Expand Up @@ -59,9 +65,15 @@ export default class MathSymbolFont extends Font {
/**
* Wraps a dynamic string in RichText that will display the string in the same font as MathSymbolFont.
*/
public static createDerivedProperty( symbolStringProperty: TReadOnlyProperty<string>, style = DEFAULT_STYLE ): TReadOnlyProperty<string> {
public static createDerivedProperty( symbolStringProperty: TReadOnlyProperty<string>, providedOptions?: CreateDerivedPropertyOptions ): TReadOnlyProperty<string> {

const options = providedOptions || {};

return new DerivedProperty( [ symbolStringProperty ],
symbolString => MathSymbolFont.getRichTextMarkup( symbolString, style ) );
symbolString => MathSymbolFont.getRichTextMarkup( symbolString, options.style || DEFAULT_STYLE ), {
tandem: options.tandem || Tandem.OPT_OUT,
phetioValueType: StringIO
} );
}
}

Expand Down

0 comments on commit 735784c

Please sign in to comment.