feat: finish UI + chore: organize all windows into separate files
This commit is contained in:
parent
43deda8646
commit
f33e0aca06
10 changed files with 149 additions and 129 deletions
102
App.cpp
102
App.cpp
|
@ -1,102 +0,0 @@
|
|||
#include "App.h"
|
||||
#include <Application.h>
|
||||
#include <GridLayout.h>
|
||||
#include <GroupLayout.h>
|
||||
#include <InterfaceDefs.h>
|
||||
#include <Layout.h>
|
||||
#include <LayoutItem.h>
|
||||
#include <Message.h>
|
||||
#include <Rect.h>
|
||||
#include <String.h>
|
||||
#include <StringView.h>
|
||||
#include <Window.h>
|
||||
#include <GroupLayoutBuilder.h>
|
||||
#include <GridLayoutBuilder.h>
|
||||
#include <Button.h>
|
||||
#include <cstdio>
|
||||
#include <format>
|
||||
#include "Contacts.h"
|
||||
#include <TextControl.h>
|
||||
|
||||
// quick and dirty function to quickly make text labels
|
||||
BStringView *MakeText(const char* text)
|
||||
{
|
||||
return new BStringView("rstr", text);
|
||||
}
|
||||
|
||||
App::App(void) : BApplication(std::format("application/x-vnd.{}-{}", APP_AUTHOR, APP_NAME).c_str())
|
||||
{
|
||||
// Initialize BRect frame for window
|
||||
BRect frame(100, 100, 500, 400);
|
||||
|
||||
// Initialize parent group for all UI elements to sit in. This is so they all get grouped nicely together
|
||||
BGroupLayout *pGroup = new BGroupLayout(B_HORIZONTAL);
|
||||
|
||||
// Create window
|
||||
BWindow *window = new BWindow(frame, std::format("{}", APP_NAME).c_str(), B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS);
|
||||
|
||||
// Set window layout to parent group created earlier
|
||||
window->SetLayout(pGroup);
|
||||
|
||||
pGroup->View()->AdoptSystemColors();
|
||||
|
||||
/*
|
||||
// Initialize special UI group for all of our "real" elements
|
||||
BGroupLayout *uGroup = new BGroupLayout(B_HORIZONTAL, 100);
|
||||
// Add label group to parent group
|
||||
pGroup->AddItem(uGroup);
|
||||
|
||||
// Center label group
|
||||
uGroup->SetExplicitAlignment(BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER));
|
||||
|
||||
// And finally, add a button!!
|
||||
|
||||
uGroup->AddView(connectButton);
|
||||
*/
|
||||
BGridLayout *uiElems = new BGridLayout(10, 0);
|
||||
pGroup->AddItem(uiElems);
|
||||
uiElems->SetExplicitAlignment(BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER));
|
||||
|
||||
BButton *connectButton = new BButton(frame, "connect", "Connect!", new BMessage(msgConnectButtonClicked));
|
||||
connectButton->SetTarget(this);
|
||||
|
||||
BTextControl *jidInput = new BTextControl("jidinput", "JID:", "Placeholder", new BMessage(msgConnectButtonClicked));
|
||||
BTextControl *pwInput = new BTextControl("jidinput", "JID:", "Placeholder", new BMessage(msgConnectButtonClicked));
|
||||
|
||||
uiElems->AddView(jidInput, 0, 0);
|
||||
uiElems->AddView(MakeText("Password placeholder"), 0, 1);
|
||||
uiElems->AddView(connectButton, 0, 2);
|
||||
uiElems->SetMinRowHeight(2, 75);
|
||||
|
||||
window->Show();
|
||||
|
||||
App::ConnectWindow = window;
|
||||
}
|
||||
|
||||
void App::MessageReceived(BMessage *msg)
|
||||
{
|
||||
switch(msg->what) {
|
||||
case msgConnectButtonClicked:
|
||||
{
|
||||
printf("Connect button clicked...\n");
|
||||
App::ConnectWindow->Hide();
|
||||
App::ContactsWindow = ShowContacts();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
printf("Unknown message received: %d\n", msg->what);
|
||||
BApplication::MessageReceived(msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
App *app = new App();
|
||||
app->Run();
|
||||
|
||||
delete app;
|
||||
return 0;
|
||||
}
|
14
Contacts.cpp
14
Contacts.cpp
|
@ -1,14 +0,0 @@
|
|||
#include "Contacts.h"
|
||||
#include "App.h"
|
||||
#include <Application.h>
|
||||
#include <Rect.h>
|
||||
#include <Window.h>
|
||||
|
||||
BWindow *ShowContacts()
|
||||
{
|
||||
// POS W H
|
||||
BRect frame(200,200,600,400);
|
||||
BWindow *window = new BWindow(frame, "Contacts List", B_TITLED_WINDOW, B_NOT_MINIMIZABLE | B_QUIT_ON_WINDOW_CLOSE);
|
||||
window->Show();
|
||||
return window;
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
#include "App.h"
|
||||
#include <Window.h>
|
||||
extern BWindow *ShowContacts();
|
2
Makefile
2
Makefile
|
@ -5,7 +5,7 @@ FLAGS=-lbe -std=c++20 -lstdc++
|
|||
all: build
|
||||
|
||||
build:
|
||||
$(CPP) *.cpp -o $(BINARY) $(FLAGS)
|
||||
$(CPP) $(shell find ./src | grep cpp) -o $(BINARY) $(FLAGS)
|
||||
test: build
|
||||
./renga
|
||||
|
||||
|
|
17
src/App.cpp
Normal file
17
src/App.cpp
Normal file
|
@ -0,0 +1,17 @@
|
|||
#include "App.h"
|
||||
#include "gui/MainWindow.h"
|
||||
|
||||
App::App(void) : BApplication(kSignature)
|
||||
{
|
||||
MainWindow *mainWindow = new MainWindow();
|
||||
mainWindow->Show();
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
App *app = new App();
|
||||
app->Run();
|
||||
|
||||
delete app;
|
||||
return 0;
|
||||
}
|
|
@ -5,14 +5,10 @@
|
|||
#include <Window.h>
|
||||
#include <gloox/connectionlistener.h>
|
||||
#include <gloox/presencehandler.h>
|
||||
|
||||
#define APP_NAME "Renga"
|
||||
#define APP_AUTHOR "hex&andre"
|
||||
|
||||
const uint32 msgConnectButtonClicked = 'mCBC';
|
||||
|
||||
#include <Application.h>
|
||||
|
||||
#define kSignature "application/x-vnd.iwakura-Renga"
|
||||
|
||||
class Client : public gloox::ConnectionListener, gloox::PresenceHandler {
|
||||
|
||||
};
|
||||
|
@ -21,9 +17,6 @@ class App : public BApplication
|
|||
{
|
||||
public:
|
||||
App(void);
|
||||
virtual void MessageReceived(BMessage *msg);
|
||||
BWindow *ConnectWindow;
|
||||
BWindow *ContactsWindow;
|
||||
Client *client;
|
||||
};
|
||||
|
11
src/gui/Contacts.cpp
Normal file
11
src/gui/Contacts.cpp
Normal file
|
@ -0,0 +1,11 @@
|
|||
#include "Contacts.h"
|
||||
#include <Application.h>
|
||||
#include <Rect.h>
|
||||
#include <Window.h>
|
||||
#include <StringView.h>
|
||||
|
||||
Contacts::Contacts(void)
|
||||
: BWindow(BRect(200,200,600,400), TITLE, B_TITLED_WINDOW, B_NOT_MINIMIZABLE | B_QUIT_ON_WINDOW_CLOSE)
|
||||
{
|
||||
AddChild(new BStringView("label", "Placeholder label (contact list to be added)"));
|
||||
}
|
12
src/gui/Contacts.h
Normal file
12
src/gui/Contacts.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#ifndef CONTACTS_H
|
||||
#define CONTACTS_H
|
||||
|
||||
#include <Window.h>
|
||||
#define TITLE "Contact List"
|
||||
|
||||
class Contacts : public BWindow {
|
||||
public:
|
||||
Contacts(void);
|
||||
};
|
||||
|
||||
#endif
|
87
src/gui/MainWindow.cpp
Normal file
87
src/gui/MainWindow.cpp
Normal file
|
@ -0,0 +1,87 @@
|
|||
#include "MainWindow.h"
|
||||
#include <Alignment.h>
|
||||
#include <Application.h>
|
||||
#include <GridLayout.h>
|
||||
#include <GroupLayout.h>
|
||||
#include <InterfaceDefs.h>
|
||||
#include <Layout.h>
|
||||
#include <LayoutItem.h>
|
||||
#include <Message.h>
|
||||
#include <Rect.h>
|
||||
#include <String.h>
|
||||
#include <StringView.h>
|
||||
#include <TextView.h>
|
||||
#include <View.h>
|
||||
#include <Window.h>
|
||||
#include <GroupLayoutBuilder.h>
|
||||
#include <GridLayoutBuilder.h>
|
||||
#include <Button.h>
|
||||
#include <cstdio>
|
||||
#include "Contacts.h"
|
||||
#include <TextControl.h>
|
||||
|
||||
MainWindow::MainWindow(void)
|
||||
: BWindow(BRect(100, 100, 500, 400), "Renga", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE)
|
||||
{
|
||||
// parent layout (defines the entire window layout)
|
||||
BGroupLayout *pGroup = new BGroupLayout(B_HORIZONTAL);
|
||||
SetLayout(pGroup);
|
||||
|
||||
// make sure window uses window colors set in haiku preferences (equivelant to system themes)
|
||||
pGroup->View()->AdoptSystemColors();
|
||||
|
||||
// prepare "renga" text banner
|
||||
BStringView *banner = new BStringView("banner", "Renga");
|
||||
|
||||
banner->SetHighColor(135,1,1);
|
||||
banner->SetFontSize(28.0);
|
||||
|
||||
// ui layout (parent of all UI elements visible to the user)
|
||||
BGridLayout *uiElems = new BGridLayout(10, 0);
|
||||
|
||||
pGroup->AddItem(uiElems);
|
||||
|
||||
// center the entire UI
|
||||
uiElems->SetExplicitAlignment(BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER));
|
||||
|
||||
BButton *connectButton = new BButton(Frame(), "connect", "Connect!", new BMessage(msgConnectButtonClicked));
|
||||
connectButton->SetTarget(this);
|
||||
|
||||
BTextControl *jidInput = new BTextControl("jidinput", "JID:", "Placeholder", new BMessage(msgConnectButtonClicked));
|
||||
BTextControl *pwInput = new BTextControl("pwinput", "Password:", "Placeholder", new BMessage(msgConnectButtonClicked));
|
||||
|
||||
pwInput->TextView()->HideTyping(true);
|
||||
|
||||
jidInput->SetExplicitSize(BSize(200,23));
|
||||
pwInput->SetExplicitSize(BSize(200,23));
|
||||
|
||||
uiElems->AddView(banner, 0, 0);
|
||||
uiElems->AddView(jidInput, 0, 1);
|
||||
uiElems->AddView(pwInput, 0, 2);
|
||||
uiElems->AddView(connectButton, 0, 3);
|
||||
uiElems->SetMinRowHeight(3, 75);
|
||||
uiElems->SetMinRowHeight(0, 25);
|
||||
|
||||
Show();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::MessageReceived(BMessage *msg)
|
||||
{
|
||||
switch(msg->what) {
|
||||
case msgConnectButtonClicked:
|
||||
{
|
||||
printf("Connect button clicked...\n");
|
||||
|
||||
Hide();
|
||||
Contacts *contacts = new Contacts();
|
||||
contacts->Show();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
printf("Unknown message received: %d\n", msg->what);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
19
src/gui/MainWindow.h
Normal file
19
src/gui/MainWindow.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <Message.h>
|
||||
#include <Window.h>
|
||||
#include <Application.h>
|
||||
#include <gloox/connectionlistener.h>
|
||||
#include <gloox/presencehandler.h>
|
||||
|
||||
const uint32 msgConnectButtonClicked = 'mCBC';
|
||||
|
||||
class MainWindow : public BWindow
|
||||
{
|
||||
public:
|
||||
MainWindow(void);
|
||||
virtual void MessageReceived(BMessage *msg);
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue