U++ framework
Do not panic. Ask here before giving up.

Home » U++ Library support » U++ Widgets - General questions or Mixed problems » ArrayCtrl with labels / layouts inside ?
ArrayCtrl with labels / layouts inside ? [message #12885] Sun, 25 November 2007 19:23 Go to next message
jiaif is currently offline  jiaif
Messages: 17
Registered: November 2007
Location: France
Promising Member
Hi,

I'm new to Upp and i'm doing tests.
I dunno if its possible but i'd like to have an array control filled with labels.

My app have a main layout called myFirstUppApp with an ArrayCtrl called testArray.
I made a second layout with a label containing 3 others labels.

I want to use this second layout as a widget to fill my testArray.

Is it posible ? How can i do it, i'm lost Smile

jf
Re: ArrayCtrl with labels / layouts inside ? [message #12886 is a reply to message #12885] Sun, 25 November 2007 19:49 Go to previous messageGo to next message
jiaif is currently offline  jiaif
Messages: 17
Registered: November 2007
Location: France
Promising Member
Sorry i just found : http://www.ultimatepp.org/reference$ArrayCtrlEdits.html

i think this partially answer to my needs Embarassed

But creating a new layout is it the right way to create a kind of new widget ?

jf

[Updated on: Sun, 25 November 2007 19:50]

Report message to a moderator

Re: ArrayCtrl with labels / layouts inside ? [message #12887 is a reply to message #12886] Sun, 25 November 2007 21:24 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14291
Registered: November 2005
Ultimate Member
jiaif wrote on Sun, 25 November 2007 13:49

Sorry i just found : http://www.ultimatepp.org/reference$ArrayCtrlEdits.html

i think this partially answer to my needs Embarassed

But creating a new layout is it the right way to create a kind of new widget ?



Yep, if layout is useful for the widget, why not...

Mirek
Re: ArrayCtrl with labels / layouts inside ? [message #12888 is a reply to message #12887] Sun, 25 November 2007 22:07 Go to previous messageGo to next message
jiaif is currently offline  jiaif
Messages: 17
Registered: November 2007
Location: France
Promising Member
Thanks for you answer.
Sorry, i'm searching and i dont find how to do what i want.

I posted a picture who looks like what i want to do.

if you can give me just a piece of code, a little example, i'll be very very happy Smile
Or maybe a tuto where i can find how to create my own widget ?
What class to derivate ?

here is my second layout :

LAYOUT(myLayout, 196, 52)
ITEM(Label, lbl_name, LeftPosZ(4, 132).TopPosZ(4, 20))
ITEM(Label, lbl_surname, LeftPosZ(4, 132).TopPosZ(28, 20))
ITEM(Label, lbl_country, LeftPosZ(144, 48).TopPosZ(4, 44))
END_LAYOUT

myArray.AddColumn("test"). ... ?

thanks

Jf
  • Attachment: thing.png
    (Size: 20.59KB, Downloaded 503 times)
Re: ArrayCtrl with labels / layouts inside ? [message #12889 is a reply to message #12888] Mon, 26 November 2007 09:07 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14291
Registered: November 2005
Ultimate Member
jiaif wrote on Sun, 25 November 2007 16:07

Thanks for you answer.
Sorry, i'm searching and i dont find how to do what i want.

I posted a picture who looks like what i want to do.

if you can give me just a piece of code, a little example, i'll be very very happy Smile
Or maybe a tuto where i can find how to create my own widget ?
What class to derivate ?

here is my second layout :

LAYOUT(myLayout, 196, 52)
ITEM(Label, lbl_name, LeftPosZ(4, 132).TopPosZ(4, 20))
ITEM(Label, lbl_surname, LeftPosZ(4, 132).TopPosZ(28, 20))
ITEM(Label, lbl_country, LeftPosZ(144, 48).TopPosZ(4, 44))
END_LAYOUT

myArray.AddColumn("test"). ... ?

thanks

Jf


Actually, for the purpose I can see on screenshot, rather use Display.

Widgets are good if you want to change things. For static stuff, Display is better.

Mirek
Re: ArrayCtrl with labels / layouts inside ? [message #12890 is a reply to message #12889] Mon, 26 November 2007 17:03 Go to previous messageGo to next message
jiaif is currently offline  jiaif
Messages: 17
Registered: November 2007
Location: France
Promising Member
Hi Mirek,

I want to change things ! Smile
I want to change the wole world !

more seriously, i think i'm near the solution but i need to understand some things..

Supposing i want to fill my array with buttons (but i don't want the user to fill this array, i want to do this programatically).

I understand that i can do :

myArray.AddColumn("test").Ctrls<Button>();

But i don't know how to add a particular button.
If i just do : myArray.Add(); its add a button but without label and i don't understand how to set its label.

Button b;
b.SetLabel("test");

How can i add this button to the array ?
It's not DoAppend, Add or AddCtrl..

jf
Re: ArrayCtrl with labels / layouts inside ? [message #12891 is a reply to message #12890] Mon, 26 November 2007 18:06 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1266
Registered: August 2007
Senior Contributor
If I understood you right, try using myArray.SetCtrl()


Below is the modified code of Arrayctrl reference example.


ArrayCtrlExample::ArrayCtrlExample()
{
	CtrlLayoutExit(*this, "ArrayCtrl example");
	

	array.AddColumn("integer").Sorting();
	array.AddIndex(ID1);
	array.AddColumn(ID2, "combined").Add(ID1).AddIndex(ID3).SetConvert(Single<MyConvert>());
	array.AddColumn("editable").Edit(myedit).Sorting();
	array.AddColumn("with display").SetDisplay(Single<MyDisplay>());
	array.AddCtrl(editor);
	array.AddRowNumColumn("rownum");
	array.WhenLeftDouble = THISBACK(DoubleClick);
	array.ColumnWidths("51 120 60 102 62");

	for(int i = 0; i < 20; i++)
		array.Add(i, AsString(i * 10), GetSysDate(), i * 3, rand() % 1000,
		          Color(byte(i * 77), byte(i * 200), byte(i * 135)), FormatIntRoman(i));
//==========================================================
	bt.SetLabel("Test"); // bt should be declared in the interface
	array.SetCtrl(2, 2, bt);
//==========================================================
}



Just overwrite the original code, and declare "Button bt" before compiling, and see what it does.
Smile


[Updated on: Mon, 26 November 2007 18:10]

Report message to a moderator

Re: ArrayCtrl with labels / layouts inside ? [message #12892 is a reply to message #12891] Mon, 26 November 2007 18:32 Go to previous messageGo to next message
jiaif is currently offline  jiaif
Messages: 17
Registered: November 2007
Location: France
Promising Member
i'm sorry but :

error: no matching function for call to ‘Upp::ArrayCtrl::SetCtrl(int, int, Upp::Button&)’

note: candidates are: Upp::Ctrl& Upp::ArrayCtrl::SetCtrl(int, int, Upp::Ctrl*)

when i try to do :

Button b;
b.SetLabel("test");
myArray.AddColumn("test").Ctrls<Button>();
myArray.SetCtrl(0,0,b);

I don't understand what means the documentation about this method. I think it's not what i need. but i maybe i'm wrong ?

If you could give me a shorter and simple example it would be very cool Smile

[Updated on: Mon, 26 November 2007 18:33]

Report message to a moderator

Re: ArrayCtrl with labels / layouts inside ? [message #12893 is a reply to message #12892] Mon, 26 November 2007 18:55 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1266
Registered: August 2007
Senior Contributor
Ok, here is a very simple example. Smile
Edit: Example removed!
Regards.


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

Report message to a moderator

Re: ArrayCtrl with labels / layouts inside ? [message #12894 is a reply to message #12893] Mon, 26 November 2007 19:18 Go to previous messageGo to next message
jiaif is currently offline  jiaif
Messages: 17
Registered: November 2007
Location: France
Promising Member
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 ?

[Updated on: Mon, 26 November 2007 19:24]

Report message to a moderator

Re: ArrayCtrl with labels / layouts inside ? [message #12896 is a reply to message #12894] Mon, 26 November 2007 20:07 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1266
Registered: August 2007
Senior Contributor
Interesting. Which version of U++ do you use?
As of Upp 711b, there should be a:

SetCtrl(int iž int colž Ctrl& ctrlž bool value = true)


You can use this instead.

Ps: If you allocate Button from the stack (e.g. Button bt), try not to "declare" it inside the same method.
And, as far as I know, you have to "Add" something before you can "append" or "set" a ctrl seperately in an ArrayCtrl.

Eg,


Button *bt = new Button();
bt->SetLabel("Test");
myArray.AddColumn("Column1");
myArray.Add("");
myArray.SetCtrl(0, 0, bt);



Or/And


Button *bt = new Button();
bt->SetLabel("Test");
myArray.AddColumn("Column1");
myArray.AddColumn("Column2");
myArray.Add("This is a text");
myArray.SetCtrl(0, 1, bt);



should work.


Re: ArrayCtrl with labels / layouts inside ? [message #12897 is a reply to message #12896] Mon, 26 November 2007 20:26 Go to previous messageGo to next message
jiaif is currently offline  jiaif
Messages: 17
Registered: November 2007
Location: France
Promising Member
I use 2007.1, there is no deb package for other versions.

my def is :
SetCtrl(int i, int j, Ctrl *newctrl)

And your code (as mine) don't work.

it's sad
Re: ArrayCtrl with labels / layouts inside ? [message #12899 is a reply to message #12897] Mon, 26 November 2007 22:16 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14291
Registered: November 2005
Ultimate Member
jiaif wrote on Mon, 26 November 2007 14:26

I use 2007.1, there is no deb package for other versions.




Yes, sorry. Our Linux maintainer took a long vacation...

Anyway, all you need to do is to download sources and create assemblies for them. It is simple.

Mirek
Re: ArrayCtrl with labels / layouts inside ? [message #12902 is a reply to message #12899] Tue, 27 November 2007 00:28 Go to previous messageGo to next message
jiaif is currently offline  jiaif
Messages: 17
Registered: November 2007
Location: France
Promising Member
OK..

But without readme or makefile, it would not be so simple.

With a tuto or a simple INSTALL it would be cool Smile

[Updated on: Tue, 27 November 2007 00:43]

Report message to a moderator

Re: ArrayCtrl with labels / layouts inside ? [message #12904 is a reply to message #12902] Tue, 27 November 2007 12:13 Go to previous messageGo to next message
jiaif is currently offline  jiaif
Messages: 17
Registered: November 2007
Location: France
Promising Member
Ouch !...

I followed a tuto on the forum for compiling svn sources under linux, and it works.. but not very well. (eats 7% of my load, layout editor as fast as a turtle, and tons of bugs when compiling my project..)
Maybe should i try a dev release instead. That's what i'm going to do.
Re: ArrayCtrl with labels / layouts inside ? [message #12905 is a reply to message #12904] Tue, 27 November 2007 12:52 Go to previous messageGo to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
The easiest way I've found of installing/updating on Linux (I don't usually use the SVN version):
1- Download last Linux installer (If you already have Upp installed you can ignore this)
2- Download latest dev release source. Replace uppsrc with new version.
3- If desired, recompile TheIDE

That's all you should have to do.
Re: ArrayCtrl with labels / layouts inside ? [message #12906 is a reply to message #12904] Tue, 27 November 2007 12:54 Go to previous messageGo to next message
jiaif is currently offline  jiaif
Messages: 17
Registered: November 2007
Location: France
Promising Member
I tried 711-dev2, it's a bit better, but why is it so slow compared to 2007.1 ?

I have the same problem, i can add buttons on my array but they don't appear.

SetCtrl method definition is the same as in 2007.1 version :
Ctrl *newctrl
and not
Ctrl& ctrl

any other ideas ?
Re: ArrayCtrl with labels / layouts inside ? [message #12907 is a reply to message #12905] Tue, 27 November 2007 12:57 Go to previous messageGo to next message
jiaif is currently offline  jiaif
Messages: 17
Registered: November 2007
Location: France
Promising Member
thanks mrjt,

but i followed this tuto
Re: ArrayCtrl with labels / layouts inside ? [message #12908 is a reply to message #12907] Tue, 27 November 2007 19:43 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1266
Registered: August 2007
Senior Contributor
Here is a "heap" version of the example. I hope that it will work. If not, there is probably a problem with the debian U++ dist.
(it works fine with ubuntu (7.10) and pardus)
code is using the:
myArray.SetCtrl(int iž int jž Ctrl *newctrl)





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

Report message to a moderator

Re: ArrayCtrl with labels / layouts inside ? [message #12909 is a reply to message #12908] Tue, 27 November 2007 21:36 Go to previous messageGo to next message
jiaif is currently offline  jiaif
Messages: 17
Registered: November 2007
Location: France
Promising Member
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
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: 1266
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 614 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: 14291
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: 14291
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: 1266
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: 14291
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: 14291
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: 1431
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: 1431
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: Sun May 10 20:55:43 GMT+2 2026

Total time taken to generate the page: 0.02584 seconds