[DEV] Multiline button is OK ==> gui display is not compleately ended

This commit is contained in:
Edouard DUPIN 2012-11-29 22:13:54 +01:00
parent d69a964459
commit fbcb6148ad
4 changed files with 366 additions and 218 deletions

View File

@ -165,14 +165,21 @@ void ewol::Text::Clear(void)
m_coordTex.Clear();
m_coordColor.Clear();
// Reset temporal variables :
Reset();
}
void ewol::Text::Reset(void)
{
m_position = etk::Vector3D<float>(0.0, 0.0, 0.0);
m_clippingPosStart = etk::Vector3D<float>(0.0, 0.0, 0.0);
m_clippingPosStop = etk::Vector3D<float>(0.0, 0.0, 0.0);
m_sizeDisplayStart = m_position;
m_sizeDisplayStop = m_position;
m_nbCharDisplayed = 0;
m_clippingEnable = false;
m_color = draw::color::black;
m_colorBg = draw::color::none;
m_mode = ewol::font::Regular;
m_kerning = false;
m_previousCharcode = 0;
m_startTextpos = 0;
m_stopTextPos = 0;
@ -181,6 +188,8 @@ void ewol::Text::Clear(void)
m_selectionStartPos = -100;
m_cursorPos = -100;
m_htmlDecoration.Clear();
m_needDisplay = true;
m_nbCharDisplayed = 0;
}
@ -192,9 +201,33 @@ etk::Vector3D<float> ewol::Text::GetPos(void)
void ewol::Text::SetPos(etk::Vector3D<float> pos)
{
// check min max for display area
if (m_nbCharDisplayed != 0) {
EWOL_VERBOSE("update size 1 " << m_sizeDisplayStart << " " << m_sizeDisplayStop);
m_sizeDisplayStop.x = etk_max(m_position.x, m_sizeDisplayStop.x);
m_sizeDisplayStop.y = etk_max(m_position.y, m_sizeDisplayStop.y);
m_sizeDisplayStart.x = etk_min(m_position.x, m_sizeDisplayStart.x);
m_sizeDisplayStart.y = etk_min(m_position.y, m_sizeDisplayStart.y);
EWOL_VERBOSE("update size 2 " << m_sizeDisplayStart << " " << m_sizeDisplayStop);
}
// update position
m_position = pos;
m_previousCharcode = 0;
m_vectorialDraw.SetPos(m_position);
// update min max of the display area:
if (m_nbCharDisplayed == 0) {
m_sizeDisplayStart = m_position;
m_sizeDisplayStop = m_position;
m_sizeDisplayStop.y += m_font->GetHeight(m_mode);
EWOL_VERBOSE("update size 0 " << m_sizeDisplayStart << " " << m_sizeDisplayStop);
} else {
EWOL_VERBOSE("update size 3 " << m_sizeDisplayStart << " " << m_sizeDisplayStop);
m_sizeDisplayStop.x = etk_max(m_position.x, m_sizeDisplayStop.x);
m_sizeDisplayStop.y = etk_max(m_position.y, m_sizeDisplayStop.y);
m_sizeDisplayStart.x = etk_min(m_position.x, m_sizeDisplayStart.x);
m_sizeDisplayStart.y = etk_min(m_position.y, m_sizeDisplayStart.y);
EWOL_VERBOSE("update size 4 " << m_sizeDisplayStart << " " << m_sizeDisplayStop);
}
}
@ -380,80 +413,85 @@ void ewol::Text::Print(const etk::UString& text)
void ewol::Text::ParseHtmlNode(void* element2)
{
// get the static real pointer
TiXmlNode* element = static_cast<TiXmlNode*>(element2);
if (NULL != element) {
/*const char *myData = element->ToElement()->GetText();
if (NULL != myData) {
etk::UString outputData(myData);
Print(myData);
} else {
*/
for (TiXmlNode * child = element->FirstChild(); NULL != child ; child = child->NextSibling() ) {
if (child->Type()==TiXmlNode::TINYXML_COMMENT) {
// nothing to do ...
} else if (child->Type()==TiXmlNode::TINYXML_TEXT) {
HtmlAddData(child->Value() );
} else if (!strcmp(child->Value(), "br")) {
HtmlFlush();
ForceLineReturn();
} else if (!strcmp(child->Value(), "font")) {
TextDecoration tmpDeco = m_htmlDecoTmp;
const char *colorValue = child->ToElement()->Attribute("color");
if (NULL != colorValue) {
draw::ParseColor(colorValue, m_htmlDecoTmp.m_colorFg);
}
colorValue = child->ToElement()->Attribute("colorBg");
if (NULL != colorValue) {
draw::ParseColor(colorValue, m_htmlDecoTmp.m_colorBg);
}
ParseHtmlNode(child);
m_htmlDecoTmp = tmpDeco;
} else if (!strcmp(child->Value(), "b")) {
TextDecoration tmpDeco = m_htmlDecoTmp;
if (m_htmlDecoTmp.m_mode == ewol::font::Regular) {
m_htmlDecoTmp.m_mode = ewol::font::Bold;
} else if (m_htmlDecoTmp.m_mode == ewol::font::Italic) {
m_htmlDecoTmp.m_mode = ewol::font::BoldItalic;
}
ParseHtmlNode(child);
m_htmlDecoTmp = tmpDeco;
} else if (!strcmp(child->Value(), "i")) {
TextDecoration tmpDeco = m_htmlDecoTmp;
if (m_htmlDecoTmp.m_mode == ewol::font::Regular) {
m_htmlDecoTmp.m_mode = ewol::font::Italic;
} else if (m_htmlDecoTmp.m_mode == ewol::font::Bold) {
m_htmlDecoTmp.m_mode = ewol::font::BoldItalic;
}
ParseHtmlNode(child);
m_htmlDecoTmp = tmpDeco;
} else if (!strcmp(child->Value(), "u")) {
ParseHtmlNode(child);
} else if (!strcmp(child->Value(), "p")) {
HtmlFlush();
m_alignement = ewol::Text::alignLeft;
ForceLineReturn();
ParseHtmlNode(child);
ForceLineReturn();
} else if (!strcmp(child->Value(), "center")) {
HtmlFlush();
m_alignement = ewol::Text::alignCenter;
ParseHtmlNode(child);
} else if (!strcmp(child->Value(), "left")) {
HtmlFlush();
m_alignement = ewol::Text::alignLeft;
ParseHtmlNode(child);
} else if (!strcmp(child->Value(), "right")) {
HtmlFlush();
m_alignement = ewol::Text::alignRight;
ParseHtmlNode(child);
} else if (!strcmp(child->Value(), "justify")) {
HtmlFlush();
m_alignement = ewol::Text::alignJustify;
ParseHtmlNode(child);
} else {
EWOL_ERROR("(l "<< child->Row() << ") node not suported type : " << child->Type() << " val=\""<< child->Value() << "\"" );
for (TiXmlNode * child = element->FirstChild(); NULL != child ; child = child->NextSibling() ) {
if (child->Type()==TiXmlNode::TINYXML_COMMENT) {
// nothing to do ...
} else if (child->Type()==TiXmlNode::TINYXML_TEXT) {
HtmlAddData(child->Value() );
EWOL_VERBOSE("XML Add : " << child->Value());
} else if (!strcmp(child->Value(), "br")) {
HtmlFlush();
EWOL_VERBOSE("XML flush & newLine");
ForceLineReturn();
} else if (!strcmp(child->Value(), "font")) {
EWOL_VERBOSE("XML Font ...");
TextDecoration tmpDeco = m_htmlDecoTmp;
const char *colorValue = child->ToElement()->Attribute("color");
if (NULL != colorValue) {
draw::ParseColor(colorValue, m_htmlDecoTmp.m_colorFg);
}
//}
colorValue = child->ToElement()->Attribute("colorBg");
if (NULL != colorValue) {
draw::ParseColor(colorValue, m_htmlDecoTmp.m_colorBg);
}
ParseHtmlNode(child);
m_htmlDecoTmp = tmpDeco;
} else if (!strcmp(child->Value(), "b")) {
EWOL_VERBOSE("XML b ...");
TextDecoration tmpDeco = m_htmlDecoTmp;
if (m_htmlDecoTmp.m_mode == ewol::font::Regular) {
m_htmlDecoTmp.m_mode = ewol::font::Bold;
} else if (m_htmlDecoTmp.m_mode == ewol::font::Italic) {
m_htmlDecoTmp.m_mode = ewol::font::BoldItalic;
}
ParseHtmlNode(child);
m_htmlDecoTmp = tmpDeco;
} else if (!strcmp(child->Value(), "i")) {
EWOL_VERBOSE("XML i ...");
TextDecoration tmpDeco = m_htmlDecoTmp;
if (m_htmlDecoTmp.m_mode == ewol::font::Regular) {
m_htmlDecoTmp.m_mode = ewol::font::Italic;
} else if (m_htmlDecoTmp.m_mode == ewol::font::Bold) {
m_htmlDecoTmp.m_mode = ewol::font::BoldItalic;
}
ParseHtmlNode(child);
m_htmlDecoTmp = tmpDeco;
} else if (!strcmp(child->Value(), "u")) {
EWOL_VERBOSE("XML u ...");
ParseHtmlNode(child);
} else if (!strcmp(child->Value(), "p")) {
EWOL_VERBOSE("XML p ...");
HtmlFlush();
m_alignement = ewol::Text::alignLeft;
ForceLineReturn();
ParseHtmlNode(child);
ForceLineReturn();
} else if (!strcmp(child->Value(), "center")) {
EWOL_VERBOSE("XML center ...");
HtmlFlush();
m_alignement = ewol::Text::alignCenter;
ParseHtmlNode(child);
} else if (!strcmp(child->Value(), "left")) {
EWOL_VERBOSE("XML left ...");
HtmlFlush();
m_alignement = ewol::Text::alignLeft;
ParseHtmlNode(child);
} else if (!strcmp(child->Value(), "right")) {
EWOL_VERBOSE("XML right ...");
HtmlFlush();
m_alignement = ewol::Text::alignRight;
ParseHtmlNode(child);
} else if (!strcmp(child->Value(), "justify")) {
EWOL_VERBOSE("XML justify ...");
HtmlFlush();
m_alignement = ewol::Text::alignJustify;
ParseHtmlNode(child);
} else {
EWOL_ERROR("(l "<< child->Row() << ") node not suported type : " << child->Type() << " val=\""<< child->Value() << "\"" );
}
}
}
}
@ -467,7 +505,7 @@ void ewol::Text::PrintDecorated(etk::UString& text)
PrintHTML(tmpData);
}
void ewol::Text::PrintHTML(etk::UString& text)
void ewol::Text::PrintHTML(etk::UString text)
{
TiXmlDocument XmlDocument;
@ -490,7 +528,7 @@ void ewol::Text::PrintHTML(etk::UString& text)
return;
}
TiXmlElement* bodyNode = root->FirstChildElement( "body" );
ParseHtmlNode(bodyNode);
(void)ParseHtmlNode(bodyNode);
HtmlFlush();
}
@ -503,10 +541,12 @@ void ewol::Text::Print(const etk::UString& text, const etk::Vector<TextDecoratio
draw::Color tmpFg(m_color);
draw::Color tmpBg(m_colorBg);
if (m_alignement == ewol::Text::alignDisable) {
if (0==m_cursorPos) {
m_vectorialDraw.SetPos(m_position);
SetColorBg(m_colorCursor);
PrintCursor(false);
if (true == m_needDisplay) {
if (0==m_cursorPos) {
m_vectorialDraw.SetPos(m_position);
SetColorBg(m_colorCursor);
PrintCursor(false);
}
}
// note this is faster when nothing is requested ...
for(int32_t iii=0; iii<text.Size(); iii++) {
@ -515,34 +555,41 @@ void ewol::Text::Print(const etk::UString& text, const etk::Vector<TextDecoratio
tmpBg = decoration[iii].m_colorBg;
SetFontMode(decoration[iii].m_mode);
}
if( ( m_selectionStartPos-1<iii
&& iii <=m_cursorPos-1)
|| ( m_selectionStartPos-1>=iii
&& iii > m_cursorPos-1) ) {
SetColor( 0x000000FF);
SetColorBg(m_colorSelection);
} else {
SetColor( tmpFg);
SetColorBg(tmpBg);
if (true == m_needDisplay) {
if( ( m_selectionStartPos-1<iii
&& iii <=m_cursorPos-1)
|| ( m_selectionStartPos-1>=iii
&& iii > m_cursorPos-1) ) {
SetColor( 0x000000FF);
SetColorBg(m_colorSelection);
} else {
SetColor( tmpFg);
SetColorBg(tmpBg);
}
}
if (m_colorBg.a != 0) {
if( true == m_needDisplay
&& m_colorBg.a != 0) {
etk::Vector3D<float> pos = m_position;
m_vectorialDraw.SetPos(pos);
Print(text[iii]);
float fontHeigh = m_font->GetHeight(m_mode);
m_vectorialDraw.RectangleWidth(etk::Vector3D<float>(m_position.x-pos.x,fontHeigh,0.0f) );
m_nbCharDisplayed++;
} else {
Print(text[iii]);
m_nbCharDisplayed++;
}
if (iii==m_cursorPos-1) {
m_vectorialDraw.SetPos(m_position);
SetColorBg(m_colorCursor);
PrintCursor(false);
if (true == m_needDisplay) {
if (iii==m_cursorPos-1) {
m_vectorialDraw.SetPos(m_position);
SetColorBg(m_colorCursor);
PrintCursor(false);
}
}
}
} else {
// special start case at the right of the endpoint :
if (m_stopTextPos <= m_position.x) {
if (m_stopTextPos < m_position.x) {
ForceLineReturn();
}
float basicSpaceWidth = CalculateSize(' ').x;
@ -566,20 +613,25 @@ void ewol::Text::Print(const etk::UString& text, const etk::Vector<TextDecoratio
// nothing to do ...
break;
case ewol::Text::alignRight:
// Move the first char at the right :
SetPos(etk::Vector3D<float>(m_position.x + freeSpace,
m_position.y,
m_position.z) );
if (m_needDisplay == true) {
// Move the first char at the right :
SetPos(etk::Vector3D<float>(m_position.x + freeSpace,
m_position.y,
m_position.z) );
}
break;
case ewol::Text::alignCenter:
// Move the first char at the right :
SetPos(etk::Vector3D<float>(m_position.x + freeSpace/2,
m_position.y,
m_position.z) );
if (m_needDisplay == true) {
// Move the first char at the right :
SetPos(etk::Vector3D<float>(m_position.x + freeSpace/2,
m_position.y,
m_position.z) );
}
break;
}
// display all the elements
if (0==m_cursorPos) {
if( true == m_needDisplay
&& 0==m_cursorPos) {
m_vectorialDraw.SetPos(m_position);
SetColorBg(m_colorCursor);
PrintCursor(false);
@ -592,42 +644,53 @@ void ewol::Text::Print(const etk::UString& text, const etk::Vector<TextDecoratio
tmpBg = decoration[iii].m_colorBg;
SetFontMode(decoration[iii].m_mode);
}
if( ( m_selectionStartPos-1<iii
&& iii <=m_cursorPos-1)
|| ( m_selectionStartPos-1>=iii
&& iii > m_cursorPos-1) ) {
SetColor( 0x000000FF);
SetColorBg(m_colorSelection);
} else {
SetColor( tmpFg);
SetColorBg(tmpBg);
if (true == m_needDisplay) {
if( ( m_selectionStartPos-1<iii
&& iii <=m_cursorPos-1)
|| ( m_selectionStartPos-1>=iii
&& iii > m_cursorPos-1) ) {
SetColor( 0x000000FF);
SetColorBg(m_colorSelection);
} else {
SetColor( tmpFg);
SetColorBg(tmpBg);
}
}
// special for the justify mode
if (text[iii] == (uniChar_t)' ') {
if (m_colorBg.a != 0) {
//EWOL_DEBUG(" generateString : \" \"");
if( true == m_needDisplay
&& m_colorBg.a != 0) {
m_vectorialDraw.SetPos(m_position);
}
// Must generate a dynamic space :
SetPos(etk::Vector3D<float>(m_position.x + interpolation,
m_position.y,
m_position.z) );
if (m_colorBg.a != 0) {
if( true == m_needDisplay
&& m_colorBg.a != 0) {
m_vectorialDraw.RectangleWidth(etk::Vector3D<float>(interpolation,fontHeigh,0.0f) );
}
} else {
if (m_colorBg.a != 0) {
//EWOL_DEBUG(" generateString : \"" << (char)text[iii] << "\"");
if( true == m_needDisplay
&& m_colorBg.a != 0) {
etk::Vector3D<float> pos = m_position;
m_vectorialDraw.SetPos(pos);
Print(text[iii]);
m_vectorialDraw.RectangleWidth(etk::Vector3D<float>(m_position.x-pos.x,fontHeigh,0.0f) );
m_nbCharDisplayed++;
} else {
Print(text[iii]);
m_nbCharDisplayed++;
}
}
if (iii==m_cursorPos-1) {
m_vectorialDraw.SetPos(m_position);
SetColorBg(m_colorCursor);
PrintCursor(false);
if (m_needDisplay == true) {
if (iii==m_cursorPos-1) {
m_vectorialDraw.SetPos(m_position);
SetColorBg(m_colorCursor);
PrintCursor(false);
}
}
}
if (currentId == stop) {
@ -638,12 +701,14 @@ void ewol::Text::Print(const etk::UString& text, const etk::Vector<TextDecoratio
SetPos(etk::Vector3D<float>(m_startTextpos,
(float)(m_position.y - m_font->GetHeight(m_mode)),
m_position.z) );
m_nbCharDisplayed++;
} else if(text[stop] == (uniChar_t)'\n') {
currentId = stop+1;
// Reset position :
SetPos(etk::Vector3D<float>(m_startTextpos,
(float)(m_position.y - m_font->GetHeight(m_mode)),
m_position.z) );
m_nbCharDisplayed++;
} else {
currentId = stop;
}
@ -750,72 +815,74 @@ void ewol::Text::Print(const uniChar_t charcode)
* | |
* 3------2
*/
etk::Vector2D<int32_t> bitmapDrawPos[4];
bitmapDrawPos[0].x = (int32_t)dxA;
bitmapDrawPos[1].x = (int32_t)dxB;
bitmapDrawPos[2].x = (int32_t)dxB;
bitmapDrawPos[3].x = (int32_t)dxA;
bitmapDrawPos[0].y = (int32_t)dyC;
bitmapDrawPos[1].y = (int32_t)dyC;
bitmapDrawPos[2].y = (int32_t)dyD;
bitmapDrawPos[3].y = (int32_t)dyD;
/* texture Position :
* 0------1
* | |
* | |
* 3------2
*/
etk::Vector2D<float> texturePos[4];
texturePos[0].x = tuA+m_mode;
texturePos[1].x = tuB+m_mode;
texturePos[2].x = tuB+m_mode;
texturePos[3].x = tuA+m_mode;
texturePos[0].y = tvC;
texturePos[1].y = tvC;
texturePos[2].y = tvD;
texturePos[3].y = tvD;
// NOTE : Android does not support the Quads elements ...
/* Step 1 :
* ********
* ******
* ****
* **
*
*/
// set texture coordonates :
m_coordTex.PushBack(texturePos[0]);
m_coordTex.PushBack(texturePos[1]);
m_coordTex.PushBack(texturePos[2]);
// set display positions :
m_coord.PushBack(bitmapDrawPos[0]);
m_coord.PushBack(bitmapDrawPos[1]);
m_coord.PushBack(bitmapDrawPos[2]);
// set the color
m_coordColor.PushBack(m_color);
m_coordColor.PushBack(m_color);
m_coordColor.PushBack(m_color);
/* Step 2 :
*
* **
* ****
* ******
* ********
*/
// set texture coordonates :
m_coordTex.PushBack(texturePos[0]);
m_coordTex.PushBack(texturePos[2]);
m_coordTex.PushBack(texturePos[3]);
// set display positions :
m_coord.PushBack(bitmapDrawPos[0]);
m_coord.PushBack(bitmapDrawPos[2]);
m_coord.PushBack(bitmapDrawPos[3]);
// set the color
m_coordColor.PushBack(m_color);
m_coordColor.PushBack(m_color);
m_coordColor.PushBack(m_color);
if (m_needDisplay == true) {
etk::Vector2D<int32_t> bitmapDrawPos[4];
bitmapDrawPos[0].x = (int32_t)dxA;
bitmapDrawPos[1].x = (int32_t)dxB;
bitmapDrawPos[2].x = (int32_t)dxB;
bitmapDrawPos[3].x = (int32_t)dxA;
bitmapDrawPos[0].y = (int32_t)dyC;
bitmapDrawPos[1].y = (int32_t)dyC;
bitmapDrawPos[2].y = (int32_t)dyD;
bitmapDrawPos[3].y = (int32_t)dyD;
/* texture Position :
* 0------1
* | |
* | |
* 3------2
*/
etk::Vector2D<float> texturePos[4];
texturePos[0].x = tuA+m_mode;
texturePos[1].x = tuB+m_mode;
texturePos[2].x = tuB+m_mode;
texturePos[3].x = tuA+m_mode;
texturePos[0].y = tvC;
texturePos[1].y = tvC;
texturePos[2].y = tvD;
texturePos[3].y = tvD;
// NOTE : Android does not support the Quads elements ...
/* Step 1 :
* ********
* ******
* ****
* **
*
*/
// set texture coordonates :
m_coordTex.PushBack(texturePos[0]);
m_coordTex.PushBack(texturePos[1]);
m_coordTex.PushBack(texturePos[2]);
// set display positions :
m_coord.PushBack(bitmapDrawPos[0]);
m_coord.PushBack(bitmapDrawPos[1]);
m_coord.PushBack(bitmapDrawPos[2]);
// set the color
m_coordColor.PushBack(m_color);
m_coordColor.PushBack(m_color);
m_coordColor.PushBack(m_color);
/* Step 2 :
*
* **
* ****
* ******
* ********
*/
// set texture coordonates :
m_coordTex.PushBack(texturePos[0]);
m_coordTex.PushBack(texturePos[2]);
m_coordTex.PushBack(texturePos[3]);
// set display positions :
m_coord.PushBack(bitmapDrawPos[0]);
m_coord.PushBack(bitmapDrawPos[2]);
m_coord.PushBack(bitmapDrawPos[3]);
// set the color
m_coordColor.PushBack(m_color);
m_coordColor.PushBack(m_color);
m_coordColor.PushBack(m_color);
}
}
}
}
@ -829,16 +896,14 @@ void ewol::Text::Print(const uniChar_t charcode)
void ewol::Text::ForceLineReturn(void)
{
// Reset position :
SetPos(etk::Vector3D<float>(m_startTextpos,
(float)(m_position.y - m_font->GetHeight(m_mode)),
m_position.z) );
SetPos(etk::Vector3D<float>(m_startTextpos, m_position.y - m_font->GetHeight(m_mode), 0) );
}
void ewol::Text::SetTextAlignement(float startTextpos, float stopTextPos, ewol::Text::aligneMode_te alignement)
{
m_startTextpos = startTextpos;
m_stopTextPos = stopTextPos;
m_stopTextPos = stopTextPos+1;
m_alignement = alignement;
if (m_startTextpos >= m_stopTextPos) {
EWOL_ERROR("Request allignement with Borne position error : " << startTextpos << " => " << stopTextPos);
@ -857,6 +922,41 @@ void ewol::Text::DisableAlignement(void)
m_alignement = ewol::Text::alignDisable;
}
etk::Vector3D<float> ewol::Text::CalculateSizeHTML(const etk::UString& text)
{
// remove intermediate result
Reset();
// disable display system
m_needDisplay = false;
SetPos(etk::Vector3D<float>(0,0,0) );
// same as print without the end display ...
PrintHTML(text);
// get the last elements
m_sizeDisplayStop.x = etk_max(m_position.x, m_sizeDisplayStop.x);
m_sizeDisplayStop.y = etk_max(m_position.y, m_sizeDisplayStop.y);
m_sizeDisplayStart.x = etk_min(m_position.x, m_sizeDisplayStart.x);
m_sizeDisplayStart.y = etk_min(m_position.y, m_sizeDisplayStart.y);
// set back the display system
m_needDisplay = true;
return etk::Vector3D<float>( m_sizeDisplayStop.x-m_sizeDisplayStart.x,
m_sizeDisplayStop.y-m_sizeDisplayStart.y,
m_sizeDisplayStop.z-m_sizeDisplayStart.z);
}
etk::Vector3D<float> ewol::Text::CalculateSizeDecorated(const etk::UString& text)
{
etk::UString tmpData("<html><body>\n");
tmpData+=text;
tmpData+="\n</body></html>\n";
etk::Vector3D<float> tmpVal = CalculateSizeHTML(tmpData);
return tmpVal;
}
etk::Vector3D<float> ewol::Text::CalculateSize(const etk::UString& text)
{
if (m_font == NULL) {
@ -925,10 +1025,17 @@ bool ewol::Text::ExtrapolateLastId(const etk::UString& text, const int32_t start
float endPos = m_position.x;
bool endOfLine = false;
float stopPosition = m_stopTextPos;
if( false == m_needDisplay
|| m_stopTextPos == m_startTextpos) {
stopPosition = m_startTextpos + 3999999999.0;
}
for (int32_t iii=start; iii<text.Size(); iii++) {
etk::Vector3D<float> tmpSize = CalculateSize(text[iii]);
// check oveflow :
if (endPos + tmpSize.x > m_stopTextPos) {
if (endPos + tmpSize.x > stopPosition) {
stop = iii;
break;
}
@ -936,7 +1043,7 @@ bool ewol::Text::ExtrapolateLastId(const etk::UString& text, const int32_t start
if (text[iii] == (uniChar_t)' ') {
space++;
lastSpacePosition = iii;
lastSpacefreeSize = m_stopTextPos - endPos;
lastSpacefreeSize = stopPosition - endPos;
} else if (text[iii] == (uniChar_t)'\n') {
stop = iii;
endOfLine = true;
@ -945,7 +1052,7 @@ bool ewol::Text::ExtrapolateLastId(const etk::UString& text, const int32_t start
// update local size :
endPos += tmpSize.x;
}
freeSpace = m_stopTextPos - endPos;
freeSpace = stopPosition - endPos;
// retore previous :
m_previousCharcode = storePrevious;
// need to align left or right ...

View File

@ -49,6 +49,11 @@ namespace ewol
private:
ewol::Drawing m_vectorialDraw; //!< This is used to draw background selection and other things ...
private:
int32_t m_nbCharDisplayed; //!< prevent some error in calculation size.
etk::Vector3D<float> m_sizeDisplayStart; //!< The start windows of the display.
etk::Vector3D<float> m_sizeDisplayStop; //!< The end windows of the display.
bool m_needDisplay; //!< This just need the display and not the size rendering.
etk::Vector3D<float> m_position; //!< The current position to draw
etk::Vector3D<float> m_clippingPosStart; //!< Clipping start position
etk::Vector3D<float> m_clippingPosStop; //!< Clipping stop position
@ -116,9 +121,13 @@ namespace ewol
*/
void Draw(void);
/**
* @brief Clear alll tre registered element in the current element
* @brief Clear all the registered element in the current element
*/
void Clear(void);
/**
* @brief Clear all the intermediate result detween 2 prints
*/
void Reset(void);
/**
* @brief Get the current display position (sometime needed in the gui control)
* @return the current position.
@ -273,7 +282,7 @@ namespace ewol
* @param[in] text The string to display.
* @TODO : implementation not done ....
*/
void PrintHTML(etk::UString& text);
void PrintHTML(etk::UString text);
/**
* @brief Display a compleat string in the current element whith specific decorations (advence mode).
* @param[in] text The string to display.
@ -289,11 +298,13 @@ namespace ewol
* @brief This Generate the line return ==> it return to the alignement position start and at the correct line position ==> it might be use to not know the line height
*/
void ForceLineReturn(void);
private:
/**
* @brief This parse a tinyXML node (void pointer to permit to hide tiny XML in include)
* @param[in] element the tynyXML element : TiXmlNode*
* @brief This parse a tinyXML node (void pointer to permit to hide tiny XML in include).
* @param[in] element the tynyXML element : TiXmlNode* .
*/
void ParseHtmlNode( void* element);
void ParseHtmlNode(void* element);
public:
/**
* @brief This generate the possibility to generate the big text property
* @param[in] startTextpos The x text start position of the display.
@ -311,6 +322,18 @@ namespace ewol
* @return the curent alignement type
*/
ewol::Text::aligneMode_te GetAlignement(void);
/**
* @brief Calculate a theoric text size
* @param[in] text The string to calculate dimention.
* @return The theoric size used.
*/
etk::Vector3D<float> CalculateSizeHTML(const etk::UString& text);
/**
* @brief Calculate a theoric text size
* @param[in] text The string to calculate dimention.
* @return The theoric size used.
*/
etk::Vector3D<float> CalculateSizeDecorated(const etk::UString& text);
/**
* @brief Calculate a theoric text size
* @param[in] text The string to calculate dimention.

View File

@ -70,10 +70,12 @@ void widget::Button::SetImageToggle(etk::UString imageName)
bool widget::Button::CalculateMinSize(void)
{
etk::Vector2D<float> padding = m_shaper.GetPadding();
etk::Vector3D<int32_t> minSize = m_displayText.CalculateSize(m_label);
m_displayText.Clear();
etk::Vector3D<int32_t> minSize = m_displayText.CalculateSizeDecorated(m_label);
if( true == m_toggleMode
&& m_labelToggle.Size()!=0) {
etk::Vector3D<int32_t> minSizeToggle = m_displayText.CalculateSize(m_labelToggle);
m_displayText.Clear();
etk::Vector3D<int32_t> minSizeToggle = m_displayText.CalculateSizeDecorated(m_labelToggle);
minSize.x = etk_max(minSize.x, minSizeToggle.x);
minSize.y = etk_max(minSize.y, minSizeToggle.y);
minSize.z = etk_max(minSize.z, minSizeToggle.z);
@ -155,40 +157,55 @@ void widget::Button::OnRegenerateDisplay(void)
if (true == NeedRedraw()) {
etk::Vector2D<float> padding = m_shaper.GetPadding();
// to know the size of one Line :
etk::Vector3D<int32_t> minSize = m_displayText.CalculateSize('A');
etk::Vector3D<int32_t> curentTextSize;
if( false == m_toggleMode
|| false == m_value) {
curentTextSize = m_displayText.CalculateSizeDecorated(m_label);
} else {
curentTextSize = m_displayText.CalculateSizeDecorated(m_labelToggle);
}
m_displayImage.Clear();
m_displayImageToggle.Clear();
m_shaper.Clear();
m_displayText.Clear();
etk::Vector2D<int32_t> localSize = m_minSize;
etk::Vector3D<float> tmpOrigin((float)((m_size.x - m_minSize.x) / 2.0),
(float)((m_size.y - m_minSize.y) / 2.0),
(float)(0.0));
etk::Vector3D<float> tmpOrigin((m_size.x - m_minSize.x) / 2.0,
(m_size.y - m_minSize.y) / 2.0,
0.0);
// no change for the text orogin :
etk::Vector3D<float> tmpTextOrigin((float)((m_size.x - m_minSize.x) / 2.0 + padding.x),
(float)((m_size.y - m_minSize.y) / 2.0 + padding.y),
(float)(0.0));
etk::Vector3D<float> tmpTextOrigin((m_size.x - m_minSize.x) / 2.0,
(m_size.y - m_minSize.y) / 2.0,
0.0);
if (true==m_userFill.x) {
localSize.x = m_size.x;
tmpOrigin.x = 0.0;
tmpTextOrigin.x = 0.0;
}
if (true==m_userFill.y) {
localSize.y = m_size.y;
//tmpOrigin.y = 0.0;
}
tmpOrigin.x += padding.x;
tmpOrigin.y += padding.y;
tmpTextOrigin.x += padding.x;
tmpTextOrigin.y += padding.y;
localSize.x -= 2*padding.x;
localSize.y -= 2*padding.y;
etk::Vector2D<float> textPos(tmpTextOrigin.x, tmpTextOrigin.x);
tmpTextOrigin.y += (m_minSize.y-2*padding.y) - minSize.y;
etk::Vector2D<float> textPos(tmpTextOrigin.x, tmpTextOrigin.y);
if( true == m_displayImage.HasSources()
|| true == m_displayImageToggle.HasSources()) {
etk::Vector3D<int32_t> minSize = m_displayText.CalculateSize(m_label);
// TODO : Remove this size calculation ==> can regenrate siomme errro
etk::Vector3D<int32_t> minSize = m_displayText.CalculateSizeDecorated(m_label);
etk::Vector3D<int32_t> imagePos(tmpTextOrigin.x-padding.x/4, tmpTextOrigin.y-padding.x/4, 0);
etk::Vector2D<int32_t> imageSize(minSize.y+padding.x/2, minSize.y+padding.x/2);
if( false==m_toggleMode
@ -203,14 +220,15 @@ void widget::Button::OnRegenerateDisplay(void)
tmpTextOrigin.x += padding.x/2 + minSize.y;
}
etk::Vector3D<float> drawClippingPos(0.0, 0.0, -0.5);
etk::Vector3D<float> drawClippingSize((float)(m_size.x - 2*padding.x),
(float)(m_size.y - 2*padding.y),
etk::Vector3D<float> drawClippingPos(padding.x, padding.y, -0.5);
etk::Vector3D<float> drawClippingSize((float)(m_size.x - padding.x),
(float)(m_size.y - padding.y),
(float)1.0);
// clean the element
m_displayText.Clear();
m_displayText.SetTextAlignement(0, localSize.x + 2*padding.x, ewol::Text::alignCenter);
m_displayText.Reset();
m_displayText.SetPos(tmpTextOrigin);
m_displayText.SetTextAlignement(tmpTextOrigin.x, tmpTextOrigin.x+localSize.x, ewol::Text::alignCenter);
m_displayText.SetClipping(drawClippingPos, drawClippingSize);
if( false == m_toggleMode
|| false == m_value) {
@ -218,7 +236,7 @@ void widget::Button::OnRegenerateDisplay(void)
} else {
m_displayText.PrintDecorated(m_labelToggle);
}
m_displayText.Translate(tmpOrigin);
//m_displayText.Translate(tmpOrigin);
if (true==m_userFill.y) {

View File

@ -55,17 +55,17 @@ MainWindows::MainWindows(void)
return;
}
mySizerVert->SubWidgetAdd(mySizerHori);
myButton = new widget::Button("<center>Expend X (false)</center>");
myButton = new widget::Button("<center>Expend X <br/> (false)</center>");
if (NULL != myButton) {
myButton->SetToggleMode(true);
myButton->SetLabelToggle("<center>Expend X (true)</center>");
myButton->SetLabelToggle("<center>Expend X <br/> (true)</center>");
myButton->RegisterOnEvent(this, ewolEventButtonValue, l_eventChangeExpendX);
mySizerHori->SubWidgetAdd(myButton);
}
myButton = new widget::Button("<center>Expend Y (false)</center>");
myButton = new widget::Button("<center>Expend Y <br/> (false)</center>");
if (NULL != myButton) {
myButton->SetToggleMode(true);
myButton->SetLabelToggle("<center>Expend Y (true)</center>");
myButton->SetLabelToggle("<center>Expend Y <br/> (true)</center>");
myButton->RegisterOnEvent(this, ewolEventButtonValue, l_eventChangeExpendY);
mySizerHori->SubWidgetAdd(myButton);
}
@ -121,7 +121,7 @@ MainWindows::MainWindows(void)
mySizerHori->SubWidgetAdd(m_spacer[idSpacer]);
}
m_button = new widget::Button("My <font color=\"#FF0000\">Button</font>");
m_button = new widget::Button("My <font color=\"#FF0000\">Button</font> <br/> And Some under line<br/> plop <br/> and an other super long line ...");
if (NULL != m_button) {
m_button->SetExpendX(false);
m_button->SetExpendY(false);