Fair enough, I’ll start over as my question was poorly worded.
First of all, here’s how it looks with fewer omissions;
GraphObject.make(Panel, Panel.Vertical,
GraphObject.make(Panel, Panel.Spot,
GraphObject.make(Shape, "Circle",
{
"width": ...,
"height": ...,
...
}),
// TextBlockA
GraphObject.make(TextBlock, {
"name": "NodeLabel",
"margin": new Margin(3, 0, 0, 0),
"maxLines": 2,
"overflow": TextBlock.OverflowEllipsis,
"stretch": GraphObject.Horizontal,
"textAlign": "center",
"width": ...,
"height" 40,
"alignment": new Spot(.5, .5, 0, 45),
}),
// Large gap here when there is no label text, or only a single line of text
GraphObject.make(Panel, Panel.Vertical,
{margin: new Margin(4, 0, 0, 0)},
// TextBlockB
GraphObject.make(TextBlock, { ...})
GraphObject.make(Panel, { ...})
// Attempted solution for 2)
new Binding("text", "", (data, targetObj) => {
// Attempt to adjust this panel's margin
// Doesn't work as lineCount hasn't been updated when this fires
if (targetObj.panel.findObject("NodeLabel").lineCount === 2) {
targetObj.margin.top = 4;
}
else {
targetObj.margin.top = -16;
}
}),
),
)
)
What I have is a shape (Circle) with a TextBlock (TextBlockA) beneath it. Beneath that I have yet another TextBlock (TextBlockB). TextBlockA is limited to 2 lines and has a fixed height. The problem with that fixed height is that it means that when TextBlockA only has one line of text, we end up with a large, unwanted gap between A and B.
Here’s what I’ve tried so far;
-
Remove the fixed height on TextBlockA so that it grows in height as the user enters text. This results in no gap between the two TextBlocks (great) and pushes TextBlockB down when the text in TextBlockA wraps. This works - except that the resize of TextBlockA results in its position changing and it ends up overlapping the shape above it.
-
Keep the fixed height on TextBlockA and adjust the top margin on TextBlockB so that it moves as the text in TextBlockA wraps. This almost works - the issue as I mentioned in my first post is that the lineCount isn’t correct at the time the model updates, presumably because TextBlockB has yet to be rerendered. I’m also not happy about using a Binding for this as I don’t believe that this is what it’s intended to be used for.