public function remove(SwatWidget $widget)
    {
        foreach ($this->children as $key => $child_widget) {
            if ($child_widget === $widget) {
                // use array_splice here instead of unset in order to re-index
                // the array keys
                array_splice($this->children, $key, 1);
                $widget->parent = null;

                if ($widget->id !== null) {
                    unset($this->children_by_id[$widget->id]);
                }

                return $widget;
            }
        }
        return null;
    }