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 » 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: 1091
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: 1091
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: 1091
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: 1366
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: 1091
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: 13975
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 previous 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

Previous Topic: Spanning Columns?
Next Topic: Cells appearance and text alignment
Goto Forum:
  


Current Time: Thu Mar 28 14:59:45 CET 2024

Total time taken to generate the page: 0.01486 seconds