Fix ProgramBlockView having too narrow width

This commit is contained in:
Shadowfacts 2019-08-10 22:04:59 -04:00
parent e79c0dd6f7
commit 1392d284d1
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 19 additions and 2 deletions

View File

@ -38,6 +38,7 @@ class ProgramBlockView(val block: ProgramBlock): StackView(Axis.VERTICAL, Distri
var xConstraint: Constraint? = null var xConstraint: Constraint? = null
var yConstraint: Constraint? = null var yConstraint: Constraint? = null
var didCreateWidthConstraint = false
override fun wasAdded() { override fun wasAdded() {
super.wasAdded() super.wasAdded()
@ -48,7 +49,7 @@ class ProgramBlockView(val block: ProgramBlock): StackView(Axis.VERTICAL, Distri
zIndex = 10.0 zIndex = 10.0
val titleStack = addArrangedSubview(StackView(Axis.HORIZONTAL, Distribution.CENTER)) 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) { if (block is ExecutableBlock) {
val incomingTexture = if (block.executionFlow.prev == null) emptyConnection else executionConnection val incomingTexture = if (block.executionFlow.prev == null) emptyConnection else executionConnection
incomingExecution = titleStack.addArrangedSubview(TextureView(incomingTexture), index = 0) incomingExecution = titleStack.addArrangedSubview(TextureView(incomingTexture), index = 0)
@ -59,7 +60,6 @@ class ProgramBlockView(val block: ProgramBlock): StackView(Axis.VERTICAL, Distri
solver.dsl { solver.dsl {
// we have to constrain the titleStack height, because it's distribution is set to CENTER, so it doesn't do it itself // 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 titleStack.heightAnchor equalTo title.heightAnchor
widthAnchor greaterThanOrEqualTo titleStack.widthAnchor
if (block is ExecutableBlock) { if (block is ExecutableBlock) {
incomingExecution!!.widthAnchor equalTo incomingExecution!!.heightAnchor incomingExecution!!.widthAnchor equalTo incomingExecution!!.heightAnchor
@ -114,6 +114,23 @@ class ProgramBlockView(val block: ProgramBlock): StackView(Axis.VERTICAL, Distri
updateDraggingConstraints() 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 { override fun mouseDragged(startPoint: Point, delta: Point, mouseButton: MouseButton): Boolean {
block.position += delta block.position += delta
updateDraggingConstraints() updateDraggingConstraints()