feat: add new contacts list and connect to xmpp button
This commit is contained in:
parent
d7781bbbf4
commit
59ac3aeb0a
5 changed files with 64 additions and 11 deletions
48
App.cpp
48
App.cpp
|
@ -4,12 +4,17 @@
|
||||||
#include <InterfaceDefs.h>
|
#include <InterfaceDefs.h>
|
||||||
#include <Layout.h>
|
#include <Layout.h>
|
||||||
#include <LayoutItem.h>
|
#include <LayoutItem.h>
|
||||||
|
#include <Message.h>
|
||||||
#include <Rect.h>
|
#include <Rect.h>
|
||||||
#include <Window.h>
|
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <StringView.h>
|
#include <StringView.h>
|
||||||
#include <GroupLayoutBuilder.h>
|
#include <GroupLayoutBuilder.h>
|
||||||
|
#include <Window.h>
|
||||||
|
#include <Button.h>
|
||||||
|
#include <cstdio>
|
||||||
#include <format>
|
#include <format>
|
||||||
|
#include <iostream>
|
||||||
|
#include "Contacts.h"
|
||||||
|
|
||||||
// quick and dirty function to quickly make text labels
|
// quick and dirty function to quickly make text labels
|
||||||
BStringView *MakeText(const char* text)
|
BStringView *MakeText(const char* text)
|
||||||
|
@ -19,31 +24,54 @@ BStringView *MakeText(const char* text)
|
||||||
|
|
||||||
App::App(void) : BApplication(std::format("application/x-vnd.{}-{}", APP_AUTHOR, APP_NAME).c_str())
|
App::App(void) : BApplication(std::format("application/x-vnd.{}-{}", APP_AUTHOR, APP_NAME).c_str())
|
||||||
{
|
{
|
||||||
|
std::cout << "hello world!!\n";
|
||||||
// Initialize BRect frame for window
|
// Initialize BRect frame for window
|
||||||
BRect frame(100, 100, 500, 400);
|
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
|
// 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);
|
BGroupLayout *pGroup = new BGroupLayout(B_HORIZONTAL);
|
||||||
// Create window
|
// Create window
|
||||||
BWindow *window = new BWindow(frame, std::format("{} by {}", APP_NAME, APP_AUTHOR).c_str(), B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE);
|
BWindow *window = new BWindow(frame, std::format("{} by {}", APP_NAME, APP_AUTHOR).c_str(), B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS);
|
||||||
|
|
||||||
// Set window layout to parent group created earlier
|
// Set window layout to parent group created earlier
|
||||||
window->SetLayout(pGroup);
|
window->SetLayout(pGroup);
|
||||||
|
|
||||||
// Initialize special "label" group for all of our labels
|
// Initialize special UI group for all of our "real" elements
|
||||||
BGroupLayout *lGroup = new BGroupLayout(B_HORIZONTAL, 100);
|
BGroupLayout *uGroup = new BGroupLayout(B_HORIZONTAL, 100);
|
||||||
// Add label group to parent group
|
// Add label group to parent group
|
||||||
pGroup->AddItem(lGroup);
|
pGroup->AddItem(uGroup);
|
||||||
|
|
||||||
// Center label group
|
// Center label group
|
||||||
lGroup->SetExplicitAlignment(BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER));
|
uGroup->SetExplicitAlignment(BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER));
|
||||||
|
|
||||||
// And finally, add allat labels!!
|
// And finally, add a button!!
|
||||||
lGroup->AddView(MakeText("label 1"));
|
BButton *connectButton = new BButton(frame, "connect", "Connect to XMPP", new BMessage(msgConnectButtonClicked));
|
||||||
lGroup->AddView(MakeText("label 2"));
|
connectButton->SetTarget(this);
|
||||||
lGroup->AddView(MakeText("label 3"));
|
|
||||||
|
uGroup->AddView(connectButton);
|
||||||
|
|
||||||
window->Show();
|
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)
|
int main(void)
|
||||||
|
|
8
App.h
8
App.h
|
@ -1,15 +1,23 @@
|
||||||
#ifndef APP_H
|
#ifndef APP_H
|
||||||
#define APP_H
|
#define APP_H
|
||||||
|
|
||||||
|
#include <Message.h>
|
||||||
|
#include <Window.h>
|
||||||
|
|
||||||
#define APP_NAME "Renga"
|
#define APP_NAME "Renga"
|
||||||
#define APP_AUTHOR "hex_andre"
|
#define APP_AUTHOR "hex_andre"
|
||||||
|
|
||||||
|
const uint32 msgConnectButtonClicked = 'mCBC';
|
||||||
|
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
|
|
||||||
class App : public BApplication
|
class App : public BApplication
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
App(void);
|
App(void);
|
||||||
|
virtual void MessageReceived(BMessage *msg);
|
||||||
|
BWindow *ConnectWindow;
|
||||||
|
BWindow *ContactsWindow;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
14
Contacts.cpp
Normal file
14
Contacts.cpp
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
#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;
|
||||||
|
}
|
3
Contacts.h
Normal file
3
Contacts.h
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
#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
|
all: build
|
||||||
|
|
||||||
build:
|
build:
|
||||||
$(CPP) App.cpp -o $(BINARY) $(FLAGS)
|
$(CPP) *.cpp -o $(BINARY) $(FLAGS)
|
||||||
test: build
|
test: build
|
||||||
./renga
|
./renga
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue