Fix ProgramBlockView having too narrow width
This commit is contained in:
parent
e79c0dd6f7
commit
1392d284d1
|
@ -38,6 +38,7 @@ class ProgramBlockView(val block: ProgramBlock): StackView(Axis.VERTICAL, Distri
|
|||
|
||||
var xConstraint: Constraint? = null
|
||||
var yConstraint: Constraint? = null
|
||||
var didCreateWidthConstraint = false
|
||||
|
||||
override fun wasAdded() {
|
||||
super.wasAdded()
|
||||
|
@ -48,7 +49,7 @@ class ProgramBlockView(val block: ProgramBlock): StackView(Axis.VERTICAL, Distri
|
|||
zIndex = 10.0
|
||||
|
||||
val titleStack = addArrangedSubview(StackView(Axis.HORIZONTAL, Distribution.CENTER))
|
||||
val title = titleStack.addArrangedSubview(Label(block.translateName()))
|
||||
val title = titleStack.addArrangedSubview(Label(block.translateName(), wrappingMode = Label.WrappingMode.NO_WRAP))
|
||||
if (block is ExecutableBlock) {
|
||||
val incomingTexture = if (block.executionFlow.prev == null) emptyConnection else executionConnection
|
||||
incomingExecution = titleStack.addArrangedSubview(TextureView(incomingTexture), index = 0)
|
||||
|
@ -59,7 +60,6 @@ class ProgramBlockView(val block: ProgramBlock): StackView(Axis.VERTICAL, Distri
|
|||
solver.dsl {
|
||||
// we have to constrain the titleStack height, because it's distribution is set to CENTER, so it doesn't do it itself
|
||||
titleStack.heightAnchor equalTo title.heightAnchor
|
||||
widthAnchor greaterThanOrEqualTo titleStack.widthAnchor
|
||||
|
||||
if (block is ExecutableBlock) {
|
||||
incomingExecution!!.widthAnchor equalTo incomingExecution!!.heightAnchor
|
||||
|
@ -114,6 +114,23 @@ class ProgramBlockView(val block: ProgramBlock): StackView(Axis.VERTICAL, Distri
|
|||
updateDraggingConstraints()
|
||||
}
|
||||
|
||||
override fun didLayout() {
|
||||
super.didLayout()
|
||||
|
||||
// we want to constrain this view's width to be the same as the widest view in the vertical stack,
|
||||
// but we don't know what view that is until after all subviews have been laid-out
|
||||
if (!didCreateWidthConstraint) {
|
||||
didCreateWidthConstraint = true
|
||||
|
||||
arrangedSubviews.maxBy { it.bounds.width }?.let { widestSubview ->
|
||||
solver.dsl {
|
||||
widthAnchor equalTo widestSubview.widthAnchor
|
||||
}
|
||||
window!!.layout()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun mouseDragged(startPoint: Point, delta: Point, mouseButton: MouseButton): Boolean {
|
||||
block.position += delta
|
||||
updateDraggingConstraints()
|
||||
|
|
Loading…
Reference in New Issue