#pragma once

#include "printf/printf.h"

namespace widget {

  struct container : widget {
    widget ** children;
    int length;

    inline container(float _x, float _y, float _width, float _height,
                     widget ** _children, int _length)
      : widget(_x, _y, _width, _height), children(_children), length(_length)
    {}

    inline void freeze(float _dx, float _dy)
    {
      dx = _dx;
      dy = _dy;

      for (int i = 0; i < length; i++) {
        children[i]->freeze(x(), y());
      }
    }

    void draw(ta_multiwriter& multi)
    {
      for (int i = 0; i < length; i++) {
        children[i]->draw(multi);
      }
    }

    inline widget * pick(float _x, float _y)
    {
      if (!inside(_x, _y))
        return nullptr;

      for (int i = 0; i < length; i++) {
        widget * w = children[i]->pick(_x, _y);
        if (w != nullptr)
          return w;
      }

      return nullptr;
    }
  };
}
