mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 04:12:43 +00:00 
			
		
		
		
	LibGUI: Mass coding style fixes.
This commit is contained in:
		
							parent
							
								
									6c4f1bad09
								
							
						
					
					
						commit
						d66b0f7dd8
					
				
					 15 changed files with 178 additions and 178 deletions
				
			
		|  | @ -4,7 +4,7 @@ | ||||||
| GButton::GButton(GWidget* parent) | GButton::GButton(GWidget* parent) | ||||||
|     : GWidget(parent) |     : GWidget(parent) | ||||||
| { | { | ||||||
|     setFillWithBackgroundColor(false); |     set_fill_with_background_color(false); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| GButton::~GButton() | GButton::~GButton() | ||||||
|  | @ -19,11 +19,11 @@ void GButton::set_caption(String&& caption) | ||||||
|     update(); |     update(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void GButton::paintEvent(GPaintEvent&) | void GButton::paint_event(GPaintEvent&) | ||||||
| { | { | ||||||
|     Color buttonColor = Color::LightGray; |     Color button_color = Color::LightGray; | ||||||
|     Color highlightColor = Color::White; |     Color highlight_color = Color::White; | ||||||
|     Color shadowColor = Color(96, 96, 96); |     Color shadow_color = Color(96, 96, 96); | ||||||
| 
 | 
 | ||||||
|     Painter painter(*this); |     Painter painter(*this); | ||||||
| 
 | 
 | ||||||
|  | @ -34,26 +34,26 @@ void GButton::paintEvent(GPaintEvent&) | ||||||
| 
 | 
 | ||||||
|     if (m_being_pressed) { |     if (m_being_pressed) { | ||||||
|         // Base
 |         // Base
 | ||||||
|         painter.fill_rect({ 1, 1, width() - 2, height() - 2 }, buttonColor); |         painter.fill_rect({ 1, 1, width() - 2, height() - 2 }, button_color); | ||||||
| 
 | 
 | ||||||
|         // Sunken shadow
 |         // Sunken shadow
 | ||||||
|         painter.draw_line({ 1, 1 }, { width() - 2, 1 }, shadowColor); |         painter.draw_line({ 1, 1 }, { width() - 2, 1 }, shadow_color); | ||||||
|         painter.draw_line({ 1, 2 }, {1, height() - 2 }, shadowColor); |         painter.draw_line({ 1, 2 }, {1, height() - 2 }, shadow_color); | ||||||
|     } else { |     } else { | ||||||
|         // Base
 |         // Base
 | ||||||
|         painter.fill_rect({ 3, 3, width() - 5, height() - 5 }, buttonColor); |         painter.fill_rect({ 3, 3, width() - 5, height() - 5 }, button_color); | ||||||
| 
 | 
 | ||||||
|         // White highlight
 |         // White highlight
 | ||||||
|         painter.draw_line({ 1, 1 }, { width() - 2, 1 }, highlightColor); |         painter.draw_line({ 1, 1 }, { width() - 2, 1 }, highlight_color); | ||||||
|         painter.draw_line({ 1, 2 }, { width() - 3, 2 }, highlightColor); |         painter.draw_line({ 1, 2 }, { width() - 3, 2 }, highlight_color); | ||||||
|         painter.draw_line({ 1, 3 }, { 1, height() - 2 }, highlightColor); |         painter.draw_line({ 1, 3 }, { 1, height() - 2 }, highlight_color); | ||||||
|         painter.draw_line({ 2, 3 }, { 2, height() - 3 }, highlightColor); |         painter.draw_line({ 2, 3 }, { 2, height() - 3 }, highlight_color); | ||||||
| 
 | 
 | ||||||
|         // Gray shadow 
 |         // Gray shadow 
 | ||||||
|         painter.draw_line({ width() - 2, 1 }, { width() - 2, height() - 4 }, shadowColor); |         painter.draw_line({ width() - 2, 1 }, { width() - 2, height() - 4 }, shadow_color); | ||||||
|         painter.draw_line({ width() - 3, 2 }, { width() - 3, height() - 4 }, shadowColor); |         painter.draw_line({ width() - 3, 2 }, { width() - 3, height() - 4 }, shadow_color); | ||||||
|         painter.draw_line({ 1, height() - 2 }, { width() - 2, height() - 2 }, shadowColor); |         painter.draw_line({ 1, height() - 2 }, { width() - 2, height() - 2 }, shadow_color); | ||||||
|         painter.draw_line({ 2, height() - 3 }, { width() - 2, height() - 3 }, shadowColor); |         painter.draw_line({ 2, height() - 3 }, { width() - 2, height() - 3 }, shadow_color); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if (!caption().is_empty()) { |     if (!caption().is_empty()) { | ||||||
|  | @ -64,24 +64,24 @@ void GButton::paintEvent(GPaintEvent&) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void GButton::mouseDownEvent(GMouseEvent& event) | void GButton::mousedown_event(GMouseEvent& event) | ||||||
| { | { | ||||||
|     dbgprintf("Button::mouseDownEvent: x=%d, y=%d, button=%u\n", event.x(), event.y(), (unsigned)event.button()); |     dbgprintf("Button::mouseDownEvent: x=%d, y=%d, button=%u\n", event.x(), event.y(), (unsigned)event.button()); | ||||||
| 
 | 
 | ||||||
|     m_being_pressed = true; |     m_being_pressed = true; | ||||||
| 
 | 
 | ||||||
|     update(); |     update(); | ||||||
|     GWidget::mouseDownEvent(event); |     GWidget::mousedown_event(event); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void GButton::mouseUpEvent(GMouseEvent& event) | void GButton::mouseup_event(GMouseEvent& event) | ||||||
| { | { | ||||||
|     dbgprintf("Button::mouseUpEvent: x=%d, y=%d, button=%u\n", event.x(), event.y(), (unsigned)event.button()); |     dbgprintf("Button::mouseUpEvent: x=%d, y=%d, button=%u\n", event.x(), event.y(), (unsigned)event.button()); | ||||||
| 
 | 
 | ||||||
|     m_being_pressed = false; |     m_being_pressed = false; | ||||||
| 
 | 
 | ||||||
|     update(); |     update(); | ||||||
|     GWidget::mouseUpEvent(event); |     GWidget::mouseup_event(event); | ||||||
| 
 | 
 | ||||||
|     if (on_click) |     if (on_click) | ||||||
|         on_click(*this); |         on_click(*this); | ||||||
|  |  | ||||||
|  | @ -15,9 +15,9 @@ public: | ||||||
|     Function<void(GButton&)> on_click; |     Function<void(GButton&)> on_click; | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     virtual void paintEvent(GPaintEvent&) override; |     virtual void paint_event(GPaintEvent&) override; | ||||||
|     virtual void mouseDownEvent(GMouseEvent&) override; |     virtual void mousedown_event(GMouseEvent&) override; | ||||||
|     virtual void mouseUpEvent(GMouseEvent&) override; |     virtual void mouseup_event(GMouseEvent&) override; | ||||||
| 
 | 
 | ||||||
|     virtual const char* class_name() const override { return "GButton"; } |     virtual const char* class_name() const override { return "GButton"; } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -11,7 +11,7 @@ GCheckBox::~GCheckBox() | ||||||
| { | { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void GCheckBox::setCaption(String&& caption) | void GCheckBox::set_caption(String&& caption) | ||||||
| { | { | ||||||
|     if (caption == m_caption) |     if (caption == m_caption) | ||||||
|         return; |         return; | ||||||
|  | @ -19,11 +19,11 @@ void GCheckBox::setCaption(String&& caption) | ||||||
|     update(); |     update(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void GCheckBox::setIsChecked(bool b) | void GCheckBox::set_checked(bool b) | ||||||
| { | { | ||||||
|     if (m_isChecked == b) |     if (m_checked == b) | ||||||
|         return; |         return; | ||||||
|     m_isChecked = b; |     m_checked = b; | ||||||
|     update(); |     update(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -72,10 +72,10 @@ static const char* checkedBitmap = { | ||||||
|     "###########" |     "###########" | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| void GCheckBox::paintEvent(GPaintEvent&) | void GCheckBox::paint_event(GPaintEvent&) | ||||||
| { | { | ||||||
|     Painter painter(*this); |     Painter painter(*this); | ||||||
|     auto bitmap = CharacterBitmap::create_from_ascii(isChecked() ? checkedBitmap : uncheckedBitmap, 11, 11); |     auto bitmap = CharacterBitmap::create_from_ascii(is_checked() ? checkedBitmap : uncheckedBitmap, 11, 11); | ||||||
| 
 | 
 | ||||||
|     auto textRect = rect(); |     auto textRect = rect(); | ||||||
|     textRect.set_left(bitmap->width() + 4); |     textRect.set_left(bitmap->width() + 4); | ||||||
|  | @ -85,18 +85,18 @@ void GCheckBox::paintEvent(GPaintEvent&) | ||||||
|     bitmapPosition.set_x(2); |     bitmapPosition.set_x(2); | ||||||
|     bitmapPosition.set_y(height() / 2 - bitmap->height() / 2 - 1); |     bitmapPosition.set_y(height() / 2 - bitmap->height() / 2 - 1); | ||||||
| 
 | 
 | ||||||
|     painter.fill_rect(rect(), backgroundColor()); |     painter.fill_rect(rect(), background_color()); | ||||||
|     painter.draw_bitmap(bitmapPosition, *bitmap, foregroundColor()); |     painter.draw_bitmap(bitmapPosition, *bitmap, foreground_color()); | ||||||
| 
 | 
 | ||||||
|     if (!caption().is_empty()) { |     if (!caption().is_empty()) { | ||||||
|         painter.draw_text(textRect, caption(), Painter::TextAlignment::TopLeft, foregroundColor()); |         painter.draw_text(textRect, caption(), Painter::TextAlignment::TopLeft, foreground_color()); | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void GCheckBox::mouseDownEvent(GMouseEvent& event) | void GCheckBox::mousedown_event(GMouseEvent& event) | ||||||
| { | { | ||||||
|     dbgprintf("GCheckBox::mouseDownEvent: x=%d, y=%d, button=%u\n", event.x(), event.y(), (unsigned)event.button()); |     dbgprintf("GCheckBox::mouseDownEvent: x=%d, y=%d, button=%u\n", event.x(), event.y(), (unsigned)event.button()); | ||||||
| 
 | 
 | ||||||
|     setIsChecked(!isChecked()); |     set_checked(!is_checked()); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -9,18 +9,18 @@ public: | ||||||
|     virtual ~GCheckBox() override; |     virtual ~GCheckBox() override; | ||||||
| 
 | 
 | ||||||
|     String caption() const { return m_caption; } |     String caption() const { return m_caption; } | ||||||
|     void setCaption(String&&); |     void set_caption(String&&); | ||||||
| 
 | 
 | ||||||
|     bool isChecked() const { return m_isChecked; } |     bool is_checked() const { return m_checked; } | ||||||
|     void setIsChecked(bool); |     void set_checked(bool); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     virtual void paintEvent(GPaintEvent&) override; |     virtual void paint_event(GPaintEvent&) override; | ||||||
|     virtual void mouseDownEvent(GMouseEvent&) override; |     virtual void mousedown_event(GMouseEvent&) override; | ||||||
| 
 | 
 | ||||||
|     virtual const char* class_name() const override { return "GCheckBox"; } |     virtual const char* class_name() const override { return "GCheckBox"; } | ||||||
| 
 | 
 | ||||||
|     String m_caption; |     String m_caption; | ||||||
|     bool m_isChecked { false }; |     bool m_checked { false }; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -10,7 +10,7 @@ GLabel::~GLabel() | ||||||
| { | { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void GLabel::setText(String&& text) | void GLabel::set_text(String&& text) | ||||||
| { | { | ||||||
|     if (text == m_text) |     if (text == m_text) | ||||||
|         return; |         return; | ||||||
|  | @ -18,11 +18,11 @@ void GLabel::setText(String&& text) | ||||||
|     update(); |     update(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void GLabel::paintEvent(GPaintEvent&) | void GLabel::paint_event(GPaintEvent&) | ||||||
| { | { | ||||||
|     Painter painter(*this); |     Painter painter(*this); | ||||||
|     if (fillWithBackgroundColor()) |     if (fill_with_background_color()) | ||||||
|         painter.fill_rect({ 0, 0, width(), height() }, backgroundColor()); |         painter.fill_rect({ 0, 0, width(), height() }, background_color()); | ||||||
|     if (!text().is_empty()) |     if (!text().is_empty()) | ||||||
|         painter.draw_text({ 4, 4, width(), height() }, text(), Painter::TextAlignment::TopLeft, foregroundColor()); |         painter.draw_text({ 4, 4, width(), height() }, text(), Painter::TextAlignment::TopLeft, foreground_color()); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -9,10 +9,10 @@ public: | ||||||
|     virtual ~GLabel() override; |     virtual ~GLabel() override; | ||||||
| 
 | 
 | ||||||
|     String text() const { return m_text; } |     String text() const { return m_text; } | ||||||
|     void setText(String&&); |     void set_text(String&&); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     virtual void paintEvent(GPaintEvent&) override; |     virtual void paint_event(GPaintEvent&) override; | ||||||
| 
 | 
 | ||||||
|     virtual const char* class_name() const override { return "GLabel"; } |     virtual const char* class_name() const override { return "GLabel"; } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -17,7 +17,7 @@ Rect GListBox::item_rect(int index) const | ||||||
|     return Rect { 2, 2 + (index * item_height), width() - 4, item_height }; |     return Rect { 2, 2 + (index * item_height), width() - 4, item_height }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void GListBox::paintEvent(GPaintEvent&) | void GListBox::paint_event(GPaintEvent&) | ||||||
| { | { | ||||||
|     Painter painter(*this); |     Painter painter(*this); | ||||||
| 
 | 
 | ||||||
|  | @ -25,32 +25,32 @@ void GListBox::paintEvent(GPaintEvent&) | ||||||
|     painter.fill_rect(rect(), Color::White); |     painter.fill_rect(rect(), Color::White); | ||||||
|     painter.draw_rect(rect(), Color::Black); |     painter.draw_rect(rect(), Color::Black); | ||||||
| 
 | 
 | ||||||
|     if (isFocused()) |     if (is_focused()) | ||||||
|         painter.draw_focus_rect(rect()); |         painter.draw_focus_rect(rect()); | ||||||
| 
 | 
 | ||||||
|     for (int i = m_scrollOffset; i < static_cast<int>(m_items.size()); ++i) { |     for (int i = m_scroll_offset; i < static_cast<int>(m_items.size()); ++i) { | ||||||
|         auto itemRect = item_rect(i); |         auto item_rect = this->item_rect(i); | ||||||
|         Rect textRect(itemRect.x() + 1, itemRect.y() + 1, itemRect.width() - 2, itemRect.height() - 2); |         Rect text_rect(item_rect.x() + 1, item_rect.y() + 1, item_rect.width() - 2, item_rect.height() - 2); | ||||||
| 
 | 
 | ||||||
|         Color itemTextColor = foregroundColor(); |         Color item_text_color = foreground_color(); | ||||||
|         if (m_selectedIndex == i) { |         if (m_selected_index == i) { | ||||||
|             if (isFocused()) |             if (is_focused()) | ||||||
|                 painter.fill_rect(itemRect, Color(0, 32, 128)); |                 painter.fill_rect(item_rect, Color(0, 32, 128)); | ||||||
|             else |             else | ||||||
|                 painter.fill_rect(itemRect, Color(96, 96, 96)); |                 painter.fill_rect(item_rect, Color(96, 96, 96)); | ||||||
|             itemTextColor = Color::White; |             item_text_color = Color::White; | ||||||
|         } |         } | ||||||
|         painter.draw_text(textRect, m_items[i], Painter::TextAlignment::TopLeft, itemTextColor); |         painter.draw_text(item_rect, m_items[i], Painter::TextAlignment::TopLeft, item_text_color); | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void GListBox::mouseDownEvent(GMouseEvent& event) | void GListBox::mousedown_event(GMouseEvent& event) | ||||||
| { | { | ||||||
|     dbgprintf("GListBox::mouseDownEvent %d,%d\n", event.x(), event.y()); |     dbgprintf("GListBox::mouseDownEvent %d,%d\n", event.x(), event.y()); | ||||||
|     for (int i = m_scrollOffset; i < static_cast<int>(m_items.size()); ++i) { |     for (int i = m_scroll_offset; i < static_cast<int>(m_items.size()); ++i) { | ||||||
|         auto itemRect = item_rect(i); |         auto item_rect = this->item_rect(i); | ||||||
|         if (itemRect.contains(event.position())) { |         if (item_rect.contains(event.position())) { | ||||||
|             m_selectedIndex = i; |             m_selected_index = i; | ||||||
|             dbgprintf("GListBox: selected item %u (\"%s\")\n", i, m_items[i].characters()); |             dbgprintf("GListBox: selected item %u (\"%s\")\n", i, m_items[i].characters()); | ||||||
|             update(); |             update(); | ||||||
|             return; |             return; | ||||||
|  | @ -58,10 +58,10 @@ void GListBox::mouseDownEvent(GMouseEvent& event) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void GListBox::addItem(String&& item) | void GListBox::add_item(String&& item) | ||||||
| { | { | ||||||
|     m_items.append(move(item)); |     m_items.append(move(item)); | ||||||
|     if (m_selectedIndex == -1) |     if (m_selected_index == -1) | ||||||
|         m_selectedIndex = 0; |         m_selected_index = 0; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -7,18 +7,18 @@ public: | ||||||
|     explicit GListBox(GWidget* parent); |     explicit GListBox(GWidget* parent); | ||||||
|     virtual ~GListBox() override; |     virtual ~GListBox() override; | ||||||
| 
 | 
 | ||||||
|     void addItem(String&&); |     void add_item(String&&); | ||||||
|     int selectedIndex() const { return m_selectedIndex; } |     int selected_index() const { return m_selected_index; } | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     virtual void paintEvent(GPaintEvent&) override; |     virtual void paint_event(GPaintEvent&) override; | ||||||
|     virtual void mouseDownEvent(GMouseEvent&) override; |     virtual void mousedown_event(GMouseEvent&) override; | ||||||
|     virtual const char* class_name() const override { return "GListBox"; } |     virtual const char* class_name() const override { return "GListBox"; } | ||||||
| 
 | 
 | ||||||
|     Rect item_rect(int index) const; |     Rect item_rect(int index) const; | ||||||
| 
 | 
 | ||||||
|     int m_scrollOffset { 0 }; |     int m_scroll_offset { 0 }; | ||||||
|     int m_selectedIndex { -1 }; |     int m_selected_index { -1 }; | ||||||
| 
 | 
 | ||||||
|     Vector<String> m_items; |     Vector<String> m_items; | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | @ -14,22 +14,22 @@ GTextBox::~GTextBox() | ||||||
| { | { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void GTextBox::setText(String&& text) | void GTextBox::set_text(String&& text) | ||||||
| { | { | ||||||
|     m_text = move(text); |     m_text = move(text); | ||||||
|     m_cursorPosition = m_text.length(); |     m_cursorPosition = m_text.length(); | ||||||
|     update(); |     update(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void GTextBox::paintEvent(GPaintEvent&) | void GTextBox::paint_event(GPaintEvent&) | ||||||
| { | { | ||||||
|     Painter painter(*this); |     Painter painter(*this); | ||||||
| 
 | 
 | ||||||
|     // FIXME: Reduce overdraw.
 |     // FIXME: Reduce overdraw.
 | ||||||
|     painter.fill_rect(rect(), backgroundColor()); |     painter.fill_rect(rect(), background_color()); | ||||||
|     painter.draw_rect(rect(), foregroundColor()); |     painter.draw_rect(rect(), foreground_color()); | ||||||
| 
 | 
 | ||||||
|     if (isFocused()) |     if (is_focused()) | ||||||
|         painter.draw_focus_rect(rect()); |         painter.draw_focus_rect(rect()); | ||||||
| 
 | 
 | ||||||
|     Rect innerRect = rect(); |     Rect innerRect = rect(); | ||||||
|  | @ -54,18 +54,18 @@ void GTextBox::paintEvent(GPaintEvent&) | ||||||
|         painter.draw_bitmap({x, y}, *bitmap, Color::Black); |         painter.draw_bitmap({x, y}, *bitmap, Color::Black); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if (isFocused() && m_cursorBlinkState) { |     if (is_focused() && m_cursorBlinkState) { | ||||||
|         unsigned visibleCursorPosition = m_cursorPosition - firstVisibleChar; |         unsigned visibleCursorPosition = m_cursorPosition - firstVisibleChar; | ||||||
|         Rect cursorRect(innerRect.x() + visibleCursorPosition * font().glyph_width(), innerRect.y(), 1, innerRect.height()); |         Rect cursorRect(innerRect.x() + visibleCursorPosition * font().glyph_width(), innerRect.y(), 1, innerRect.height()); | ||||||
|         painter.fill_rect(cursorRect, foregroundColor()); |         painter.fill_rect(cursorRect, foreground_color()); | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void GTextBox::mouseDownEvent(GMouseEvent&) | void GTextBox::mousedown_event(GMouseEvent&) | ||||||
| { | { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void GTextBox::handleBackspace() | void GTextBox::handle_backspace() | ||||||
| { | { | ||||||
|     if (m_cursorPosition == 0) |     if (m_cursorPosition == 0) | ||||||
|         return; |         return; | ||||||
|  | @ -88,7 +88,7 @@ void GTextBox::handleBackspace() | ||||||
|     update(); |     update(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void GTextBox::keyDownEvent(GKeyEvent& event) | void GTextBox::keydown_event(GKeyEvent& event) | ||||||
| { | { | ||||||
|     switch (event.key()) { |     switch (event.key()) { | ||||||
|     case GKeyboardKey::LeftArrow: |     case GKeyboardKey::LeftArrow: | ||||||
|  | @ -104,7 +104,7 @@ void GTextBox::keyDownEvent(GKeyEvent& event) | ||||||
|         update(); |         update(); | ||||||
|         return; |         return; | ||||||
|     case GKeyboardKey::Backspace: |     case GKeyboardKey::Backspace: | ||||||
|         return handleBackspace(); |         return handle_backspace(); | ||||||
|     case GKeyboardKey::Return: |     case GKeyboardKey::Return: | ||||||
|         if (onReturnPressed) |         if (onReturnPressed) | ||||||
|             onReturnPressed(*this); |             onReturnPressed(*this); | ||||||
|  | @ -131,7 +131,7 @@ void GTextBox::keyDownEvent(GKeyEvent& event) | ||||||
| void GTextBox::timerEvent(GTimerEvent&) | void GTextBox::timerEvent(GTimerEvent&) | ||||||
| { | { | ||||||
|     // FIXME: Disable the timer when not focused.
 |     // FIXME: Disable the timer when not focused.
 | ||||||
|     if (!isFocused()) |     if (!is_focused()) | ||||||
|         return; |         return; | ||||||
| 
 | 
 | ||||||
|     m_cursorBlinkState = !m_cursorBlinkState; |     m_cursorBlinkState = !m_cursorBlinkState; | ||||||
|  |  | ||||||
|  | @ -9,18 +9,18 @@ public: | ||||||
|     virtual ~GTextBox() override; |     virtual ~GTextBox() override; | ||||||
| 
 | 
 | ||||||
|     String text() const { return m_text; } |     String text() const { return m_text; } | ||||||
|     void setText(String&&); |     void set_text(String&&); | ||||||
| 
 | 
 | ||||||
|     Function<void(GTextBox&)> onReturnPressed; |     Function<void(GTextBox&)> onReturnPressed; | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     virtual const char* class_name() const override { return "GTextBox"; } |     virtual const char* class_name() const override { return "GTextBox"; } | ||||||
|     virtual void paintEvent(GPaintEvent&) override; |     virtual void paint_event(GPaintEvent&) override; | ||||||
|     virtual void mouseDownEvent(GMouseEvent&) override; |     virtual void mousedown_event(GMouseEvent&) override; | ||||||
|     virtual void keyDownEvent(GKeyEvent&) override; |     virtual void keydown_event(GKeyEvent&) override; | ||||||
|     virtual void timerEvent(GTimerEvent&) override; |     virtual void timerEvent(GTimerEvent&) override; | ||||||
| 
 | 
 | ||||||
|     void handleBackspace(); |     void handle_backspace(); | ||||||
| 
 | 
 | ||||||
|     String m_text; |     String m_text; | ||||||
|     unsigned m_cursorPosition { 0 }; |     unsigned m_cursorPosition { 0 }; | ||||||
|  |  | ||||||
|  | @ -9,19 +9,19 @@ | ||||||
| GWidget::GWidget(GWidget* parent) | GWidget::GWidget(GWidget* parent) | ||||||
|     : GObject(parent) |     : GObject(parent) | ||||||
| { | { | ||||||
|     setFont(nullptr); |     set_font(nullptr); | ||||||
|     m_backgroundColor = Color::White; |     m_background_color = Color::White; | ||||||
|     m_foregroundColor = Color::Black; |     m_foreground_color = Color::Black; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| GWidget::~GWidget() | GWidget::~GWidget() | ||||||
| { | { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void GWidget::setWindowRelativeRect(const Rect& rect, bool should_update) | void GWidget::set_relative_rect(const Rect& rect, bool should_update) | ||||||
| { | { | ||||||
|     // FIXME: Make some kind of event loop driven ResizeEvent?
 |     // FIXME: Make some kind of event loop driven ResizeEvent?
 | ||||||
|     m_relativeRect = rect; |     m_relative_rect = rect; | ||||||
|     if (should_update) |     if (should_update) | ||||||
|         update(); |         update(); | ||||||
| } | } | ||||||
|  | @ -35,33 +35,33 @@ void GWidget::event(GEvent& event) | ||||||
| { | { | ||||||
|     switch (event.type()) { |     switch (event.type()) { | ||||||
|     case GEvent::Paint: |     case GEvent::Paint: | ||||||
|         m_hasPendingPaintEvent = false; |         m_has_pending_paint_event = false; | ||||||
|         return paintEvent(static_cast<GPaintEvent&>(event)); |         return paint_event(static_cast<GPaintEvent&>(event)); | ||||||
|     case GEvent::Show: |     case GEvent::Show: | ||||||
|         return showEvent(static_cast<GShowEvent&>(event)); |         return show_event(static_cast<GShowEvent&>(event)); | ||||||
|     case GEvent::Hide: |     case GEvent::Hide: | ||||||
|         return hideEvent(static_cast<GHideEvent&>(event)); |         return hide_event(static_cast<GHideEvent&>(event)); | ||||||
|     case GEvent::KeyDown: |     case GEvent::KeyDown: | ||||||
|         return keyDownEvent(static_cast<GKeyEvent&>(event)); |         return keydown_event(static_cast<GKeyEvent&>(event)); | ||||||
|     case GEvent::KeyUp: |     case GEvent::KeyUp: | ||||||
|         return keyUpEvent(static_cast<GKeyEvent&>(event)); |         return keyup_event(static_cast<GKeyEvent&>(event)); | ||||||
|     case GEvent::MouseMove: |     case GEvent::MouseMove: | ||||||
|         return mouseMoveEvent(static_cast<GMouseEvent&>(event)); |         return mousemove_event(static_cast<GMouseEvent&>(event)); | ||||||
|     case GEvent::MouseDown: |     case GEvent::MouseDown: | ||||||
|         // FIXME: Focus self if needed.
 |         // FIXME: Focus self if needed.
 | ||||||
|         return mouseDownEvent(static_cast<GMouseEvent&>(event)); |         return mousedown_event(static_cast<GMouseEvent&>(event)); | ||||||
|     case GEvent::MouseUp: |     case GEvent::MouseUp: | ||||||
|         return mouseUpEvent(static_cast<GMouseEvent&>(event)); |         return mouseup_event(static_cast<GMouseEvent&>(event)); | ||||||
|     default: |     default: | ||||||
|         return GObject::event(event); |         return GObject::event(event); | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void GWidget::paintEvent(GPaintEvent& event) | void GWidget::paint_event(GPaintEvent& event) | ||||||
| { | { | ||||||
|     if (fillWithBackgroundColor()) { |     if (fill_with_background_color()) { | ||||||
|         Painter painter(*this); |         Painter painter(*this); | ||||||
|         painter.fill_rect(event.rect(), backgroundColor()); |         painter.fill_rect(event.rect(), background_color()); | ||||||
|     } |     } | ||||||
|     for (auto* ch : children()) { |     for (auto* ch : children()) { | ||||||
|         auto* child = (GWidget*)ch; |         auto* child = (GWidget*)ch; | ||||||
|  | @ -69,31 +69,31 @@ void GWidget::paintEvent(GPaintEvent& event) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void GWidget::showEvent(GShowEvent&) | void GWidget::show_event(GShowEvent&) | ||||||
| { | { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void GWidget::hideEvent(GHideEvent&) | void GWidget::hide_event(GHideEvent&) | ||||||
| { | { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void GWidget::keyDownEvent(GKeyEvent&) | void GWidget::keydown_event(GKeyEvent&) | ||||||
| { | { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void GWidget::keyUpEvent(GKeyEvent&) | void GWidget::keyup_event(GKeyEvent&) | ||||||
| { | { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void GWidget::mouseDownEvent(GMouseEvent&) | void GWidget::mousedown_event(GMouseEvent&) | ||||||
| { | { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void GWidget::mouseUpEvent(GMouseEvent&) | void GWidget::mouseup_event(GMouseEvent&) | ||||||
| { | { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void GWidget::mouseMoveEvent(GMouseEvent&) | void GWidget::mousemove_event(GMouseEvent&) | ||||||
| { | { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -102,19 +102,19 @@ void GWidget::update() | ||||||
|     auto* w = window(); |     auto* w = window(); | ||||||
|     if (!w) |     if (!w) | ||||||
|         return; |         return; | ||||||
|     if (m_hasPendingPaintEvent) |     if (m_has_pending_paint_event) | ||||||
|         return; |         return; | ||||||
|     m_hasPendingPaintEvent = true; |     m_has_pending_paint_event = true; | ||||||
|     GEventLoop::main().post_event(w, make<GPaintEvent>(relativeRect())); |     GEventLoop::main().post_event(w, make<GPaintEvent>(relative_rect())); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| GWidget::HitTestResult GWidget::hitTest(int x, int y) | GWidget::HitTestResult GWidget::hit_test(int x, int y) | ||||||
| { | { | ||||||
|     // FIXME: Care about z-order.
 |     // FIXME: Care about z-order.
 | ||||||
|     for (auto* ch : children()) { |     for (auto* ch : children()) { | ||||||
|         auto* child = (GWidget*)ch; |         auto* child = (GWidget*)ch; | ||||||
|         if (child->relativeRect().contains(x, y)) { |         if (child->relative_rect().contains(x, y)) { | ||||||
|             return child->hitTest(x - child->relativeRect().x(), y - child->relativeRect().y()); |             return child->hit_test(x - child->relative_rect().x(), y - child->relative_rect().y()); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|     return { this, x, y }; |     return { this, x, y }; | ||||||
|  | @ -127,20 +127,20 @@ void GWidget::set_window(GWindow* window) | ||||||
|     m_window = window; |     m_window = window; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool GWidget::isFocused() const | bool GWidget::is_focused() const | ||||||
| { | { | ||||||
|     // FIXME: Implement.
 |     // FIXME: Implement.
 | ||||||
|     return false; |     return false; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void GWidget::setFocus(bool focus) | void GWidget::set_focus(bool focus) | ||||||
| { | { | ||||||
|     if (focus == isFocused()) |     if (focus == is_focused()) | ||||||
|         return; |         return; | ||||||
|     // FIXME: Implement.
 |     // FIXME: Implement.
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void GWidget::setFont(RetainPtr<Font>&& font) | void GWidget::set_font(RetainPtr<Font>&& font) | ||||||
| { | { | ||||||
|     if (!font) |     if (!font) | ||||||
|         m_font = Font::default_font(); |         m_font = Font::default_font(); | ||||||
|  |  | ||||||
|  | @ -13,87 +13,87 @@ class GWindow; | ||||||
| class GWidget : public GObject { | class GWidget : public GObject { | ||||||
| public: | public: | ||||||
|     explicit GWidget(GWidget* parent = nullptr); |     explicit GWidget(GWidget* parent = nullptr); | ||||||
|     virtual ~GWidget(); |     virtual ~GWidget() override; | ||||||
| 
 | 
 | ||||||
|     virtual void event(GEvent&) override; |     virtual void event(GEvent&) override; | ||||||
|     virtual void paintEvent(GPaintEvent&); |     virtual void paint_event(GPaintEvent&); | ||||||
|     virtual void showEvent(GShowEvent&); |     virtual void show_event(GShowEvent&); | ||||||
|     virtual void hideEvent(GHideEvent&); |     virtual void hide_event(GHideEvent&); | ||||||
|     virtual void keyDownEvent(GKeyEvent&); |     virtual void keydown_event(GKeyEvent&); | ||||||
|     virtual void keyUpEvent(GKeyEvent&); |     virtual void keyup_event(GKeyEvent&); | ||||||
|     virtual void mouseMoveEvent(GMouseEvent&); |     virtual void mousemove_event(GMouseEvent&); | ||||||
|     virtual void mouseDownEvent(GMouseEvent&); |     virtual void mousedown_event(GMouseEvent&); | ||||||
|     virtual void mouseUpEvent(GMouseEvent&); |     virtual void mouseup_event(GMouseEvent&); | ||||||
| 
 | 
 | ||||||
|     Rect relativeRect() const { return m_relativeRect; } |     Rect relative_rect() const { return m_relative_rect; } | ||||||
|     Point relativePosition() const { return m_relativeRect.location(); } |     Point relative_position() const { return m_relative_rect.location(); } | ||||||
| 
 | 
 | ||||||
|     int x() const { return m_relativeRect.x(); } |     int x() const { return m_relative_rect.x(); } | ||||||
|     int y() const { return m_relativeRect.y(); } |     int y() const { return m_relative_rect.y(); } | ||||||
|     int width() const { return m_relativeRect.width(); } |     int width() const { return m_relative_rect.width(); } | ||||||
|     int height() const { return m_relativeRect.height(); } |     int height() const { return m_relative_rect.height(); } | ||||||
| 
 | 
 | ||||||
|     Rect rect() const { return { 0, 0, width(), height() }; } |     Rect rect() const { return { 0, 0, width(), height() }; } | ||||||
|     Size size() const { return m_relativeRect.size(); } |     Size size() const { return m_relative_rect.size(); } | ||||||
| 
 | 
 | ||||||
|     void update(); |     void update(); | ||||||
|     void repaint(const Rect&); |     void repaint(const Rect&); | ||||||
| 
 | 
 | ||||||
|     bool isFocused() const; |     bool is_focused() const; | ||||||
|     void setFocus(bool); |     void set_focus(bool); | ||||||
| 
 | 
 | ||||||
|     struct HitTestResult { |     struct HitTestResult { | ||||||
|         GWidget* widget { nullptr }; |         GWidget* widget { nullptr }; | ||||||
|         int localX { 0 }; |         int localX { 0 }; | ||||||
|         int localY { 0 }; |         int localY { 0 }; | ||||||
|     }; |     }; | ||||||
|     HitTestResult hitTest(int x, int y); |     HitTestResult hit_test(int x, int y); | ||||||
| 
 | 
 | ||||||
|     virtual const char* class_name() const override { return "GWidget"; } |     virtual const char* class_name() const override { return "GWidget"; } | ||||||
| 
 | 
 | ||||||
|     void setWindowRelativeRect(const Rect&, bool should_update = true); |     void set_relative_rect(const Rect&, bool should_update = true); | ||||||
| 
 | 
 | ||||||
|     Color backgroundColor() const { return m_backgroundColor; } |     Color background_color() const { return m_background_color; } | ||||||
|     Color foregroundColor() const { return m_foregroundColor; } |     Color foreground_color() const { return m_foreground_color; } | ||||||
| 
 | 
 | ||||||
|     void setBackgroundColor(Color color) { m_backgroundColor = color; } |     void set_background_color(Color color) { m_background_color = color; } | ||||||
|     void setForegroundColor(Color color) { m_foregroundColor = color; } |     void set_foreground_color(Color color) { m_foreground_color = color; } | ||||||
| 
 | 
 | ||||||
|     GWindow* window() |     GWindow* window() | ||||||
|     { |     { | ||||||
|         if (auto* pw = parentWidget()) |         if (auto* pw = parent_widget()) | ||||||
|             return pw->window(); |             return pw->window(); | ||||||
|         return m_window; |         return m_window; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     const GWindow* window() const |     const GWindow* window() const | ||||||
|     { |     { | ||||||
|         if (auto* pw = parentWidget()) |         if (auto* pw = parent_widget()) | ||||||
|             return pw->window(); |             return pw->window(); | ||||||
|         return m_window; |         return m_window; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     void set_window(GWindow*); |     void set_window(GWindow*); | ||||||
| 
 | 
 | ||||||
|     GWidget* parentWidget() { return static_cast<GWidget*>(parent()); } |     GWidget* parent_widget() { return static_cast<GWidget*>(parent()); } | ||||||
|     const GWidget* parentWidget() const { return static_cast<const GWidget*>(parent()); } |     const GWidget* parent_widget() const { return static_cast<const GWidget*>(parent()); } | ||||||
| 
 | 
 | ||||||
|     void setFillWithBackgroundColor(bool b) { m_fillWithBackgroundColor = b; } |     void set_fill_with_background_color(bool b) { m_fill_with_background_color = b; } | ||||||
|     bool fillWithBackgroundColor() const { return m_fillWithBackgroundColor; } |     bool fill_with_background_color() const { return m_fill_with_background_color; } | ||||||
| 
 | 
 | ||||||
|     const Font& font() const { return *m_font; } |     const Font& font() const { return *m_font; } | ||||||
|     void setFont(RetainPtr<Font>&&); |     void set_font(RetainPtr<Font>&&); | ||||||
| 
 | 
 | ||||||
|     GraphicsBitmap* backing(); |     GraphicsBitmap* backing(); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     GWindow* m_window { nullptr }; |     GWindow* m_window { nullptr }; | ||||||
| 
 | 
 | ||||||
|     Rect m_relativeRect; |     Rect m_relative_rect; | ||||||
|     Color m_backgroundColor { 0xffffff }; |     Color m_background_color { 0xffffff }; | ||||||
|     Color m_foregroundColor { 0x000000 }; |     Color m_foreground_color { 0x000000 }; | ||||||
|     RetainPtr<Font> m_font; |     RetainPtr<Font> m_font; | ||||||
| 
 | 
 | ||||||
|     bool m_hasPendingPaintEvent { false }; |     bool m_has_pending_paint_event { false }; | ||||||
|     bool m_fillWithBackgroundColor { true }; |     bool m_fill_with_background_color { true }; | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | @ -91,7 +91,7 @@ void GWindow::event(GEvent& event) | ||||||
|             return; |             return; | ||||||
|         auto& mouse_event = static_cast<GMouseEvent&>(event); |         auto& mouse_event = static_cast<GMouseEvent&>(event); | ||||||
|         if (m_main_widget) { |         if (m_main_widget) { | ||||||
|             auto result = m_main_widget->hitTest(mouse_event.x(), mouse_event.y()); |             auto result = m_main_widget->hit_test(mouse_event.x(), mouse_event.y()); | ||||||
|             auto local_event = make<GMouseEvent>(event.type(), Point { result.localX, result.localY }, mouse_event.buttons(), mouse_event.button()); |             auto local_event = make<GMouseEvent>(event.type(), Point { result.localX, result.localY }, mouse_event.buttons(), mouse_event.button()); | ||||||
|             ASSERT(result.widget); |             ASSERT(result.widget); | ||||||
|             return result.widget->event(*local_event); |             return result.widget->event(*local_event); | ||||||
|  |  | ||||||
|  | @ -25,13 +25,13 @@ Painter::Painter(GWidget& widget) | ||||||
|     m_target = widget.backing(); |     m_target = widget.backing(); | ||||||
|     ASSERT(m_target); |     ASSERT(m_target); | ||||||
|     m_window = widget.window(); |     m_window = widget.window(); | ||||||
|     m_translation.move_by(widget.relativePosition()); |     m_translation.move_by(widget.relative_position()); | ||||||
|     // NOTE: m_clip_rect is in Window coordinates since we are painting into its backing store.
 |     // NOTE: m_clip_rect is in Window coordinates since we are painting into its backing store.
 | ||||||
|     m_clip_rect = widget.relativeRect(); |     m_clip_rect = widget.relative_rect(); | ||||||
| 
 | 
 | ||||||
| #ifdef DEBUG_WIDGET_UNDERDRAW | #ifdef DEBUG_WIDGET_UNDERDRAW | ||||||
|     // If the widget is not opaque, let's not mess it up with debugging color.
 |     // If the widget is not opaque, let's not mess it up with debugging color.
 | ||||||
|     if (widget.fillWithBackgroundColor() && m_window->main_widget() != &widget) |     if (widget.fill_with_background_color() && m_window->main_widget() != &widget) | ||||||
|         fill_rect(widget.rect(), Color::Red); |         fill_rect(widget.rect(), Color::Red); | ||||||
| #endif | #endif | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -36,23 +36,23 @@ GWindow* make_font_test_window() | ||||||
| 
 | 
 | ||||||
|     auto* widget = new GWidget; |     auto* widget = new GWidget; | ||||||
|     window->set_main_widget(widget); |     window->set_main_widget(widget); | ||||||
|     widget->setWindowRelativeRect({ 0, 0, 300, 80 }); |     widget->set_relative_rect({ 0, 0, 300, 80 }); | ||||||
| 
 | 
 | ||||||
|     auto* l1 = new GLabel(widget); |     auto* l1 = new GLabel(widget); | ||||||
|     l1->setWindowRelativeRect({ 0, 0, 300, 20 }); |     l1->set_relative_rect({ 0, 0, 300, 20 }); | ||||||
|     l1->setText("0123456789"); |     l1->set_text("0123456789"); | ||||||
| 
 | 
 | ||||||
|     auto* l2 = new GLabel(widget); |     auto* l2 = new GLabel(widget); | ||||||
|     l2->setWindowRelativeRect({ 0, 20, 300, 20 }); |     l2->set_relative_rect({ 0, 20, 300, 20 }); | ||||||
|     l2->setText("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); |     l2->set_text("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); | ||||||
| 
 | 
 | ||||||
|     auto* l3 = new GLabel(widget); |     auto* l3 = new GLabel(widget); | ||||||
|     l3->setWindowRelativeRect({ 0, 40, 300, 20 }); |     l3->set_relative_rect({ 0, 40, 300, 20 }); | ||||||
|     l3->setText("abcdefghijklmnopqrstuvwxyz"); |     l3->set_text("abcdefghijklmnopqrstuvwxyz"); | ||||||
| 
 | 
 | ||||||
|     auto* l4 = new GLabel(widget); |     auto* l4 = new GLabel(widget); | ||||||
|     l4->setWindowRelativeRect({ 0, 60, 300, 20 }); |     l4->set_relative_rect({ 0, 60, 300, 20 }); | ||||||
|     l4->setText("!\"#$%&'()*+,-./:;<=>?@[\\]^_{|}~"); |     l4->set_text("!\"#$%&'()*+,-./:;<=>?@[\\]^_{|}~"); | ||||||
| 
 | 
 | ||||||
|     return window; |     return window; | ||||||
| } | } | ||||||
|  | @ -65,14 +65,14 @@ GWindow* make_launcher_window() | ||||||
| 
 | 
 | ||||||
|     auto* widget = new GWidget; |     auto* widget = new GWidget; | ||||||
|     window->set_main_widget(widget); |     window->set_main_widget(widget); | ||||||
|     widget->setWindowRelativeRect({ 0, 0, 80, 200 }); |     widget->set_relative_rect({ 0, 0, 80, 200 }); | ||||||
| 
 | 
 | ||||||
|     auto* label = new GLabel(widget); |     auto* label = new GLabel(widget); | ||||||
|     label->setWindowRelativeRect({ 0, 0, 80, 20 }); |     label->set_relative_rect({ 0, 0, 80, 20 }); | ||||||
|     label->setText("Apps"); |     label->set_text("Apps"); | ||||||
| 
 | 
 | ||||||
|     auto* button = new GButton(widget); |     auto* button = new GButton(widget); | ||||||
|     button->setWindowRelativeRect({ 5, 20, 70, 20 }); |     button->set_relative_rect({ 5, 20, 70, 20 }); | ||||||
|     button->set_caption("Terminal"); |     button->set_caption("Terminal"); | ||||||
| 
 | 
 | ||||||
|     button->on_click = [] (GButton&) { |     button->on_click = [] (GButton&) { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling