all repos — fluxbox @ fe2e6b32e7fd285a32d5210220e18da9abb7732f

custom fork of the fluxbox windowmanager

alignment function
fluxgen fluxgen
commit

fe2e6b32e7fd285a32d5210220e18da9abb7732f

parent

e980fe82969013db45daa0cc0bce90b3df180f62

2 files changed, 37 insertions(+), 16 deletions(-)

jump to
M src/DrawUtil.ccsrc/DrawUtil.cc

@@ -13,31 +13,49 @@ // all copies or substantial portions of the Software.

// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: DrawUtil.cc,v 1.9 2002/11/25 14:00:20 fluxgen Exp $ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif //HAVE_CONFIG_H +// $Id: DrawUtil.cc,v 1.10 2002/11/26 15:50:46 fluxgen Exp $ #include "DrawUtil.hh" -#include "StringUtil.hh" -#include "i18n.hh" -#include <cstdlib> -#include <cassert> -#include <cstdio> -#include <iostream> -#include <X11/Xutil.h> +namespace DrawUtil { -using namespace std; +int doAlignment(int max_width, int bevel, Font::FontJustify justify, + const FbTk::Font &font, const char * const text, size_t textlen, size_t &newlen) { -namespace DrawUtil { + if (text == 0 || textlen == 0) + return 0; + int l = font.textWidth(text, textlen) + bevel; + size_t dlen = textlen; + int dx = bevel; + if (l > max_width) { + for (; dlen > 0; dlen--) { + l = font.textWidth(text, dlen) + bevel; + if (l<=max_width) + break; + } + } + + newlen = dlen; + + switch (justify) { + case DrawUtil::Font::RIGHT: + dx = max_width - l - bevel; + break; + case DrawUtil::Font::CENTER: + dx = (max_width - l)/2; + break; + case DrawUtil::Font::LEFT: + break; + } + + return dx; +} }; //end namespace DrawUtil
M src/DrawUtil.hhsrc/DrawUtil.hh

@@ -19,12 +19,13 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING

// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: DrawUtil.hh,v 1.8 2002/11/25 14:00:20 fluxgen Exp $ +// $Id: DrawUtil.hh,v 1.9 2002/11/26 15:45:48 fluxgen Exp $ #ifndef DRAWUTIL_HH #define DRAWUTIL_HH #include <X11/Xlib.h> +#include "Font.hh" namespace DrawUtil { // note: obsolete!

@@ -37,6 +38,8 @@ XFontStruct *fontstruct;

FontJustify justify; }; + int doAlignment(int max_width, int bevel, Font::FontJustify justify, + const FbTk::Font &font, const char * const text, size_t textlen, size_t &newlen); }; //end namespace DrawUtil #endif //DRAWUTIL_HH