Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HalfLifeNumberLine to support dynamic layout #102

Closed
zepumph opened this issue Jul 24, 2023 · 3 comments
Closed

HalfLifeNumberLine to support dynamic layout #102

zepumph opened this issue Jul 24, 2023 · 3 comments
Assignees

Comments

@zepumph
Copy link
Member

zepumph commented Jul 24, 2023

From #90,

Here is a bad patch that I won't use, because we should actually just be using layout boxes now that we know things will need to change.

Subject: [PATCH] boundsProperty listeners junk
---
Index: js/decay/view/HalfLifeNumberLineNode.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/decay/view/HalfLifeNumberLineNode.ts b/js/decay/view/HalfLifeNumberLineNode.ts
--- a/js/decay/view/HalfLifeNumberLineNode.ts	(revision 7c86718f68c1af371efa4375ffab6873644cabc3)
+++ b/js/decay/view/HalfLifeNumberLineNode.ts	(date 1690211718928)
@@ -164,16 +164,20 @@
       maxWidth: 115
     } );
     this.halfLifeDisplayNode.addChild( halfLifeColonText );
-    this.halfLifeDisplayNode.left = this.left + BANConstants.INFO_BUTTON_INDENT_DISTANCE + BANConstants.INFO_BUTTON_MAX_HEIGHT + 10;
-    this.halfLifeDisplayNode.bottom = halfLifeArrow.top - 8;
+    this.halfLifeDisplayNode.boundsProperty.link( () => {
+      this.halfLifeDisplayNode.left = this.left + BANConstants.INFO_BUTTON_INDENT_DISTANCE + BANConstants.INFO_BUTTON_MAX_HEIGHT + 10;
+      this.halfLifeDisplayNode.bottom = halfLifeArrow.top - 8;
+    } );
 
     // create and add the "Unknown" text
     const halfLifeUnknownText = new RichText( BuildANucleusStrings.unknownStringProperty, {
       font: TITLE_FONT,
       maxWidth: 115
     } );
-    halfLifeUnknownText.left = halfLifeColonText.right + 8;
-    halfLifeUnknownText.bottom = halfLifeColonText.bottom;
+    halfLifeUnknownText.boundsProperty.link( () => {
+      halfLifeUnknownText.left = halfLifeColonText.right + 8;
+      halfLifeUnknownText.bottom = halfLifeColonText.bottom;
+    } );
     this.halfLifeDisplayNode.addChild( halfLifeUnknownText );
 
     // create and add the infinity node, which represents a math infinity symbol
@@ -324,8 +328,12 @@
       font: options.unitsLabelFont,
       maxWidth: 150
     } );
-    numberLineUnitsLabel.centerY = this.bottom + numberLineUnitsLabel.height / 2;
-    numberLineUnitsLabel.centerX = this.centerX;
+    const height = numberLineUnitsLabel.height;
+    numberLineUnitsLabel.localBoundsProperty.link( () => {
+      console.log( 'changed' );
+      numberLineUnitsLabel.centerY = numberLineNode.bottom + height / 2;
+      numberLineUnitsLabel.centerX = this.centerX;
+    } );
     this.addChild( numberLineUnitsLabel );
   }
 
@@ -426,8 +434,10 @@
       } );
     this.addChild( arrow );
     const numberText = new RichText( label, { font: this.numberLineLabelFont, maxWidth: 25 } );
-    numberText.bottom = arrow.top;
-    numberText.centerX = arrow.centerX;
+    numberText.boundsProperty.link( () => {
+      numberText.bottom = arrow.top;
+      numberText.centerX = arrow.centerX;
+    } );
     this.addChild( numberText );
   }
 
@zepumph zepumph self-assigned this Jul 24, 2023
@zepumph
Copy link
Member Author

zepumph commented Jul 24, 2023

Good progress here today. I will be on the lookout for future bugs this may have caused, but I tried to refactor the layout into HBox and VBoxes so that dynamic stuff is done for free.

@zepumph
Copy link
Member Author

zepumph commented Jul 31, 2023

Things are looking here. Closing

@zepumph zepumph closed this as completed Jul 31, 2023
@Luisav1
Copy link
Contributor

Luisav1 commented Aug 15, 2023

There is a TODO remaining in HalfLifeNumberLineNode pointing to this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants