Skip to content

Commit

Permalink
Add color highlights to text, #4
Browse files Browse the repository at this point in the history
  • Loading branch information
marlitas committed Sep 13, 2024
1 parent 6b5a233 commit 5437c40
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
54 changes: 52 additions & 2 deletions js/common/view/NumberSentenceAccordionBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import numberPairs from '../../numberPairs.js';
import PatternStringProperty from '../../../../axon/js/PatternStringProperty.js';
import NumberPairsStrings from '../../NumberPairsStrings.js';
import { RichText, Text } from '../../../../scenery/js/imports.js';
import { RichText, Text, Node, Rectangle } from '../../../../scenery/js/imports.js';
import NumberPairsConstants from '../NumberPairsConstants.js';
import SumRepresentationAccordionBox, { SumRepresentationAccordionBoxOptions } from './SumRepresentationAccordionBox.js';
import optionize, { EmptySelfOptions } from '../../../../phet-core/js/optionize.js';
Expand Down Expand Up @@ -84,8 +84,58 @@ export default class NumberSentenceAccordionBox extends SumRepresentationAccordi
rightAddend: value => LOWERCASE_NUMBER_TO_WORD_MAP.get( value ).value
}
} );

let sumHighlight: Rectangle;
let leftAddendHighlight: Rectangle;
let rightAddendHighlight: Rectangle;
const richText = new RichText( numberSentencePatternStringProperty, {
lineWrap: 250
lineWrap: 250,
leading: 10,
tags: {
sum: node => {
sumHighlight = new Rectangle( node.bounds.dilated( 1 ), {
fill: model.sumColorProperty.value
} );
return new Node( {
children: [
sumHighlight,
node
]
} );
},
left: node => {
leftAddendHighlight = new Rectangle( node.bounds.dilated( 1 ), {
fill: model.leftAddendColorProperty.value
} );
return new Node( {
children: [
leftAddendHighlight,
node
]
} );
},
right: node => {
rightAddendHighlight = new Rectangle( node.bounds.dilated( 1 ), {
fill: model.rightAddendColorProperty.value
} );
return new Node( {
children: [
rightAddendHighlight,
node
]
} );
}
}
} );

model.sumColorProperty.link( color => {
sumHighlight.fill = color;
} );
model.leftAddendColorProperty.link( color => {
leftAddendHighlight.fill = color;
} );
model.rightAddendColorProperty.link( color => {
rightAddendHighlight.fill = color;
} );

const titleNode = new Text( NumberPairsStrings.numberSentenceStringProperty, {
Expand Down
2 changes: 1 addition & 1 deletion number-pairs-strings_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"value": "Equation"
},
"numberSentencePattern": {
"value": "{{sum}} can be decomposed into {{leftAddend}} and {{rightAddend}}."
"value": "<sum>{{sum}}</sum> can be decomposed into <left>{{leftAddend}}</left> and <right>{{rightAddend}}</right>."
},
"zero": {
"value": "zero"
Expand Down

0 comments on commit 5437c40

Please sign in to comment.