cimgui-go icon indicating copy to clipboard operation
cimgui-go copied to clipboard

Custom Axis Formatter Function

Open hexvalid opened this issue 1 year ago • 1 comments

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")

hexvalid avatar Aug 02 '24 19:08 hexvalid

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

gucio321 avatar Aug 03 '24 13:08 gucio321

@hexvalid unfortunately this is blocked by #224

gucio321 avatar Sep 24 '24 19:09 gucio321

heh, its just missimplemented. The first argument to our callbacks is not userData itself but it is *Context

    const char* (*Platform_GetClipboardTextFn)(ImGuiContext* ctx);
    void (*Platform_SetClipboardTextFn)(ImGuiContext* ctx, const char* text);
    void* Platform_ClipboardUserData;

gucio321 avatar Sep 24 '24 19:09 gucio321

@hexvalid this is fixed - see PlotSetupAxisFormatPlotFormatterV

gucio321 avatar Nov 04 '24 13:11 gucio321