87 lines
2.4 KiB
C++
87 lines
2.4 KiB
C++
#include <iostream>
|
|
|
|
#include <basic_widgets/horizontal_layout.hpp>
|
|
#include <basic_widgets/numeric_input.hpp>
|
|
#include <basic_widgets/utils/font.hpp>
|
|
#include <basic_widgets/vertical_layout.hpp>
|
|
|
|
using namespace bwidgets::utils;
|
|
using namespace bwidgets::widget;
|
|
|
|
int main()
|
|
{
|
|
int width = 640;
|
|
int height = 480;
|
|
|
|
TTF_Init();
|
|
TTF_Font* font = TTF_OpenFont(font::find("Monospace").c_str(), 20);
|
|
|
|
SDL_Init(SDL_INIT_VIDEO);
|
|
SDL_Window* win = SDL_CreateWindow(
|
|
"Widget test",
|
|
SDL_WINDOWPOS_UNDEFINED,
|
|
SDL_WINDOWPOS_UNDEFINED,
|
|
width,
|
|
height,
|
|
SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE
|
|
);
|
|
SDL_Renderer* rend = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED);
|
|
SDL_SetRenderDrawBlendMode(rend, SDL_BLENDMODE_BLEND);
|
|
|
|
SDL_Rect layout_vp = {0, 0, width, height};
|
|
auto layout = new Horizontal_Layout();
|
|
for (int i = 0; i < 3; i++)
|
|
{
|
|
auto column = new Vertical_Layout();
|
|
for (int j = 0; j < 3; j++)
|
|
{
|
|
auto widget = new Numeric_Input<float>();
|
|
widget->button_step = 0.5;
|
|
widget->font(font);
|
|
widget->value_range(-2.5, 2.5);
|
|
column->add_widget(widget);
|
|
}
|
|
layout->add_widget(column);
|
|
}
|
|
layout->viewport(layout_vp);
|
|
bool quit = false;
|
|
while (!quit)
|
|
{
|
|
SDL_Event ev;
|
|
while (SDL_PollEvent(&ev) != 0)
|
|
{
|
|
switch (ev.type)
|
|
{
|
|
case SDL_QUIT:
|
|
quit = true;
|
|
break;
|
|
case SDL_WINDOWEVENT:
|
|
if (ev.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
|
|
{
|
|
SDL_GetRendererOutputSize(rend, &width, &height);
|
|
layout_vp.w = width;
|
|
layout_vp.h = height;
|
|
std::cerr << "== WINDOW RESIZED == " << width << "x" << height << std::endl;
|
|
layout->viewport(layout_vp);
|
|
}
|
|
break;
|
|
}
|
|
layout->handle_event(ev);
|
|
}
|
|
|
|
SDL_SetRenderDrawColor(rend, 75, 75, 75, SDL_ALPHA_OPAQUE);
|
|
SDL_RenderClear(rend);
|
|
|
|
layout->render(rend);
|
|
SDL_RenderPresent(rend);
|
|
}
|
|
|
|
delete layout;
|
|
SDL_DestroyRenderer(rend);
|
|
SDL_DestroyWindow(win);
|
|
SDL_Quit();
|
|
TTF_CloseFont(font);
|
|
TTF_Quit();
|
|
return 0;
|
|
}
|