HaikuDepot: Refactor usage conditions windows.

* Set only a minimum width and then resize to preferred on window.
 * Set a minimum height for the text view itself.
 * Use the new TextView controls instead of the old BTextView.
 * Adjust other size constraints as needed.

Fixes #17998.
This commit is contained in:
Augustin Cavalier 2022-10-19 14:25:09 -04:00
parent 6a4c3457cf
commit 46a2beb0f8
4 changed files with 30 additions and 50 deletions

View File

@ -14,7 +14,6 @@
#include <LayoutBuilder.h>
#include <Locker.h>
#include <SeparatorView.h>
#include <TextView.h>
#include "AppUtils.h"
#include "LinkView.h"
@ -24,14 +23,13 @@
#include "UserUsageConditionsWindow.h"
#include "ServerHelper.h"
#include "WebAppInterface.h"
#include "TextView.h"
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "ToLatestUserUsageConditionsWindow"
#define PLACEHOLDER_TEXT B_UTF8_ELLIPSIS
#define WINDOW_FRAME BRect(0, 0, 500, 280)
#define KEY_USER_USAGE_CONDITIONS "userUsageConditions"
#define NO_PRIOR_MESSAGE_TEXT "The user [%Nickname%] has authenticated, but " \
@ -54,10 +52,10 @@ ToLatestUserUsageConditionsWindow::ToLatestUserUsageConditionsWindow(
BWindow* parent,
Model& model, const UserDetail& userDetail)
:
BWindow(WINDOW_FRAME, B_TRANSLATE("Update usage conditions"),
BWindow(BRect(), B_TRANSLATE("Update usage conditions"),
B_FLOATING_WINDOW_LOOK, B_MODAL_SUBSET_WINDOW_FEEL,
B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS
| B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_NOT_CLOSABLE ),
| B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_NOT_CLOSABLE),
fModel(model),
fUserDetail(userDetail),
fWorkerThread(-1),
@ -91,6 +89,8 @@ ToLatestUserUsageConditionsWindow::ToLatestUserUsageConditionsWindow(
.Add(fWorkerIndicator, 1)
.SetInsets(B_USE_WINDOW_INSETS);
GetLayout()->SetExplicitMinSize(BSize(500, B_SIZE_UNSET));
ResizeToPreferred();
CenterOnScreen();
_FetchData();
@ -110,10 +110,7 @@ ToLatestUserUsageConditionsWindow::~ToLatestUserUsageConditionsWindow()
void
ToLatestUserUsageConditionsWindow::_InitUiControls()
{
fMessageTextView = new BTextView("message text view");
fMessageTextView->AdoptSystemColors();
fMessageTextView->MakeEditable(false);
fMessageTextView->MakeSelectable(false);
fMessageTextView = new TextView("message text view");
BString message;
if (fUserDetail.Agreement().Code().IsEmpty())
message = B_TRANSLATE(NO_PRIOR_MESSAGE_TEXT);
@ -445,4 +442,4 @@ ToLatestUserUsageConditionsWindow::_HandleAgree()
debugger("the user has not agreed to the age and conditions");
_Agree();
}
}

View File

@ -16,7 +16,7 @@
class BButton;
class BCheckBox;
class BTextView;
class TextView;
class LinkView;
class Model;
@ -59,7 +59,7 @@ private:
Model& fModel;
UserDetail fUserDetail;
BTextView* fMessageTextView;
TextView* fMessageTextView;
BButton* fLogoutButton;
BButton* fAgreeButton;
BCheckBox* fConfirmMinimumAgeCheckBox;

View File

@ -11,7 +11,6 @@
#include <LayoutBuilder.h>
#include <ScrollView.h>
#include <StringView.h>
#include <TextView.h>
#include "AppUtils.h"
#include "BarberPole.h"
@ -22,6 +21,7 @@
#include "Model.h"
#include "UserUsageConditions.h"
#include "ServerHelper.h"
#include "TextView.h"
#include "WebAppInterface.h"
@ -48,13 +48,11 @@
#define LINES_INTRODUCTION_TEXT 2
#define WINDOW_FRAME BRect(0, 0, 500, 400)
UserUsageConditionsWindow::UserUsageConditionsWindow(Model& model,
UserUsageConditions& userUsageConditions)
:
BWindow(WINDOW_FRAME, B_TRANSLATE("Usage conditions"),
BWindow(BRect(), B_TRANSLATE("Usage conditions"),
B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS
| B_NOT_RESIZABLE | B_NOT_ZOOMABLE),
@ -65,8 +63,13 @@ UserUsageConditionsWindow::UserUsageConditionsWindow(Model& model,
{
_InitUiControls();
font_height fontHeight;
be_plain_font->GetHeight(&fontHeight);
const float lineHeight = fontHeight.ascent + fontHeight.descent;
BScrollView* scrollView = new BScrollView("copy scroll view", fCopyView,
0, false, true, B_PLAIN_BORDER);
scrollView->SetExplicitMinSize(BSize(B_SIZE_UNSET, lineHeight * 6));
BButton* okButton = new BButton("ok", B_TRANSLATE("OK"),
new BMessage(B_QUIT_REQUESTED));
@ -81,6 +84,8 @@ UserUsageConditionsWindow::UserUsageConditionsWindow(Model& model,
.End()
.End();
GetLayout()->SetExplicitMinSize(BSize(500, B_SIZE_UNSET));
ResizeToPreferred();
CenterOnScreen();
UserDetail userDetail;
@ -91,7 +96,7 @@ UserUsageConditionsWindow::UserUsageConditionsWindow(Model& model,
UserUsageConditionsWindow::UserUsageConditionsWindow(
Model& model, UserUsageConditionsSelectionMode mode)
:
BWindow(WINDOW_FRAME, B_TRANSLATE("Usage conditions"),
BWindow(BRect(), B_TRANSLATE("Usage conditions"),
B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS
| B_NOT_RESIZABLE | B_NOT_ZOOMABLE),
@ -101,25 +106,22 @@ UserUsageConditionsWindow::UserUsageConditionsWindow(
{
_InitUiControls();
font_height fontHeight;
be_plain_font->GetHeight(&fontHeight);
const float lineHeight = fontHeight.ascent + fontHeight.descent;
fWorkerIndicator = new BarberPole("fetch data worker indicator");
BSize workerIndicatorSize;
workerIndicatorSize.SetHeight(20);
workerIndicatorSize.SetHeight(lineHeight);
fWorkerIndicator->SetExplicitSize(workerIndicatorSize);
fIntroductionTextView = new BTextView("introduction text view");
fIntroductionTextView->AdoptSystemColors();
fIntroductionTextView->MakeEditable(false);
fIntroductionTextView->MakeSelectable(false);
fIntroductionTextView = new TextView("introduction text view");
UserDetail userDetail;
fIntroductionTextView->SetText(_IntroductionTextForMode(mode, userDetail));
BSize introductionSize;
introductionSize.SetHeight(
_ExpectedIntroductionTextHeight(fIntroductionTextView));
fIntroductionTextView->SetExplicitPreferredSize(introductionSize);
BScrollView* scrollView = new BScrollView("copy scroll view", fCopyView,
0, false, true, B_PLAIN_BORDER);
scrollView->SetExplicitMinSize(BSize(B_SIZE_UNSET, lineHeight * 6));
BButton* okButton = new BButton("ok", B_TRANSLATE("OK"),
new BMessage(B_QUIT_REQUESTED));
@ -137,6 +139,8 @@ UserUsageConditionsWindow::UserUsageConditionsWindow(
.Add(fWorkerIndicator, 1)
.End();
GetLayout()->SetExplicitMinSize(BSize(500, B_SIZE_UNSET));
ResizeToPreferred();
CenterOnScreen();
_FetchData();
@ -164,8 +168,6 @@ UserUsageConditionsWindow::_InitUiControls()
fAgeNoteStringView = new BStringView("age note string view",
PLACEHOLDER_TEXT);
fAgeNoteStringView->AdoptSystemColors();
fAgeNoteStringView->SetExplicitMaxSize(
BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
BFont versionFont(be_plain_font);
versionFont.SetSize(versionFont.Size() * 0.75f);
@ -176,8 +178,6 @@ UserUsageConditionsWindow::_InitUiControls()
fVersionStringView->SetFont(&versionFont);
fVersionStringView->SetAlignment(B_ALIGN_RIGHT);
fVersionStringView->SetHighUIColor(B_PANEL_TEXT_COLOR, B_DARKEN_3_TINT);
fVersionStringView->SetExplicitMaxSize(
BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
}
@ -474,18 +474,3 @@ UserUsageConditionsWindow::_IntroductionTextForMode(
return "???";
}
}
/*static*/ float
UserUsageConditionsWindow::_ExpectedIntroductionTextHeight(
BTextView* introductionTextView)
{
float insetTop;
float insetBottom;
introductionTextView->GetInsets(NULL, &insetTop, NULL, &insetBottom);
font_height fh;
be_plain_font->GetHeight(&fh);
return ((fh.ascent + fh.descent + fh.leading) * LINES_INTRODUCTION_TEXT)
+ insetTop + insetBottom;
}

View File

@ -16,7 +16,7 @@
class BarberPole;
class BTextView;
class TextView;
class BStringView;
class MarkupTextView;
class Model;
@ -41,8 +41,6 @@ private:
static const BString _IntroductionTextForMode(
UserUsageConditionsSelectionMode mode,
const UserDetail& userDetail);
static float _ExpectedIntroductionTextHeight(
BTextView* introductionTextView);
void _DisplayData(const UserDetail& userDetail,
const UserUsageConditions&
@ -65,7 +63,7 @@ private:
Model& fModel;
BStringView* fAgeNoteStringView;
BStringView* fVersionStringView;
BTextView* fIntroductionTextView;
TextView* fIntroductionTextView;
BarberPole* fWorkerIndicator;
thread_id fWorkerThread;
};