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

View File

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

View File

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