1 namespace gui::controls;
7 define defaultMinInfoWidth = 300;
9 public class StatusBar : Window
11 class_property(icon) = "<:ecere>controls/statusBar.png";
13 background = formColor;
16 anchor = Anchor { left = 0, right = 0, bottom = 0 };
17 minInfoWidth = defaultMinInfoWidth;
20 property int minInfoWidth
22 set { minInfoWidth = value; }
23 get { return minInfoWidth; }
26 void AddField(StatusField field)
30 field._statusBar = this;
32 width += field.width + (guiApp.textMode ? 0 : 6);
38 void RemoveField(StatusField field)
42 field._statusBar = null;
43 width -= field.width + (guiApp.textMode ? 0 : 6);
56 RemoveField(fields.first);
63 fields.offset = (uint)(uintptr)&((StatusField)0).prev;
71 FontResource boldFont { font.faceName, font.size, true, window = this };
77 for(field = fields.first; field; field = field.next)
78 width += field.width + (guiApp.textMode ? 0 : 6);
82 bool OnResizing(int * w, int * h)
84 *h = Max(*h, statusBarHeight);
89 void OnRedraw(Surface surface)
92 int position = Max(clientSize.w, minInfoWidth + width)-1-2;
93 Box clip { 2, 2, minInfoWidth, statusBarHeight-1 };
94 Window parent = this.parent;
97 surface.ThinBevel(false, -1,0, clientSize.w+2, clientSize.h+1);
99 for(field = fields.first; field; field = field.next)
101 int x = position - field.width;
103 surface.SetBackground(white);
106 surface.ThinBevel(true, x - 2, 2, field.width + 4, statusBarHeight-2);
107 surface.SetForeground(field.colorSet ? field.color : foreground);
111 if(parent.borderStyle == sizable && parent.state == normal)
112 surface.SetForeground(field.colorSet ? (field.color == black ? white : field.color) : (foreground == black ? white : foreground));
114 surface.SetForeground(field.colorSet ? field.color : foreground);
118 Box clip { x, 2, x + field.width - 1, statusBarHeight-3 };
123 surface.SetBackground(field.backColor);
124 surface.Clear(colorBuffer);
126 surface.font = field.bold ? boldFont.font : fontObject;
127 surface.TextExtent(field.text, strlen(field.text), &tw, null);
128 surface.WriteTextf(x + (field.width - tw) / 2, 2, field.text);
131 position -= field.width + (guiApp.textMode ? 0 : 6);
134 // TESTING THIS HERE!
135 clip.right = position;
137 if(guiApp.textMode && parent.borderStyle == sizable && parent.state == normal)
138 surface.SetForeground(white);
140 surface.SetForeground(foreground);
142 surface.WriteTextf(2, 2, text);
148 text = property::text;
158 public class StatusField
162 property StatusBar statusBar
169 _statusBar.RemoveField(this);
171 value.AddField(this);
185 _statusBar.Update(null);
189 property ColorAlpha backColor
198 _statusBar.Update(null);
206 if(this) this.bold = value;
210 property const char * text
218 int len = strlen(value);
219 text = renew text char[len + 1];
220 CopyBytes(text, value, len + 1);
225 _statusBar.Update(null);
238 _statusBar.width += value - width;
239 _statusBar.Update(null);
246 void SetTextf(const char * format, ...)
253 char tempText[MAX_F_STRING];
255 va_start(args, format);
256 vsnprintf(tempText, sizeof(tempText), format, args);
257 tempText[sizeof(tempText)-1] = 0;
259 text = CopyString(tempText);
262 _statusBar.Update(null);
272 StatusField prev, next;
276 ColorAlpha backColor;
277 StatusBar _statusBar;