2 * Simple Framebuffer Gfx/GUI lib
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/>.
19 module iv
.egra
.gui
.widgets
.labels
/*is aliced*/;
22 import arsd
.simpledisplay
;
32 import iv
.egra
.gui
.subwindows
;
33 import iv
.egra
.gui
.widgets
.base
;
36 // ////////////////////////////////////////////////////////////////////////// //
37 public class LabelWidget
: Widget
{
57 HAlign halign
= HAlign
.Left
;
58 VAlign valign
= VAlign
.Center
;
63 this(T
:const(char)[]) (Widget aparent
, T atext
, HAlign horiz
=HAlign
.Left
, VAlign vert
=VAlign
.Center
) {
66 rect
.size
.w
= gxTextWidthUtf(mText
);
67 rect
.size
.h
= gxTextHeightUtf
;
73 this(T
:const(char)[]) (T atext
, HAlign horiz
=HAlign
.Left
, VAlign vert
=VAlign
.Center
) {
74 assert(creatorCurrentParent
!is null);
75 this(creatorCurrentParent
, atext
, horiz
, vert
);
78 mixin(WidgetStringPropertyMixin
!("text", "mText"));
80 protected void drawLabel (GxRect grect
) {
81 if (mText
.length
== 0) return;
83 final switch (halign
) {
84 case HAlign
.Left
: x
= grect
.x0
+hpad
; break;
85 case HAlign
.Center
: x
= grect
.x0
+(grect
.width
-gxTextWidthUtf(mText
))/2; break;
86 case HAlign
.Right
: x
= grect
.x0
+grect
.width
-hpad
-gxTextWidthUtf(mText
); break;
89 final switch (valign
) {
90 case VAlign
.Top
: y
= grect
.y0
+vpad
; break;
91 case VAlign
.Center
: y
= grect
.y0
+(grect
.height
-gxTextHeightUtf
)/2; break;
92 case VAlign
.Bottom
: y
= grect
.y0
+grect
.height
-vpad
-gxTextHeightUtf
; break;
94 //gxDrawTextUtf(x0+(width-gxTextWidthUtf(mText))/2, y0+(height-gxTextHeightUtf)/2, mText, parent.clrWinText);
95 gxDrawTextUtf(x
, y
, mText
, getColor("text"));
96 //gxDrawTextOutScaledUtf(1, x, y, mText, getColor("text"), gxRGB!(255, 0, 0));
97 //{ import core.stdc.stdio : printf; printf("LBL: 0x%08x\n", getColor("text")); }
98 if (hotxlen
> 0) gxHLine(x
+hotxpos
, y
+gxTextUnderLineUtf
, hotxlen
, getColor("hotline"));
101 protected override void doPaint (GxRect grect
) {
102 gxFillRect(grect
, getColor("back"));
108 // ////////////////////////////////////////////////////////////////////////// //
109 public class HotLabelWidget
: LabelWidget
{
111 Widget dest
; // if `null`, activate next focusable sibling
114 this(T
:const(char)[]) (Widget aparent
, T atext
, HAlign horiz
=HAlign
.Left
, VAlign vert
=VAlign
.Center
) {
115 super(aparent
, atext
, horiz
, vert
);
116 if (extractHotKey(ref mText
, ref mHotkey
, ref hotxpos
, ref hotxlen
)) rect
.size
.w
= gxTextWidthUtf(mText
);
119 this(T
:const(char)[]) (T atext
, HAlign horiz
=HAlign
.Left
, VAlign vert
=VAlign
.Center
) {
120 assert(creatorCurrentParent
!is null);
121 this(creatorCurrentParent
, atext
, horiz
, vert
);
124 // will be called if `isMyHotkey()` returned `true`
125 // return `true` if some action was done
126 override bool hotkeyActivated () {
128 if (d
is null && parent
!is null) {
129 bool seenSelf
= false;
131 while (top
.parent
!is null) top
= top
.parent
;
132 foreach (Widget w
; top
.allVisualDepth
) {
134 seenSelf
= (w
is this);
136 if (w
.canAcceptFocus()) { d
= w
; break; }
140 if (d
is null ||
!d
.canAcceptFocus()) return false;