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 » U++ Widgets - General questions or Mixed problems » ArrayCtrl with labels / layouts inside ?
Re: ArrayCtrl with labels / layouts inside ? [message #12910 is a reply to message #12909] Tue, 27 November 2007 22:10 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1092
Registered: August 2007
Senior Contributor
Quote:



OK.. so.. in fact your code runs, but try with another layout.
For example try a layout with a label, some arrays and buttons, and the famous myarray
Try to do it with the layout editor.

Then try your code again.. without "Add(myArray.SizePos());"

And you will see the problem i'm talking about.
There is a grayed case, but the button don't appear.



Smile

Yes, I've encountered the problem you've mentioned. And guess what: It has a very simple solution
Just add, "myArray.Layout()", and voila! it works Smile
(I hope it will work in your case too)

I'm not sure, but this could be a bug...

I've updated the example, and added the "myArray", and some other ctrls with layout editor. Please take a look at it.
  • Attachment: Test.rar
    (Size: 1.03KB, Downloaded 468 times)


[Updated on: Tue, 27 November 2007 22:21]

Report message to a moderator

Re: ArrayCtrl with labels / layouts inside ? [message #12911 is a reply to message #12894] Tue, 27 November 2007 22:55 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
jiaif wrote on Mon, 26 November 2007 13:18

Thank you for the code, but i'm sorry, i have the same errors Sad
I don't understand why.

Maybe because myArray is added before i add buttons ?
I mean in my code, myArray is defined in the layout.

Maybe because i'm under linux ? Very Happy

[edit]
if i do :
Button b;
b.SetLabel("test");
myArray.AddColumn("test");
myArray.SetCtrl(0,0,&b);

it compile well but the button don't appear. Any idea ?


First of all, SetCtrl(..., Ctrl *ctrl);

is deprecated and should not be used in any new code, in fact, it will likely be removed.

Anyway, now I believe that the fundamental problem of your code is that you are doing something like:

MyApp::MyApp() {
   Button b;
   ...
   myArray.SetCtrl(0,0,b);
}


This cannot work (or in fact, works as expected), as Button is destroyed at the and of MyApp().

To make it more clear, have fun:

#include <CtrlLib/CtrlLib.h>

using namespace Upp;

#define LAYOUTFILE <Test/Test.lay>
#include <CtrlCore/lay.h>

class ArrayTest : public WithArrayTestLayout<TopWindow> {
public:
	typedef ArrayTest CLASSNAME;
	ArrayTest();
	
	Array<Button> btn;
	Array<Option> opt;
};

ArrayTest::ArrayTest()
{
	CtrlLayout(*this, "Window title");
	Sizeable().Zoomable();
	
	myArray.AddColumn("Column1");
	myArray.AddColumn("Column2");
	
	for(int i = 0; i < 100; i++) {
		myArray.Add("Row: " + AsString(i + 1));
		if(i & 1) {
			Button& b = btn.Add();
			b.SetLabel(Format("Button %d", i + 1));
			myArray.SetCtrl(i, 1, b);
		}
		else {
			Option& o = opt.Add();
			o.SetLabel(Format("Option %d", i + 1));
			myArray.SetCtrl(i, 1, o);
		}
	}
}

GUI_APP_MAIN
{
	ArrayTest().Run();
}


Mirek

Re: ArrayCtrl with labels / layouts inside ? [message #12912 is a reply to message #12910] Tue, 27 November 2007 22:57 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Oblivion wrote on Tue, 27 November 2007 16:10


Yes, I've encountered the problem you've mentioned. And guess what: It has a very simple solution
Just add, "myArray.Layout()", and voila! it works Smile
(I hope it will work in your case too)

I'm not sure, but this could be a bug...



Well, that pointer version SetCtrl should not really be public. Do not use it Smile

Mirek
Re: ArrayCtrl with labels / layouts inside ? [message #12922 is a reply to message #12912] Wed, 28 November 2007 18:59 Go to previous messageGo to next message
jiaif is currently offline  jiaif
Messages: 17
Registered: November 2007
Location: France
Promising Member
I don't understand why you use

Button& b = btn.Add();

Where does btn array appear ?
What is your layout ?

And why SetCtrl( ... Ctrl *ctrl ...) deprecated ?
And how to do with the deprecated version ?

Because i followed your indications and i have the same error. Moreover i can't use SetCtrl with a Button& value, in 2007.1 and 711-dev2 it's the same declaration.

I can make a screenshot if you want to see, it's like an empty label who appears.

And how to add buttons programmatically once the constructor have finished ? Because i tried but it does nothing.


Oblivion: Yeaahaaa ! Layout() do the job !.. Very Happy but mirek said that it's deprecated.. Any other ideas ? Razz


One more question, how to add a layout to an array ?
Is it possible ? What's the way to follow ?

(and i dunno if i previously do that but: Thank you very much for all your answers, you're very very user friendly, as like your IDE Wink)

[Updated on: Wed, 28 November 2007 19:04]

Report message to a moderator

Re: ArrayCtrl with labels / layouts inside ? [message #12923 is a reply to message #12922] Wed, 28 November 2007 19:24 Go to previous messageGo to next message
jiaif is currently offline  jiaif
Messages: 17
Registered: November 2007
Location: France
Promising Member
i tried that :

Withwaiter<ArrayCtrl> *test = new Withwaiter<ArrayCtrl>();
test->lbl_callername.SetLabel("test");
test->lbl_country.SetLabel("test");
test->lbl_telnum.SetLabel("test");

array_waiters.Add("");
array_waiters.SetCtrl(0,0,test);
array_waiters.Layout();

with this layout :

LAYOUT(waiter, 196, 52)
ITEM(Label, lbl_telnum, LeftPosZ(4, 132).TopPosZ(4, 20))
ITEM(Label, lbl_callername, LeftPosZ(4, 132).TopPosZ(28, 20))
ITEM(Label, lbl_country, LeftPosZ(144, 48).TopPosZ(4, 44))
END_LAYOUT

But it don't appear correctly. Maybe it's a problem of height of the array cells. So i tried with SetLineCy(0,50); but the layout continue to not appear correctly.

If you could try with your version to tell me if you have a different result.

[Updated on: Wed, 28 November 2007 19:26]

Report message to a moderator

Re: ArrayCtrl with labels / layouts inside ? [message #12924 is a reply to message #12923] Wed, 28 November 2007 22:27 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1092
Registered: August 2007
Senior Contributor
Quote:


I can make a screenshot if you want to see, it's like an empty label who appears.



Yes, It would be helpful. Also, please upload a simple example if you could. It's better to examine the problem on a source code.

Quote:


One more question, how to add a layout to an array ?
Is it possible ? What's the way to follow ?



AFAIK, "theoretically" it is possible, but not with the current "CtrlLib.usc" (layout editor, ctrl "drawing" file) I suppose; for, it has to be modified first.


Actually, It might be a good idea...






[Updated on: Wed, 28 November 2007 22:45]

Report message to a moderator

Re: ArrayCtrl with labels / layouts inside ? [message #12928 is a reply to message #12923] Thu, 29 November 2007 05:49 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
jiaif wrote on Wed, 28 November 2007 13:24

i tried that :

Withwaiter<ArrayCtrl> *test = new Withwaiter<ArrayCtrl>();



Never use "delete" with U++. And in most cases, avoid "new".

"ArrayCtrl" is wrong here. This would mean you are deriving your widget (that you want to place into single ArrayCtrl cell) from ArrayCtrl. It is like putting another ArrayCtrl into ArrayCtrl, with some other widgets over it.

IMO you want something like Withwaiter<ParentCtrl>.

Then you also have to call CtrlLayout for it to actually place widgets.

See, it is not that hard to understand. Withwaiter<ArrayCtrl> is a type that contains all layout members as instance variables.

CtrlLayout adds these variables using Ctrl::Add and places them on correct positions.

Mirek
Re: ArrayCtrl with labels / layouts inside ? [message #12935 is a reply to message #12928] Thu, 29 November 2007 13:57 Go to previous messageGo to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
Quote:

Well, that pointer version SetCtrl should not really be public. Do not use it
Are you sure a about this? The documentation says:
Sets an external control to use as the editor for a single array cell. This function transfers the ownership to the control (from now on, it is stored within the array and destroyed as necessary - upon destruction of the array, deletion of the relevant row or another call to SetCtrl).
And this makes sense because it is very difficult to use SetCtrl and have to manage ctrls externally.

Also, since I have some time on my hands I'm going to wade in with my opinion whether you like it or not Smile. I'm not sure if SetCtrl is the correct approach to use in this case. The code above should work with the addition of:
CtrlLayout(*test); array_waiters.SetLineCy(0, w.GetMinSize().cy);
but there are two (and probably more) ways of doing this that may be more suitable:

1- Avoids SetCtrl completely
struct CallerInfo {
	String callername;
	String country;
	String telephone;
};

class MainWindow : public TopWindow
{
public:
	typedef MainWindow CLASSNAME;
	ArrayCtrl array;
	
	struct Waiter : public WithWaiterLayout<ParentCtrl> {
		Value data;
		
		Waiter() { CtrlLayout(*this); }
		virtual void SetData(const Value &v) {
			if (IsTypeRaw<CallerInfo>(v)) {
				const CallerInfo &c = ValueTo<CallerInfo>(v);
				callername.SetLabel(c.callername);
				country.SetLabel(c.country);
				telephone.SetLabel(c.telephone);
				data = v;
			}
		}
		virtual Value GetData() const { return data; }
	};
	
	MainWindow() {
		Sizeable();
		
		array.AddColumn("Data 1");
		array.AddColumn("Data 2");
		array.AddColumn("Waiter").Ctrls<Waiter>();
		Add(array.SizePos());

		CallerInfo c;
		c.callername = "Joe Sixpack";
		c.country = "USA";
		c.telephone = "666-666666";
		
		array.Add("Cell (0,0)", "Cell (1,0)", RawToValue<CallerInfo>(c)); 
		array.Add("Cell (0,1)", "Cell (1,1)", RawToValue<CallerInfo>(c));
		array.Add("Cell (0,2)", "Cell (1,2)", RawToValue<CallerInfo>(c));
	}
};

2- Uses Display. Unless you have a really good reason for using controls (ie. some sort of user interaction required) this should be the default method:
struct CallerInfo {
	String callername;
	String country;
	String telephone;
};

class MainWindow : public TopWindow
{
public:
	typedef MainWindow CLASSNAME;
	ArrayCtrl array;

	struct CallerDisplay : public Display
	{
		void Paint(Draw& w, const Rect& r, const Value& q, Color ink, Color paper, dword style) const {
			PaintBackground(w, r, q, ink, paper, style);
			if (IsTypeRaw<CallerInfo>(q)) {
				const CallerInfo &c = ValueTo<CallerInfo>(q);
				int ccy = r.GetWidth() / 3;
				int h = r.Height();
				int x = r.right - ccy;
				
				w.Begin();
				w.DrawText(x, r.top+1, c.telephone, StdFont(), ink);
				w.ExcludeClip(x, r.top, ccy, h);
				x -= ccy;
				w.DrawText(x, r.top+1, c.country, StdFont(), ink);
				w.ExcludeClip(x, r.top, ccy, h);
				x -= ccy;
				w.DrawText(x, r.top+1, c.callername, StdFont(), ink);
				w.End();
			}
		}	
	};
	
	MainWindow() {
		Sizeable();
		
		array.AddColumn("Data 1");
		array.AddColumn("Data 2");
		array.AddColumn("Waiter").SetDisplay(Single<CallerDisplay>());
		Add(array.SizePos());

		CallerInfo c;
		c.callername = "Joe Sixpack";
		c.country = "USA";
		c.telephone = "666-666666";
		
		array.Add("Cell (0,0)", "Cell (1,0)", RawToValue<CallerInfo>(c)); 
		array.Add("Cell (0,1)", "Cell (1,1)", RawToValue<CallerInfo>(c));
		array.Add("Cell (0,2)", "Cell (1,2)", RawToValue<CallerInfo>(c));
	}
};
you could further improve the Paint function with the '...' when string are cut short and give a much better appearance than using Labels. See StdDisplayClass::Paint0 for how to do this.

Hope that helps.
James
Re: ArrayCtrl with labels / layouts inside ? [message #12991 is a reply to message #12935] Tue, 04 December 2007 09:39 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
mrjt wrote on Thu, 29 November 2007 07:57

Quote:

Well, that pointer version SetCtrl should not really be public. Do not use it
Are you sure a about this? The documentation says:
Sets an external control to use as the editor for a single array cell. This function transfers the ownership to the control (from now on, it is stored within the array and destroyed as necessary - upon destruction of the array, deletion of the relevant row or another call to SetCtrl).
And this makes sense because it is very difficult to use SetCtrl and have to manage ctrls externally.

Also, since I have some time on my hands I'm going to wade in with my opinion whether you like it or not Smile.



Well, yes, I am sure.. Smile Buggy documentation.

Managing Ctrls externally is not at all difficult - just add Array<T> somewhere. The only possible problem is Insert/Remove, where you have to be a little bit more careful....

Mirek
Re: ArrayCtrl with labels / layouts inside ? [message #13036 is a reply to message #12991] Thu, 06 December 2007 18:25 Go to previous messageGo to next message
jiaif is currently offline  jiaif
Messages: 17
Registered: November 2007
Location: France
Promising Member
Hi,

thanks for your answers.

In fact i need to fill an array with a kind of widgets where the user can click on it. When clicking, the program will modify some other labels and arrays.

So yes i need interactivity with the user, and i need a userfriendly design, not an OOo Calc like array.. Wink

That's why i want to create widgets with labels, colors and images.

I'll try your code later but thanks for help Smile

jf
Re: ArrayCtrl with labels / layouts inside ? [message #13037 is a reply to message #13036] Thu, 06 December 2007 19:15 Go to previous messageGo to next message
jiaif is currently offline  jiaif
Messages: 17
Registered: November 2007
Location: France
Promising Member
Thanks mrjt,
your code (first example) runs pretty well, but how to add elts to the array when the application is running ?

I tried to create a simple method like :
void AddTruc(String o, String s, String a) {
   CallerInfo c;
   c.callername = o;
   c.country = s;
   c.telephone = a;
   array.Add("test", "test", RawToValue<CallerInfo>(c));
};

and further in the code :
GUI_APP_MAIN
{
	MainWindow mw;
	mw.Run();
	
	mw.AddTruc("joe","USA","09890");
}

but nothing appear

[Updated on: Thu, 06 December 2007 19:16]

Report message to a moderator

Re: ArrayCtrl with labels / layouts inside ? [message #13039 is a reply to message #12911] Thu, 06 December 2007 20:29 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
luzr wrote on Tue, 27 November 2007 16:55


First of all, SetCtrl(..., Ctrl *ctrl);

is deprecated and should not be used in any new code, in fact, it will likely be removed.



// Linux/xcode
#define DEPRECATED_FUNC __attribute__((__deprecated__))
// MSVC
#define DEPRECATED_FUNC __declspec(deprecated)

You might consider using of DEPRECATED_FUNC macro above to inform users about deprecated methods/functions.

It is more informative than just comments in the source code.


Regards,
Novo
Re: ArrayCtrl with labels / layouts inside ? [message #13057 is a reply to message #13039] Fri, 07 December 2007 11:28 Go to previous messageGo to next message
waxblood is currently offline  waxblood
Messages: 95
Registered: January 2007
Member
Novo wrote on Thu, 06 December 2007 20:29

luzr wrote on Tue, 27 November 2007 16:55


First of all, SetCtrl(..., Ctrl *ctrl);

is deprecated and should not be used in any new code, in fact, it will likely be removed.



// Linux/xcode
#define DEPRECATED_FUNC __attribute__((__deprecated__))
// MSVC
#define DEPRECATED_FUNC __declspec(deprecated)

You might consider using of DEPRECATED_FUNC macro above to inform users about deprecated methods/functions.

It is more informative than just comments in the source code.






This post interests me, but I think is a little OT so I've created a new topic here:

http://www.ultimatepp.org/forum/index.php?t=msg&goto=130 55&#msg_13055



David

[Updated on: Fri, 07 December 2007 11:28]

Report message to a moderator

Re: ArrayCtrl with labels / layouts inside ? [message #13063 is a reply to message #13057] Fri, 07 December 2007 18:31 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
waxblood wrote on Fri, 07 December 2007 05:28

This post interests me, but I think is a little OT.



Sorry, I didn't want to take that out of context.


Regards,
Novo
Re: ArrayCtrl with labels / layouts inside ? [message #13066 is a reply to message #13063] Sat, 08 December 2007 00:56 Go to previous message
jiaif is currently offline  jiaif
Messages: 17
Registered: November 2007
Location: France
Promising Member
Sorry, i finally decided to use xul for my application.
I will not try ultimate++ anymore for this project, but it was a cool experience anyway.

Thanks for your answers and your help.

jf

PS: And for Christmas i give you a little gift..
( have a look to your paypal account Wink )

[Updated on: Sat, 08 December 2007 01:01]

Report message to a moderator

Previous Topic: How to use WithDropChoice?
Next Topic: PromptOK - little error in textselection
Goto Forum:
  


Current Time: Fri Apr 26 12:47:44 CEST 2024

Total time taken to generate the page: 0.03661 seconds