label.h (1539B)
1 // Copyright (c) 2003 - 2009 Anselm R Garbe <anselm@garbe.us> 2 // See LICENSE for license details. 3 4 #ifndef __LABEL_H 5 #define __LABEL_H 6 7 extern "C" { 8 #include <X11/Xlib.h> 9 } 10 11 #include <string> 12 #include "wmi.h" 13 14 #include "rectangle.h" 15 16 class Monitor; 17 class WFont; 18 19 /** 20 * Represents a low-level label widget implementation with alignment 21 * handling. 22 * 23 * This widget is capable of using old style PCF fonts and new style 24 * XFT fonts. 25 */ 26 class Label : public Rectangle 27 { 28 29 public: 30 31 enum Alignment {LEFT, CENTER, RIGHT}; 32 33 Label(Monitor *monitor, Window window, Alignment align, GC gc); 34 35 ~Label(); 36 37 void setText(string text); 38 39 string text() const; 40 41 /** 42 * Updates this label. 43 * @param leftBorder if <code>true</code> a left border 44 * will be drawn. 45 * @param rightBorder if <code>true</code> a right border 46 * will be drawn. 47 */ 48 void update(unsigned long background, unsigned long text, 49 unsigned long shine, unsigned long shadow, 50 bool shineBorder = false, bool shadowBorder = false); 51 52 void setAlignment(const Alignment align); 53 54 /** 55 * Adjusts label width with the currently set text. 56 * Returns the adjusted width. 57 */ 58 unsigned int adjustWidth(); 59 60 /** 61 * Helper method for adjustWidth, also useful for menu and bar stuff. 62 */ 63 unsigned int textWidth(); 64 65 private: 66 67 Alignment align_; 68 GC gc_; 69 Monitor *monitor_; 70 string text_; 71 Window window_; 72 WFont *font_; 73 }; 74 75 #endif // __LABEL_H