/*
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_CONSTRAINT_HPP
#define POLYGUN_GUI_CONSTRAINT_HPP

#define POLYGUN_AUTO_CONSTRAINT nullptr
#define POLYGUN_DEREF_CONSTRAINT(c) (c?c->value():0)

#include <string>

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

	class Constraint {
	public:
		Constraint() = default;
		virtual ~Constraint() = default;

		void set_parent(Container* parent) { m_parent = parent; }
		void set_component(Component* component) { m_component = component; }

		virtual float value() const = 0;

		static Constraint* from_string(const std::string& str, const std::string& name);

	protected:
		Container* m_parent;
		Component* m_component;
	};

	class FixedConstraint final : public Constraint {
	public:
		FixedConstraint(float val);

		virtual float value() const override;

	private:
		float m_val;
	};

	class WidthRelConstraint final : public Constraint {
	public:
		WidthRelConstraint(float width_fraction);

		virtual float value() const override;

	private:
		float m_width_fraction;
	};

	class HeightRelConstraint final : public Constraint {
	public:
		HeightRelConstraint(float height_fraction);

		virtual float value() const override;

	private:
		float m_height_fraction;
	};

	class XCenteredConstraint final : public Constraint {
	public:
		virtual float value() const override;
	};

	class YCenteredConstraint final : public Constraint {
	public:
		virtual float value() const override;
	};

	class RightAlignedConstraint final : public Constraint {
	public:
		RightAlignedConstraint(float padding);

		virtual float value() const override;

	private:
		float m_padding;
	};

	class BottomAlignedConstraint final : public Constraint {
	public:
		BottomAlignedConstraint(float padding);

		virtual float value() const override;

	private:
		float m_padding;
	};

}

#endif // POLYGUN_GUI_CONSTRAINT_HPP
