mod widget;

use crate::elements::Math;
use crate::widget_factory::WidgetBuilder;
use gtk4::{IconSize, Image, Widget, prelude::*};

pub use widget::MathWidget;

impl WidgetBuilder {
    pub(super) fn render_math(&self, math: Math) -> Widget {
        let Some(math_renderer) = self.math_renderer.clone() else {
            return Image::builder()
                .icon_name("image-missing")
                .icon_size(IconSize::Large)
                .build()
                .upcast();
        };

        let widget = MathWidget::default();
        widget.load(
            math.clone(),
            self.config.font_size,
            self.scale_factor,
            math_renderer,
        );
        widget.upcast()
    }
}
