Nimbin[12]?SDL & Graphics / sdl_runtime_compiler / src/text/line.cpp

sdl_runtime_compiler git · main

SDL3 game for running and compiling code at runtime

sdl3 c++ compiler dlopen cmake · first commit 2026-04-19 · last commit 2026-07-03 (3 months ago) · synced 3 days ago · upstream: git.ide3.de/hsnr/sdl-runtime-compiler

C++ 72.3% C 26.2%
git clone https://git.christianimmanuel.de/sdl-graphics/sdl_runtime_compiler.gitwget https://git.christianimmanuel.de/sdl-graphics/sdl_runtime_compiler/archive/sdl_runtime_compiler.tar.gz
src/text/line.cpp 781 B · 51 lines raw
// text/line.cpp

#include "text/token.hpp"

namespace
Nimbin
{

namespace
Text
{


double
Line::width(double gap) const
{
    if (tokens.empty()) return 0.0;
    double w = 0.0;
    for (const TokenPtr& t : tokens)
        if (t) w += 2.0 * static_cast<double>(t->half_extent);
    w += gap * static_cast<double>(tokens.size() - 1);
    return w;
}


Token::Data*
Line::token_At_Byte(size_t off) const
{
    for (const TokenPtr& t : tokens)
        if (t && off >= t->byte_begin && off < t->byte_end)
            return t.get();
    return nullptr;
}


void
Line::clear()
{
    tokens.clear();
    num_left .reset();
    num_right.reset();
    number      = -1;
    show_number = false;
    bounce_off  = 0.0;
    bounce_vel  = 0.0;
}


} // namespace Text

} // namespace Nimbin