serenity/Widgets/test.cpp

108 lines
3.2 KiB
C++
Raw Normal View History

2018-10-10 09:12:38 -04:00
#include "FrameBufferSDL.h"
#include "EventLoopSDL.h"
#include "RootWidget.h"
2018-10-10 10:49:36 -04:00
#include "Label.h"
2018-10-10 19:48:09 -04:00
#include "Button.h"
2018-10-10 20:50:08 -04:00
#include "TerminalWidget.h"
2018-10-11 10:52:40 -04:00
#include "WindowManager.h"
2018-10-11 19:03:22 -04:00
#include "Window.h"
2018-10-12 06:18:59 -04:00
#include "ClockWidget.h"
2018-10-12 08:15:14 -04:00
#include "CheckBox.h"
2018-10-12 18:20:44 -04:00
#include "ListBox.h"
#include "TextBox.h"
2018-10-10 09:12:38 -04:00
#include <cstdio>
2018-10-12 08:15:14 -04:00
int main(int argc, char** argv)
2018-10-10 09:12:38 -04:00
{
FrameBufferSDL fb(800, 600);
fb.show();
EventLoopSDL loop;
RootWidget w;
WindowManager::the().setRootWidget(&w);
2018-10-11 10:52:40 -04:00
2018-10-12 04:06:50 -04:00
auto* fontTestWindow = new Window;
fontTestWindow->setTitle("Font test");
2018-10-12 08:15:14 -04:00
fontTestWindow->setRect({ 140, 100, 300, 80 });
2018-10-12 04:06:50 -04:00
auto* fontTestWindowWidget = new Widget;
fontTestWindow->setMainWidget(fontTestWindowWidget);
2018-10-12 08:15:14 -04:00
fontTestWindowWidget->setWindowRelativeRect({ 0, 0, 300, 80 });
2018-10-12 04:06:50 -04:00
auto* l1 = new Label(fontTestWindowWidget);
2018-10-12 08:15:14 -04:00
l1->setWindowRelativeRect({ 0, 0, 300, 20 });
l1->setText("0123456789");
2018-10-12 04:06:50 -04:00
auto* l2 = new Label(fontTestWindowWidget);
2018-10-12 08:15:14 -04:00
l2->setWindowRelativeRect({ 0, 20, 300, 20 });
l2->setText("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
2018-10-12 04:06:50 -04:00
auto* l3 = new Label(fontTestWindowWidget);
2018-10-12 08:15:14 -04:00
l3->setWindowRelativeRect({ 0, 40, 300, 20 });
l3->setText("abcdefghijklmnopqrstuvwxyz");
2018-10-12 04:06:50 -04:00
auto* l4 = new Label(fontTestWindowWidget);
2018-10-12 08:15:14 -04:00
l4->setWindowRelativeRect({ 0, 60, 300, 20 });
l4->setText("!\"#$%&'()*+,-./:;<=>?@[\\]^_{|}~");
{
auto* widgetTestWindow = new Window;
widgetTestWindow->setTitle("Widget test");
widgetTestWindow->setRect({ 20, 40, 100, 180 });
2018-10-12 08:15:14 -04:00
auto* widgetTestWindowWidget = new Widget;
widgetTestWindowWidget->setWindowRelativeRect({ 0, 0, 100, 100 });
widgetTestWindow->setMainWidget(widgetTestWindowWidget);
auto* l = new Label(widgetTestWindowWidget);
l->setWindowRelativeRect({ 0, 0, 100, 20 });
l->setText("Label");
auto* b = new Button(widgetTestWindowWidget);
b->setWindowRelativeRect({ 0, 20, 100, 20 });
b->setCaption("Button");
2018-10-12 08:15:14 -04:00
b->onClick = [] (Button& button) {
printf("Button %p clicked!\n", &button);
};
auto* c = new CheckBox(widgetTestWindowWidget);
c->setWindowRelativeRect({ 0, 40, 100, 20 });
c->setCaption("CheckBox");
2018-10-12 18:20:44 -04:00
auto *lb = new ListBox(widgetTestWindowWidget);
lb->setWindowRelativeRect({ 0, 60, 100, 100 });
2018-10-12 18:20:44 -04:00
lb->addItem("This");
lb->addItem("is");
lb->addItem("a");
lb->addItem("ListBox");
auto *tb = new TextBox(widgetTestWindowWidget);
tb->setWindowRelativeRect({ 0, 160, 100, 20 });
tb->setText("Hello!");
tb->setFocus(true);
2018-10-13 17:19:44 -04:00
tb->onReturnPressed = [] (TextBox& textBox) {
printf("TextBox %p return pressed: '%s'\n", &textBox, textBox.text().characters());
};
WindowManager::the().setActiveWindow(widgetTestWindow);
}
2018-10-10 10:49:36 -04:00
2018-10-11 19:03:22 -04:00
auto* win = new Window;
win->setTitle("Console");
2018-10-12 06:18:59 -04:00
win->setRect({ 100, 300, 644, 254 });
2018-10-11 19:03:22 -04:00
auto* t = new TerminalWidget(nullptr);
2018-10-11 19:03:22 -04:00
win->setMainWidget(t);
2018-10-13 11:52:47 -04:00
t->setFocus(true);
2018-10-10 20:50:08 -04:00
2018-10-12 06:18:59 -04:00
auto* clockWin = new Window;
clockWin->setTitle("Clock");
clockWin->setRect({ 500, 50, 100, 40 });
clockWin->setMainWidget(new ClockWidget);
2018-10-10 09:12:38 -04:00
return loop.exec();
}