#pragma once
/**
 * @file hit_test_result.h
 * @brief 定义UI命中测试结果的数据结构
 */

#include <memory>
#include <Eigen/Core>

class mwidget;
/**
 * @enum hit_test_result_behavior
 * @brief 定义命中测试结果的行为
 */
enum class hit_test_result_behavior {
	continue_test,      ///< 继续命中测试
	handle_event        ///< 处理事件并停止测试
};

struct hit_test_handle {
public:
	static auto unhandled() {
		hit_test_handle result{};
		result.behavior_ = hit_test_result_behavior::continue_test;
		return result;
	}
	static auto handled() {
		hit_test_handle result{};
		result.behavior_ = hit_test_result_behavior::handle_event;
		return result;
	}

	bool is_handled() const {
		return behavior_ == hit_test_result_behavior::handle_event;
	}

	operator bool() const {
		return is_handled();
	}
private:
	hit_test_result_behavior behavior_{ hit_test_result_behavior::continue_test };
};

struct hit_test_result {
	std::shared_ptr<mwidget> widget;
	Eigen::Vector2f widget_space_pos;

	operator bool() const {
		return static_cast<bool>(widget);
	}
	operator const auto&() const { return widget; }
};
