Skip to content

Commit

Permalink
Throw up some widgets on screen so we can see what they look like.
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomekling committed Jan 11, 2019
1 parent e5e2950 commit a3c39ea
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 8 deletions.
3 changes: 3 additions & 0 deletions Kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 = \
Expand Down
51 changes: 51 additions & 0 deletions Kernel/WindowComposer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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();

Expand Down
3 changes: 1 addition & 2 deletions Widgets/CheckBox.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "CheckBox.h"
#include "Painter.h"
#include "CharacterBitmap.h"
#include <cstdio>

CheckBox::CheckBox(Widget* parent)
: Widget(parent)
Expand All @@ -16,7 +15,7 @@ void CheckBox::setCaption(String&& caption)
{
if (caption == m_caption)
return;
m_caption = std::move(caption);
m_caption = move(caption);
update();
}

Expand Down
2 changes: 1 addition & 1 deletion Widgets/ListBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions Widgets/TextBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions Widgets/TextBox.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "Widget.h"
#include <functional>
#include <AK/Function.h>

class TextBox final : public Widget {
public:
Expand All @@ -11,7 +11,7 @@ class TextBox final : public Widget {
String text() const { return m_text; }
void setText(String&&);

std::function<void(TextBox&)> onReturnPressed;
Function<void(TextBox&)> onReturnPressed;

private:
virtual void paintEvent(PaintEvent&) override;
Expand Down
1 change: 1 addition & 0 deletions Widgets/WindowManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a3c39ea

Please sign in to comment.