Home » Community » Newbie corner » Buttons in Array using ArrayCtrl
Buttons in Array using ArrayCtrl [message #37757] |
Fri, 09 November 2012 19:30  |
nejnadusho
Messages: 60 Registered: October 2012
|
Member |
|
|
Hi,
I have been trying to stuff an array with buttons and use it with ArrayCtrl and I had not had the chase to succeed.
I have been trying the following.
The .lay file has just one ArrayCtrl myArray; thrown alone on a single layout.
main.cpp
#include "test.h"
test::test()
{
//Array<Button*> myButt;
//Button* a = new Button;
//Button* b = new Button;
//myButt.Add(a);
//myButt.Add(b);
Array<Button> myButt;
myButt.Add();
myButt.Add();
CtrlLayout(*this, "Window title");
myArray.AddColumn("List of Tables");
//myArray.Add(myButt[0]->SetLabel("Push1"));
//myArray.Add(myButt[1]->SetLabel("Push2"));
myArray.Add(myButt[0].SetLabel("Push1"));
myArray.Add(myButt[1].SetLabel("Push2"));
}
GUI_APP_MAIN
{
test().Run();
}
My goal is to have a column of buttons in ArrayCtrl.
As you can see I have also been trying to be just pointers of buttons which I believe is preferable.
Any help/suggestions will be greatly appreciated.
Best,
nejnio
|
|
|
|
Re: Buttons in Array using ArrayCtrl [message #37759 is a reply to message #37757] |
Fri, 09 November 2012 20:48   |
nejnadusho
Messages: 60 Registered: October 2012
|
Member |
|
|
Luigi,
Thank you.
Yes I have been trying to figure exactly this out.
I just tweaked the code a little now I have no compiling errors but it does not display the buttons, however, the rows are there and clickable but once I click them the app crashes.
#include "test.h"
test::test()
{
Array<Button> myButt;
myButt.Add();
myButt.Add();
CtrlLayout(*this, "Window title");
myArray.AddColumn("List of Tables");
myArray.Add();
myArray.Add();
myArray.SetCtrl(0,0, myButt[0].SetLabel("Push1").SizePos());
myArray.SetCtrl(1,0, myButt[1].SetLabel("Push2").SizePos());
}
GUI_APP_MAIN
{
test().Run();
}
I just cannot get complete understanding of the ArrayCtrlSetCtrl package.
Best,
nejnio
|
|
|
Re: Buttons in Array using ArrayCtrl [message #37761 is a reply to message #37759] |
Sat, 10 November 2012 14:32   |
omari
Messages: 276 Registered: March 2010
|
Experienced Member |
|
|
Hi,
you can use WidgetFactory callback:
.h
#define LAYOUTFILE <XXXXXX/XXX.lay>
#include <CtrlCore/lay.h>
struct test : WithXXX<TopWindow> {
typedef test CLASSNAME;
test();
void WidgetFactory(int line, One<Ctrl>& x);
void OnButton(int n);
};
.cpp
#include <CtrlLib/CtrlLib.h>
using namespace Upp;
#include "test.h"
void test::OnButton(int n)
{
PromptOK(AsString(n));
}
void test::WidgetFactory(int line, One<Ctrl>& x)
{
Button& b = x.Create<Button>();
b.SetLabel("Line " + AsString(line));
b.LeftPos(10, 60).TopPos(4, 16);
b <<= THISBACK1(OnButton, line);
}
test::test()
{
CtrlLayout(*this, "Window title");
myArray.AddColumn("List of Tables").Ctrls(THISBACK(WidgetFactory));
myArray.SetLineCy( 20);
myArray.Add();
myArray.Add();
myArray.Add();
myArray.Add();
myArray.Add();
}
GUI_APP_MAIN
{
test().Run();
}
Regards,
Omari
regards
omari.
|
|
|
|
|
Re: Buttons in Array using ArrayCtrl [message #38114 is a reply to message #38080] |
Sat, 01 December 2012 15:56  |
omari
Messages: 276 Registered: March 2010
|
Experienced Member |
|
|
Hi,
ArrayCtrl has three overload of the Ctrls method, one of thems is described in the referance manual as:
Column& Ctrls(Callback1<One<Ctrl>&> factory)
The methods sets up a factory which the ArrayCtrl uses as necessary to create new Ctrl's for editing a given column. The argument of this function is a callback, which, upon execution, should allocate (normally using the new operator) the desired editor object and set it to its argument. If the position of Ctrl is equivalent to 'SetRect(0, 0, 0, 0)', which is the default value, Ctrl is resized to fit the ArrayCtrl cell accurately, otherwise the position represents the position within the cell.
factory callback used for new control creation
Return value *this
you can edit a cell by : myArray.Set(row, col, value);
Regards,
Omari
regards
omari.
|
|
|
Goto Forum:
Current Time: Tue Apr 29 01:48:21 CEST 2025
Total time taken to generate the page: 0.01366 seconds
|