<commit_before>package org.liquidengine.legui.system.renderer.nvg.component;

import static org.liquidengine.legui.system.renderer.nvg.NvgRenderer.renderBorderWScissor;
import static org.liquidengine.legui.system.renderer.nvg.util.NvgRenderUtils.createScissor;
import static org.liquidengine.legui.system.renderer.nvg.util.NvgRenderUtils.resetScissor;

import org.joml.Vector4f;
import org.liquidengine.legui.component.Component;
import org.liquidengine.legui.layout.Layout;
import org.liquidengine.legui.layout.borderlayout.BorderLayout;
import org.liquidengine.legui.layout.borderlayout.BorderLayoutConstraint;
import org.liquidengine.legui.layout.boxlayout.BoxLayout;
import org.liquidengine.legui.style.Style;
import org.liquidengine.legui.system.context.Context;
import org.liquidengine.legui.system.renderer.RendererProvider;
import org.liquidengine.legui.system.renderer.nvg.NvgComponentRenderer;
import org.liquidengine.legui.system.renderer.nvg.util.NvgShapes;

/**
 * Default component renderer.
 *
 * @param <C> component type.
 */
public class NvgDefaultComponentRenderer<C extends Component> extends NvgComponentRenderer<C> {

    /**
     * Used to render component.
     *
     * @param component component to render.
     * @param context legui context.
     * @param nanovg nanovg context pointer.
     */
    @Override
    protected void renderComponent(C component, Context context, long nanovg) {
        if (component.isVisible() && component.getSize().lengthSquared() > 0.01) {
            renderSelf(component, context, nanovg);
            renderChildComponents(component, context, nanovg);
            renderBorder(component, context, nanovg);
        }
    }

    /**
     * Used to render component without childComponents.
     *
     * @param component component to render.
     * @param context context.
     * @param nanovg nanovg context pointer.
     */
    protected void renderSelf(C component, Context context, long nanovg) {
        createScissor(nanovg, component);
        {
            Style style = component.getStyle();
            Vector4f radius = new Vector4f(style.getTopLeftCornerRadius(), style.getTopRightCornerRadius(), style.getBottomRightCornerRadius(),
                style.getBottomLeftCornerRadius());
            NvgShapes.drawRect(nanovg, component.getAbsolutePosition(), component.getSize(), style.getBackground().getColor(), radius);
        }
        resetScissor(nanovg);
    }

    /**
     * Used to render component childComponents.
     *
     * @param component component to render.
     * @param context context.
     * @param nanovg nanovg context pointer.
     */
    protected void renderChildComponents(C component, Context context, long nanovg) {
        // TODO : Could be created per layout renderer for child components.
        Layout layout = component.getLayout();
        if (layout == null || (layout instanceof BoxLayout)) {
            for (Component child : component.getChildComponents()) {
                RendererProvider.getInstance().getComponentRenderer(child.getClass()).render(child, context);
            }
        } else if (layout instanceof BorderLayout) {
            BorderLayout borderLayout = (BorderLayout) layout;
            renderBorderLayoutComponent(context, borderLayout.getComponent(BorderLayoutConstraint.TOP));
            renderBorderLayoutComponent(context, borderLayout.getComponent(BorderLayoutConstraint.LEFT));
            renderBorderLayoutComponent(context, borderLayout.getComponent(BorderLayoutConstraint.CENTER));
            renderBorderLayoutComponent(context, borderLayout.getComponent(BorderLayoutConstraint.RIGHT));
            renderBorderLayoutComponent(context, borderLayout.getComponent(BorderLayoutConstraint.BOTTOM));
        }
    }

    /**
     * Used to render border layout components.
     *
     * @param context context.
     * @param cToRender component to render.
     */
    private void renderBorderLayoutComponent(Context context, Component cToRender) {
        if (cToRender != null) {
            RendererProvider.getInstance().getComponentRenderer(cToRender.getClass()).render(cToRender, context);
        }
    }

    /**
     * Used to render component border.
     *
     * @param component component to render.
     * @param context context.
     * @param nanovg nanovg context pointer.
     */
    protected void renderBorder(C component, Context context, long nanovg) {
        renderBorderWScissor(component, context, nanovg);
    }
}<commit_msg>Fixed default component renderer<commit_after>package org.liquidengine.legui.system.renderer.nvg.component;

import static org.liquidengine.legui.system.renderer.nvg.NvgRenderer.renderBorderWScissor;
import static org.liquidengine.legui.system.renderer.nvg.util.NvgRenderUtils.createScissor;
import static org.liquidengine.legui.system.renderer.nvg.util.NvgRenderUtils.resetScissor;

import org.joml.Vector4f;
import org.liquidengine.legui.component.Component;
import org.liquidengine.legui.layout.Layout;
import org.liquidengine.legui.layout.borderlayout.BorderLayout;
import org.liquidengine.legui.layout.borderlayout.BorderLayoutConstraint;
import org.liquidengine.legui.style.Style;
import org.liquidengine.legui.system.context.Context;
import org.liquidengine.legui.system.renderer.RendererProvider;
import org.liquidengine.legui.system.renderer.nvg.NvgComponentRenderer;
import org.liquidengine.legui.system.renderer.nvg.util.NvgShapes;

/**
 * Default component renderer.
 *
 * @param <C> component type.
 */
public class NvgDefaultComponentRenderer<C extends Component> extends NvgComponentRenderer<C> {

    /**
     * Used to render component.
     *
     * @param component component to render.
     * @param context legui context.
     * @param nanovg nanovg context pointer.
     */
    @Override
    protected void renderComponent(C component, Context context, long nanovg) {
        if (component.isVisible() && component.getSize().lengthSquared() > 0.01) {
            renderSelf(component, context, nanovg);
            renderChildComponents(component, context, nanovg);
            renderBorder(component, context, nanovg);
        }
    }

    /**
     * Used to render component without childComponents.
     *
     * @param component component to render.
     * @param context context.
     * @param nanovg nanovg context pointer.
     */
    protected void renderSelf(C component, Context context, long nanovg) {
        createScissor(nanovg, component);
        {
            Style style = component.getStyle();
            Vector4f radius = new Vector4f(style.getTopLeftCornerRadius(), style.getTopRightCornerRadius(), style.getBottomRightCornerRadius(),
                style.getBottomLeftCornerRadius());
            NvgShapes.drawRect(nanovg, component.getAbsolutePosition(), component.getSize(), style.getBackground().getColor(), radius);
        }
        resetScissor(nanovg);
    }

    /**
     * Used to render component childComponents.
     *
     * @param component component to render.
     * @param context context.
     * @param nanovg nanovg context pointer.
     */
    protected void renderChildComponents(C component, Context context, long nanovg) {
        // TODO : Could be created per layout renderer for child components.
        Layout layout = component.getLayout();
        if (layout == null) {
            for (Component child : component.getChildComponents()) {
                RendererProvider.getInstance().getComponentRenderer(child.getClass()).render(child, context);
            }
        } else if (layout instanceof BorderLayout) {
            BorderLayout borderLayout = (BorderLayout) layout;
            renderBorderLayoutComponent(context, borderLayout.getComponent(BorderLayoutConstraint.TOP));
            renderBorderLayoutComponent(context, borderLayout.getComponent(BorderLayoutConstraint.LEFT));
            renderBorderLayoutComponent(context, borderLayout.getComponent(BorderLayoutConstraint.CENTER));
            renderBorderLayoutComponent(context, borderLayout.getComponent(BorderLayoutConstraint.RIGHT));
            renderBorderLayoutComponent(context, borderLayout.getComponent(BorderLayoutConstraint.BOTTOM));
        } else {
            for (Component child : component.getChildComponents()) {
                RendererProvider.getInstance().getComponentRenderer(child.getClass()).render(child, context);
            }
        }
    }

    /**
     * Used to render border layout components.
     *
     * @param context context.
     * @param cToRender component to render.
     */
    private void renderBorderLayoutComponent(Context context, Component cToRender) {
        if (cToRender != null) {
            RendererProvider.getInstance().getComponentRenderer(cToRender.getClass()).render(cToRender, context);
        }
    }

    /**
     * Used to render component border.
     *
     * @param component component to render.
     * @param context context.
     * @param nanovg nanovg context pointer.
     */
    protected void renderBorder(C component, Context context, long nanovg) {
        renderBorderWScissor(component, context, nanovg);
    }
}
{'fraction_non_alphanumeric': 0.09540481400437636, 'fraction_numerical': 0.001312910284463895, 'mean_word_length': 3.3322274881516587, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '145763', 'n_tokens_mistral': 2472, 'n_tokens_neox': 2389, 'n_words': 517}