Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Extra libraries, Code snippets, applications etc. » U++ users applications in progress and useful code snippets, including reference examples! » Multiline text display
Multiline text display [message #7466] Sat, 30 December 2006 17:10
andrei-catalin is currently offline  andrei-catalin
Messages: 62
Registered: May 2006
Location: Romania
Member
Based from my drawing code used in PieChart I've coded a display that is useful into an ArrayCtrl:

void GetPoss(const Rect& box, const String& content, Font f, Vector<int>& pos)
{
	int _L=box.Width();	
	pos.Add(0);
	int spacepos=content.Find(' ');
	int lastpos=-1;
	Size sz;
		
	while(spacepos>=0)
	{
		sz=GetTextSize(content.Mid(pos.Top(),spacepos-pos.Top()),f);		
		if (sz.cx>_L)
		{
		 	pos.Add(lastpos+1);
		 	sz=GetTextSize(content.Mid(pos.Top(),spacepos-pos.Top()),f);
		 	if (sz.cx>_L) break;
		}
		else 
		{
			lastpos=spacepos;
			spacepos=content.Find(' ',spacepos+1);
			if(spacepos==-1)
			{
				sz=GetTextSize(content.Mid(pos.Top(),content.GetLength()-pos.Top()),f);
				if (sz.cx>_L) pos.Add(lastpos+1);
			}
		}
	}
	pos.Add(content.GetLength()+1);	
}
void DrawMLText(Vector<int>& pos, Draw& w, const Rect& box, const String& content,
				 Font f, class::Color textColor)
{
	for (int i=0; i<pos.GetCount()-1; i++)
	{
		w.DrawText(box.left, box.top+i*fround(f.GetHeight()*1.2),
		  content.Mid(pos[i],pos[i+1]-pos[i]-1),f,textColor);
	}
}

class MLDisplayClass : public Display
{
public:
	void Paint(Draw& draw, 
			   const Rect& rc, 
			   const Value& v, 
			   Color ink, 
			   Color paper, 
			   dword style) const
	{
		draw.DrawRect(rc, paper);
		Vector<int> vpos;
		GetPoss(rc,v,StdFont(),vpos);
		int cy=13*(vpos.GetCount()-1);
		if (cy<rc.Height()){
			Rect rcc(rc.left,rc.top+(rc.Height()-cy)/2,rc.right,rc.bottom);			
			DrawMLText(vpos,draw, rcc, v, StdFont(),ink);
		}
		else DrawMLText(vpos,draw, rc, v, StdFont(),ink);
	}
};


I used in this way:

array1.AddColumn("MEMO").SetDisplay(Single<MLDisplayClass>()).HeaderTab().SetAlign(3);


Andrei

Screenshot:
index.php?t=getfile&id=419&private=0
  • Attachment: cell.png
    (Size: 0.74KB, Downloaded 1525 times)
Previous Topic: Undefined symbols: Display::Paint()
Next Topic: MASM Implementation
Goto Forum:
  


Current Time: Thu Mar 28 19:05:33 CET 2024

Total time taken to generate the page: 0.00972 seconds