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

class font_face_interface;

class mtext_block : public mleaf_widget {
public:
	void on_paint(mirage_paint_context& in_context) override;

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

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

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

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

	void set_max_width(float in_max_width) {
		max_width_ = in_max_width;
		update_layout();
	}

	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        get_max_width() const { return max_width_; }

	auto compute_desired_size(float in_layout_scale_multiplier) const -> Eigen::Vector2f override;
private:
	void update_layout();

	std::u32string text_;
	text_layout_t layout_{};
	float font_size_ = 48.0f;
	float line_spacing_ = 1.2f;
	float max_width_ = 0.0f;
	std::shared_ptr<font_face_interface> font_;
};
