Home » U++ Library support » U++ Widgets - General questions or Mixed problems » ArrayCtrl with labels / layouts inside ?
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
|
|
|
 |
|
ArrayCtrl with labels / layouts inside ?
By: jiaif on Sun, 25 November 2007 19:23
|
 |
|
Re: ArrayCtrl with labels / layouts inside ?
By: jiaif on Sun, 25 November 2007 19:49
|
 |
|
Re: ArrayCtrl with labels / layouts inside ?
By: mirek on Sun, 25 November 2007 21:24
|
 |
|
Re: ArrayCtrl with labels / layouts inside ?
By: jiaif on Sun, 25 November 2007 22:07
|
 |
|
Re: ArrayCtrl with labels / layouts inside ?
By: mirek on Mon, 26 November 2007 09:07
|
 |
|
Re: ArrayCtrl with labels / layouts inside ?
By: jiaif on Mon, 26 November 2007 17:03
|
 |
|
Re: ArrayCtrl with labels / layouts inside ?
By: Oblivion on Mon, 26 November 2007 18:06
|
 |
|
Re: ArrayCtrl with labels / layouts inside ?
By: jiaif on Mon, 26 November 2007 18:32
|
 |
|
Re: ArrayCtrl with labels / layouts inside ?
By: Oblivion on Mon, 26 November 2007 18:55
|
 |
|
Re: ArrayCtrl with labels / layouts inside ?
By: jiaif on Mon, 26 November 2007 19:18
|
 |
|
Re: ArrayCtrl with labels / layouts inside ?
By: Oblivion on Mon, 26 November 2007 20:07
|
 |
|
Re: ArrayCtrl with labels / layouts inside ?
By: jiaif on Mon, 26 November 2007 20:26
|
 |
|
Re: ArrayCtrl with labels / layouts inside ?
By: mirek on Mon, 26 November 2007 22:16
|
 |
|
Re: ArrayCtrl with labels / layouts inside ?
By: jiaif on Tue, 27 November 2007 00:28
|
 |
|
Re: ArrayCtrl with labels / layouts inside ?
By: jiaif on Tue, 27 November 2007 12:13
|
 |
|
Re: ArrayCtrl with labels / layouts inside ?
By: mrjt on Tue, 27 November 2007 12:52
|
 |
|
Re: ArrayCtrl with labels / layouts inside ?
By: jiaif on Tue, 27 November 2007 12:57
|
 |
|
Re: ArrayCtrl with labels / layouts inside ?
By: Oblivion on Tue, 27 November 2007 19:43
|
 |
|
Re: ArrayCtrl with labels / layouts inside ?
By: jiaif on Tue, 27 November 2007 21:36
|
 |
|
Re: ArrayCtrl with labels / layouts inside ?
By: Oblivion on Tue, 27 November 2007 22:10
|
 |
|
Re: ArrayCtrl with labels / layouts inside ?
By: mirek on Tue, 27 November 2007 22:57
|
 |
|
Re: ArrayCtrl with labels / layouts inside ?
By: jiaif on Wed, 28 November 2007 18:59
|
 |
|
Re: ArrayCtrl with labels / layouts inside ?
By: jiaif on Wed, 28 November 2007 19:24
|
 |
|
Re: ArrayCtrl with labels / layouts inside ?
By: Oblivion on Wed, 28 November 2007 22:27
|
 |
|
Re: ArrayCtrl with labels / layouts inside ?
By: mirek on Thu, 29 November 2007 05:49
|
 |
|
Re: ArrayCtrl with labels / layouts inside ?
By: mrjt on Thu, 29 November 2007 13:57
|
 |
|
Re: ArrayCtrl with labels / layouts inside ?
By: mirek on Tue, 04 December 2007 09:39
|
 |
|
Re: ArrayCtrl with labels / layouts inside ?
By: jiaif on Thu, 06 December 2007 18:25
|
 |
|
Re: ArrayCtrl with labels / layouts inside ?
By: jiaif on Thu, 06 December 2007 19:15
|
 |
|
Re: ArrayCtrl with labels / layouts inside ?
By: jiaif on Tue, 27 November 2007 12:54
|
 |
|
Re: ArrayCtrl with labels / layouts inside ?
By: mirek on Tue, 27 November 2007 22:55
|
 |
|
Re: ArrayCtrl with labels / layouts inside ?
By: Novo on Thu, 06 December 2007 20:29
|
 |
|
Re: ArrayCtrl with labels / layouts inside ?
By: waxblood on Fri, 07 December 2007 11:28
|
 |
|
Re: ArrayCtrl with labels / layouts inside ?
By: Novo on Fri, 07 December 2007 18:31
|
 |
|
Re: ArrayCtrl with labels / layouts inside ?
By: jiaif on Sat, 08 December 2007 00:56
|
Goto Forum:
Current Time: Mon Jun 09 07:16:16 CEST 2025
Total time taken to generate the page: 0.04364 seconds
|