BTextView: Use document colors on AdoptSystemColors()

AdoptSystemColors() tints document background color to match panel
color if uneditable.

Calling MakeEditable() will automatically apply or unapply uneditable
background tint if you have previously called AdoptSystemColors().

Parent BView::AdoptSystemColors() sets panel colors, we want document
colors here. Do not alter text color - only view, low and high colors
are changed.

Document AdoptSystemColors() and MakeEditable() in BTextView docs.

Change-Id: Ib215735f27bb01fc2f95fcf2fee0185e5fc83f70
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8263
Haiku-Format: Haiku-format Bot <no-reply+haikuformatbot@haiku-os.org>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
This commit is contained in:
John Scipione 2024-09-09 12:44:20 -04:00 committed by waddlesplash
parent 13553050f9
commit 9105063938
3 changed files with 78 additions and 3 deletions

View File

@ -183,6 +183,8 @@
to be selectable or editable off. A non-editable, non-selectable text to be selectable or editable off. A non-editable, non-selectable text
view can be useful as a BStringView that wraps. view can be useful as a BStringView that wraps.
Call AdoptSystemColors() to set default colors.
Call MakeResizable() to make the view width track with text width, Call MakeResizable() to make the view width track with text width,
this can be useful for short single-line text views. this can be useful for short single-line text views.
@ -1226,9 +1228,14 @@
\fn void BTextView::MakeEditable(bool editable) \fn void BTextView::MakeEditable(bool editable)
\brief Sets whether or not the text is editable. \brief Sets whether or not the text is editable.
Will automatically tint document colors to indicate uneditable
if you have previously called AdoptSystemColors().
\param editable Pass in \c true to set the text to be editable, \param editable Pass in \c true to set the text to be editable,
\c false to set the object to be not editable. \c false to set the object to be not editable.
\see AdoptSystemColors()
\since BeOS R3 \since BeOS R3
*/ */
@ -1341,13 +1348,41 @@
/*! /*!
\name Word Wrap \name Color Adoption
*/ */
//! @{ //! @{
/*!
\fn BTextView::AdoptSystemColors()
\brief Adopts document colors tinted to match panel background if uneditable.
- \c B_DOCUMENT_BACKGROUND_COLOR for ViewUIColor()
- \c B_DOCUMENT_BACKGROUND_COLOR for LowUIColor()
- \c B_DOCUMENT_TEXT_COLOR for HighUIColor()
View and low colors tinted \c B_DARKEN_1_TINT (inverse on dark) if uneditable.
Does not alter text color.
\see BView::AdoptSystemColors(), MakeEditable()
\since Haiku R1
*/
//! @}
/*!
\name Word Wrap
*/
//! @{
/*! /*!
\fn void BTextView::SetWordWrap(bool wrap) \fn void BTextView::SetWordWrap(bool wrap)

View File

@ -131,6 +131,8 @@ public:
void SelectAll(); void SelectAll();
void GetSelection(int32* _start, int32* _end) const; void GetSelection(int32* _start, int32* _end) const;
void AdoptSystemColors();
void SetFontAndColor(const BFont* font, void SetFontAndColor(const BFont* font,
uint32 mode = B_FONT_ALL, uint32 mode = B_FONT_ALL,
const rgb_color* color = NULL); const rgb_color* color = NULL);
@ -426,6 +428,9 @@ private:
float _TextHeight(); float _TextHeight();
BRect _TextRect(); BRect _TextRect();
float _UneditableTint();
bool _UsesSystemColors();
private: private:
BPrivate::TextGapBuffer* fText; BPrivate::TextGapBuffer* fText;
LineBuffer* fLines; LineBuffer* fLines;

View File

@ -1589,8 +1589,20 @@ BTextView::GetSelection(int32* _start, int32* _end) const
void void
BTextView::SetFontAndColor(const BFont* font, uint32 mode, BTextView::AdoptSystemColors()
const rgb_color* color) {
if (IsEditable())
SetViewUIColor(B_DOCUMENT_BACKGROUND_COLOR);
else
SetViewUIColor(B_DOCUMENT_BACKGROUND_COLOR, _UneditableTint());
SetLowUIColor(ViewUIColor());
SetHighUIColor(B_DOCUMENT_TEXT_COLOR);
}
void
BTextView::SetFontAndColor(const BFont* font, uint32 mode, const rgb_color* color)
{ {
SetFontAndColor(fSelStart, fSelEnd, font, mode, color); SetFontAndColor(fSelStart, fSelEnd, font, mode, color);
} }
@ -2371,6 +2383,11 @@ BTextView::MakeEditable(bool editable)
return; return;
fEditable = editable; fEditable = editable;
// apply uneditable colors or unapply them
if (_UsesSystemColors())
AdoptSystemColors();
// TextControls change the color of the text when // TextControls change the color of the text when
// they are made editable, so we need to invalidate // they are made editable, so we need to invalidate
// the NULL style here // the NULL style here
@ -6093,6 +6110,24 @@ BTextView::_TextRect()
} }
float
BTextView::_UneditableTint()
{
return ui_color(B_DOCUMENT_BACKGROUND_COLOR).IsLight() ? B_DARKEN_1_TINT : 0.853;
}
bool
BTextView::_UsesSystemColors()
{
float tint = B_NO_TINT;
return ViewUIColor(&tint) == B_DOCUMENT_BACKGROUND_COLOR
&& LowUIColor(&tint) == B_DOCUMENT_BACKGROUND_COLOR
&& HighUIColor() == B_DOCUMENT_TEXT_COLOR;
}
// #pragma mark - BTextView::TextTrackState // #pragma mark - BTextView::TextTrackState