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

Home » U++ Library support » ArrayCtrl, HeaderCtrl & GridCtrl » How to Setup ArrayCtrl colors ?
How to Setup ArrayCtrl colors ? [message #16874] Fri, 18 July 2008 19:20 Go to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

How to Setup ArrayCtrl colors?
I need to setup ArrayCtrl color and current line color.


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: How to Setup ArrayCtrl colors ? [message #16898 is a reply to message #16874] Sun, 20 July 2008 01:05 Go to previous messageGo to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

Íàïðàøèâàþòñÿ äâà îñíîâíûõ âàðèàíòà: ÷åðåç Display (ïðîùå) ëèáî ÷åðåç Chameleon.

---------------------------------------

There are two main options: through Display (easy way) or with Chameleon (hard way).
Re: How to Setup ArrayCtrl colors ? [message #16907 is a reply to message #16898] Sun, 20 July 2008 14:18 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

Can you say about CHAmeleon technology. I need to use it anywhere in my application.



SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: How to Setup ArrayCtrl colors ? [message #18461 is a reply to message #16907] Thu, 02 October 2008 06:44 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

Solved.
	SColorPaper_Write(Color(205,205,205));
	SColorHighlight_Write(Color(85,85,85));
	SColorHighlightText_Write(Color(255,255,255));

	static HeaderCtrl::Style  s = HeaderCtrl::StyleDefault();
	s.look[0] = Color(130,125,125);
	types.HeaderObject().SetStyle(s);
	types.OddRowColor(Color(205,205,205),Color(85,85,85));
	types.EvenRowColor(Color(205,205,205),Color(85,85,85));
	types.GridColor(Color(80,80,80));



SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: How to Setup ArrayCtrl colors ? [message #18577 is a reply to message #18461] Fri, 10 October 2008 10:06 Go to previous messageGo to next message
TeCNoYoTTa is currently offline  TeCNoYoTTa
Messages: 138
Registered: July 2008
Location: Egypt
Experienced Member
sergeynikitin wrote on Thu, 02 October 2008 06:44

Solved.
	SColorPaper_Write(Color(205,205,205));
	SColorHighlight_Write(Color(85,85,85));
	SColorHighlightText_Write(Color(255,255,255));

	static HeaderCtrl::Style  s = HeaderCtrl::StyleDefault();
	s.look[0] = Color(130,125,125);
	types.HeaderObject().SetStyle(s);
	types.OddRowColor(Color(205,205,205),Color(85,85,85));
	types.EvenRowColor(Color(205,205,205),Color(85,85,85));
	types.GridColor(Color(80,80,80));




can you explain more .......where must i put this code ??
Re: How to Setup ArrayCtrl colors ? [message #18578 is a reply to message #18577] Fri, 10 October 2008 10:38 Go to previous messageGo to next message
TeCNoYoTTa is currently offline  TeCNoYoTTa
Messages: 138
Registered: July 2008
Location: Egypt
Experienced Member
i want to set a color and then add a row with this color then change it and add another row with another color ......how can i do that ?
Re: How to Setup ArrayCtrl colors ? [message #18579 is a reply to message #18578] Fri, 10 October 2008 12:41 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1266
Registered: August 2007
Senior Contributor
Quote:


i want to set a color and then add a row with this color then change it and add another row with another color ......how can i do that ?



You can use Display structure and SetDisplay() method to set column colors and content:

First you should add a Display object. For example:
struct Column1Display : Display {
	virtual void Paint(Draw& w, const Rect& r, const Value& q, Color ink, Color paper, dword style) const
	{
		w.DrawRect(r, Color(500,0,0));
	}
};

struct Column2Display : Display {
	virtual void Paint(Draw& w, const Rect& r, const Value& q, Color ink, Color paper, dword style) const
	{
		w.DrawRect(r, Color(0,500,0));
	}
};



Then, Set the Display of the column, using ArrayCtrl::Column::SetDisplay() or Array::SetDisplay() in your constructor or wherever you instantiate your ArrayCtrl object:

MyApp::MyApp()
{
//.....
//.....

MyArray.AddColumn("Column 1").SetDisplay(Single<Column1Display>());
MyArray.AddColumn("Column 2").SetDisplay(Single<Column2Display>());

}


This will set the "column 1" and "column 2" colors. You can set other columns' displays as such. As you may have noticed, by using the Display structure you can also do other specific operations on a single column (eg, adding images, changing background, fonts, etc.). Display also has a virtual PaintBackground() method which you can set background seperately See Display structure for more information.

Regards.


[Updated on: Fri, 10 October 2008 13:08]

Report message to a moderator

Re: How to Setup ArrayCtrl colors ? [message #18581 is a reply to message #18579] Fri, 10 October 2008 13:23 Go to previous messageGo to next message
TeCNoYoTTa is currently offline  TeCNoYoTTa
Messages: 138
Registered: July 2008
Location: Egypt
Experienced Member
Oblivion wrote on Fri, 10 October 2008 12:41

Quote:


i want to set a color and then add a row with this color then change it and add another row with another color ......how can i do that ?



You can use Display structure and SetDisplay() method to set column colors and content:

First you should add a Display object. For example:
struct Column1Display : Display {
	virtual void Paint(Draw& w, const Rect& r, const Value& q, Color ink, Color paper, dword style) const
	{
		w.DrawRect(r, Color(500,0,0));
	}
};

struct Column2Display : Display {
	virtual void Paint(Draw& w, const Rect& r, const Value& q, Color ink, Color paper, dword style) const
	{
		w.DrawRect(r, Color(0,500,0));
	}
};



Then, Set the Display of the column, using ArrayCtrl::Column::SetDisplay() or Array::SetDisplay() in your constructor or wherever you instantiate your ArrayCtrl object:

MyApp::MyApp()
{
//.....
//.....

MyArray.AddColumn("Column 1").SetDisplay(Single<Column1Display>());
MyArray.AddColumn("Column 2").SetDisplay(Single<Column2Display>());

}


This will set the "column 1" and "column 2" colors. You can set other columns' displays as such. As you may have noticed, by using the Display structure you can also do other specific operations on a single column (eg, adding images, changing background, fonts, etc.). Display also has a virtual PaintBackground() method which you can set background seperately See Display structure for more information.

Regards.



thanxxxxxxxxx alot ......but i think that you are talking about columns colors ......but i want to color rows background not columns

thx again
Re: How to Setup ArrayCtrl colors ? [message #18582 is a reply to message #18581] Fri, 10 October 2008 14:23 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1266
Registered: August 2007
Senior Contributor
Smile I'm sorry. Here is an example which demonstrates both (row and column coloring). On the other hand, if you want every row to be in different color, AFAIK there is no specific method. Probably you'll have to derive your own class from ArrayCtrl and override Paint().

[Updated on: Fri, 10 October 2008 14:31]

Report message to a moderator

Re: How to Setup ArrayCtrl colors ? [message #18583 is a reply to message #18582] Fri, 10 October 2008 14:28 Go to previous messageGo to next message
TeCNoYoTTa is currently offline  TeCNoYoTTa
Messages: 138
Registered: July 2008
Location: Egypt
Experienced Member
thanks alot ..... can u tell me also how to change the color off all the text in my program or color of text in menubar

and thxxxxxxxxxx alot for your help again
Re: How to Setup ArrayCtrl colors ? [message #18584 is a reply to message #18582] Fri, 10 October 2008 14:36 Go to previous messageGo to next message
TeCNoYoTTa is currently offline  TeCNoYoTTa
Messages: 138
Registered: July 2008
Location: Egypt
Experienced Member
Oblivion wrote on Fri, 10 October 2008 14:23

Smile I'm sorry. Here is an example which demonstrates both (row and column coloring). On the other hand, if you want every row to be in different color, AFAIK there is no specific method. Probably you'll have to derive your own class from ArrayCtrl and override Paint().


does that mean i cant choose a row number and set it's color easly Sad Sad
Re: How to Setup ArrayCtrl colors ? [message #18585 is a reply to message #18584] Fri, 10 October 2008 14:56 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1266
Registered: August 2007
Senior Contributor
Well, at least I don't know a public method that seperately sets the color. Sad You have to find a workaround if you want every row to be in different color. You may want to look at ArrayCtrl::UpdateRow() protected method. It seems that you can override that to reach your goal.

Regards.


Re: How to Setup ArrayCtrl colors ? [message #18586 is a reply to message #18584] Fri, 10 October 2008 14:59 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1367
Registered: November 2005
Location: Poland
Ultimate Contributor

You can use GridCtrl:
grid.AddRow("text").Bg(Red);
grid.GetRow(10).Bg(Yellow);
Re: How to Setup ArrayCtrl colors ? [message #18588 is a reply to message #18586] Fri, 10 October 2008 16:07 Go to previous messageGo to next message
TeCNoYoTTa is currently offline  TeCNoYoTTa
Messages: 138
Registered: July 2008
Location: Egypt
Experienced Member
unodgs wrote on Fri, 10 October 2008 14:59

You can use GridCtrl:
grid.AddRow("text").Bg(Red);
grid.GetRow(10).Bg(Yellow);



thx but i already used Array CTRL

so is there a function like Addkey as i use it in arrayctrl
Re: How to Setup ArrayCtrl colors ? [message #18589 is a reply to message #18588] Fri, 10 October 2008 16:15 Go to previous messageGo to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
You can set the display for individual cells in an ArrayCtrl with
	void            SetDisplay(int i, int col, const Display& d);

then you just have to iterate through the columns to set each cell on a row.

And an easier way of getting colored displays:
template <const int COLOR>
class ColorDisplayTemplate : public Display
{
	virtual void Paint(Draw& w, const Rect& r, const Value& q,
			Color ink, Color paper, dword style) const
			{ StdDisplay().Paint(w, r, q, ink, Color::FromRaw(COLOR), style); }
};

const Display &RedDisplay() 	{ return Single< ColorDisplayTemplate<RGB(255, 0, 0)> >(); }
const Display &BlueDisplay() 	{ return Single< ColorDisplayTemplate<RGB(0, 0, 255)> >(); }
const Display &GreenDisplay() 	{ return Single< ColorDisplayTemplate<RGB(0, 255, 0)> >(); }


A template? Is not it a bit brutal? Smile

What about a nice little Color attribute (and perhaps global variables instead of Single)?

Mirek

[Updated on: Sat, 11 October 2008 00:10] by Moderator

Report message to a moderator

Re: How to Setup ArrayCtrl colors ? [message #18591 is a reply to message #18589] Fri, 10 October 2008 18:14 Go to previous messageGo to next message
TeCNoYoTTa is currently offline  TeCNoYoTTa
Messages: 138
Registered: July 2008
Location: Egypt
Experienced Member
thanks alot ....... but this dont color the whole cell

it leaves some parts uncolored .....how can i fix this problem ??
Re: How to Setup ArrayCtrl colors ? [message #18594 is a reply to message #18591] Fri, 10 October 2008 21:29 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1266
Registered: August 2007
Senior Contributor
Quote:


thanks alot ....... but this dont color the whole cell

it leaves some parts uncolored .....how can i fix this problem ??



That part is background. You should handle background too. Same as Paint (You can safely apply the below code to Mrjt's code).

	virtual void Paint(Draw& w, const Rect& r, const Value& q, Color ink, Color paper, dword style) const 
	{
		w.DrawRect(r, SColorInfo);
		w.DrawText(r.left, r.top, q.ToString());
	}
	virtual void PaintBackground(Draw& w, const Rect& r, const Value& q, Color ink, Color paper, dword style) const
	{
		w.DrawRect(r, SColorInfo);
	}
}


But if you paint background manually, you should handle "highlighted state" of cell manually too.


[Updated on: Fri, 10 October 2008 21:33]

Report message to a moderator

Re: How to Setup ArrayCtrl colors ? [message #18631 is a reply to message #18589] Mon, 13 October 2008 12:44 Go to previous messageGo to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
mrjt didn't write


A template? Is not it a bit brutal? Smile

What about a nice little Color attribute (and perhaps global variables instead of Single)?

Mirek

You are correct, this is horribly over-engineered. I just can't resist a cute idea Smile A Color attribute would give the extra advantage of being able to use the Chameleon colors.

I think the extra white bits in the cells are probably the margin. Try:
arrayctrl.AddColumn("A Column").Margin(0);

Re: How to Setup ArrayCtrl colors ? [message #18755 is a reply to message #18591] Mon, 20 October 2008 07:42 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
TeCNoYoTTa wrote on Fri, 10 October 2008 12:14

thanks alot ....... but this dont color the whole cell

it leaves some parts uncolored .....how can i fix this problem ??


Also not mentioned here is possibility to use AttrText. It is very simple, with disadvantage is that it is then hard to read data back from ArrayCtrl.

Anyway:

myarrayctrl.Add(AttrText("My colored text").Ink(Red));

Mirek
Re: How to Setup ArrayCtrl colors ? [message #18790 is a reply to message #18755] Tue, 21 October 2008 09:50 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

How do I change the color of the paper only on the current window.

I tried

SColorPaper_Write (color (205205205)),
however, change the background color of the full application.

I need to change the color of the paper at 1 window.


SetDisplay - is not suitable as it will not change the background color ArrayCtrl where no lines.


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}

[Updated on: Tue, 21 October 2008 09:55]

Report message to a moderator

Re: How to Setup ArrayCtrl colors ? [message #18791 is a reply to message #18790] Tue, 21 October 2008 14:27 Go to previous messageGo to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
This is not possible.

I think the closest you could get is to SetNoBackground() on the ArrayCtrl, and set the colour of the cells manually using any of the methods above. Not sure if this will work though.
Re: How to Setup ArrayCtrl colors ? [message #18794 is a reply to message #18791] Tue, 21 October 2008 19:00 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
In fact, NoBackground makes ArrayCtrl transparent - you can then put some other widget "behind".

If you want a solid color, put StaticRect behind. But it can also be picture or anything else Smile (Not also that StaticRect accepts "chameleon" visuals values, so you can put Image in it directly, with chameleon style hotspots..).

BTW, it also applies to EditFile, LineEdit, DocEdit, ColumnList and TreeCtrl Smile

Mirek

[Updated on: Tue, 21 October 2008 19:01]

Report message to a moderator

Re: How to Setup ArrayCtrl colors ? [message #18799 is a reply to message #18794] Wed, 22 October 2008 01:32 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

Thanks.

SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: How to Setup ArrayCtrl colors ? [message #18811 is a reply to message #16874] Thu, 23 October 2008 19:56 Go to previous messageGo to next message
darki699 is currently offline  darki699
Messages: 3
Registered: October 2008
Location: Hell
Junior Member
sergeynikitin wrote on Fri, 18 July 2008 19:20

How to Setup ArrayCtrl colors?
I need to setup ArrayCtrl color and current line color.



This is pretty simple if you are willing to change ArrayCtrl just a bit... Wink

Step 1: In ArrayCtrl.h add this:
void SetRowDisplay(int i, const Display& d);
void SetColDisplay(int j, const Display& d);


Step 2: In ArrayCtrl.cpp add this:
void ArrayCtrl::SetRowDisplay(int i, const Display& d)
{
	if(i >= 0 && i < GetCount())
		for (int j = 0 ; j < GetSize().cx ; j++)	
			cellinfo.At(i).At(j).Set(d);
	RefreshRow(i);
}

void ArrayCtrl::SetColDisplay(int j, const Display& d)
{
	if (j >= 0 && j < column.GetCount())
		column[j].SetDisplay(d);
}


Step 3: In your program add this:
struct MyJDisplay : Display {
	virtual void Paint(Draw& w, const Rect& r, const Value& q, Color ink, Color paper, dword style) const
	{
		PaintBackground(w, r, q, Blend(ink, Color(0,0,0)) , Blend(paper, Color(0,0,0)), style);
		w.DrawText(r.left, r.top, q.ToString());
	}
};

For example... You can choose any color of course, but I really suggest you use Blend unless you want your Selected row to not-show.

and that's about it... Add your SetRowDisplay or SetColDisplay any way you like it. =)
If you want a nice look use this
Quote:


[your ArrayCtrl].AddColumn(column, column, columnSize).Margin(0)


when you add your column.

And an example of how I used it:
 UserMovies.SetRowDisplay(j , Single<MyJDisplay>());	


NJoy and remember that the code is not a god.
If you need to improve it, don't be afraid to add (backup everything first lol)

Darki699

[Updated on: Thu, 23 October 2008 19:57]

Report message to a moderator

Re: How to Setup ArrayCtrl colors ? [message #18940 is a reply to message #18811] Sat, 01 November 2008 23:37 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
darki699 wrote on Thu, 23 October 2008 13:56

sergeynikitin wrote on Fri, 18 July 2008 19:20

How to Setup ArrayCtrl colors?
I need to setup ArrayCtrl color and current line color.



This is pretty simple if you are willing to change ArrayCtrl just a bit... Wink

Step 1: In ArrayCtrl.h add this:
void SetRowDisplay(int i, const Display& d);
void SetColDisplay(int j, const Display& d);


Step 2: In ArrayCtrl.cpp add this:
void ArrayCtrl::SetRowDisplay(int i, const Display& d)
{
	if(i >= 0 && i < GetCount())
		for (int j = 0 ; j < GetSize().cx ; j++)	
			cellinfo.At(i).At(j).Set(d);
	RefreshRow(i);
}

void ArrayCtrl::SetColDisplay(int j, const Display& d)
{
	if (j >= 0 && j < column.GetCount())
		column[j].SetDisplay(d);
}




Or you can also define these as external functions (there is no private/procted stuff needed).

Personally, I would not add these methods to solve this issue, and I CAN DO IT EASILY:)

Mirek
Re: How to Setup ArrayCtrl colors ? [message #25102 is a reply to message #18589] Wed, 10 February 2010 17:36 Go to previous messageGo to next message
whiteman is currently offline  whiteman
Messages: 11
Registered: May 2009
Promising Member
I'm using an arrayctrl, in my application I need to set some cell color and i don't want to use AttrText: is too slow!
I have 200-300 cells and is the user that choose what color want to use, so, I can't use



SetDisplay(row, column, Single<MyColor<RGB(col.R, col.G, col.B)> >())

because an error say me that I must use costant value.
What should I do for set dinamically the color of my grid without
AttrText?
thank you!!
Re: How to Setup ArrayCtrl colors ? [message #25303 is a reply to message #25102] Tue, 16 February 2010 20:53 Go to previous message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
e.g.

.SetDisplay(row, column, ColorDisplay());
.Set(row, column, Color(...));
Previous Topic: Spanning Columns?
Next Topic: Cells appearance and text alignment
Goto Forum:
  


Current Time: Mon Apr 27 23:46:38 GMT+2 2026

Total time taken to generate the page: 0.01579 seconds