summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-01-11 04:10:07 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-01-11 04:10:07 +0100
commita3c39ea9d6782b69196eb623cdc2d30276e0f1fa (patch)
treee5324ae77f083ad94a55bd928ca02db5d0932763
parente5e295052faf8ea1e622c8d67c766f8213c71b81 (diff)
downloadserenity-a3c39ea9d6782b69196eb623cdc2d30276e0f1fa.zip
Throw up some widgets on screen so we can see what they look like.
-rw-r--r--Kernel/Makefile3
-rw-r--r--Kernel/WindowComposer.cpp51
-rw-r--r--Widgets/CheckBox.cpp3
-rw-r--r--Widgets/ListBox.cpp2
-rw-r--r--Widgets/TextBox.cpp6
-rw-r--r--Widgets/TextBox.h4
-rw-r--r--Widgets/WindowManager.cpp1
7 files changed, 62 insertions, 8 deletions
diff --git a/Kernel/Makefile b/Kernel/Makefile
index 96aaac4d16..6d35faf34d 100644
--- a/Kernel/Makefile
+++ b/Kernel/Makefile
@@ -59,6 +59,9 @@ WIDGETS_OBJS = \
../Widgets/Label.o \
../Widgets/Button.o \
../Widgets/MsgBox.o \
+ ../Widgets/ListBox.o \
+ ../Widgets/CheckBox.o \
+ ../Widgets/TextBox.o \
../Widgets/AbstractScreen.o
AK_OBJS = \
diff --git a/Kernel/WindowComposer.cpp b/Kernel/WindowComposer.cpp
index c33d236950..7a883d6dc9 100644
--- a/Kernel/WindowComposer.cpp
+++ b/Kernel/WindowComposer.cpp
@@ -6,6 +6,12 @@
#include <Widgets/RootWidget.h>
#include <Widgets/EventLoop.h>
#include <Widgets/MsgBox.h>
+#include <Widgets/TextBox.h>
+#include <Widgets/Label.h>
+#include <Widgets/ListBox.h>
+#include <Widgets/Button.h>
+#include <Widgets/CheckBox.h>
+#include <Widgets/Window.h>
void WindowComposer_main()
{
@@ -27,6 +33,51 @@ void WindowComposer_main()
MsgBox(nullptr, "Serenity Operating System");
+ {
+ auto* widgetTestWindow = new Window;
+ widgetTestWindow->setTitle("Widget test");
+ widgetTestWindow->setRect({ 20, 40, 100, 180 });
+
+ 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");
+
+ b->onClick = [] (Button& button) {
+ printf("Button %p clicked!\n", &button);
+ };
+
+ auto* c = new CheckBox(widgetTestWindowWidget);
+ c->setWindowRelativeRect({ 0, 40, 100, 20 });
+ c->setCaption("CheckBox");
+
+ auto *lb = new ListBox(widgetTestWindowWidget);
+ lb->setWindowRelativeRect({ 0, 60, 100, 100 });
+ 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);
+
+ tb->onReturnPressed = [] (TextBox& textBox) {
+ printf("TextBox %p return pressed: '%s'\n", &textBox, textBox.text().characters());
+ MsgBox(nullptr, textBox.text());
+ };
+
+ WindowManager::the().setActiveWindow(widgetTestWindow);
+ }
+
dbgprintf("Entering WindowComposer main loop.\n");
loop.exec();
diff --git a/Widgets/CheckBox.cpp b/Widgets/CheckBox.cpp
index 99849ea435..c61b568372 100644
--- a/Widgets/CheckBox.cpp
+++ b/Widgets/CheckBox.cpp
@@ -1,7 +1,6 @@
#include "CheckBox.h"
#include "Painter.h"
#include "CharacterBitmap.h"
-#include <cstdio>
CheckBox::CheckBox(Widget* parent)
: Widget(parent)
@@ -16,7 +15,7 @@ void CheckBox::setCaption(String&& caption)
{
if (caption == m_caption)
return;
- m_caption = std::move(caption);
+ m_caption = move(caption);
update();
}
diff --git a/Widgets/ListBox.cpp b/Widgets/ListBox.cpp
index 4e3d0a6627..b23d10c0c6 100644
--- a/Widgets/ListBox.cpp
+++ b/Widgets/ListBox.cpp
@@ -60,7 +60,7 @@ void ListBox::mouseDownEvent(MouseEvent& event)
void ListBox::addItem(String&& item)
{
- m_items.append(std::move(item));
+ m_items.append(move(item));
if (m_selectedIndex == -1)
m_selectedIndex = 0;
}
diff --git a/Widgets/TextBox.cpp b/Widgets/TextBox.cpp
index b5e143a595..1012d81e5f 100644
--- a/Widgets/TextBox.cpp
+++ b/Widgets/TextBox.cpp
@@ -16,7 +16,7 @@ TextBox::~TextBox()
void TextBox::setText(String&& text)
{
- m_text = std::move(text);
+ m_text = move(text);
m_cursorPosition = m_text.length();
update();
}
@@ -83,7 +83,7 @@ void TextBox::handleBackspace()
memcpy(buffer, m_text.characters(), m_cursorPosition - 1);
memcpy(buffer + m_cursorPosition - 1, m_text.characters() + m_cursorPosition, m_text.length() - (m_cursorPosition - 1));
- m_text = std::move(newText);
+ m_text = move(newText);
--m_cursorPosition;
update();
}
@@ -121,7 +121,7 @@ void TextBox::keyDownEvent(KeyEvent& event)
buffer[m_cursorPosition] = event.text()[0];
memcpy(buffer + m_cursorPosition + 1, m_text.characters() + m_cursorPosition, m_text.length() - m_cursorPosition);
- m_text = std::move(newText);
+ m_text = move(newText);
++m_cursorPosition;
update();
return;
diff --git a/Widgets/TextBox.h b/Widgets/TextBox.h
index 626ea6d8df..97b0ab1de2 100644
--- a/Widgets/TextBox.h
+++ b/Widgets/TextBox.h
@@ -1,7 +1,7 @@
#pragma once
#include "Widget.h"
-#include <functional>
+#include <AK/Function.h>
class TextBox final : public Widget {
public:
@@ -11,7 +11,7 @@ public:
String text() const { return m_text; }
void setText(String&&);
- std::function<void(TextBox&)> onReturnPressed;
+ Function<void(TextBox&)> onReturnPressed;
private:
virtual void paintEvent(PaintEvent&) override;
diff --git a/Widgets/WindowManager.cpp b/Widgets/WindowManager.cpp
index b1214e39cc..9f4a7d844c 100644
--- a/Widgets/WindowManager.cpp
+++ b/Widgets/WindowManager.cpp
@@ -156,6 +156,7 @@ void WindowManager::did_paint(Window& window)
if (m_windows_in_order.tail() == &window) {
ASSERT(window.backing());
framebuffer.blit(window.position(), *window.backing());
+ redraw_cursor();
framebuffer.flush();
printf("[WM] frontmost_only_compose_count: %u\n", ++m_frontmost_only_compose_count);
return;