raylibtech / rtools

rtools feedback and issues
17 stars 1 forks source link

[rGuiLayout] Suggestion: Break up output file into multiple header files #16

Closed Andidy closed 2 years ago

Andidy commented 2 years ago

Note: I am using v2.1 ZERO (the free one) if these issues are solved in the ONE version (the paid one) please let me know.

Right now the way the export works in the tool is to generate what is effectively an example program template with the GUI stuff filled in based on the layout. I believe this limits the utility of rGuiLayout because it makes it difficult to iterate on existing layouts and programs that have had significant amounts of work done to them already.

Here is an example export with a few controls:

#include "raylib.h"

#define RAYGUI_IMPLEMENTATION
#include "raygui.h"

//----------------------------------------------------------------------------------
// Controls Functions Declaration
//----------------------------------------------------------------------------------
static void Button000();

//------------------------------------------------------------------------------------
// Program main entry point
//------------------------------------------------------------------------------------
int main()
{
    // Initialization
    //---------------------------------------------------------------------------------------
    int screenWidth = 800;
    int screenHeight = 450;

    InitWindow(screenWidth, screenHeight, "my_layout");

    // my_layout: controls initialization
    //----------------------------------------------------------------------------------
    const char *Button000Text = "Spawn Entity";

    bool ValueBOx001EditMode = false;
    int ValueBOx001Value = 0;

    Rectangle layoutRecs[2] = {
        (Rectangle){ anchor01.x + 10, anchor01.y + 10, 125, 30 },
        (Rectangle){ anchor01.x + 10, anchor01.y + 45, 125, 25 },
    };
    //----------------------------------------------------------------------------------

    SetTargetFPS(60);
    //--------------------------------------------------------------------------------------

    // Main game loop
    while (!WindowShouldClose())    // Detect window close button or ESC key
    {
        // Update
        //----------------------------------------------------------------------------------
        // TODO: Implement required update logic
        //----------------------------------------------------------------------------------

        // Draw
        //----------------------------------------------------------------------------------
        BeginDrawing();

            ClearBackground(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR))); 

            // raygui: controls drawing
            //----------------------------------------------------------------------------------
            if (GuiButton(layoutRecs[0], Button000Text)) Button000(); 
            if (GuiValueBox(layoutRecs[1], ValueBOx001Text, &ValueBOx001Value, 0, 100, ValueBOx001EditMode)) ValueBOx001EditMode = !ValueBOx001EditMode;
            //----------------------------------------------------------------------------------

        EndDrawing();
        //----------------------------------------------------------------------------------
    }

    // De-Initialization
    //--------------------------------------------------------------------------------------
    CloseWindow();        // Close window and OpenGL context
    //--------------------------------------------------------------------------------------

    return 0;
}

//------------------------------------------------------------------------------------
// Controls Functions Definitions (local)
//------------------------------------------------------------------------------------
static void Button000()
{
    // TODO: Implement control logic
}

I think it would be helpful to have an option to break apart the generated file into the raygui specific portions into something like the below set of files.

control_function_declarations.h

//----------------------------------------------------------------------------------
// Controls Functions Declaration
//----------------------------------------------------------------------------------
static void Button000();

control_data.h

    // my_layout: controls initialization
    //----------------------------------------------------------------------------------
    const char *Button000Text = "Spawn Entity";

    bool ValueBOx001EditMode = false;
    int ValueBOx001Value = 0;

    Rectangle layoutRecs[2] = {
        (Rectangle){ anchor01.x + 10, anchor01.y + 10, 125, 30 },
        (Rectangle){ anchor01.x + 10, anchor01.y + 45, 125, 25 },
    };
    //----------------------------------------------------------------------------------

control_drawing.h

            // raygui: controls drawing
            //----------------------------------------------------------------------------------
            if (GuiButton(layoutRecs[0], Button000Text)) Button000(); 
            if (GuiValueBox(layoutRecs[1], ValueBOx001Text, &ValueBOx001Value, 0, 100, ValueBOx001EditMode)) ValueBOx001EditMode = !ValueBOx001EditMode;
            //----------------------------------------------------------------------------------

control_function_definitions.h

//------------------------------------------------------------------------------------
// Controls Functions Definitions (local)
//------------------------------------------------------------------------------------
static void Button000()
{
    // TODO: Implement control logic
}

This way the user of rGuiLayout can position their exported code within their projects how they see fit and reduce potential for copy-paste errors when moving the exported code into existing projects and exported layouts.

Thank you for your consideration.

raysan5 commented 2 years ago

@Andidy Thanks for the feedback, I can consider that option for a future.

raysan5 commented 2 years ago

I'm not adding this option for the moment.