1. Text color in wxEuphoria

How can I add colors to text in a "wxTextCtrl"?

Here is the code

	include wxeud.e 
 
	constant main = create( wxFrame, {0, -1, "Client", -1, -1, 700, 400, wxDEFAULT_FRAME_STYLE} ) 
	constant textbox = create( wxTextCtrl , {main, -1, "", -1, -1, -1, -1, wxTE_MULTILINE + wxTE_READONLY } ) 
 
	append_text(textbox, "This text in BLACK\n") 
	append_text(textbox, "This text in RED\n") 
	append_text(textbox, "This text in BLUE\n") 
 
	wxMain( main ) 

I have tried a lot of different things, but I could not set the text in colors.

new topic     » topic index » view message » categorize

2. Re: Text color in wxEuphoria

I'm truly just guessing, but did you try:

set_font ( atom dc, atom font ) for the wxTextCtrl?

Don't know what "dc" is exactly, but it might be like the control Id in Win32Lib?

Dan

new topic     » goto parent     » topic index » view message » categorize

3. Re: Text color in wxEuphoria

xfox26 said...

How can I add colors to text in a "wxTextCtrl"?

I have tried a lot of different things, but I could not set the text in colors.

You need to use set_text_style() along with a wxTextAttr object.

include wxeud.e 
 
constant main = create( wxFrame, {0, -1, "Client", -1, -1, 700, 400, wxDEFAULT_FRAME_STYLE} ) 
constant textbox = create( wxTextCtrl , {main, -1, "", -1, -1, -1, -1, wxTE_MULTILINE + wxTE_READONLY } ) 
 
constant ATTRS= { 
	create( wxTextAttr, {} ), 
	create( wxTextAttr, {} ), 
	create( wxTextAttr, {} ) } 
 
set_text_attr_color( ATTRS[1], create( wxColour, {"Black"}) ) 
set_text_attr_color( ATTRS[2], create( wxColour, {"Red"}) ) 
set_text_attr_color( ATTRS[3], create( wxColour, {"Blue"}) ) 
 
constant lines = { 
	"This text in BLACK\n", 
	"This text in RED\n", 
	"This text in BLUE\n" } 
 
integer start, finish 
start = 0 
finish = 0 
for i = 1 to length(lines) do 
	finish += length( lines[i] ) 
	append_text(textbox, lines[i]) 
	set_text_style( textbox, start, finish, ATTRS[i] ) 
	start += length( lines[i] ) 
end for 
 
wxMain( main ) 

Matt

new topic     » goto parent     » topic index » view message » categorize

4. Re: Text color in wxEuphoria

It does not work, Matt. All three lines remain ... beautifully BLACK! XP Pro, Eu 4.0a2

jiri

new topic     » goto parent     » topic index » view message » categorize

5. Re: Text color in wxEuphoria

DanM said...

I'm truly just guessing, but did you try:

set_font ( atom dc, atom font ) for the wxTextCtrl?

Don't know what "dc" is exactly, but it might be like the control Id in Win32Lib?

"dc" is the device context, and should only be used withing a drawing operation such as wxEVT_PAINT, or by creating DC manually with wxMemoryDC, etc. To use "set_font" outside of a drawing operation, see set_default_font().

-Greg

new topic     » goto parent     » topic index » view message » categorize

6. Re: Text color in wxEuphoria

jiri said...

It does not work, Matt. All three lines remain ... beautifully BLACK! XP Pro, Eu 4.0a2

Sorry, I had only tested on Linux. Windows requires the wxTE_RICH style to allow color:

include wxeud.e  
  
constant main = create( wxFrame, {0, -1, "Client", -1, -1, 700, 400, wxDEFAULT_FRAME_STYLE} )  
constant textbox = create( wxTextCtrl , {main, -1, "", -1, -1, -1, -1, wxTE_MULTILINE + wxTE_READONLY + wxTE_RICH } )  
  
constant ATTRS= {  
	create( wxTextAttr, {} ),  
	create( wxTextAttr, {} ),  
	create( wxTextAttr, {} ) }  
  
set_text_attr_color( ATTRS[1], create( wxColour, {"Black"}) )  
set_text_attr_color( ATTRS[2], create( wxColour, {"Red"}) )  
set_text_attr_color( ATTRS[3], create( wxColour, {"Blue"}) )  
  
constant lines = {  
	"This text in BLACK\n",  
	"This text in RED\n",  
	"This text in BLUE\n" }  
  
integer start, finish  
start = 0  
finish = 0  
for i = 1 to length(lines) do  
	finish += length( lines[i] )  
	append_text(textbox, lines[i])  
	set_text_style( textbox, start, finish, ATTRS[i] )  
	start += length( lines[i] )  
end for  
  
wxMain( main )  

Matt

new topic     » goto parent     » topic index » view message » categorize

7. Re: Text color in wxEuphoria

ghaberek said...
DanM said...

I'm truly just guessing, but did you try:

set_font ( atom dc, atom font ) for the wxTextCtrl?

Don't know what "dc" is exactly, but it might be like the control Id in Win32Lib?

"dc" is the device context, and should only be used withing a drawing operation such as wxEVT_PAINT, or by creating DC manually with wxMemoryDC, etc. To use "set_font" outside of a drawing operation, see set_default_font().

-Greg

Ok, I'm going to paste that note on my forehead so I don't forget it! smile

Dan

new topic     » goto parent     » topic index » view message » categorize

8. Re: Text color in wxEuphoria

Thanks, Matt! The world is full of colour again... jiri

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu