From 27afee635639fa60e0b826f47ceef282be0e1209 Mon Sep 17 00:00:00 2001 From: Jonathan Olson Date: Thu, 3 Mar 2022 11:15:03 -0700 Subject: [PATCH] Layout options fixes and TypeScript work --- js/layout/FlowConstraint.ts | 20 ++++++++++---------- js/layout/GridConstraint.ts | 8 ++++---- js/layout/HeightSizable.ts | 4 ++-- js/layout/WidthSizable.ts | 4 ++-- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/js/layout/FlowConstraint.ts b/js/layout/FlowConstraint.ts index 085b72f9a..9fbc25ec1 100644 --- a/js/layout/FlowConstraint.ts +++ b/js/layout/FlowConstraint.ts @@ -11,7 +11,7 @@ import TinyProperty from '../../../axon/js/TinyProperty.js'; import Bounds2 from '../../../dot/js/Bounds2.js'; import Orientation from '../../../phet-core/js/Orientation.js'; import arrayRemove from '../../../phet-core/js/arrayRemove.js'; -import merge from '../../../phet-core/js/merge.js'; +import optionize from '../../../phet-core/js/optionize.js'; import mutate from '../../../phet-core/js/mutate.js'; import { scenery, Node, Divider, FlowCell, FlowConfigurable, LayoutConstraint, FLOW_CONFIGURABLE_OPTION_KEYS, FlowConfigurableOptions, FlowConfigurableAlign } from '../imports.js'; import EnumerationValue from '../../../phet-core/js/EnumerationValue.js'; @@ -123,19 +123,19 @@ const internalToJustify = ( orientation: Orientation, justify: FlowConstraintJus } }; -type FlowConstraintSelfOptions = { +type SelfOptions = { spacing?: number; lineSpacing?: number; justify?: FlowHorizontalJustifys | FlowVerticalJustifys; wrap?: boolean; excludeInvisible?: boolean; - preferredWidthProperty: IProperty; - preferredHeightProperty: IProperty; - minimumWidthProperty: IProperty; - minimumHeightProperty: IProperty; + preferredWidthProperty?: IProperty; + preferredHeightProperty?: IProperty; + minimumWidthProperty?: IProperty; + minimumHeightProperty?: IProperty; }; -type FlowConstraintOptions = FlowConstraintSelfOptions & FlowConfigurableOptions; +type FlowConstraintOptions = SelfOptions & FlowConfigurableOptions; // TODO: Have LayoutBox use this when we're ready class FlowConstraint extends FlowConfigurable( LayoutConstraint ) { @@ -156,16 +156,16 @@ class FlowConstraint extends FlowConfigurable( LayoutConstraint ) { // will include margins, etc.) layoutBoundsProperty: IProperty; - constructor( ancestorNode: Node, options?: FlowConstraintOptions ) { + constructor( ancestorNode: Node, providedOptions?: FlowConstraintOptions ) { assert && assert( ancestorNode instanceof Node ); - options = merge( { + const options = optionize>( { // As options, so we could hook into a Node's preferred/minimum sizes if desired preferredWidthProperty: new TinyProperty( null ), preferredHeightProperty: new TinyProperty( null ), minimumWidthProperty: new TinyProperty( null ), minimumHeightProperty: new TinyProperty( null ) - }, options ); + }, providedOptions ); super( ancestorNode ); diff --git a/js/layout/GridConstraint.ts b/js/layout/GridConstraint.ts index ab7f4fd52..c8d6676f9 100644 --- a/js/layout/GridConstraint.ts +++ b/js/layout/GridConstraint.ts @@ -30,10 +30,10 @@ type GridConstraintSelfOptions = { xSpacing?: number; ySpacing?: number; - preferredWidthProperty: IProperty; - preferredHeightProperty: IProperty; - minimumWidthProperty: IProperty; - minimumHeightProperty: IProperty; + preferredWidthProperty?: IProperty; + preferredHeightProperty?: IProperty; + minimumWidthProperty?: IProperty; + minimumHeightProperty?: IProperty; }; type GridConstraintOptions = GridConstraintSelfOptions & GridConfigurableOptions; diff --git a/js/layout/HeightSizable.ts b/js/layout/HeightSizable.ts index c002be963..841ca3cb4 100644 --- a/js/layout/HeightSizable.ts +++ b/js/layout/HeightSizable.ts @@ -19,8 +19,8 @@ const HEIGHT_SIZABLE_OPTION_KEYS = [ ]; type HeightSizableSelfOptions = { - preferredHeight: number | null, - minimumHeight: number | null + preferredHeight?: number | null, + minimumHeight?: number | null }; const HeightSizable = memoize( ( type: SuperType ) => { diff --git a/js/layout/WidthSizable.ts b/js/layout/WidthSizable.ts index 15179faea..092342eb4 100644 --- a/js/layout/WidthSizable.ts +++ b/js/layout/WidthSizable.ts @@ -19,8 +19,8 @@ const WIDTH_SIZABLE_OPTION_KEYS = [ ]; type WidthSizableSelfOptions = { - preferredWidth: number | null, - minimumWidth: number | null + preferredWidth?: number | null, + minimumWidth?: number | null }; const WidthSizable = memoize( ( type: SuperType ) => {