Skip to content

Commit

Permalink
set max widths for labels where they were missing, see #246
Browse files Browse the repository at this point in the history
(cherry picked from commit 95fa513)
  • Loading branch information
jbphet committed Jan 25, 2023
1 parent be16149 commit 7e18283
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion js/common/view/AtmosphereLayerNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ class AtmosphereLayerNode extends Node {
cornerRadius: 3,
noValueAlign: 'center',
textOptions: {
font: new PhetFont( 14 )
font: new PhetFont( 14 ),
maxWidth: 120
}
} );

Expand Down
6 changes: 5 additions & 1 deletion js/common/view/GreenhouseEffectCheckbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Property from '../../../../axon/js/Property.js';
import TReadOnlyProperty from '../../../../axon/js/TReadOnlyProperty.js';
import optionize from '../../../../phet-core/js/optionize.js';
import PhetFont from '../../../../scenery-phet/js/PhetFont.js';
import { HBox, Node, Text } from '../../../../scenery/js/imports.js';
import { HBox, Node, Text, TextOptions } from '../../../../scenery/js/imports.js';
import Checkbox, { CheckboxOptions } from '../../../../sun/js/Checkbox.js';
import Tandem from '../../../../tandem/js/Tandem.js';
import greenhouseEffect from '../../greenhouseEffect.js';
Expand All @@ -24,6 +24,8 @@ const LABEL_FONT = new PhetFont( {

type SelfOptions = {

maxLabelTextWidth?: number;

// if provided, will be included in the icon for the checkbox
iconNode?: Node | null;
};
Expand All @@ -36,6 +38,7 @@ class GreenhouseEffectCheckbox extends Checkbox {

const options = optionize<GreenhouseEffectCheckboxOptions, SelfOptions, CheckboxOptions>()( {
iconNode: null,
maxLabelTextWidth: 180, // empirically determined, works well for most cases in Greenhouse

// i18n
maxWidth: 250,
Expand All @@ -49,6 +52,7 @@ class GreenhouseEffectCheckbox extends Checkbox {

const labelText = new Text( labelStringProperty, {
font: LABEL_FONT,
maxWidth: options.maxLabelTextWidth,
tandem: options.tandem.createTandem( 'labelText' )
} );

Expand Down
7 changes: 6 additions & 1 deletion js/layer-model/view/TemperatureUnitsSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import greenhouseEffect from '../../greenhouseEffect.js';
import GreenhouseEffectStrings from '../../GreenhouseEffectStrings.js';

const LABEL_FONT = new PhetFont( 14 );
const UNITS_LABEL_MAX_WIDTH = 50;

/**
* TemperatureUnitsSelector is a UI component that allows a user to select between Kelvin, degrees Celsius, or degrees
Expand All @@ -23,6 +24,7 @@ class TemperatureUnitsSelector extends VBox {
// Create the label that sits above the radio button selectors.
const label = new Text( GreenhouseEffectStrings.temperatureUnitsStringProperty, {
font: LABEL_FONT,
maxWidth: 200,
tandem: tandem.createTandem( 'labelText' )
} );

Expand All @@ -33,6 +35,7 @@ class TemperatureUnitsSelector extends VBox {
{
createNode: tandem => new Text( GreenhouseEffectStrings.temperature.units.kelvinStringProperty, {
font: LABEL_FONT,
maxWidth: UNITS_LABEL_MAX_WIDTH,
tandem: tandem.createTandem( 'text' )
} ),
value: TemperatureUnits.KELVIN,
Expand All @@ -41,14 +44,16 @@ class TemperatureUnitsSelector extends VBox {
{
createNode: tandem => new Text( GreenhouseEffectStrings.temperature.units.celsiusStringProperty, {
font: LABEL_FONT,
maxWidth: UNITS_LABEL_MAX_WIDTH,
tandem: tandem.createTandem( 'text' )
} ),
value: TemperatureUnits.CELSIUS,
tandemName: 'celciusRadioButton'
tandemName: 'celsiusRadioButton'
},
{
createNode: tandem => new Text( GreenhouseEffectStrings.temperature.units.fahrenheitStringProperty, {
font: LABEL_FONT,
maxWidth: UNITS_LABEL_MAX_WIDTH,
tandem: tandem.createTandem( 'text' )
} ),
value: TemperatureUnits.FAHRENHEIT,
Expand Down
1 change: 1 addition & 0 deletions js/waves/view/CloudCheckbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class CloudCheckbox extends GreenhouseEffectCheckbox {
const options = optionize<CloudCheckboxOptions, SelfOptions, GreenhouseEffectCheckboxOptions>()( {
iconNode: iconNode,
helpText: GreenhouseEffectStrings.a11y.cloudCheckboxHelpTextStringProperty,
maxLabelTextWidth: 120,

// phet-io
tandem: Tandem.REQUIRED
Expand Down

0 comments on commit 7e18283

Please sign in to comment.