entry ending box should tick
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit

This commit is contained in:
IoIxD 2026-07-21 00:15:33 -07:00
commit 2c19489acd
3 changed files with 78 additions and 31 deletions

View file

@ -117,6 +117,7 @@ struct _MwWidget {
int top_step; int top_step;
MwWidget* draw_queue; MwWidget* draw_queue;
MwWidget* resize_queue; MwWidget* resize_queue;
MwWidget* monitored_entries;
int berserk; int berserk;
long last_tick; long last_tick;
@ -138,6 +139,8 @@ struct _MwEntry {
int cursor; int cursor;
int right; int right;
int length; int length;
int active;
int cursor_blink_timer;
MwPoint mouse; MwPoint mouse;
}; };

View file

@ -262,9 +262,10 @@ static MwWidget MwCreateWidget_Internal(MwClass widget_class, const char* name,
h->opaque = NULL; h->opaque = NULL;
h->user = NULL; h->user = NULL;
h->top_step = 0; h->top_step = 0;
h->draw_queue = NULL; h->draw_queue = NULL;
h->resize_queue = NULL; h->resize_queue = NULL;
h->monitored_entries = NULL;
if(parent == NULL) arrput(h->tick_list, h); if(parent == NULL) arrput(h->tick_list, h);

View file

@ -1,12 +1,18 @@
#include <Mw/Milsko.h> #include <Mw/Milsko.h>
#include "stb_ds.h"
static int wcreate(MwWidget handle) { static int wcreate(MwWidget handle) {
MwEntry t = malloc(sizeof(*t)); MwEntry t = malloc(sizeof(*t));
MwWidget topmost_parent = handle->parent;
t->cursor = 0; t->cursor = 0;
t->right = 0; t->right = 0;
t->length = 0; t->length = 0;
handle->internal = t; t->cursor_blink_timer = 0;
handle->internal = t;
while(topmost_parent->parent) topmost_parent = topmost_parent->parent;
arrpush(topmost_parent->monitored_entries, handle);
MwSetDefault(handle); MwSetDefault(handle);
@ -16,9 +22,27 @@ static int wcreate(MwWidget handle) {
} }
static void destroy(MwWidget handle) { static void destroy(MwWidget handle) {
int i;
MwWidget topmost_parent = handle->parent;
while(topmost_parent->parent) topmost_parent = topmost_parent->parent;
for(i = 0; i < arrlen(topmost_parent->monitored_entries); i++) {
if(topmost_parent->monitored_entries[i] == handle) {
arrdel(topmost_parent->monitored_entries, i);
break;
}
}
free(handle->internal); free(handle->internal);
} }
static void tick(MwWidget handle) {
MwEntry t = handle->internal;
if(t->active) {
if(++t->cursor_blink_timer >= 30) {
t->cursor_blink_timer = 0;
}
MwDispatch(handle, draw);
}
}
static void draw(MwWidget handle) { static void draw(MwWidget handle) {
MwRect r; MwRect r;
MwEntry t = handle->internal; MwEntry t = handle->internal;
@ -71,11 +95,13 @@ static void draw(MwWidget handle) {
for(i = 0; i < textlen; i++) show[i] = 'M'; for(i = 0; i < textlen; i++) show[i] = 'M';
show[i] = 0; show[i] = 0;
currc.x = p.x + MwTextWidth(handle, font, show); if(t->active && t->cursor_blink_timer <= 15) {
currc.y = (r.height - h) / 2 + MwDefaultBorderWidth(handle); currc.x = p.x + MwTextWidth(handle, font, show);
currc.width = 1; currc.y = (r.height - h) / 2 + MwDefaultBorderWidth(handle);
currc.height = h; currc.width = 1;
MwDrawRect(handle, &currc, text); currc.height = h;
MwDrawRect(handle, &currc, text);
}
free(show); free(show);
} }
@ -148,6 +174,23 @@ static void mouse_up(MwWidget handle, void* ptr) {
#define mouse_up MwForceRender2 #define mouse_up MwForceRender2
#endif #endif
static void mouse_down(MwWidget handle, void* ptr) {
int i = 0;
MwEntry t = handle->internal;
MwWidget topmost_parent = handle->parent;
while(topmost_parent->parent) topmost_parent = topmost_parent->parent;
for(i = 0; i < arrlen(topmost_parent->monitored_entries); i++) {
MwEntry t = topmost_parent->monitored_entries[i]->internal;
t->active = MwFALSE;
t->cursor_blink_timer = 0;
MwDispatch(topmost_parent->monitored_entries[i], draw);
}
t->active = MwTRUE;
MwForceRender2(handle, NULL);
}
static void prop_change(MwWidget handle, const char* prop) { static void prop_change(MwWidget handle, const char* prop) {
if(strcmp(prop, MwNtext) == 0 || strcmp(prop, MwNhideInput) == 0) MwForceRender(handle); if(strcmp(prop, MwNtext) == 0 || strcmp(prop, MwNhideInput) == 0) MwForceRender(handle);
@ -187,23 +230,23 @@ static void clipboard(MwWidget handle, const char* data) {
} }
MwClassRec MwEntryClassRec = { MwClassRec MwEntryClassRec = {
wcreate, /* create */ wcreate, /* create */
destroy, /* destroy */ destroy, /* destroy */
draw, /* draw */ draw, /* draw */
NULL, /* click */ NULL, /* click */
NULL, /* parent_resize */ NULL, /* parent_resize */
prop_change, /* prop_change */ prop_change, /* prop_change */
NULL, /* mouse_move */ NULL, /* mouse_move */
mouse_up, /* mouse_up */ mouse_up, /* mouse_up */
MwForceRender2, /* mouse_down */ mouse_down, /* mouse_down */
key, /* key */ key, /* key */
NULL, /* execute */ NULL, /* execute */
NULL, /* tick */ tick, /* tick */
NULL, /* resize */ NULL, /* resize */
NULL, /* children_update */ NULL, /* children_update */
NULL, /* children_prop_change */ NULL, /* children_prop_change */
clipboard, /* clipboard */ clipboard, /* clipboard */
NULL, /* props_change */ NULL, /* props_change */
NULL, NULL,
NULL, NULL,
NULL}; NULL};