#include "panel.hpp"

void Panel::resize(int w, int h) {
  $dirty = true;
  width = w;
  height = h;
  $screen = Screen(width, height);
}

void Panel::set_renderer(Component renderer) {
  $dirty = true;
  $component = renderer;
}

void Panel::add(Component child) {
  $dirty = true;
  $component->Add(child);
}

void Panel::render() {
  $dirty = true;
  if(must_clear) $screen.Clear();
  Render($screen, $component->Render());
}

const std::wstring& Panel::to_string() {
  if($dirty) {
    std::string as_text = $screen.ToString();
    $screenout = $converter.from_bytes(as_text);
    $dirty = false;
  }

  return $screenout;
}

const Screen &Panel::screen() {
  return $screen;
}
