Text Style issue.

Discuss suspected bugs with other users and Sim Innovations Staff

Moderators: russ, Ralph

Post Reply
Message
Author
User avatar
Keith Baxter
Posts: 4685
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Text Style issue.

#1 Post by Keith Baxter »

Hi,

Not sure this is a bug or if one has to code this way but it does not make sense to me.

I have a table with a a bunch of text to place in a canvas. The table looks like this.

Code: Select all

{
	"character":
	[
		[
			"Hellow World",
			"style1b",
			"50",
			"50"
		],
		[
			"Good By World",
			"style1w",
			"50",
			"100"
		]
	]
{			
		
This code places the text in the correct position but the style is ignored. There is just tiny black text of some unknown font left aligned.

Code: Select all

style1b= "font:arimo_regular.ttf; size:70; color: black; halign:center;valign:center;"
style1w= "font:arimo_regular.ttf; size:70; color: white; halign:center;valign:center;"
style2b= "font:arimo_regular.ttf; size:40; color: black; halign:center;valign:center;"
style2w= "font:arimo_regular.ttf; size:40; color: white; halign:center;valign:center;"
style3b= "font:arimo_regular.ttf; size:30; color: black; halign:center;valign:center;"
style3w= "font:arimo_regular.ttf; size:30; color: white; halign:center;valign:center;"

--- Lets place the text	
	for ti = 1, #char_data["character"] do	
		text_char = char_data["character"][ti][1]
		text_style = char_data["character"][ti][2]
		x3 = tonumber(char_data["character"][ti][3])
		y3 = tonumber(char_data["character"][ti][4])
		

---******************************************************************---			
_txt(text_char,text_style,x3,y3)
---******************************************************************---
	end
	

To get the style to work I have to use a bunch of elseif's like this. Not elegant coding IMHO
Why is this?? Is it a bug??

Code: Select all

	for ti = 1, #char_data["character"] do	
		text_char = char_data["character"][ti][1]
		x3 = tonumber(char_data["character"][ti][3])
		y3 = tonumber(char_data["character"][ti][4])
		if char_data["character"][ti][2]=="style1w" then text_style = "font:arimo_regular.ttf; size:70; color: white; halign:center;valign:center;"
		elseif char_data["character"][ti][2]=="style1b" then text_style = "font:arimo_regular.ttf; size:70; color: black; halign:center;valign:center;"
		elseif char_data["character"][ti][2]=="style2w" then text_style = "font:arimo_regular.ttf; size:32; color: white; halign:center;valign:center;"
		elseif char_data["character"][ti][2]=="style2b" then text_style = "font:arimo_regular.ttf; size:32; color: black; halign:center;valign:center;"
		elseif char_data["character"][ti][2]=="style3w" then text_style = "font:arimo_regular.ttf; size:25; color: white; halign:center;valign:center;"
		elseif char_data["character"][ti][2]=="style3b" then text_style = "font:arimo_regular.ttf; size:25; color: black; halign:center;valign:center;"		

---******************************************************************---			
_txt(text_char,text_style,x3,y3)
---******************************************************************---		
	end
	

This also works

Code: Select all



style1b= "font:arimo_regular.ttf; size:70; color: black; halign:center;valign:center;"
style1w= "font:arimo_regular.ttf; size:70; color: white; halign:center;valign:center;"
style2b= "font:arimo_regular.ttf; size:40; color: black; halign:center;valign:center;"
style2w= "font:arimo_regular.ttf; size:40; color: white; halign:center;valign:center;"
style3b= "font:arimo_regular.ttf; size:30; color: black; halign:center;valign:center;"
style3w= "font:arimo_regular.ttf; size:30; color: white; halign:center;valign:center;"


--- Lets place the text	
	for ti = 1, #char_data["character"] do	
		text_char = char_data["character"][ti][1]
		x3 = tonumber(char_data["character"][ti][3])
		y3 = tonumber(char_data["character"][ti][4])
		if char_data["character"][ti][2]=="style1w" then text_style = style1w
		elseif char_data["character"][ti][2]=="style1b" then text_style = style1b
		elseif char_data["character"][ti][2]=="style2w" then text_style = style2w
		elseif char_data["character"][ti][2]=="style2b" then text_style = style2b
		elseif char_data["character"][ti][2]=="style3w" then text_style = style3w
		elseif char_data["character"][ti][2]=="style3b" then text_style = style3b	
---******************************************************************---			
_txt(text_char,text_style,x3,y3)
---******************************************************************---		
	end
This is in AM4 beta. Tested in AM3.7 it the same.

Keith
Last edited by Keith Baxter on Mon Oct 19, 2020 5:34 am, edited 1 time in total.
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
Keith Baxter
Posts: 4685
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Text Style issue.

#2 Post by Keith Baxter »

Hi,

Ok not to worry too much. Found a elegant way.

Changed my table to look like this.

Code: Select all

{
	"character":
	[
		[
			"Hellow World",
			"font:arimo_regular.ttf; size:80; color: black; halign:center;valign:center;",
			"50",
			"50"
		],
		[
			"Good By World",
			"arimo_regular.ttf; size:80; color: white; halign:center;valign:center;",
			"50",
			"100"
		]
	]
{			
		
and the code is now very elegant.

Code: Select all

--- Lets place the text	
	for ti = 1, #char_data["character"] do	
		text_char = char_data["character"][ti][1]
		text_style = char_data["character"][ti][2]
		x3 = tonumber(char_data["character"][ti][3])
		y3 = tonumber(char_data["character"][ti][4])
---******************************************************************---			
_txt(text_char,text_style,x3,y3)
---******************************************************************---
	end


Which is better? This one or the previous one?

Code: Select all

--- Lets place the text	
	for ti = 1, #char_data["character"] do				
		_txt(char_data["character"][ti][1],char_data["character"][ti][2], tonumber(char_data["character"][ti][3]), tonumber(char_data["character"][ti][4]))
	end



Still like to know why though.


Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
Sling
Posts: 5241
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Text Style issue.

#3 Post by Sling »

Keith,

No bug but a coding issue. style3b as an example is a variable name but it retrieves a string from your table. So rather than refer to it as “style3b” It needs to be style3b.

You can put all the styles in a table and recall them by index if that helps.

Tony

User avatar
Keith Baxter
Posts: 4685
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Text Style issue.

#4 Post by Keith Baxter »

Sling wrote: Mon Oct 19, 2020 2:51 am Keith,

No bug but a coding issue. style3b as an example is a variable name but it retrieves a string from your table. So rather than refer to it as “style3b” It needs to be style3b.

You can put all the styles in a table and recall them by index if that helps.

Tony
Ahhh makes sense Tony, Thank you for that explanation. That should have dawned on me. Specially knowing one has to use <tonumber) to change the string to a number. These things happen at my age. :oops:

It was easy just to change "style3b" in the table to "font:arimo_regular.ttf; size:25; color: black; halign:center;valign:center;". Also made the code slightly slimmer without all the style variables.

But I will remember that for future.

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
Keith Baxter
Posts: 4685
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Text Style issue.

#5 Post by Keith Baxter »

Hi

txt_style() does not remove the background_color.

Code: Select all

robR_20blkwbgC="font:roboto_regular.ttf; size:20px; color: #1b1b1b; halign:center; valign:center;background_color:#d5d5d5;"
robR_20vlgC="font:roboto_regular.ttf; size:20px; color: red; halign:center; valign:center;"

my_text= txt_add("Hellow World",robR_20blkwbgC, 30,30,100,25)

txt_style(my_text,robR_20vlgC)

Keith
Last edited by Keith Baxter on Mon Nov 09, 2020 7:24 am, edited 1 time in total.
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
Sling
Posts: 5241
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Text Style issue.

#6 Post by Sling »

Keith,

Try setting a background colour within your second style. As far as I remember only the items you specify in the new style will change. So you can change as much or as little as you need.

Tony

User avatar
Keith Baxter
Posts: 4685
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Text Style issue.

#7 Post by Keith Baxter »

Sling wrote: Mon Nov 09, 2020 7:11 am Keith,

Try setting a background colour within your second style. As far as I remember only the items you specify in the new style will change. So you can change as much or as little as you need.

Tony
Tony

Ahh Ok that makes sense. Thank you

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

Post Reply