Add some widget layout and ability event handling.
This commit is contained in:
parent
b99708e7d3
commit
4e85edacc8
24 changed files with 285 additions and 31 deletions
|
@ -1,4 +1,4 @@
|
|||
list(APPEND client_LIB_INCLUDES GuiApplication.cpp)
|
||||
list(APPEND client_LIB_INCLUDES GuiApplication.cpp TextEditorPanel.cpp)
|
||||
|
||||
add_library(client SHARED ${client_LIB_INCLUDES})
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
||||
}
|
||||
|
|
|
@ -23,4 +23,6 @@ public:
|
|||
void SetMainApplication(MainApplicationPtr app);
|
||||
|
||||
void Run();
|
||||
|
||||
void SetUpWidget();
|
||||
};
|
||||
|
|
0
src/client/LeftNavPanel.cpp
Normal file
0
src/client/LeftNavPanel.cpp
Normal file
0
src/client/LeftNavPanel.h
Normal file
0
src/client/LeftNavPanel.h
Normal file
0
src/client/MainPanel.cpp
Normal file
0
src/client/MainPanel.cpp
Normal file
0
src/client/MainPanel.h
Normal file
0
src/client/MainPanel.h
Normal file
0
src/client/StatusBar.cpp
Normal file
0
src/client/StatusBar.cpp
Normal file
0
src/client/StatusBar.h
Normal file
0
src/client/StatusBar.h
Normal file
59
src/client/TextEditorPanel.cpp
Normal file
59
src/client/TextEditorPanel.cpp
Normal file
|
@ -0,0 +1,59 @@
|
|||
#include "TextEditorPanel.h"
|
||||
#include "HorizontalSpacer.h"
|
||||
#include "VerticalSpacer.h"
|
||||
|
||||
TextEditorPanel::TextEditorPanel()
|
||||
: mSaveFunction(),
|
||||
mTextBox()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TextEditorPanel::Initialize()
|
||||
{
|
||||
auto textEditorLabel = Label::Create();
|
||||
textEditorLabel->SetLabel("Text Editor");
|
||||
textEditorLabel->SetBackgroundColor(Color::Create(81, 89, 102));
|
||||
|
||||
auto textEditorBox = TextBox::Create();
|
||||
mTextBox = textEditorBox.get();
|
||||
|
||||
auto textEditorSaveButton = Button::Create();
|
||||
textEditorSaveButton->SetLabel("Save");
|
||||
textEditorSaveButton->SetBackgroundColor(Color::Create(156, 156, 156));
|
||||
if (mSaveFunction)
|
||||
{
|
||||
auto onSave = [this]()
|
||||
{
|
||||
if(this && mSaveFunction && mTextBox)
|
||||
{
|
||||
mSaveFunction(mTextBox->GetContent());
|
||||
};
|
||||
};
|
||||
textEditorSaveButton->SetOnClickFunction(onSave);
|
||||
}
|
||||
|
||||
auto textEditorClearButton = Button::Create();
|
||||
textEditorClearButton->SetLabel("Clear");
|
||||
textEditorClearButton->SetBackgroundColor(Color::Create(156, 156, 156));
|
||||
auto buttonSpacer = VerticalSpacer::Create();
|
||||
buttonSpacer->AddWidgetWithScale(std::move(textEditorSaveButton), 1);
|
||||
buttonSpacer->AddWidgetWithScale(std::move(textEditorClearButton), 1);
|
||||
|
||||
auto hSpacer = HorizontalSpacer::Create();
|
||||
hSpacer->AddWidgetWithScale(std::move(textEditorLabel), 1);
|
||||
hSpacer->AddWidgetWithScale(std::move(textEditorBox), 8);
|
||||
hSpacer->AddWidgetWithScale(std::move(buttonSpacer), 1);
|
||||
|
||||
AddWidget(std::move(hSpacer));
|
||||
}
|
||||
|
||||
std::unique_ptr<TextEditorPanel> TextEditorPanel::Create()
|
||||
{
|
||||
return std::make_unique<TextEditorPanel>();
|
||||
}
|
||||
|
||||
void TextEditorPanel::SetOnSaveFunction(saveFunc func)
|
||||
{
|
||||
mSaveFunction = func;
|
||||
}
|
24
src/client/TextEditorPanel.h
Normal file
24
src/client/TextEditorPanel.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
#pragma once
|
||||
|
||||
#include "Widget.h"
|
||||
#include "Button.h"
|
||||
#include "Label.h"
|
||||
#include "TextBox.h"
|
||||
|
||||
class TextEditorPanel : public Widget
|
||||
{
|
||||
using saveFunc = void (*)(const std::string& content);
|
||||
saveFunc mSaveFunction;
|
||||
TextBox* mTextBox;
|
||||
|
||||
public:
|
||||
|
||||
TextEditorPanel();
|
||||
|
||||
static std::unique_ptr<TextEditorPanel> Create();
|
||||
|
||||
void Initialize();
|
||||
|
||||
void SetOnSaveFunction(saveFunc func);
|
||||
};
|
||||
using TextEditorPanelUPtr = std::unique_ptr<TextEditorPanel>;
|
0
src/client/TopBar.cpp
Normal file
0
src/client/TopBar.cpp
Normal file
0
src/client/TopBar.h
Normal file
0
src/client/TopBar.h
Normal file
Loading…
Add table
Add a link
Reference in a new issue