ladybird/Widgets/test.cpp

112 lines
3.3 KiB
C++
Raw Normal View History

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