mirror of
https://git.checksum.fail/alec/erythros
synced 2025-12-10 13:09:55 +02:00
System/Libraries/Widget: Initial support for ListViewWidget
This commit is contained in:
@@ -786,6 +786,16 @@ U0 @compositor_handle_window_input_events(Window* win)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (win->focused_widget->type == WIDGET_TYPE_LISTVIEW) {
|
||||||
|
if (@widget_listview_handle_key(win->focused_widget)) {
|
||||||
|
msg = CAlloc(sizeof(IpcMessage));
|
||||||
|
System.Log(Fs, "Sent message → WinKeyPress");
|
||||||
|
msg->client = win->client;
|
||||||
|
msg->type = CPZ_MSG_WIN_KEY_PRESS;
|
||||||
|
msg->payload = win;
|
||||||
|
Ipc.MsgSend(msg->client, msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Mouse.z != Compositor.mouse.delta_z) {
|
if (Mouse.z != Compositor.mouse.delta_z) {
|
||||||
|
|||||||
@@ -232,18 +232,12 @@ class VerticalScrollBarWidget : Widget {
|
|||||||
I64 value;
|
I64 value;
|
||||||
};
|
};
|
||||||
|
|
||||||
class @list_view_item
|
|
||||||
{
|
|
||||||
@list_view_item* prev;
|
|
||||||
@list_view_item* next;
|
|
||||||
Context2D* icon;
|
|
||||||
U8 text[1024];
|
|
||||||
};
|
|
||||||
|
|
||||||
class ListViewWidget : Widget {
|
class ListViewWidget : Widget {
|
||||||
BitmapFont* font;
|
BitmapFont* font;
|
||||||
U32 color;
|
U32 color;
|
||||||
@list_view_item* items;
|
I64 index;
|
||||||
|
JsonArray* columns;
|
||||||
|
JsonArray* items;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TabPanelTab {
|
class TabPanelTab {
|
||||||
@@ -650,6 +644,42 @@ Bool @widget_input_handle_key(BitmapFontTextInputWidget* widget)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
U0 @widget_listview_select_row(ListViewWidget* widget)
|
||||||
|
{
|
||||||
|
if (widget->index > -1 && widget->items && widget->items->length && widget->index < widget->items->length) {
|
||||||
|
widget->items->o(widget->index)->set("selected", 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Bool @widget_listview_handle_key(ListViewWidget* widget)
|
||||||
|
{
|
||||||
|
I64 key = Keyboard.active_key;
|
||||||
|
I64 tS = Keyboard.active_key_tS;
|
||||||
|
I64 i;
|
||||||
|
if (key && tS != Keyboard.last_key_tS) {
|
||||||
|
if (!KeyDown(SC_SHIFT)) {
|
||||||
|
// Clear selection
|
||||||
|
for (i = 0; i < widget->items->length; i++) {
|
||||||
|
widget->items->o(i)->set("selected", 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch (key) {
|
||||||
|
case SC_CURSOR_UP:
|
||||||
|
widget->index = Max(0, widget->index - 1);
|
||||||
|
@widget_listview_select_row(widget);
|
||||||
|
break;
|
||||||
|
case SC_CURSOR_DOWN:
|
||||||
|
widget->index = Min(widget->items->length - 1, widget->index + 1);
|
||||||
|
@widget_listview_select_row(widget);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
Widget* @widget_create_widget(Window* win, I64 type, I64 x, I64 y, I64 width,
|
Widget* @widget_create_widget(Window* win, I64 type, I64 x, I64 y, I64 width,
|
||||||
I64 height)
|
I64 height)
|
||||||
{
|
{
|
||||||
@@ -750,7 +780,9 @@ Widget* @widget_create_widget(Window* win, I64 type, I64 x, I64 y, I64 width,
|
|||||||
break;
|
break;
|
||||||
case WIDGET_TYPE_LISTVIEW:
|
case WIDGET_TYPE_LISTVIEW:
|
||||||
widget(ListViewWidget*)->color = Color(0, 0, 0);
|
widget(ListViewWidget*)->color = Color(0, 0, 0);
|
||||||
widget(ListViewWidget*)->items = CAlloc(sizeof(@list_view_item));
|
widget(ListViewWidget*)->columns = Json.CreateArray(Fs);
|
||||||
|
widget(ListViewWidget*)->items = Json.CreateArray(Fs);
|
||||||
|
widget(ListViewWidget*)->index = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -874,7 +906,9 @@ U0 @widget_init_widget(Widget* widget, Window* win, I64 type, I64 x, I64 y,
|
|||||||
break;
|
break;
|
||||||
case WIDGET_TYPE_LISTVIEW:
|
case WIDGET_TYPE_LISTVIEW:
|
||||||
widget(ListViewWidget*)->color = Color(0, 0, 0);
|
widget(ListViewWidget*)->color = Color(0, 0, 0);
|
||||||
widget(ListViewWidget*)->items = CAlloc(sizeof(@list_view_item));
|
widget(ListViewWidget*)->columns = Json.CreateArray(Fs);
|
||||||
|
widget(ListViewWidget*)->items = Json.CreateArray(Fs);
|
||||||
|
widget(ListViewWidget*)->index = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user