AllenDang / cimgui-go

Auto generated Go wrapper for Dear ImGui via cimgui
MIT License
318 stars 48 forks source link

Custom Axis Formatter Function #292

Open hexvalid opened 1 month ago

hexvalid commented 1 month ago

Hi. Can I use custom axis formatter like that:

ImPlot::SetupAxisFormat(ImAxis_X1, secondFormatter); //<-- example
//...
int secondFormatter(double value, char* buff, int size, void* data)
{
    static double v[]      = {3600000,60000,1000,1,0.001,0.000001};
    static const char* p[] = {"h","m","s","ms","us","ns"};
    if (value == 0) {
        return snprintf(buff,size,"0s");
    }
    for (int i = 0; i < 6; ++i) {
        if (fabs(value) >= v[i]) {
            return snprintf(buff,size,"%g%s",value/v[i],p[i]);
        }
    }
    return snprintf(buff,size,"%g%s",value/v[5],p[5]);
}

I couldn't find anything else other than this function:

imgui.PlotSetupAxisFormatStr(imgui.AxisX1,"%.0f second timestamp")
gucio321 commented 1 month ago

Unfortunately not yet. There is a dedicated issue for that https://github.com/AllenDang/cimgui-go/issues/224