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
Calculate needed cell width to fit some text [message #25168] Sat, 13 February 2010 10:31 Go to next message
mdelfede is currently offline  mdelfede
Messages: 1264
Registered: September 2007
Senior Contributor
I need to setup cell widths to fit some text; with HeaderCtrl().Absolute() I can set absoulte cell widths, but I can't manage to get pixel width of a given text.
trying with

StdFont().GetAveWidth() * myString.GetCount()


gives me a by far too big value for character width.

Any hint ?

Another stuff... I have a DropGrid containing images, embedded into an ArrayCtrl. I also need to set the cell width to fit the image, but doing with Image.GetSize().cx misses the width needed for the drop arrow.... By now I do it adding a fixed value, but I'm afraid that it'll behave bad changing platform.

Ciao

Max
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 next 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

Re: Calculate needed cell width to fit some text [message #25184 is a reply to message #25173] Sat, 13 February 2010 14:29 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1264
Registered: September 2007
Senior Contributor
Hi Sender Ghost,

I missed that one :

GetTextSize(sampleText, Draw::GetStdFont()).cx;


Thank you very much ! Smile

Ciao

Max
Re: Calculate needed cell width to fit some text [message #25647 is a reply to message #25184] Sat, 06 March 2010 00:42 Go to previous message
nixnixnix is currently offline  nixnixnix
Messages: 415
Registered: February 2007
Location: Kelowna, British Columbia
Senior Member
It looks to me like there should be a GetFont method in GridCtrl::ItemRect. How can you be sure that the return from GetStdFont is the font being used by the GridCtrl Column?

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


Current Time: Sun Jan 17 10:25:32 CET 2021

Total time taken to generate the page: 0.01298 seconds