Browse Source

Throw up some widgets on screen so we can see what they look like.

Andreas Kling 6 năm trước cách đây
mục cha
commit
a3c39ea9d6

+ 3 - 0
Kernel/Makefile

@@ -59,6 +59,9 @@ WIDGETS_OBJS = \
     ../Widgets/Label.o \
     ../Widgets/Label.o \
     ../Widgets/Button.o \
     ../Widgets/Button.o \
     ../Widgets/MsgBox.o \
     ../Widgets/MsgBox.o \
+    ../Widgets/ListBox.o \
+    ../Widgets/CheckBox.o \
+    ../Widgets/TextBox.o \
     ../Widgets/AbstractScreen.o
     ../Widgets/AbstractScreen.o
 
 
 AK_OBJS = \
 AK_OBJS = \

+ 51 - 0
Kernel/WindowComposer.cpp

@@ -6,6 +6,12 @@
 #include <Widgets/RootWidget.h>
 #include <Widgets/RootWidget.h>
 #include <Widgets/EventLoop.h>
 #include <Widgets/EventLoop.h>
 #include <Widgets/MsgBox.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()
 void WindowComposer_main()
 {
 {
@@ -27,6 +33,51 @@ void WindowComposer_main()
 
 
     MsgBox(nullptr, "Serenity Operating System");
     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");
     dbgprintf("Entering WindowComposer main loop.\n");
     loop.exec();
     loop.exec();
 
 

+ 1 - 2
Widgets/CheckBox.cpp

@@ -1,7 +1,6 @@
 #include "CheckBox.h"
 #include "CheckBox.h"
 #include "Painter.h"
 #include "Painter.h"
 #include "CharacterBitmap.h"
 #include "CharacterBitmap.h"
-#include <cstdio>
 
 
 CheckBox::CheckBox(Widget* parent)
 CheckBox::CheckBox(Widget* parent)
     : Widget(parent)
     : Widget(parent)
@@ -16,7 +15,7 @@ void CheckBox::setCaption(String&& caption)
 {
 {
     if (caption == m_caption)
     if (caption == m_caption)
         return;
         return;
-    m_caption = std::move(caption);
+    m_caption = move(caption);
     update();
     update();
 }
 }
 
 

+ 1 - 1
Widgets/ListBox.cpp

@@ -60,7 +60,7 @@ void ListBox::mouseDownEvent(MouseEvent& event)
 
 
 void ListBox::addItem(String&& item)
 void ListBox::addItem(String&& item)
 {
 {
-    m_items.append(std::move(item));
+    m_items.append(move(item));
     if (m_selectedIndex == -1)
     if (m_selectedIndex == -1)
         m_selectedIndex = 0;
         m_selectedIndex = 0;
 }
 }

+ 3 - 3
Widgets/TextBox.cpp

@@ -16,7 +16,7 @@ TextBox::~TextBox()
 
 
 void TextBox::setText(String&& text)
 void TextBox::setText(String&& text)
 {
 {
-    m_text = std::move(text);
+    m_text = move(text);
     m_cursorPosition = m_text.length();
     m_cursorPosition = m_text.length();
     update();
     update();
 }
 }
@@ -83,7 +83,7 @@ void TextBox::handleBackspace()
     memcpy(buffer, m_text.characters(), m_cursorPosition - 1);
     memcpy(buffer, m_text.characters(), m_cursorPosition - 1);
     memcpy(buffer + m_cursorPosition - 1, m_text.characters() + m_cursorPosition, m_text.length() - (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;
     --m_cursorPosition;
     update();
     update();
 }
 }
@@ -121,7 +121,7 @@ void TextBox::keyDownEvent(KeyEvent& event)
         buffer[m_cursorPosition] = event.text()[0];
         buffer[m_cursorPosition] = event.text()[0];
         memcpy(buffer + m_cursorPosition + 1, m_text.characters() + m_cursorPosition, m_text.length() - m_cursorPosition);
         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;
         ++m_cursorPosition;
         update();
         update();
         return;
         return;

+ 2 - 2
Widgets/TextBox.h

@@ -1,7 +1,7 @@
 #pragma once
 #pragma once
 
 
 #include "Widget.h"
 #include "Widget.h"
-#include <functional>
+#include <AK/Function.h>
 
 
 class TextBox final : public Widget {
 class TextBox final : public Widget {
 public:
 public:
@@ -11,7 +11,7 @@ public:
     String text() const { return m_text; }
     String text() const { return m_text; }
     void setText(String&&);
     void setText(String&&);
 
 
-    std::function<void(TextBox&)> onReturnPressed;
+    Function<void(TextBox&)> onReturnPressed;
 
 
 private:
 private:
     virtual void paintEvent(PaintEvent&) override;
     virtual void paintEvent(PaintEvent&) override;

+ 1 - 0
Widgets/WindowManager.cpp

@@ -156,6 +156,7 @@ void WindowManager::did_paint(Window& window)
     if (m_windows_in_order.tail() == &window) {
     if (m_windows_in_order.tail() == &window) {
         ASSERT(window.backing());
         ASSERT(window.backing());
         framebuffer.blit(window.position(), *window.backing());
         framebuffer.blit(window.position(), *window.backing());
+        redraw_cursor();
         framebuffer.flush();
         framebuffer.flush();
         printf("[WM] frontmost_only_compose_count: %u\n", ++m_frontmost_only_compose_count);
         printf("[WM] frontmost_only_compose_count: %u\n", ++m_frontmost_only_compose_count);
         return;
         return;