Linebreak in a TextGadget

Just starting out? Need help? Post your questions and find answers here.
Little John
Posts: 11
Joined: Fri May 15, 2015 8:41 am

Linebreak in a TextGadget

Post by Little John »

Hi,

I tested the following code both with PB 5.31 on Windows, and with SB 1.02 on Windows (with Firefox):

Code: Select all

If OpenWindow(0, 0, 0, 270, 160, "TextGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
   TextGadget(0, 10,  10, 150, 40, "Line 1 " + #CR$   + "Line 2")
   TextGadget(1, 10,  60, 150, 40, "Line 1 " + #LF$   + "Line 2")
   TextGadget(2, 10, 110, 150, 40, "Line 1 " + #CRLF$ + "Line 2")
EndIf

CompilerIf #PB_Compiler_OS <> #PB_OS_Web
   Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
CompilerEndIf
Output with PureBasic (as expected):
Line 1
Line 2

Line 1
Line 2

Line 1
Line 2
Output with SpiderBasic:
Line 1 Line 2


Line 1 Line 2


Line 1 Line 2
So how can I force a linebreak in a TextGadget with SpiderBasic?
Sirius-2337
Posts: 35
Joined: Wed Mar 26, 2014 5:47 pm

Re: Linebreak in a TextGadget

Post by Sirius-2337 »

HTML uses "<br>" for Line Breaks

Code: Select all

If OpenWindow(0, 0, 0, 270, 160, "TextGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
   TextGadget(0, 10,  10, 150, 40, "Line 1 " + "<br>"   + "Line 2")
EndIf

CompilerIf #PB_Compiler_OS <> #PB_OS_Web
   Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
CompilerEndIf
Little John
Posts: 11
Joined: Fri May 15, 2015 8:41 am

Re: Linebreak in a TextGadget

Post by Little John »

Uuuh, I didn't know that we have to ( in other words: "can" :-) ) use HTML tags in the text of a SpiderBasic TextGadget.
Many thanks for the info!

But the code that you posted above does not work with PureBasic. So we have to use CompilerIf just in order to use the proper line break.
SpiderBasic could translate #LF$ itself to <b>, that would make our PB code more compatible with SB (which is an imortant part of SpiderBasic's concept, as far as I understood).

Anyway, my problem is solved. Thanks again!
User avatar
skywalk
Posts: 55
Joined: Tue Feb 25, 2014 2:13 am
Location: Boston, MA

Re: Linebreak in a TextGadget

Post by skywalk »

I thought SpiderBasic would convert string contents generated from PureBasic syntax to display properly in the browser? Is this a bug, or do I have to mix and match html markup in my code.
When working toward the solution of a problem, it always helps if you know the answer. ~ ?
An expert is one who knows more and more about less and less until he knows absolutely everything about nothing. ~ Weber
Fred
Site Admin
Posts: 1820
Joined: Mon Feb 24, 2014 10:51 am

Re: Linebreak in a TextGadget

Post by Fred »

I think in this particular case, it would be easier for anyone to have the LF converted to <br> automatically
Fred
Site Admin
Posts: 1820
Joined: Mon Feb 24, 2014 10:51 am

Re: Linebreak in a TextGadget

Post by Fred »

After more thoughs, I think it's better to leave it as is, it's a particularity of web to have <br> instead of #CRLF$, like Linux has LF$ instead of CRLF$. Introducing automatic conversion could tends to incorrect results if you explicitely want to have <br> in it.
Post Reply