1 // Written in the D programming language.
2
3 /**
4 This module contains definition for status line control.
5
6 Status line is usually shown in the bottom of window, and shows status of app.
7
8 Contains one or more text and/or icon items
9
10 Synopsis:
11
12 ----
13 import dlangui.widgets.statusline;
14
15 ----
16
17 Copyright: Vadim Lopatin, 2015
18 License: Boost License 1.0
19 Authors: Vadim Lopatin, coolreader.org@gmail.com
20 */
21 module dlangui.widgets.statusline;
22
23 import dlangui.widgets.layouts;
24 import dlangui.widgets.controls;
25
26 class StatusLinePanelBase : HorizontalLayout {
27 this(string ID) {
28 super(ID);
29 }
30 }
31
32 class StatusLineTextPanel : StatusLinePanelBase {
33 protected TextWidget _text;
34 this(string ID) {
35 super(ID);
36 _text = new TextWidget(null, ""d);
37 addChild(_text);
38 }
39 /// returns widget content text (override to support this)
40 override @property dstring text() { return _text.text; }
41 /// sets widget content text (override to support this)
42 override @property Widget text(dstring s) { _text.text = s; return this; }
43 /// sets widget content text (override to support this)
44 override @property Widget text(UIString s) { _text.text = s; return this; }
45 }
46
47 class StatusLineIconPanel : StatusLinePanelBase {
48 protected ImageWidget _icon;
49 this(string ID) {
50 super(ID);
51 _icon = new ImageWidget(null);
52 addChild(_icon);
53 }
54 @property string iconId() {
55 return _icon.drawableId;
56 }
57 @property void iconId(string icon) {
58 _icon.drawableId = icon;
59 }
60 }
61
62 class StatusLineTextAndIconPanel : StatusLineTextPanel {
63 protected ImageWidget _icon;
64 this(string ID) {
65 super(ID);
66 _icon = new ImageWidget(null);
67 _icon.minWidth = BACKEND_CONSOLE ? 1 : 20;
68 _icon.minHeight = BACKEND_CONSOLE ? 1 : 20;
69 _icon.alignment = Align.Center;
70 addChild(_icon);
71 }
72 @property string iconId() {
73 return _icon.drawableId;
74 }
75 @property void iconId(string icon) {
76 _icon.drawableId = icon;
77 }
78 }
79
80 class StatusLineBackgroundOperationPanel : StatusLineTextAndIconPanel {
81 this(string ID) {
82 super(ID);
83 visibility = Visibility.Gone;
84 }
85 protected uint animationProgress;
86 /// show / update / animate background operation status; when both parameters are nulls, hide background op status panel
87 void setBackgroundOperationStatus(string icon, dstring statusText) {
88 if (icon || statusText) {
89 visibility = Visibility.Visible;
90 text = statusText;
91 iconId = icon;
92 animationProgress = (animationProgress + 30) % 512;
93 uint a = animationProgress;
94 if (a >= 256)
95 a = 512 - a;
96 _icon.backgroundColor((a << 24) | (0x00FF00));
97 } else {
98 visibility = Visibility.Gone;
99 }
100 }
101 }
102
103 /// Status line control
104 class StatusLine : HorizontalLayout {
105 protected TextWidget _defStatus;
106 protected StatusLineBackgroundOperationPanel _backgroundOperationPanel;
107 this() {
108 super("STATUS_LINE");
109 styleId = STYLE_STATUS_LINE;
110 initialize();
111 }
112 void initialize() {
113 _defStatus = new TextWidget("STATUS_LINE_TEXT");
114 _defStatus.layoutWidth(FILL_PARENT);
115 _defStatus.text = " "d;
116 addChild(_defStatus);
117 _backgroundOperationPanel = new StatusLineBackgroundOperationPanel("BACKGROUND_OP_STATUS");
118 addChild(_backgroundOperationPanel);
119 }
120 /// set text to show in status line in specific panel
121 void setStatusText(string itemId, dstring value) {
122 _defStatus.text = value;
123 }
124 /// set text to show in status line
125 void setStatusText(dstring value) {
126 setStatusText(null, value);
127 }
128 /// show / update / animate background operation status; when both parameters are nulls, hide background op status panel
129 void setBackgroundOperationStatus(string icon, dstring statusText = null) {
130 _backgroundOperationPanel.setBackgroundOperationStatus(icon, statusText);
131 }
132 }