2 * Acess2 Window Manager v3
3 * - By John Hodge (thePowersGang)
5 * renderer/widget/textinput.c
6 * - Single line text box
8 * TODO: Support Right-to-Left text
12 #include "./colours.h"
16 int DrawOfs; // Byte offset for the leftmost character
17 int CursorXOfs; // Pixel offset of the cursor
20 void Widget_TextInput_Render(tWindow *Window, tElement *Element)
22 struct sTextInputInfo *info = (void*)Element->Data;
23 struct sWidgetWin *wininfo = Window->RendererInfo;
25 WM_Render_FillRect(Window,
26 Element->CachedX, Element->CachedY,
27 Element->CachedW, Element->CachedH,
30 WM_Render_DrawRect(Window,
31 Element->CachedX, Element->CachedY,
32 Element->CachedW, Element->CachedH,
35 WM_Render_DrawRect(Window,
36 Element->CachedX+1, Element->CachedY+1,
37 Element->CachedW-2, Element->CachedH-2,
42 WM_Render_DrawText(Window,
43 Element->CachedX+2, Element->CachedY+2,
44 Element->CachedW-4, Element->CachedW-4,
46 &Element->Text[info->DrawOfs]
49 // TODO: Determine if this element has focus
50 if( wininfo->FocusedElement == Element )
52 // TODO: Multiple Cursors
53 WM_Render_SetTextCursor(Window,
54 Element->CachedX+2+info->CursorXOfs,
56 Element->CachedW-4, 1,
62 void Widget_TextInput_Init(tElement *Element)
64 struct sTextInputInfo *info;
67 // TODO: Select font correctly
68 WM_Render_GetTextDims(NULL, "jJ", NULL, &h);
70 h += 2+2; // Border padding
75 info = Element->Data = malloc(sizeof(*info));
79 // No need to explicitly update parent min dims, as the AddElement routine does that
82 DEFWIDGETTYPE(ELETYPE_TEXTINPUT,
83 WIDGETTYPE_FLAG_NOCHILDREN,
84 .Render = Widget_TextInput_Render,
85 .Init = Widget_TextInput_Init