Add some widget layout and ability event handling.

This commit is contained in:
jmsgrogan 2020-06-20 19:00:06 +01:00
parent b99708e7d3
commit 4e85edacc8
24 changed files with 285 additions and 31 deletions

View file

@ -2,6 +2,7 @@
#include "Widget.h"
#include "HorizontalSpacer.h"
#include "VerticalSpacer.h"
#include "TextBox.h"
#include "Button.h"
#include "Label.h"
@ -10,6 +11,8 @@
#include "Window.h"
#include "TextElement.h"
#include "WindowManager.h"
#include "TextEditorPanel.h"
#include <iostream>
GuiApplication::GuiApplication()
: AbstractDesktopApp(),
@ -29,28 +32,55 @@ void GuiApplication::SetMainApplication(MainApplicationPtr app)
mMainApplication = app;
}
void GuiApplication::SetUpWidget()
{
auto mainWindow = mDesktopManager->GetWindowManager()->GetMainWindow();
mainWindow->SetSize(800, 600);
// Left panel
auto textEditorButton = Button::Create();
textEditorButton->SetLabel("Text Editor");
textEditorButton->SetBackgroundColor(Color::Create(156, 156, 156));
auto imageEditorButton = Button::Create();
imageEditorButton->SetLabel("Image Editor");
imageEditorButton->SetBackgroundColor(Color::Create(156, 156, 156));
auto audioEditorButton = Button::Create();
audioEditorButton->SetLabel("Audio Editor");
audioEditorButton->SetBackgroundColor(Color::Create(156, 156, 156));
auto webClientButton = Button::Create();
webClientButton->SetLabel("Web Client");
webClientButton->SetBackgroundColor(Color::Create(156, 156, 156));
auto leftSpacer = HorizontalSpacer::Create();
leftSpacer->AddWidget(std::move(textEditorButton));
leftSpacer->AddWidget(std::move(imageEditorButton));
leftSpacer->AddWidget(std::move(audioEditorButton));
leftSpacer->AddWidget(std::move(webClientButton));
leftSpacer->SetMaxHeight(200);
// Right panel
auto textEditor = TextEditorPanel::Create();
textEditor->SetOnSaveFunction([](const std::string& content)
{
std::cout << content << std::endl;
});
textEditor->Initialize();
auto vertSpacer = VerticalSpacer::Create();
vertSpacer->AddWidgetWithScale(std::move(leftSpacer), 1);
vertSpacer->AddWidgetWithScale(std::move(textEditor), 4);
mainWindow->AddWidget(std::move(vertSpacer));
}
void GuiApplication::Run()
{
auto mainWindow = mDesktopManager->GetWindowManager()->GetMainWindow();
SetUpWidget();
mainWindow->SetSize(800, 600);
auto label = Label::Create();
label->SetLabel("Type text!!");
label->SetBackgroundColor(Color::Create(0, 200, 200));
auto textBox = TextBox::Create();
auto button = Button::Create();
button->SetLabel("Save");
button->SetBackgroundColor(Color::Create(0, 0, 200));
auto spacer = HorizontalSpacer::Create();
spacer->AddWidget(std::move(label));
spacer->AddWidget(std::move(textBox));
spacer->AddWidget(std::move(button));
mainWindow->AddWidget(std::move(spacer));
mDesktopManager->SetKeyboard(XcbKeyboard::Create());
bool useOpenGl = false;
@ -63,9 +93,6 @@ void GuiApplication::Run()
{
window_interface.CreateOpenGlDrawable(mainWindow);
}
window_interface.Loop(mDesktopManager.get());
window_interface.ShutDown();
}