AllenDang / giu

Cross platform rapid GUI framework for golang based on Dear ImGui.
MIT License
2.16k stars 128 forks source link

[Feature Request] Support Begin End style API #707

Closed 0-issue closed 8 months ago

0-issue commented 9 months ago

Related problem

Deeply nested structures/indents is an anti-pattern in Go:

func loop() {
    g.SingleWindow().Layout(
        g.SplitLayout(g.DirectionHorizontal, &sashPos1,
            g.Layout{
                g.Label("Left panel"),
                g.Row(g.Button("Button1"), g.Button("Button2")),
            },
            g.SplitLayout(g.DirectionVertical, &sashPos2,
                g.Layout{},
                g.SplitLayout(g.DirectionHorizontal, &sashPos3,
                    g.Layout{},
                    g.SplitLayout(g.DirectionVertical, &sashPos4,
                        g.Layout{},
                        g.Layout{},
                    ),
                ),
            ),
        ),
    )
}

Your request

Support Being, End style api like of imguiplot:

int   bar_data[11] = ...;
float x_data[1000] = ...;
float y_data[1000] = ...;

ImGui::Begin("My Window");
if (ImPlot::BeginPlot("My Plot")) {
    ImPlot::PlotBars("My Bar Plot", bar_data, 11);
    ImPlot::PlotLine("My Line Plot", x_data, y_data, 1000);
    ...
    ImPlot::EndPlot();
}
ImGui::End();

src: https://github.com/epezent/implot#usage

Alternative solution

No response

Additional context

No response

gucio321 commented 9 months ago

@amanvm you can always use style api from imgui (it is called PushStyle/PopStyle)

AllenDang commented 9 months ago

The reason why I use nested structures instead begin/end is I don't need to remember every pair and avoid crash if I forget a proper end somewhere.

0-issue commented 9 months ago

Sure there is a tradeoff, though creating a check for orphaned begin/end is simple in Vim using vim script or even by binding an external sed/awk command. Power users can create something like that for their work, and newbies code will anyway be short to not have many such errors. If you provide an additional API of the mentioned style, perhaps I can provide a awk command for you to post in the README.md to do such checks.

AllenDang commented 9 months ago

That's not only pair check, also involve some tricky and inconsistent, for example, some end should called when begin return's true, some end need to be called no matter what, in my past experience, this part drives me crazy.

gucio321 commented 8 months ago

I think we can close it for now. If you nneed imgui-styled api just use it ;-) (you can use cimgui-go api in your giu app)