/*
PolyGun

Copyright (c) 2023 mrkubax10 <mrkubax10@onet.pl>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#ifndef POLYGUN_GUI_LAYOUT_HPP
#define POLYGUN_GUI_LAYOUT_HPP

#include <vector>
#include <string>

namespace polygun::gui {
	class Component;
	class Container;

	class Layout {
		friend class Container;
	public:
		Layout();
		virtual ~Layout() = default;

		virtual void position_component(Component* component) = 0;
		virtual void reposition_components() {}

		static Layout* from_string(const std::string& str);

	protected:
		Container* m_container;
	};

	class FixedLayout final : public Layout {
	public:
		virtual void position_component(Component* component) override;
	};

	class StackLayout final : public Layout {
	public:
		enum Direction {
			DIRECTION_VERTICAL,
			DIRECTION_HORIZONTAL
		};

	public:
		StackLayout(Direction direction);

		virtual void position_component(Component* component) override;
		virtual void reposition_components() override;

	private:
		Direction m_direction;
		std::vector<float> m_segments;
		std::vector<Component*> m_components;
		float m_current_x;
		float m_current_y;
		bool m_repositioning;
	};
}

#endif // POLYGUN_GUI_LAYOUT_HPP
