1 /* Invisible Vector Library
2 * simple FlexBox-based TUI engine
4 * coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
5 * Understanding is not required. Only obedience.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, version 3 of the License ONLY.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 module iv
.tuing
.controls
.button
/*is aliced*/;
28 import iv
.tuing
.events
;
31 import iv
.tuing
.types
;
34 // ////////////////////////////////////////////////////////////////////////// //
35 public class FuiButton
: FuiControl
{
36 alias onMyEvent
= super.onMyEvent
;
38 this (FuiControl aparent
, string atext
) {
39 this.connectListeners();
42 minSize
.w
= XtWindow
.hotStrLen(atext
)+4;
44 aligning
= Align
.Start
;
45 minSize
.h
= maxSize
.h
= 1;
48 acceptClick(TtyEvent
.MButton
.Left
);
49 assert(clickMask
!= 0);
52 override void doAction () {
54 if (auto desk
= getDesk
) desk
.switchFocusTo(this, false);
56 if (onAction
!is null) { onAction(this); return; }
60 protected override void drawSelf (XtWindow win
) {
61 win
.color
= (focused ? palColor
!"sel"() : disabled ? palColor
!"disabled"() : palColor
!"def"());
62 auto hotcolor
= (focused ? palColor
!"hotsel"() : disabled ? palColor
!"disabled" : palColor
!"hot"());
63 win
.fill(0, 0, win
.width
, win
.height
);
65 win
.writeCharAt(0, 0, '<');
66 win
.writeCharAt(win
.width
-1, 0, '>');
68 win
.writeCharAt(0, 0, '{');
69 win
.writeCharAt(win
.width
-1, 0, '}');
71 win
.writeCharAt(0, 0, '[');
72 win
.writeCharAt(win
.width
-1, 0, ']');
74 win
.writeHotStrAt(2, 0, win
.width
-4, caption
, hotcolor
, win
.Align
.Center
, hotkeyed
, focused
);
77 void onMyEvent (FuiEventClick evt
) {
84 void onMyEvent (FuiEventKey evt
) {
85 if (evt
.key
== "Space" || evt
.key
== "Enter") { evt
.eat(); doAction(); return; }
86 if (tryHotKey(evt
.key
)) { evt
.eat(); doAction(); return; }
91 // ////////////////////////////////////////////////////////////////////////// //
92 public class FuiCheckBox
: FuiControl
{
93 alias onMyEvent
= super.onMyEvent
;
97 this (FuiControl aparent
, string atext
, string agroupid
) {
98 this.connectListeners();
100 cbSetup(atext
, agroupid
);
103 this (FuiControl aparent
, string atext
, string agroupid
, bool defval
) {
104 this.connectListeners();
106 cbSetup(atext
, agroupid
);
107 if (agroupid
.length
) {
108 if (auto w
= topwindow
) w
.checkbox(agroupid
, defval
);
112 private final void cbSetup (string atext
, string agroupid
) {
115 minSize
.w
= XtWindow
.hotStrLen(atext
)+4;
117 aligning
= Align
.Start
;
118 minSize
.h
= maxSize
.h
= 1;
121 acceptClick(TtyEvent
.MButton
.Left
);
124 override void doAction () {
126 if (auto desk
= getDesk
) desk
.switchFocusTo(this, false);
128 if (onAction
!is null) { onAction(this); return; }
129 if (groupid
.length
) {
130 if (auto w
= topwindow
) {
131 auto nv
= !w
.checkbox(groupid
);
132 static assert(is(typeof(nv
) == bool));
133 w
.checkbox(groupid
, nv
);
134 (new FuiEventCheckBoxChanged(this, groupid
, nv
)).post
;
139 protected override void drawSelf (XtWindow win
) {
140 win
.color
= (focused ? palColor
!"sel"() : disabled ? palColor
!"disabled"() : palColor
!"def"());
141 auto hotcolor
= (focused ? palColor
!"hotsel"() : disabled ? palColor
!"disabled" : palColor
!"hot"());
142 win
.fill(0, 0, win
.width
, win
.height
);
143 win
.writeStrAt(0, 0, "[ ]");
144 if (auto w
= topwindow
) {
145 if (w
.checkbox(groupid
)) win
.writeCharAt(1, 0, 'x');
147 win
.writeHotStrAt(4, 0, win
.width
-4, caption
, hotcolor
, win
.Align
.Center
, hotkeyed
);
148 if (focused
) win
.gotoXY(1, 0);
151 void onMyEvent (FuiEventClick evt
) {
158 void onMyEvent (FuiEventKey evt
) {
159 if (evt
.key
== "Space" /*|| evt.key == "Enter"*/) { evt
.eat(); doAction(); return; }
160 if (tryHotKey(evt
.key
)) { evt
.eat(); doAction(); return; }
165 // ////////////////////////////////////////////////////////////////////////// //
166 public class FuiRadio
: FuiControl
{
167 alias onMyEvent
= super.onMyEvent
;
172 this (FuiControl aparent
, string atext
, string agroupid
, int amyval
) {
173 this.connectListeners();
178 minSize
.w
= XtWindow
.hotStrLen(atext
)+4;
180 aligning
= Align
.Start
;
181 minSize
.h
= maxSize
.h
= 1;
184 acceptClick(TtyEvent
.MButton
.Left
);
185 assert(clickMask
!= 0);
188 override void doAction () {
190 if (auto desk
= getDesk
) desk
.switchFocusTo(this, false);
192 if (onAction
!is null) { onAction(this); return; }
193 if (groupid
.length
&& myval
>= 0) {
194 if (auto w
= topwindow
) {
195 auto nv
= w
.radio(groupid
);
197 w
.radio(groupid
, myval
);
198 (new FuiEventRadioChanged(this, groupid
, myval
)).post
;
204 protected override void drawSelf (XtWindow win
) {
205 win
.color
= (focused ? palColor
!"sel"() : disabled ? palColor
!"disabled"() : palColor
!"def"());
206 auto hotcolor
= (focused ? palColor
!"hotsel"() : disabled ? palColor
!"disabled" : palColor
!"hot"());
207 win
.fill(0, 0, win
.width
, win
.height
);
208 win
.writeStrAt(0, 0, "( )");
210 if (auto w
= topwindow
) {
211 if (w
.radio(groupid
) == myval
) win
.writeCharAt(1, 0, '*');
214 win
.writeHotStrAt(4, 0, win
.width
-4, caption
, hotcolor
, win
.Align
.Center
, hotkeyed
);
215 if (focused
) win
.gotoXY(1, 0);
218 void onMyEvent (FuiEventClick evt
) {
225 void onMyEvent (FuiEventKey evt
) {
226 if (evt
.key
== "Space" /*|| evt.key == "Enter"*/) { evt
.eat(); doAction(); return; }
227 if (tryHotKey(evt
.key
)) { evt
.eat(); doAction(); return; }