App.cpp: make UI base (add group layouts and allat)

Signed-off-by: hex <hex@iwakura.rip>
This commit is contained in:
hexlocation 2025-02-08 10:29:06 +00:00
parent f5f26b7025
commit 0ff2dae233

41
App.cpp
View file

@ -1,19 +1,48 @@
#include "App.h"
#include <Application.h>
#include <GroupLayout.h>
#include <InterfaceDefs.h>
#include <Layout.h>
#include <LayoutItem.h>
#include <Rect.h>
#include <Window.h>
#include <String.h>
#include <StringView.h>
#include <GroupLayoutBuilder.h>
// quick and dirty function to quickly make text labels
BStringView *MakeText(const char* text)
{
return new BStringView("rstr", text);
}
App::App(void) : BApplication("application/x-vnd.hex-Renga")
{
// Initialize BRect frame for window
BRect frame(100, 100, 500, 400);
BWindow *myWindow = new BWindow(frame, "Hello World!", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE);
frame.Set(10,10,11,11);
BStringView *label = new BStringView(frame, "melabel", "This is a label!");
label->ResizeToPreferred();
myWindow->AddChild(label);
myWindow->Show();
// 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, "Hello World!", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE);
// Set window layout to parent group created earlier
window->SetLayout(pGroup);
// Initialize special "label" group for all of our labels
BGroupLayout *lGroup = new BGroupLayout(B_HORIZONTAL, 100);
// Add label group to parent group
pGroup->AddItem(lGroup);
// Center label group
lGroup->SetExplicitAlignment(BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER));
// And finally, add allat labels!!
lGroup->AddView(MakeText("label 1"));
lGroup->AddView(MakeText("label 2"));
lGroup->AddView(MakeText("label 3"));
window->Show();
}
int main(void)