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 » U++ Library support » ArrayCtrl, HeaderCtrl & GridCtrl » Calculate needed cell width to fit some text
Re: Calculate needed cell width to fit some text [message #25173 is a reply to message #25168] Sat, 13 February 2010 12:29 Go to previous messageGo to previous message
Sender Ghost is currently offline  Sender Ghost
Messages: 301
Registered: November 2008
Senior Member
Hello, Max.

I made following sample application for your first question from which you can understand about how to setup ArrayCtrl columns with fixed width.
#include <CtrlLib/CtrlLib.h>

using namespace Upp;

const String sampleText("Another Sample Text");

void CreateOption(One<Ctrl>& ctrl)
{
	ctrl.Create<Option>().NoWantFocus();
}

class FixedArray : public TopWindow {
public:
	typedef FixedArray CLASSNAME;
	FixedArray();

	ArrayCtrl list;

	void ArrayBar(Bar& bar);

	void ToggleOption();
	void FillWithData();
};

FixedArray::FixedArray()
{
	Title("Fixed ArrayCtrl test application");
	CenterScreen().MaximizeBox().MinimizeBox().Sizeable();
	SetRect(Size(320, 240));

	list.AutoHideSb();
	list.WhenBar = THISBACK(ArrayBar);
	// Initialize ArrayCtrl columns
	list.AddColumn().Ctrls(CreateOption).HeaderTab().Fixed(26); // first method
	list.AddColumn("Content");
	list.AddColumn("Description");
	// Get width for sampleText
	const int sampleWidth = GetTextSize(sampleText, Draw::GetStdFont()).cx;
	// Set width for column
	HeaderCtrl& hc = list.HeaderObject();
	hc.Tab(1).Fixed(sampleWidth + hc.Tab(1).GetMargin() * 2 + 1); // second method

	Add(list.VSizePosZ(4, 4).HSizePosZ(4, 4));
}

void FixedArray::ArrayBar(Bar& bar)
{
	if (list.HasFocus() && list.IsCursor())
		bar.AddKey(K_SPACE, THISBACK(ToggleOption));

	list.StdBar(bar);
}

void FixedArray::ToggleOption()
{
	GuiLock __;

	list.Set(0, !list.Get(0));
}

void FixedArray::FillWithData()
{
	GuiLock __;

	list.Clear();

	for (int i = 1; i <= 10; ++i)
		list.Add(i % 2 == 0, sampleText, Format("Description of %d", i));
}

GUI_APP_MAIN
{
	//Ctrl::GlobalBackPaintHint();

	FixedArray fa;
	fa.FillWithData();

	fa.Run();
}

index.php?t=getfile&id=2255&private=0

[Updated on: Sat, 13 February 2010 14:06]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Previous Topic: GridCtrl large data set from DB
Next Topic: GridCtrl::Reset does not reset.
Goto Forum:
  


Current Time: Sat May 04 06:25:06 CEST 2024

Total time taken to generate the page: 0.04611 seconds