introduce drw_fontset_getwidth_clamp()
authorNRK <nrk@disroot.org>
Wed, 23 Mar 2022 20:00:00 +0000 (02:00 +0600)
committerHiltjo Posthuma <hiltjo@codemadness.org>
Fri, 25 Mar 2022 21:49:07 +0000 (22:49 +0100)
commit6be057f060543bb0f3ed9423904263617cdffffe
tree1c38c588659ed513040068e3cafd6561b4917f55
parent41fdabbf7c517f8d524b70cbd78238cc319ccef3
introduce drw_fontset_getwidth_clamp()

getting the width of a string is an O(n) operation, and in many cases
users only care about getting the width upto a certain number.

instead of calling drw_fontset_getwidth() and *then* clamping the
result, this patch introduces drw_fontset_getwidth_clamp() function,
similar to strnlen(), which will stop once we reach n.

the `invert` parameter was overloaded internally to preserve the API,
however library users should be calling drw_fontset_getwidth_clamp() and
not depend upon internal behavior of drw_text().
drw.c
drw.h