|
|
@ -42,7 +42,6 @@ fn void! Ctx.init(&ctx) |
|
|
|
{ |
|
|
|
{ |
|
|
|
ctx.tree.init(MAX_ELEMENTS)!; |
|
|
|
ctx.tree.init(MAX_ELEMENTS)!; |
|
|
|
defer catch { (void)ctx.tree.free(); } |
|
|
|
defer catch { (void)ctx.tree.free(); } |
|
|
|
//ug_fifo_init(&ctx.fifo, MAX_CMDS); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctx.cache.init()!; |
|
|
|
ctx.cache.init()!; |
|
|
|
defer catch { (void)ctx.cache.free(); } |
|
|
|
defer catch { (void)ctx.cache.free(); } |
|
|
@ -72,7 +71,8 @@ fn void! Ctx.frame_begin(&ctx) |
|
|
|
// The root should have the updated flag only if the size of the window |
|
|
|
// The root should have the updated flag only if the size of the window |
|
|
|
// was changed between frames, this propagates an element size recalculation |
|
|
|
// was changed between frames, this propagates an element size recalculation |
|
|
|
// down the element tree |
|
|
|
// down the element tree |
|
|
|
c_elem.flags.updated = ctx.input.events.resize; |
|
|
|
c_elem.flags.updated = ctx.input.events.resize | ctx.input.events.force_update; |
|
|
|
|
|
|
|
ctx.input.events.force_update = false; |
|
|
|
// if the window has focus then the root element also has focus, no other |
|
|
|
// if the window has focus then the root element also has focus, no other |
|
|
|
// computation needed, child elements need to check the mouse positon and |
|
|
|
// computation needed, child elements need to check the mouse positon and |
|
|
|
// other stuff |
|
|
|
// other stuff |
|
|
@ -106,13 +106,20 @@ fn void! Ctx.frame_begin(&ctx) |
|
|
|
// TODO: add a background color taken from a theme or config |
|
|
|
// TODO: add a background color taken from a theme or config |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn void! Ctx.force_update(&ctx) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ctx.input.events.force_update = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn void! Ctx.frame_end(&ctx) |
|
|
|
fn void! Ctx.frame_end(&ctx) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// 1. clear the tree |
|
|
|
// 1. clear the tree |
|
|
|
ctx.tree.prune(0)!; |
|
|
|
ctx.tree.prune(0)!; |
|
|
|
|
|
|
|
|
|
|
|
// 2. clear input fields |
|
|
|
// 2. clear input fields |
|
|
|
|
|
|
|
bool f = ctx.input.events.force_update; |
|
|
|
ctx.input.events = (InputEvents)0; |
|
|
|
ctx.input.events = (InputEvents)0; |
|
|
|
|
|
|
|
ctx.input.events.force_update = f; |
|
|
|
|
|
|
|
|
|
|
|
// draw mouse position |
|
|
|
// draw mouse position |
|
|
|
$if 1: |
|
|
|
$if 1: |
|
|
@ -130,9 +137,9 @@ $if 1: |
|
|
|
$endif |
|
|
|
$endif |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
<* |
|
|
|
* @ensure elem != null |
|
|
|
* @ensure elem != null |
|
|
|
**/ |
|
|
|
*> |
|
|
|
fn bool Ctx.is_hovered(&ctx, Elem *elem) |
|
|
|
fn bool Ctx.is_hovered(&ctx, Elem *elem) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return point_in_rect(ctx.input.mouse.pos, elem.bounds); |
|
|
|
return point_in_rect(ctx.input.mouse.pos, elem.bounds); |
|
|
|