1. centering display

integer RM = 50 
display("[c:50]", {"This text is centered"}) 
display("[c:RM]", {"This text is not centered"}) 
constant VC=graphcst:video_config() 
-- or 
RM = VC[VC_COLUMNS] 
display("[c:RM]", {"This text is not centered"}) 

              This text is centered                
This text is not centered 
This text is not centered 

Is there anyway to use a variable to pass a value to the the display center function?

new topic     » topic index » view message » categorize

2. Re: centering display

Senator said...
integer RM = 50 
display("[c:50]", {"This text is centered"}) 
display("[c:RM]", {"This text is not centered"}) 
constant VC=graphcst:video_config() 
-- or 
RM = VC[VC_COLUMNS] 
display("[c:RM]", {"This text is not centered"}) 

Is there anyway to use a variable to pass a value to the the display center function?

Since it's a string anyway, you could use

display("[c:" & sprint(RM) & "]", {"This text is not centered"}) 

That's one way.

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

3. Re: centering display

euphoric said...

Since it's a string anyway, you could use

display("[c:" & sprint(RM) & "]", {"This text is not centered"}) 

That's one way.

Thanks euphoric, works like a charm. smile

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

4. Re: centering display

Senator said...
euphoric said...

Since it's a string anyway, you could use

display("[c:" & sprint(RM) & "]", {"This text is not centered"}) 

That's one way.

Thanks euphoric, works like a charm. smile

Yeah, but doesn't that say This text is not centered when actually it is centered? scnr blink

On a slightly more serious note,

printf(1,">%6s<\n",{"four"}) -- produces ">  four<" 
printf(1,">%-6s<\n",{"four"}) -- produces ">four  <" 

Does anyone any have any suggestion/preference for a format string that would produce "> four <"?
(Obviously, there isn't one, but if I were to implement it what would feel right as the third alternative to "%6s" and "%-6s"? "%|6s"? "%=6s"?)

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

5. Re: centering display

petelomax said...

On a slightly more serious note,

printf(1,">%6s<\n",{"four"}) -- produces ">  four<" 
printf(1,">%-6s<\n",{"four"}) -- produces ">four  <" 

Does anyone any have any suggestion/preference for a format string that would produce "> four <"?
(Obviously, there isn't one, but if I were to implement it what would feel right as the third alternative to "%6s" and "%-6s"? "%|6s"? "%=6s"?)

I'd recommend "%^6s" or "%+6s".

-Greg

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

6. Re: centering display

ghaberek said...

I'd recommend "%^6s" or "%+6s".

Thanks, unfortunately + is already in use on numbers to show a plus sign on positive values, so using that would mean you cannot centre numbers and/or break existing code.

Is there any preference for splitting say 7 spaces as 4:3 or 3:4?

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

7. Re: centering display

How about "%<6s" for left, "%>6s" for right, and "%|6s" for middle (centre) justification? The'|' suggests dividing space in middle to me.

3/4 or 4/3 - why not just toss a coin? smile

Sasha

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

8. Re: centering display

Quick and Dirty:

-- add this at the end of std/console.e 
public sequence CS --Center text string  
public function CenterString(integer RM) 
--returns center string for the display routine, 
--given RM, the margin width 
return "[c:" & sprint(RM) & "]" 
end function 
----------------------------------------------------- 
-- test 
sequence text = "this is a test" 
CS = CenterString(25) 
display(CS,{txt})  
new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu