How to align multiline text

Posted on
  • Not sure if this is necessary or just a bug that multilines do not follow the setFontAlign() setting?

    // run this code in the emulator
    
    var sd = require('StringDecoders');
    
    var drawStrCenter = function(t,x,y,dy){
            var ta = t.split('\n');
            ta.forEach((e)=>{
               g.setFontAlign(0,-1).drawString(e,x,y);
               y += dy;
            });
    };
    
    var drawStr = function(t,x,y){
            g.drawString(t,x,y);
    };
    
    var t = 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor';
    var tml = sd.fitWords(t,5,20);
    
    g.setBgColor(0xfffff).clear().setColor(0­).setFont("Vector", 15).setFontAlign(0,-1);
    
    drawStrCenter(tml,119,0,15);
    drawStr(tml,119,100);
    
    

    1 Attachment

    • Bildschirmfoto 2021-05-20 um 17.17.15.jpg
  • Sadly it was just too much trouble to implement when I did it, so it didn't get done. The text block is centered, but each line isn't.

    Potentially it could be fixed, but right now the way it works everything is implemented multiple times for vector/bitmap/custom fonts I believe so it gets complicated very fast.

  • No problem, as long as there is a workaround ;-)

  • Have seen some infos about adding this feature, so now there is no more need for the workaround - Thanks for the implementation.


    1 Attachment

    • screenshot.png
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

How to align multiline text

Posted by Avatar for MaBe @MaBe

Actions