From 53c98a227d6ff0ff8d7d405b399c5cd7f0882d82 Mon Sep 17 00:00:00 2001 From: James Grogan Date: Fri, 11 Nov 2022 14:22:31 +0000 Subject: [PATCH] More window cleaning --- apps/sample-gui/MediaTool.cpp | 17 +- .../audio_editor/AudioEditorView.cpp | 8 +- apps/sample-gui/gui-main.cpp | 5 +- .../image_editor/ImageEditorView.cpp | 8 +- .../sample-gui/text_editor/TextEditorView.cpp | 38 ++-- apps/sample-gui/web_client/WebClientView.cpp | 8 +- src/client/StatusBar.cpp | 2 +- src/client/TabbedPanelWidget.cpp | 16 +- src/client/TopBar.cpp | 2 +- src/geometry/DiscretePoint.h | 10 + src/ui_elements/desktop_elements/Window.cpp | 13 +- src/ui_elements/widgets/Button.cpp | 57 +++-- src/ui_elements/widgets/Button.h | 24 +- src/ui_elements/widgets/HorizontalSpacer.cpp | 31 +-- src/ui_elements/widgets/HorizontalSpacer.h | 8 +- src/ui_elements/widgets/Label.cpp | 54 +++-- src/ui_elements/widgets/Label.h | 4 +- src/ui_elements/widgets/StackWidget.cpp | 4 +- src/ui_elements/widgets/TextBox.cpp | 8 +- src/ui_elements/widgets/TextBox.h | 4 +- src/ui_elements/widgets/VerticalSpacer.cpp | 18 +- src/ui_elements/widgets/VerticalSpacer.h | 6 +- src/ui_elements/widgets/Widget.cpp | 210 ++++++++++++------ src/ui_elements/widgets/Widget.h | 104 ++++++--- src/windows/managers/DesktopManager.cpp | 1 - src/windows/managers/WindowManager.h | 2 - .../ui_interfaces/x11/XcbInterface.cpp | 3 +- .../ui_interfaces/x11/XcbLayerInterface.cpp | 10 +- .../ui_interfaces/x11/XcbLayerInterface.h | 8 +- 29 files changed, 422 insertions(+), 261 deletions(-) diff --git a/apps/sample-gui/MediaTool.cpp b/apps/sample-gui/MediaTool.cpp index 45e39a6..6de1603 100644 --- a/apps/sample-gui/MediaTool.cpp +++ b/apps/sample-gui/MediaTool.cpp @@ -23,6 +23,7 @@ void MediaTool::initializeViews() auto mainWindow = mDesktopManager->GetWindowManager()->GetMainWindow(); mainWindow->SetSize(800, 600); + /* auto tabbedPanel = TabbedPanelWidget::Create(); auto textEditor = TextEditorView::Create(); @@ -50,5 +51,19 @@ void MediaTool::initializeViews() horizontalSpace->AddWidgetWithScale(std::move(tabbedPanel), 20); horizontalSpace->AddWidgetWithScale(std::move(statusBar), 1); - mainWindow->AddWidget(std::move(horizontalSpace)); + */ + + auto button = Button::Create(); + button->setLabel("Click!"); + button->setBounds(100, 200); + button->setBackgroundColor(Color::Create(0, 0, 255, 0)); + + auto background_widget = Widget::Create(); + background_widget->setBackgroundColor(Color::Create(0, 255, 255, 0)); + + auto horizontal_spacer = HorizontalSpacer::Create(); + horizontal_spacer->addWidgetWithScale(std::move(button), 1); + horizontal_spacer->addWidgetWithScale(std::move(background_widget), 1); + + mainWindow->AddWidget(std::move(horizontal_spacer)); } diff --git a/apps/sample-gui/audio_editor/AudioEditorView.cpp b/apps/sample-gui/audio_editor/AudioEditorView.cpp index 06a90b6..94e9fdf 100644 --- a/apps/sample-gui/audio_editor/AudioEditorView.cpp +++ b/apps/sample-gui/audio_editor/AudioEditorView.cpp @@ -6,10 +6,10 @@ AudioEditorView::AudioEditorView() { auto label = Label::Create(); - label->SetLabel("Audio Editor"); - label->SetBackgroundColor(Color::Create(200, 189, 160)); - label->SetMargin(1); - AddWidget(std::move(label)); + label->setLabel("Audio Editor"); + label->setBackgroundColor(Color::Create(200, 189, 160)); + label->setMargin(1); + addWidget(std::move(label)); } std::unique_ptr AudioEditorView::Create() diff --git a/apps/sample-gui/gui-main.cpp b/apps/sample-gui/gui-main.cpp index 3a2d324..9a964a6 100644 --- a/apps/sample-gui/gui-main.cpp +++ b/apps/sample-gui/gui-main.cpp @@ -11,8 +11,9 @@ int main(int argc, char *argv[]) args->recordLaunchPath(); // Start the gui app - auto gui_app = GuiApplication(std::move(args)); - gui_app.run(); + auto app = MediaTool(std::move(args)); + app.setUiInterfaceBackend(UiInterfaceFactory::Backend::X11_RASTER); + app.run(); return 0; } diff --git a/apps/sample-gui/image_editor/ImageEditorView.cpp b/apps/sample-gui/image_editor/ImageEditorView.cpp index b1519d6..41f2f91 100644 --- a/apps/sample-gui/image_editor/ImageEditorView.cpp +++ b/apps/sample-gui/image_editor/ImageEditorView.cpp @@ -6,10 +6,10 @@ ImageEditorView::ImageEditorView() { auto label = Label::Create(); - label->SetLabel("Image Editor"); - label->SetBackgroundColor(Color::Create(200, 189, 160)); - label->SetMargin(1); - AddWidget(std::move(label)); + label->setLabel("Image Editor"); + label->setBackgroundColor(Color::Create(200, 189, 160)); + label->setMargin(1); + addWidget(std::move(label)); } std::unique_ptr ImageEditorView::Create() diff --git a/apps/sample-gui/text_editor/TextEditorView.cpp b/apps/sample-gui/text_editor/TextEditorView.cpp index 0294bab..4df5614 100644 --- a/apps/sample-gui/text_editor/TextEditorView.cpp +++ b/apps/sample-gui/text_editor/TextEditorView.cpp @@ -18,17 +18,17 @@ TextEditorController* TextEditorView::GetController() void TextEditorView::Initialize() { auto label = Label::Create(); - label->SetLabel("Text Editor"); - label->SetBackgroundColor(Color::Create(181, 189, 200)); - label->SetMargin(1); + label->setLabel("Text Editor"); + label->setBackgroundColor(Color::Create(181, 189, 200)); + label->setMargin(1); auto textBox = TextBox::Create(); mTextBox = textBox.get(); auto saveButton = Button::Create(); - saveButton->SetLabel("Save"); - saveButton->SetBackgroundColor(Color::Create(200, 200, 200)); - saveButton->SetMargin(2); + saveButton->setLabel("Save"); + saveButton->setBackgroundColor(Color::Create(200, 200, 200)); + saveButton->setMargin(2); auto onSave = [this](Widget* self){ if(this && mController && mTextBox) { @@ -36,12 +36,12 @@ void TextEditorView::Initialize() mController->OnSave(); }; }; - saveButton->SetOnClickFunction(onSave); + saveButton->setOnClickFunction(onSave); auto clearButton = Button::Create(); - clearButton->SetLabel("Clear"); - clearButton->SetBackgroundColor(Color::Create(200, 200, 200)); - clearButton->SetMargin(2); + clearButton->setLabel("Clear"); + clearButton->setBackgroundColor(Color::Create(200, 200, 200)); + clearButton->setMargin(2); auto onClear = [this](Widget* self){ if(this && mController && mTextBox) { @@ -49,12 +49,12 @@ void TextEditorView::Initialize() mTextBox->SetContent(""); }; }; - clearButton->SetOnClickFunction(onClear); + clearButton->setOnClickFunction(onClear); auto loadButton = Button::Create(); - loadButton->SetLabel("Load"); - loadButton->SetBackgroundColor(Color::Create(200, 200, 200)); - loadButton->SetMargin(2); + loadButton->setLabel("Load"); + loadButton->setBackgroundColor(Color::Create(200, 200, 200)); + loadButton->setMargin(2); auto onLoad = [this](Widget* self){ if(this && mController && mTextBox) { @@ -62,7 +62,7 @@ void TextEditorView::Initialize() mTextBox->SetContent(mController->GetContent()); }; }; - loadButton->SetOnClickFunction(onLoad); + loadButton->setOnClickFunction(onLoad); auto buttonSpacer = VerticalSpacer::Create(); buttonSpacer->AddWidgetWithScale(std::move(saveButton), 1); @@ -70,11 +70,11 @@ void TextEditorView::Initialize() buttonSpacer->AddWidgetWithScale(std::move(loadButton), 1); auto hSpacer = HorizontalSpacer::Create(); - hSpacer->AddWidgetWithScale(std::move(label), 1); - hSpacer->AddWidgetWithScale(std::move(textBox), 14); - hSpacer->AddWidgetWithScale(std::move(buttonSpacer), 1); + hSpacer->addWidgetWithScale(std::move(label), 1); + hSpacer->addWidgetWithScale(std::move(textBox), 14); + hSpacer->addWidgetWithScale(std::move(buttonSpacer), 1); - AddWidget(std::move(hSpacer)); + addWidget(std::move(hSpacer)); } std::unique_ptr TextEditorView::Create() diff --git a/apps/sample-gui/web_client/WebClientView.cpp b/apps/sample-gui/web_client/WebClientView.cpp index 7fad55c..0cd152b 100644 --- a/apps/sample-gui/web_client/WebClientView.cpp +++ b/apps/sample-gui/web_client/WebClientView.cpp @@ -6,10 +6,10 @@ WebClientView::WebClientView() { auto label = Label::Create(); - label->SetLabel("Web Client"); - label->SetBackgroundColor(Color::Create(200, 189, 160)); - label->SetMargin(1); - AddWidget(std::move(label)); + label->setLabel("Web Client"); + label->setBackgroundColor(Color::Create(200, 189, 160)); + label->setMargin(1); + addWidget(std::move(label)); } std::unique_ptr WebClientView::Create() diff --git a/src/client/StatusBar.cpp b/src/client/StatusBar.cpp index 851df2b..bf98098 100644 --- a/src/client/StatusBar.cpp +++ b/src/client/StatusBar.cpp @@ -4,7 +4,7 @@ StatusBar::StatusBar() { - SetBackgroundColor(Color::Create(200, 200, 200)); + setBackgroundColor(Color::Create(200, 200, 200)); } std::unique_ptr StatusBar::Create() diff --git a/src/client/TabbedPanelWidget.cpp b/src/client/TabbedPanelWidget.cpp index d51db5d..a6851cd 100644 --- a/src/client/TabbedPanelWidget.cpp +++ b/src/client/TabbedPanelWidget.cpp @@ -13,12 +13,12 @@ TabbedPanelWidget::TabbedPanelWidget() auto nav = HorizontalSpacer::Create(); mNavPanel = nav.get(); - nav->SetSize({0, 0, 0, 0, 200, 0}); + nav->setSize({0, 0, 0, 0, 200, 0}); auto vertSpacer = VerticalSpacer::Create(); vertSpacer->AddWidgetWithScale(std::move(nav), 1); vertSpacer->AddWidgetWithScale(std::move(stack), 4); - AddWidget(std::move(vertSpacer)); + addWidget(std::move(vertSpacer)); } std::unique_ptr TabbedPanelWidget::Create() @@ -34,9 +34,9 @@ StackWidget* TabbedPanelWidget::GetStack() const void TabbedPanelWidget::AddPanel(WidgetUPtr panel, const std::string& label) { auto button = Button::Create(); - button->SetLabel(label); - button->SetBackgroundColor(Color::Create(156, 156, 156)); - button->SetMargin({1, 0, 0, 1}); + button->setLabel(label); + button->setBackgroundColor(Color::Create(156, 156, 156)); + button->setMargin({1, 0, 0, 1}); auto rawPanel = panel.get(); auto onClick = [this, rawPanel](Widget*){ if(this && rawPanel) @@ -44,9 +44,9 @@ void TabbedPanelWidget::AddPanel(WidgetUPtr panel, const std::string& label) this->GetStack()->ShowChild(rawPanel); } }; - button->SetOnClickFunction(onClick); - mStack->AddWidget(std::move(panel)); - mNavPanel->AddWidget(std::move(button)); + button->setOnClickFunction(onClick); + mStack->addWidget(std::move(panel)); + mNavPanel->addWidget(std::move(button)); } diff --git a/src/client/TopBar.cpp b/src/client/TopBar.cpp index 24db275..be83727 100644 --- a/src/client/TopBar.cpp +++ b/src/client/TopBar.cpp @@ -4,7 +4,7 @@ TopBar::TopBar() { - SetBackgroundColor(Color::Create(50, 50, 50)); + setBackgroundColor(Color::Create(50, 50, 50)); } std::unique_ptr TopBar::Create() diff --git a/src/geometry/DiscretePoint.h b/src/geometry/DiscretePoint.h index 06c8399..2735fb0 100644 --- a/src/geometry/DiscretePoint.h +++ b/src/geometry/DiscretePoint.h @@ -18,6 +18,16 @@ public: unsigned GetX() const; unsigned GetY() const; + + bool operator==(const DiscretePoint& rhs) const + { + return (mX == rhs.mX) + && (mY == rhs.mY); + } + bool operator!=(const DiscretePoint& rhs) const + { + return !operator==(rhs); + } }; using Pixel = DiscretePoint; diff --git a/src/ui_elements/desktop_elements/Window.cpp b/src/ui_elements/desktop_elements/Window.cpp index 37186f2..fa833ee 100644 --- a/src/ui_elements/desktop_elements/Window.cpp +++ b/src/ui_elements/desktop_elements/Window.cpp @@ -14,7 +14,7 @@ Window::Window() mHeight(600), mWidget(Widget::Create()) { - + mWidget->setBounds(mWidth, mHeight); } Window::~Window() @@ -29,23 +29,22 @@ std::unique_ptr Window::Create() std::vector Window::GetLayers() { - return mWidget->GetLayers(); + return mWidget->getLayers(); } void Window::OnMouseEvent(const MouseEvent* event) { - mWidget->OnMouseEvent(event); + mWidget->onMouseEvent(event); } void Window::OnKeyboardEvent(const KeyboardEvent* event) { - mWidget->OnKeyboardEvent(event); + mWidget->onKeyboardEvent(event); } void Window::OnPaint(const PaintEvent* event) { - mWidget->SetBounds(mWidth, mHeight); - mWidget->OnPaintEvent(event); + mWidget->onPaintEvent(event); } void Window::AddWidget(WidgetUPtr widget) @@ -55,6 +54,7 @@ void Window::AddWidget(WidgetUPtr widget) mWidget.reset(); } mWidget = std::move(widget); + mWidget->setBounds(mWidth, mHeight); } Widget* Window::GetWidget() const @@ -76,6 +76,7 @@ void Window::SetSize(unsigned width, unsigned height) { mWidth = width; mHeight = height; + mWidget->setBounds(mWidth, mHeight); } IPlatformWindow* Window::GetPlatformWindow() const diff --git a/src/ui_elements/widgets/Button.cpp b/src/ui_elements/widgets/Button.cpp index 310d391..ac21a5a 100644 --- a/src/ui_elements/widgets/Button.cpp +++ b/src/ui_elements/widgets/Button.cpp @@ -21,22 +21,26 @@ std::unique_ptr