Siv3D / OpenSiv3D

C++20 framework for creative coding 🎮🎨🎹 / Cross-platform support (Windows, macOS, Linux, and the Web)
https://siv3d.github.io/
MIT License
994 stars 136 forks source link

指定した矩形内にテキストを描画できるかを、実際の描画を行わずに取得する関数 #1202

Closed Reputeless closed 1 month ago

Reputeless commented 6 months ago
Reputeless commented 1 month ago
# include <Siv3D.hpp>

void Main()
{
    Scene::SetBackground(ColorF{ 0.6, 0.8, 0.7 });

    const Font font{ FontMethod::MSDF, 48, Typeface::Bold };
    const String text = U"The quick brown fox jumps over the lazy dog.";

    while (System::Update())
    {
        const Rect rect = Rect::FromPoints(Point{ 50, 20 }, Cursor::Pos());

        rect.draw();

        if (not font(text).draw(60, rect.stretched(-10), ColorF{ 0.11, 0.1 }))
        {
            rect.drawFrame(0, 5, ColorF{ 0.11 });
        }

        if (not font(text).fits(60, rect.stretched(-10)))
        {
            rect.drawFrame(5, 0, ColorF{ 0.5 });
        }
    }
}