From 457e5ee245fe519cef2d785a2938ae2449daeb6e Mon Sep 17 00:00:00 2001 From: Zach Dykstra Date: Mon, 3 Apr 2023 20:19:36 -0500 Subject: [PATCH] mail: switch 'Set to' window to use layout lib 'File -> Close and -> Set to' used a hard-coded window size and control/button layout. Switch this to use the layout library for proper scaling. Change-Id: Ieeed93da82fb6bdcca852e3bb2f5a3315222ec27 Reviewed-on: https://review.haiku-os.org/c/haiku/+/6303 Reviewed-by: waddlesplash --- src/apps/mail/MailWindow.cpp | 5 ---- src/apps/mail/Status.cpp | 57 ++++++++++++------------------------ src/apps/mail/Status.h | 3 -- 3 files changed, 18 insertions(+), 47 deletions(-) diff --git a/src/apps/mail/MailWindow.cpp b/src/apps/mail/MailWindow.cpp index a0dd10badb..79aac919dd 100644 --- a/src/apps/mail/MailWindow.cpp +++ b/src/apps/mail/MailWindow.cpp @@ -1327,11 +1327,6 @@ TMailWindow::MessageReceived(BMessage* msg) PostMessage(&message); } else { BRect r = Frame(); - r.left += ((r.Width() - STATUS_WIDTH) / 2); - r.right = r.left + STATUS_WIDTH; - r.top += 40; - r.bottom = r.top + STATUS_HEIGHT; - BString string = "could not read"; BNode node(fRef); if (node.InitCheck() == B_OK) diff --git a/src/apps/mail/Status.cpp b/src/apps/mail/Status.cpp index dce4065c3e..fa7b06567c 100644 --- a/src/apps/mail/Status.cpp +++ b/src/apps/mail/Status.cpp @@ -37,6 +37,7 @@ All rights reserved. #include #include #include +#include #include #include #include @@ -54,27 +55,6 @@ All rights reserved. #include "Messages.h" -#define STATUS_TEXT "Status:" -#define STATUS_FIELD_H 10 -#define STATUS_FIELD_V 8 -#define STATUS_FIELD_WIDTH (STATUS_WIDTH - STATUS_FIELD_H) -#define STATUS_FIELD_HEIGHT 16 - -#define BUTTON_WIDTH 70 -#define BUTTON_HEIGHT 20 - -#define S_OK_BUTTON_X1 (STATUS_WIDTH - BUTTON_WIDTH - 6) -#define S_OK_BUTTON_Y1 (STATUS_HEIGHT - (BUTTON_HEIGHT + 10)) -#define S_OK_BUTTON_X2 (S_OK_BUTTON_X1 + BUTTON_WIDTH) -#define S_OK_BUTTON_Y2 (S_OK_BUTTON_Y1 + BUTTON_HEIGHT) -#define S_OK_BUTTON_TEXT "OK" - -#define S_CANCEL_BUTTON_X1 (S_OK_BUTTON_X1 - (BUTTON_WIDTH + 10)) -#define S_CANCEL_BUTTON_Y1 S_OK_BUTTON_Y1 -#define S_CANCEL_BUTTON_X2 (S_CANCEL_BUTTON_X1 + BUTTON_WIDTH) -#define S_CANCEL_BUTTON_Y2 S_OK_BUTTON_Y2 -#define S_CANCEL_BUTTON_TEXT "Cancel" - enum status_messages { STATUS = 128, OK, @@ -86,28 +66,27 @@ TStatusWindow::TStatusWindow(BRect rect, BMessenger target, const char* status) : BWindow(rect, "", B_MODAL_WINDOW, B_NOT_RESIZABLE), fTarget(target) { - BView* view = new BView(Bounds(), "", B_FOLLOW_ALL, B_WILL_DRAW); - view->SetViewUIColor(B_PANEL_BACKGROUND_COLOR); - AddChild(view); + fStatus = new BTextControl("status", "Status:", status, + new BMessage(STATUS)); - BRect r(STATUS_FIELD_H, STATUS_FIELD_V, - STATUS_FIELD_WIDTH, STATUS_FIELD_V + STATUS_FIELD_HEIGHT); + BButton *ok = new BButton("ok", "OK", new BMessage(OK)); + ok->MakeDefault(true); - fStatus = new BTextControl(r, "", STATUS_TEXT, status, new BMessage(STATUS)); - view->AddChild(fStatus); + BButton *cancel = new BButton("cancel", "Cancel", new BMessage(CANCEL)); + + BLayoutBuilder::Group<>(this, B_VERTICAL, 0) + .SetInsets(B_USE_DEFAULT_SPACING) + .AddGroup(B_HORIZONTAL, 0) + .Add(fStatus) + .End() + .AddStrut(B_USE_SMALL_SPACING) + .AddGroup(B_HORIZONTAL, B_USE_SMALL_SPACING, 0) + .AddStrut(B_USE_SMALL_SPACING) + .Add(cancel) + .Add(ok); - fStatus->SetDivider(fStatus->StringWidth(STATUS_TEXT) + 6); fStatus->BTextControl::MakeFocus(true); - - r.Set(S_OK_BUTTON_X1, S_OK_BUTTON_Y1, S_OK_BUTTON_X2, S_OK_BUTTON_Y2); - BButton *button = new BButton(r, "", S_OK_BUTTON_TEXT, new BMessage(OK)); - view->AddChild(button); - button->MakeDefault(true); - - r.Set(S_CANCEL_BUTTON_X1, S_CANCEL_BUTTON_Y1, S_CANCEL_BUTTON_X2, S_CANCEL_BUTTON_Y2); - button = new BButton(r, "", S_CANCEL_BUTTON_TEXT, new BMessage(CANCEL)); - view->AddChild(button); - + ResizeToPreferred(); Show(); } diff --git a/src/apps/mail/Status.h b/src/apps/mail/Status.h index d4ca47f89b..364ac86849 100644 --- a/src/apps/mail/Status.h +++ b/src/apps/mail/Status.h @@ -43,9 +43,6 @@ class BTextControl; #define INDEX_STATUS "_status" -#define STATUS_WIDTH 220 -#define STATUS_HEIGHT 80 - class TStatusWindow : public BWindow { public: