#pragma once
#include "font/font_type.h"
#include "widget/mleaf_widget.h"

class font_face_interface;

struct text_block_args {
	WARG(std::u32string, text, {})
	WARG(std::shared_ptr<font_face_interface>, font, {})
	WARG(float, font_size, 24.f)
	WARG(float, line_spacing, 1.2f)
	WARG(bool, warp_text, false)
};

class mtext_block : public mleaf_widget<text_block_args> {
public:
	void setup_widget(const text_block_args& in_args) override;
	void on_paint(mirage_paint_context& in_context) override;

	void set_text(const std::u32string& in_text) {
		text_ = in_text;
		update_no_wrap_size();
	}

	void set_font(const std::shared_ptr<font_face_interface>& in_font) {
		font_ = in_font;
		update_no_wrap_size();
	}

	void set_font_size(float in_font_size) {
		font_size_ = in_font_size;
		update_no_wrap_size();
	}

	void set_line_spacing(float in_line_spacing) {
		line_spacing_ = in_line_spacing;
		update_no_wrap_size();
	}

	const auto& get_text() const { return text_; }
	const auto& get_font() const { return font_; }
	auto        get_font_size() const { return font_size_; }
	auto        get_line_spacing() const { return line_spacing_; }

	auto compute_desired_size(float in_layout_scale_multiplier) const -> Eigen::Vector2f override;
	void arrange_children(const geometry_t& in_allotted_geometry) override;
private:
	void update_no_wrap_size();

	std::u32string text_;
	text_layout_t layout_{};
	Eigen::Vector2f no_warp_size_{};
	float font_size_ = .0f;
	float line_spacing_ = 1.f;
	bool warp_text_ = false;
	std::shared_ptr<font_face_interface> font_;
};
