CoolFace
Datasetpublic

dlxjj/imradv3

sourceHugging Faceupdated 8mo agoView on Hugging Face
0likes263downloads
binding_property.cpp104 linesDownload Raw Back to src
1#include "binding_property.h"2#include "cppgen.h"3#include <imgui.h>4 5float direct_val<dimension_t>::eval_px(const UIContext& ctx) const6{7    return val * ctx.zoomFactor;8}9 10float direct_val<pzdimension_t>::eval_px(const UIContext& ctx) const11{12    return val * ctx.zoomFactor;13}14 15ImVec2 direct_val<pzdimension2_t>::eval_px(const UIContext& ctx) const16{17    return { val[0] * ctx.zoomFactor, val[1] * ctx.zoomFactor };18}19 20float bindable<dimension_t>::eval_px(int axis, const UIContext& ctx) const21{22    if (empty()) {23        return 0;24    }25    else if (stretched()) {26        return ctx.stretchSize[axis];27    }28    else if (has_value()) {29        return value() * ctx.zoomFactor;30    }31    else if (const auto* var = ctx.codeGen->GetVar(str)) {32        float val;33        std::istringstream is(var->init);34        if (is >> val)35            return val * ctx.zoomFactor;36        else37            return 0;38    }39    else {40        //experimental - currently parses:41        //num*dp42        //cond ? num1*dp : num2*dp43        //extracts min value as that may be the preferrable one when some widgets show/hide44        //e.g. -1 vs -20 or 20 vs 5045        std::istringstream is(str);46        int state = 1; //0 - skip, 1 - number, 2 - *, 3 - dp47        float val = 0, ret = 0;48        for (cpp::token_iterator it(is), ite; it != ite; ++it) {49            if (*it == "?") {50                state = 1;51            }52            else if (*it == ":") {53                if (state >= 2)54                    ret = std::min(ret ? ret : 1e9f, val);55                state = 1;56            }57            else if (state == 1) {58                std::istringstream iss(*it);59                if (iss >> val)60                    state = 2;61                else62                    state = 0;63            }64            else if (state == 2) {65                if (*it == "*")66                    state = 3;67                else68                    state = 0;69            }70            else if (state == 3) {71                if (*it != "dp")72                    state = 0;73            }74        }75        if (state >= 2)76            ret = std::min(ret ? ret : 1e9f, val);77        return ret * ctx.zoomFactor;78    }79}80 81ImU32 bindable<color_t>::eval(int defClr, const UIContext& ctx) const82{83    if (empty()) //default color84        return ImGui::ColorConvertFloat4ToU32(ctx.style.Colors[defClr]);85 86    int idx = style_color();87    if (idx >= 0)88        return ImGui::ColorConvertFloat4ToU32(ctx.style.Colors[idx]);89 90    ImU32 clr;91    std::istringstream is(str);92    if (is.get() == '0' && is.get() == 'x' && is >> std::hex >> clr)93        return clr;94 95    return ImGui::ColorConvertFloat4ToU32(ctx.style.Colors[defClr]);96}97 98std::string bindable<font_name_t>::eval(const UIContext&) const99{100    if (!has_value())101        return "";102    return str.substr(22, str.size() - 22 - 2);103}104