Skip to content

Store default values of structure attributes #316

@janarombe

Description

@janarombe

C++ attributes in a struct are often assigned a default value, like ImPlotSpec in ImPlot 1.0:

struct ImPlotSpec {
    ImVec4          LineColor       = IMPLOT_AUTO_COL;      
    ImU32*          LineColors      = nullptr;              
    float           LineWeight      = 1.0f;                 
    ImVec4          FillColor       = IMPLOT_AUTO_COL;      
    ImU32*          FillColors      = nullptr;              
    float           FillAlpha       = 1.0f;                 
    ImPlotMarker    Marker          = ImPlotMarker_None;    
    float           MarkerSize      = 4;                    
    float*          MarkerSizes     = nullptr;              
    ImVec4          MarkerLineColor = IMPLOT_AUTO_COL;      
    ImU32*          MarkerLineColors = nullptr;             
    ImVec4          MarkerFillColor = IMPLOT_AUTO_COL;      
    ImU32*          MarkerFillColors = nullptr;             
    float           Size            = 4;                    
    int             Offset          = 0;                    
    int             Stride          = IMPLOT_AUTO;          
    ImPlotItemFlags Flags           = ImPlotItemFlags_None; 

// [...]

};

This is a convenient way to know the default value of the different attributes, without looking in the constructor.

It would be nice if the generator could include the default value, if any, in the generated structs_and_enums.json.

For the cimplot example, that would give something like:

"ImPlotSpec": [
      {
        "name": "LineColor",
        "type": "ImVec4",
        "default": "IMPLOT_AUTO_COL"
      },
      {
        "name": "LineColors",
        "type": "ImU32*",
        "default": "nullptr"
      },
     ...
]

Having these default values in the JSON is not necessary at the moment because the ImPlotSpec_ImPlotSpec performs the initialization to the default values; but it would be nice for completeness, or to generate documentation for example.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions