<commit_before>/*  -*- mode: c++; coding: utf-8; c-file-style: "stroustrup"; -*-

    Contributors: <NAME>

    All rights reserved. Use of this source code is governed by a
    BSD-style license that can be found in the LICENSE.txt file.
*/

#include "widget.h"
#include "input.h"
#include "nanovg.h"
#include "context.h"
#include <cstdlib>
#include <cstddef>

using namespace std;
using namespace webui;

namespace {

    TypeWidget widgetType = {
        Identifier::Widget, sizeof(Widget), {
            { Identifier::x,              PROP(Widget, box.pos.x, Float,        4, 0, 0) },
            { Identifier::y,              PROP(Widget, box.pos.y, Float,        4, 0, 0) },
            { Identifier::w,              PROP(Widget, box.size.x,Float,        4, 0, 0) },
            { Identifier::h,              PROP(Widget, box.size.y,Float,        4, 0, 0) },
            { Identifier::id,             PROP(Widget, id,        Id,           4, 0, 1) },
            { Identifier::width,          PROP(Widget, size[0],   SizeRelative, 2, 0, 0) },
            { Identifier::height,         PROP(Widget, size[1],   SizeRelative, 2, 0, 0) },
            { Identifier::background,     PROP(Widget, background,Color,        4, 0, 0) },
            { Identifier::foreground,     PROP(Widget, foreground,Color,        4, 0, 0) },
            { Identifier::all,            PROP(Widget, all,       Int32,        4, 0, 0) },
            { Identifier::visible,        PROP(Widget, byte0,     Bit,          1, 0, 1) },
            { Identifier::canFocus,       PROP(Widget, byte0,     Bit,          1, 3, 1) },
            { Identifier::active,         PROP(Widget, byte0,     Bit,          1, 4, 1) },
            { Identifier::draggable,      PROP(Widget, byte0,     Bit,          1, 5, 1) },
            { Identifier::onEnter,        PROP(Widget, actions,   ActionTable,  4, 0, 1) },
            { Identifier::onLeave,        PROP(Widget, actions,   ActionTable,  4, 0, 1) },
            { Identifier::onClick,        PROP(Widget, actions,   ActionTable,  4, 0, 1) },
            { Identifier::onRender,       PROP(Widget, actions,   ActionTable,  4, 0, 1) },
            { Identifier::onRenderActive, PROP(Widget, actions,   ActionTable,  4, 0, 1) },
            { Identifier::text,           PROP(Widget, text,      Text,         sizeof(void*), 0, 0) },
        }
    };

}

namespace webui {

    Widget::Widget(Widget* parent): parent(parent), text(nullptr),
                                    size { SizeRelative(100.0f, true), SizeRelative(100.0f, true) },
                                    all(0x00ff4009), actions(0) {
        typeWidget = &widgetType;
    }

    Widget::~Widget() {
        free(text);
    }

    TypeWidget& Widget::getType() {
        return widgetType;
    }

    void Widget::render(int alphaMult) {
        alphaMult = Context::render.multAlpha(alphaMult, alpha);

        const auto& actionTable(Context::app.getActionTable(actions));
        if (active || (Input::mouseButtonWidget == this && inside))
            Context::actions.execute(actionTable.onRenderActive, this);
        else
            Context::actions.execute(actionTable.onRender, this);

        if (alphaMult)
            for (auto* child: children) child->render(alphaMult);
    }

    bool Widget::input() {
        if (canFocus && Input::mouseButtonAction) {
            // this widget takes care of the event and does not propagate upwards
            Input::mouseButtonAction = false;<commit_msg>Bugfix: only call onRenderActive if defined.<commit_after>/*  -*- mode: c++; coding: utf-8; c-file-style: "stroustrup"; -*-

    Contributors: <NAME>re

    All rights reserved. Use of this source code is governed by a
    BSD-style license that can be found in the LICENSE.txt file.
*/

#include "widget.h"
#include "input.h"
#include "nanovg.h"
#include "context.h"
#include <cstdlib>
#include <cstddef>

using namespace std;
using namespace webui;

namespace {

    TypeWidget widgetType = {
        Identifier::Widget, sizeof(Widget), {
            { Identifier::x,              PROP(Widget, box.pos.x, Float,        4, 0, 0) },
            { Identifier::y,              PROP(Widget, box.pos.y, Float,        4, 0, 0) },
            { Identifier::w,              PROP(Widget, box.size.x,Float,        4, 0, 0) },
            { Identifier::h,              PROP(Widget, box.size.y,Float,        4, 0, 0) },
            { Identifier::id,             PROP(Widget, id,        Id,           4, 0, 1) },
            { Identifier::width,          PROP(Widget, size[0],   SizeRelative, 2, 0, 0) },
            { Identifier::height,         PROP(Widget, size[1],   SizeRelative, 2, 0, 0) },
            { Identifier::background,     PROP(Widget, background,Color,        4, 0, 0) },
            { Identifier::foreground,     PROP(Widget, foreground,Color,        4, 0, 0) },
            { Identifier::all,            PROP(Widget, all,       Int32,        4, 0, 0) },
            { Identifier::visible,        PROP(Widget, byte0,     Bit,          1, 0, 1) },
            { Identifier::canFocus,       PROP(Widget, byte0,     Bit,          1, 3, 1) },
            { Identifier::active,         PROP(Widget, byte0,     Bit,          1, 4, 1) },
            { Identifier::draggable,      PROP(Widget, byte0,     Bit,          1, 5, 1) },
            { Identifier::onEnter,        PROP(Widget, actions,   ActionTable,  4, 0, 1) },
            { Identifier::onLeave,        PROP(Widget, actions,   ActionTable,  4, 0, 1) },
            { Identifier::onClick,        PROP(Widget, actions,   ActionTable,  4, 0, 1) },
            { Identifier::onRender,       PROP(Widget, actions,   ActionTable,  4, 0, 1) },
            { Identifier::onRenderActive, PROP(Widget, actions,   ActionTable,  4, 0, 1) },
            { Identifier::text,           PROP(Widget, text,      Text,         sizeof(void*), 0, 0) },
        }
    };

}

namespace webui {

    Widget::Widget(Widget* parent): parent(parent), text(nullptr),
                                    size { SizeRelative(100.0f, true), SizeRelative(100.0f, true) },
                                    all(0x00ff4009), actions(0) {
        typeWidget = &widgetType;
    }

    Widget::~Widget() {
        free(text);
    }

    TypeWidget& Widget::getType() {
        return widgetType;
    }

    void Widget::render(int alphaMult) {
        alphaMult = Context::render.multAlpha(alphaMult, alpha);

        const auto& actionTable(Context::app.getActionTable(actions));
        if (actionTable.onRenderActive && (active || (Input::mouseButtonWidget == this && inside)))
            Context::actions.execute(actionTable.onRenderActive, this);
        else
            Context::actions.execute(actionTable.onRender, this);

        if (alphaMult)
            for (auto* child: children) child->render(alphaMult);
    }

    bool Widget::input() {
        if (canFocus && Input::mouseButtonAction) {
            // this widget takes care of the event and does not propagate upwards
            Input::mouseButtonAction = false;
{'fraction_non_alphanumeric': 0.1367436587785178, 'fraction_numerical': 0.0238061499220632, 'mean_word_length': 1.8973727422003284, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6391836', 'n_tokens_mistral': 2220, 'n_tokens_neox': 2057, 'n_words': 517}