dalerank / nanogui-sdl

Minimalistic port of NanoGUI claim works with SDL API w/o external dependencies.
Other
437 stars 77 forks source link

Placement of widgets for specific coordinates (x,y) #40

Closed siredmar closed 4 years ago

siredmar commented 4 years ago

Can widgets be placed on specific coordinates? I guess it can be done via AdvancedGridLayout but i currently don't seem to understand the usage properly.

dalerank commented 4 years ago

What you mean specific? without layout?

siredmar commented 4 years ago

I want to position some widgets for specific coordinates. E.g. i have a window with 800x600 size and want to put a button at position 23, 98. How would i achieve that?

dalerank commented 4 years ago

something here auto& btn = wdg

siredmar commented 4 years ago

sorry, i guess i did not write correctly what i need. For some widgets i do need to paint them directly on the SDL_Window. I don't need this 'window in a window' thing but rather an full sized widget within my SDL_Window to put the widgets at given coordinates.

dalerank commented 4 years ago

class TestScreen : public Screen { public: TestScreen( SDL_Window* pwindow, int rwidth, int rheight ) : Screen( pwindow, Vector2i(rwidth, rheight), "SDL_gui Test") { button("Button").setPosition(Vector2i{15, 15}) } };

main() { .... SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND); TestScreen *screen = new TestWindow(window, winWidth, winHeight);

while(draw) { //your code
screen->drawAll(); SDL_RenderPresent(renderer); } }

dalerank commented 4 years ago

screen it not a window, it specific class which manage all widget it contain

siredmar commented 4 years ago

Thanks a lot!

siredmar commented 4 years ago

Hi! I have one more question regarding the imageView widget. I tried placing an imageView with an valid SDL_Texture* like buttons or labels. When i do, i get the following error: Caught a fatal error: Widget:internal error (could not find parent window)

Looking at the previous example:

class TestScreen : public Screen
{
public:
  TestScreen(SDL_Window* pwindow, int rwidth, int rheight)
    : Screen(pwindow, Vector2i(rwidth, rheight), "SDL_gui Test")
  {

    auto& btn = wdg<Button>("Button");
    btn.setPosition(Vector2i{15, 15})
    // singlePlayerTexture is valid in this scope
    auto& singlePlayerButton = wdg<ImageView>(singlePlayerTexture);
   }
};

main()
{
  ....SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
  TestScreen* screen = new TestWindow(window, winWidth, winHeight);

  while (draw)
  {
    // your code
    screen->drawAll();
    SDL_RenderPresent(renderer);
  }
}

What am i doing wrong? Why am i asking this? I want to make a clickable image that behaves like a button. Is there another way? I have two SDL_Textures. One for clicked and one for unclicked. I need to specify a callback function and to the Textureswitch when clicked and revert it if click has finished.