Skip to content

Commit a9b3018

Browse files
jscipionepulkomandy
authored andcommitted
IK: align BTextView text rect/fix alignment
Preserve passed in text rect in fTextRext (unless in layout) and create an internal version fAlignedTextRect which is used in place of fTextRect. fAlignedTextRext is aligned to fit the text rect bounds and grows to fit. fAlignedTextRect always grows vertically but only grows horizontally if wrap is off. Left-aligned text view's grow right, right-aligned ones grow left, and center center aligned ones grow out. Set fTextRect to bounds in _DoLayout(). Reduce left and right padding inside text views from full label spacing to half label spacing. Unify padding between BTextControl and BTextView. Fixing padding also fixes right and center-aligned BTextViews. Undo extra scrolling for non-left text views from hrev24130 fixing a scrolling left and right with mouse bug when it shouldn't. Replace max_c and min_c with std::max and std::min respectively. Remove scrolling from one instance of BTextView::SetText as it produced undesired results while editing a scrolled text view. Set text rect in BTextControl::DoLayout() and ScreenSaver PreviewView::AddPreview(). Don't add padding if BTextView::SetInsets() is called. Set insets to 0 in Tracker "Edit name" setting which prevents default padding from being added. This is so that when you rename a file in Tracker the TextView appears on top of the file name text with no padding. 80 char limit fixes. Fixes #1651 #12608 #13796 #15189 #15688 Change-Id: I8c6106effc612f49aff374f29742471628b5df86 Reviewed-on: https://review.haiku-os.org/c/haiku/+/3054 Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
1 parent a8ea8cd commit a9b3018

File tree

9 files changed

+251
-175
lines changed

9 files changed

+251
-175
lines changed

3rdparty/mmu_man/irc/Haiku/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def download(self, irc, msg, args):
136136
to = None
137137
if len(args) > 0:
138138
to = args[0]
139-
t = "Current release: http://www.haiku-os.org/get-haiku - Nightly builds: http://haiku-files.org/haiku/development/"
139+
t = "Current release: http://www.haiku-os.org/get-haiku - Nightly builds: http://download.haiku-os.org"
140140
irc.reply(t, to = to)
141141

142142
def dl(self, irc, msg, args):

headers/os/interface/TextView.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2007-2009, Haiku, Inc. All rights reserved.
2+
* Copyright 2007-2020 Haiku, Inc. All rights reserved.
33
* Distributed under the terms of the MIT License.
44
*/
55
#ifndef _TEXTVIEW_H
@@ -416,6 +416,7 @@ class BTextView : public BView {
416416
LineBuffer* fLines;
417417
StyleBuffer* fStyles;
418418
BRect fTextRect;
419+
BRect fAlignedTextRect;
419420
int32 fSelStart;
420421
int32 fSelEnd;
421422
bool fCaretVisible;
@@ -463,7 +464,7 @@ class BTextView : public BView {
463464
bool fInstalledRemoveCommandWordwiseShortcuts : 1;
464465
bool fInstalledRemoveOptionWordwiseShortcuts : 1;
465466

466-
uint32 _reserved[6];
467+
uint32 _reserved[2];
467468
};
468469

469470
#endif // _TEXTVIEW_H

src/kits/interface/TextControl.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/*
2-
* Copyright 2001-2015, Haiku Inc.
2+
* Copyright 2001-2020 Haiku Inc. All rights reserved.
33
* Distributed under the terms of the MIT License.
44
*
55
* Authors:
66
* Frans van Nispen (xlr8@tref.nl)
77
* Stephan Aßmus <superstippi@gmx.de>
88
* Ingo Weinhold <bonefish@cs.tu-berlin.de>
9+
* John Scipione <jscipione@gmail.com>
910
*/
1011

1112

@@ -637,7 +638,6 @@ void
637638
BTextControl::SetAlignment(alignment labelAlignment, alignment textAlignment)
638639
{
639640
fText->SetAlignment(textAlignment);
640-
fText->AlignTextRect();
641641

642642
if (fLabelAlign != labelAlignment) {
643643
fLabelAlign = labelAlignment;
@@ -911,6 +911,7 @@ BTextControl::DoLayout()
911911
// place the text view and set the divider
912912
textFrame.InsetBy(kFrameMargin, kFrameMargin);
913913
BLayoutUtils::AlignInFrame(fText, textFrame);
914+
fText->SetTextRect(textFrame.OffsetToCopy(B_ORIGIN));
914915

915916
fDivider = divider;
916917

@@ -1115,7 +1116,6 @@ BTextControl::_InitText(const char* initialText, const BMessage* archive)
11151116

11161117
SetText(initialText);
11171118
fText->SetAlignment(B_ALIGN_LEFT);
1118-
fText->AlignTextRect();
11191119
}
11201120

11211121
// Although this is not strictly initializing the text view,
@@ -1171,7 +1171,6 @@ BTextControl::_LayoutTextView()
11711171
frame.InsetBy(kFrameMargin, kFrameMargin);
11721172
fText->MoveTo(frame.left, frame.top);
11731173
fText->ResizeTo(frame.Width(), frame.Height());
1174-
fText->AlignTextRect();
11751174

11761175
TRACE("width: %.2f, height: %.2f\n", Frame().Width(), Frame().Height());
11771176
TRACE("fDivider: %.2f\n", fDivider);

src/kits/interface/TextInput.cpp

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
/*
2-
* Copyright 2001-2015, Haiku Inc. All rights reserved.
2+
* Copyright 2001-2020 Haiku Inc. All rights reserved.
33
* Distributed under the terms of the MIT License.
44
*
55
* Authors:
66
* Frans van Nispen (xlr8@tref.nl)
77
* Marc Flerackers (mflerackers@androme.be)
8+
* John Scipione (jscipione@gmail.com)
89
*/
910

1011

@@ -14,7 +15,6 @@
1415
#include <stdlib.h>
1516
#include <string.h>
1617

17-
#include <ControlLook.h>
1818
#include <InterfaceDefs.h>
1919
#include <LayoutUtils.h>
2020
#include <Message.h>
@@ -84,8 +84,6 @@ void
8484
_BTextInput_::FrameResized(float width, float height)
8585
{
8686
BTextView::FrameResized(width, height);
87-
88-
AlignTextRect();
8987
}
9088

9189

@@ -162,42 +160,6 @@ _BTextInput_::MinSize()
162160
}
163161

164162

165-
void
166-
_BTextInput_::AlignTextRect()
167-
{
168-
// the label font could require the control to be higher than
169-
// necessary for the text view, we compensate this by layouting
170-
// the text rect to be in the middle, normally this means there
171-
// is one pixel spacing on each side
172-
BRect textRect(Bounds());
173-
float vInset = max_c(1,
174-
floorf((textRect.Height() - LineHeight(0)) / 2.0));
175-
float hInset = 2;
176-
float textFontWidth = TextRect().right;
177-
178-
switch (Alignment()) {
179-
case B_ALIGN_LEFT:
180-
hInset = be_control_look->DefaultLabelSpacing();
181-
break;
182-
183-
case B_ALIGN_RIGHT:
184-
hInset = textRect.right - textFontWidth;
185-
hInset -= be_control_look->DefaultLabelSpacing();
186-
break;
187-
188-
case B_ALIGN_CENTER:
189-
hInset = (textRect.right - textFontWidth) / 2.0;
190-
break;
191-
192-
default:
193-
break;
194-
}
195-
196-
textRect.InsetBy(hInset, vInset);
197-
SetTextRect(textRect);
198-
}
199-
200-
201163
void
202164
_BTextInput_::SetInitialText()
203165
{

src/kits/interface/TextInput.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2001-2008, Haiku Inc. All rights reserved.
2+
* Copyright 2001-2020 Haiku Inc. All rights reserved.
33
* Distributed under the terms of the MIT License.
44
*
55
* Authors:
@@ -11,6 +11,7 @@
1111
#ifndef _TEXT_CONTROLI_H
1212
#define _TEXT_CONTROLI_H
1313

14+
1415
#include <TextView.h>
1516

1617

@@ -36,7 +37,6 @@ virtual void MakeFocus(bool focusState = true);
3637

3738
virtual BSize MinSize();
3839

39-
void AlignTextRect();
4040
void SetInitialText();
4141

4242
virtual void Paste(BClipboard *clipboard);

0 commit comments

Comments
 (0)