1. Text color in wxEuphoria
- Posted by xfox26 Feb 08, 2009
- 984 views
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.
2. Re: Text color in wxEuphoria
- Posted by DanM Feb 08, 2009
- 977 views
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
3. Re: Text color in wxEuphoria
- Posted by mattlewis (admin) Feb 08, 2009
- 1039 views
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
4. Re: Text color in wxEuphoria
- Posted by jiri Feb 09, 2009
- 1041 views
It does not work, Matt. All three lines remain ... beautifully BLACK! XP Pro, Eu 4.0a2
jiri
5. Re: Text color in wxEuphoria
- Posted by ghaberek (admin) Feb 09, 2009
- 943 views
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
6. Re: Text color in wxEuphoria
- Posted by mattlewis (admin) Feb 09, 2009
- 949 views
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
7. Re: Text color in wxEuphoria
- Posted by DanM Feb 09, 2009
- 883 views
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!
Dan
8. Re: Text color in wxEuphoria
- Posted by jiri Feb 09, 2009
- 977 views
Thanks, Matt! The world is full of colour again... jiri