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   |
Oblivion
Messages: 1204 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.
|

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 
(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 552 times)
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[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   |
 |
mirek
Messages: 14255 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 
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 ? 
[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 #12923 is a reply to message #12922] |
Wed, 28 November 2007 19:24   |
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   |
Oblivion
Messages: 1204 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...
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Wed, 28 November 2007 22:45] Report message to a moderator
|
|
|
|
Re: ArrayCtrl with labels / layouts inside ? [message #12935 is a reply to message #12928] |
Thu, 29 November 2007 13:57   |
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 . 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 #13037 is a reply to message #13036] |
Thu, 06 December 2007 19:15   |
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   |
Novo
Messages: 1430 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   |
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 #13066 is a reply to message #13063] |
Sat, 08 December 2007 00:56  |
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 )
[Updated on: Sat, 08 December 2007 01:01] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Mon Apr 28 21:52:45 CEST 2025
Total time taken to generate the page: 0.03548 seconds
|