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 » Community » Newbie corner » Buttons in Array using ArrayCtrl
Buttons in Array using ArrayCtrl [message #37757] Fri, 09 November 2012 19:30 Go to next message
nejnadusho is currently offline  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 #37758 is a reply to message #37757] Fri, 09 November 2012 20:17 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1182
Registered: March 2006
Location: Italy
Senior Contributor
Hello,

have you had a look to ArrayCtrlSetCtrl package in reference assembly?

Regards,
Luigi
Re: Buttons in Array using ArrayCtrl [message #37759 is a reply to message #37757] Fri, 09 November 2012 20:48 Go to previous messageGo to next message
nejnadusho is currently offline  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 Go to previous messageGo to next message
omari is currently offline  omari
Messages: 264
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 #38002 is a reply to message #37757] Tue, 27 November 2012 22:47 Go to previous messageGo to next message
nejnadusho is currently offline  nejnadusho
Messages: 60
Registered: October 2012
Member
Omari,

Thank you very much for your help.
It totally works.

However, I am not clear how this widget factory is working.
I guess I do not understand the Ctrls well.

I read the code and understand everything, but this line.

myArray.AddColumn("List of Tables").Ctrls(THISBACK(WidgetFactory));

What is it happening on this line? Is there a notion of a constructor in that line or what?


And why not adding/removing a button with every
myArray.Add();
//for example like
myArray.Add(add.button);

instead of by default in the way it is currently?


Thank you very much for your time.

Best,
nejnio
Re: Buttons in Array using ArrayCtrl [message #38080 is a reply to message #37757] Thu, 29 November 2012 19:49 Go to previous messageGo to next message
nejnadusho is currently offline  nejnadusho
Messages: 60
Registered: October 2012
Member
OK I think I understood. What is going on in the factory. Still how come the factory is not taking two param which are not optional and that is not an error?!?!?!?!

However, how can I edit cell by cell in the grid/array.

myArray[0][1]; does not work here.

I looked the spec of Array Ctrl and still no luck in figuring it out.

Thank you for your help.

Best,
nejnio
Re: Buttons in Array using ArrayCtrl [message #38114 is a reply to message #38080] Sat, 01 December 2012 15:56 Go to previous message
omari is currently offline  omari
Messages: 264
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.
Previous Topic: Changing EditFields from header files
Next Topic: No Export to PDF button in Windows?
Goto Forum:
  


Current Time: Thu Mar 28 23:08:09 CET 2024

Total time taken to generate the page: 0.01044 seconds