1 namespace gui::controls;
7 #define MIN_INFO_WIDTH 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 };
19 void AddField(StatusField field)
23 field._statusBar = this;
25 width += field.width + (guiApp.textMode ? 0 : 6);
31 void RemoveField(StatusField field)
35 field._statusBar = null;
36 width -= field.width + (guiApp.textMode ? 0 : 6);
49 RemoveField(fields.first);
56 fields.offset = (uint)(uintptr)&((StatusField)0).prev;
64 FontResource boldFont { font.faceName, font.size, true, window = this };
70 for(field = fields.first; field; field = field.next)
71 width += field.width + (guiApp.textMode ? 0 : 6);
75 bool OnResizing(int * w, int * h)
77 *h = Max(*h, statusBarHeight);
82 void OnRedraw(Surface surface)
85 int position = Max(clientSize.w, MIN_INFO_WIDTH + width)-1-2;
86 Box clip { 2, 2, MIN_INFO_WIDTH, statusBarHeight-1 };
87 Window parent = this.parent;
90 surface.ThinBevel(false, -1,0, clientSize.w+2, clientSize.h+1);
92 for(field = fields.first; field; field = field.next)
94 int x = position - field.width;
96 surface.SetBackground(white);
99 surface.ThinBevel(true, x - 2, 2, field.width + 4, statusBarHeight-2);
100 surface.SetForeground(field.colorSet ? field.color : foreground);
104 if(parent.borderStyle == sizable && parent.state == normal)
105 surface.SetForeground(field.colorSet ? (field.color == black ? white : field.color) : (foreground == black ? white : foreground));
107 surface.SetForeground(field.colorSet ? field.color : foreground);
111 Box clip { x, 2, x + field.width - 1, statusBarHeight-3 };
116 surface.SetBackground(field.backColor);
117 surface.Clear(colorBuffer);
119 surface.font = field.bold ? boldFont.font : fontObject;
120 surface.TextExtent(field.text, strlen(field.text), &tw, null);
121 surface.WriteTextf(x + (field.width - tw) / 2, 2, field.text);
124 position -= field.width + (guiApp.textMode ? 0 : 6);
127 // TESTING THIS HERE!
128 clip.right = position;
130 if(guiApp.textMode && parent.borderStyle == sizable && parent.state == normal)
131 surface.SetForeground(white);
133 surface.SetForeground(foreground);
135 surface.WriteTextf(2, 2, text);
141 text = property::text;
150 public class StatusField
154 property StatusBar statusBar
161 _statusBar.RemoveField(this);
163 value.AddField(this);
177 _statusBar.Update(null);
181 property ColorAlpha backColor
190 _statusBar.Update(null);
198 if(this) this.bold = value;
210 int len = strlen(value);
211 text = renew text char[len + 1];
212 CopyBytes(text, value, len + 1);
217 _statusBar.Update(null);
230 _statusBar.width += value - width;
231 _statusBar.Update(null);
238 void SetTextf(char * format, ...)
245 char tempText[MAX_F_STRING];
247 va_start(args, format);
248 vsnprintf(tempText, sizeof(tempText), format, args);
249 tempText[sizeof(tempText)-1] = 0;
251 text = CopyString(tempText);
254 _statusBar.Update(null);
264 StatusField prev, next;
268 ColorAlpha backColor;
269 StatusBar _statusBar;