Giter Site home page Giter Site logo

Comments (2)

sbradwrk avatar sbradwrk commented on May 18, 2024

put into GuiLite source would look a bit different, but this is a starting point if it helps. inserting \n was a nonstarter

void draw_string_in_wrapped_rect(c_surface* surface, int z_order, std::string instr, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT)
{
    int w = 0, h = 0;
    c_word::get_str_size( instr.c_str(), font, w, h );

    const int width  = rect.width();
    const int height = rect.height();

    if( w <= width )
    {
        c_word::draw_string_in_rect( surface, z_order, instr.c_str(), rect, font, font_color, bg_color, align_type );
        return;
    }

    int x = 0, y = 0, rowy = 0;
    int est_chars_per_line = ( (float)width / w * instr.size() );
    int nrows              = std::max( 1, std::min( 1 + ( w - 1 ) / width, ( height + h ) / h ) );

    for( int row = 0, pos = 0; row < nrows; row++, pos += est_chars_per_line, rowy += h )
    {
        std::string linestr = instr.substr( pos, est_chars_per_line );
        const char *line    = linestr.c_str();
        c_word::fontOperator->get_string_pos( (const void *)line, (const LATTICE_FONT_INFO *)font, rect, align_type, x, y );
        c_word::draw_string(
            surface, z_order, (const void *)line, rect.m_left + x, rect.m_top + rowy + y, font, font_color, bg_color );
    }
}

from guilite.

sbradwrk avatar sbradwrk commented on May 18, 2024

also worth looking at existing code

while (*s)
		{
			s += get_utf8_code(s, utf8_code);
			offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, (const LATTICE_FONT_INFO*)font, font_color, bg_color);
		}

if char == \n you could increase a y offset and reset x

from guilite.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.