mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 12:32:43 +00:00 
			
		
		
		
	Throw up some widgets on screen so we can see what they look like.
This commit is contained in:
		
							parent
							
								
									e5e295052f
								
							
						
					
					
						commit
						a3c39ea9d6
					
				
					 7 changed files with 62 additions and 8 deletions
				
			
		|  | @ -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 = \
 | ||||
|  |  | |||
|  | @ -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(); | ||||
| 
 | ||||
|  |  | |||
|  | @ -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(); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -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; | ||||
| } | ||||
|  |  | |||
|  | @ -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; | ||||
|  |  | |||
|  | @ -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; | ||||
|  |  | |||
|  | @ -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; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling