HaikuDepot: Added TextSpan class
This commit is contained in:
parent
aa26b5f5f0
commit
f1071521b3
|
@ -31,6 +31,7 @@ Application HaikuDepot :
|
|||
ParagraphStyle.cpp
|
||||
ParagraphStyleData.cpp
|
||||
TextLayout.cpp
|
||||
TextSpan.cpp
|
||||
TextStyle.cpp
|
||||
TextView.cpp
|
||||
|
||||
|
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* Copyright 2013, Stephan Aßmus <superstippi@gmx.de>.
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#include "TextSpan.h"
|
||||
|
||||
|
||||
TextSpan::TextSpan()
|
||||
:
|
||||
fText(),
|
||||
fStyle()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TextSpan::TextSpan(const BString& text, const TextStyle& style)
|
||||
:
|
||||
fText(text),
|
||||
fStyle(style)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TextSpan::TextSpan(const TextSpan& other)
|
||||
:
|
||||
fText(other.fText),
|
||||
fStyle(other.fStyle)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TextSpan&
|
||||
TextSpan::operator=(const TextSpan& other)
|
||||
{
|
||||
fText = other.fText;
|
||||
fStyle = other.fStyle;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
TextSpan::operator==(const TextSpan& other) const
|
||||
{
|
||||
return fText == other.fText
|
||||
&& fStyle == other.fStyle;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
TextSpan::operator!=(const TextSpan& other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TextSpan::SetText(const BString& text)
|
||||
{
|
||||
fText = text;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TextSpan::SetStyle(const TextStyle& style)
|
||||
{
|
||||
fStyle = style;
|
||||
}
|
||||
|
||||
|
||||
TextSpan
|
||||
TextSpan::SubSpan(int32 start, int32 count) const
|
||||
{
|
||||
if (start < 0) {
|
||||
count += start;
|
||||
start = 0;
|
||||
}
|
||||
|
||||
BString subString;
|
||||
|
||||
int32 charCount = fText.CountChars();
|
||||
if (start < charCount) {
|
||||
if (start + count > charCount)
|
||||
count = charCount - start;
|
||||
|
||||
fText.CopyCharsInto(subString, start, count);
|
||||
}
|
||||
|
||||
return TextSpan(subString, fStyle);
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright 2013, Stephan Aßmus <superstippi@gmx.de>.
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef TEXT_SPAN_H
|
||||
#define TEXT_SPAN_H
|
||||
|
||||
|
||||
#include <String.h>
|
||||
|
||||
#include "TextStyle.h"
|
||||
|
||||
|
||||
class TextSpan {
|
||||
public:
|
||||
TextSpan();
|
||||
TextSpan(const BString& text,
|
||||
const TextStyle& style);
|
||||
TextSpan(const TextSpan& other);
|
||||
|
||||
TextSpan& operator=(const TextSpan& other);
|
||||
bool operator==(const TextSpan& other) const;
|
||||
bool operator!=(const TextSpan& other) const;
|
||||
|
||||
void SetText(const BString& text);
|
||||
inline const BString& Text() const
|
||||
{ return fText; }
|
||||
|
||||
void SetStyle(const TextStyle& style);
|
||||
inline const TextStyle& Style() const
|
||||
{ return fStyle; }
|
||||
|
||||
TextSpan SubSpan(int32 start, int32 count) const;
|
||||
|
||||
private:
|
||||
BString fText;
|
||||
TextStyle fStyle;
|
||||
};
|
||||
|
||||
|
||||
#endif // TEXT_SPAN_H
|
Loading…
Reference in New Issue