<commit_before>package io.youi.layout

import io.youi.component.{AbstractContainer, Component}
import reactify._

class VerticalLayout(spacing: Double = 0.0,
                     fromTop: Boolean = true) extends Layout {
  override def connect(container: AbstractContainer): Unit = {
    update(container, Vector.empty)
  }

  override def disconnect(container: AbstractContainer): Unit = AbstractContainer.children(container).foreach { c =>
    Snap(c).verticalReset()
  }

  override def childrenChanged(container: AbstractContainer, removed: Vector[Component], added: Vector[Component]): Unit = {
    super.childrenChanged(container, removed, added)

    update(container, removed)
  }

  private def update(container: AbstractContainer, removed: Vector[Component]): Unit = {
    val children = AbstractContainer.children(container)
    val items = children()
    removed.foreach { c =>
      Snap(c).verticalReset()
    }
    if (items.nonEmpty) {
      var previous = items.head
      if (fromTop) {
        Snap(previous).verticalReset().topTo(container.position.top + spacing)
      } else {
        Snap(previous).verticalReset().bottomTo(container.position.bottom - spacing)
      }
      items.tail.foreach { child =>
        if (fromTop) {
          Snap(child).verticalReset().topTo(previous.position.bottom + spacing)
        } else {
          Snap(child).verticalReset().bottomTo(previous.position.top - spacing)
        }
        previous = child
      }
    }
  }
}<commit_msg>Minor fix to VerticalLayout starting position.<commit_after>package io.youi.layout

import io.youi.component.{AbstractContainer, Component}
import reactify._

class VerticalLayout(spacing: Double = 0.0,
                     fromTop: Boolean = true) extends Layout {
  override def connect(container: AbstractContainer): Unit = {
    update(container, Vector.empty)
  }

  override def disconnect(container: AbstractContainer): Unit = AbstractContainer.children(container).foreach { c =>
    Snap(c).verticalReset()
  }

  override def childrenChanged(container: AbstractContainer, removed: Vector[Component], added: Vector[Component]): Unit = {
    super.childrenChanged(container, removed, added)

    update(container, removed)
  }

  private def update(container: AbstractContainer, removed: Vector[Component]): Unit = {
    val children = AbstractContainer.children(container)
    val items = children()
    removed.foreach { c =>
      Snap(c).verticalReset()
    }
    if (items.nonEmpty) {
      var previous = items.head
      if (fromTop) {
        Snap(previous).verticalReset().topTo(spacing)
      } else {
        Snap(previous).verticalReset().bottomTo(container.size.height - spacing)
      }
      items.tail.foreach { child =>
        if (fromTop) {
          Snap(child).verticalReset().topTo(previous.position.bottom + spacing)
        } else {
          Snap(child).verticalReset().bottomTo(previous.position.top - spacing)
        }
        previous = child
      }
    }
  }
}
{'fraction_non_alphanumeric': 0.1143048128342246, 'fraction_numerical': 0.001336898395721925, 'mean_word_length': 3.209563994374121, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4331108', 'n_tokens_mistral': 827, 'n_tokens_neox': 796, 'n_words': 172}