Function tcod::print_rect

Function Documentation

inline int tcod::print_rect(TCOD_Console &console, const std::array<int, 4> &rect, std::string_view str, std::optional<TCOD_ColorRGB> fg, std::optional<TCOD_ColorRGB> bg, TCOD_alignment_t alignment = TCOD_LEFT, TCOD_bkgnd_flag_t flag = TCOD_BKGND_SET)

Print a string to a console constrained to a bounding box.

auto console = tcod::Console{80, 50};
static constexpr auto TEAL = tcod::ColorRGB{0, 255, 255};
// Print "Hello World" centered along the top row, ignoring the background color.
tcod::print(console, {0, 0, console->w, 1}, "Hello World", TEAL, std::nullopt, TCOD_CENTER);

New in version 1.19.

Parameters
  • console – A reference to a TCOD_Console.

  • rect – An {x, y, width, height} rectangle, starting from the upper-left-most tile as zero. A width or height of zero will leave that axis unconstrained.

  • str – The text to print. This string can contain libtcod color codes.

  • fg – The foreground color. The printed text is set to this color. If std::nullopt then the foreground will be left unchanged, inheriting the previous value of the tile.

  • bg – The background color. The background tile under the printed text is set to this color. If std::nullopt then the background will be left unchanged.

  • alignment – The text justification.

  • flag – The background blending flag.

Returns

int The height of the printed output.