
root_function void 
UI_draw(void)
{

  
  //OS_Handle window = ui_state->window;
  for(UI_Box *box = ui_state->root, *next_box = &ui_g_nil_box; !UI_box_is_nil(box); box = next_box)
  {
    // We do a depth first recursion to go through the nodes.
    // The post part means that the sibling is UI_Box prev, and the child is UI_Box last.
    // TODO(anton): Draw this with pen and paper and make sure I understand how this works
    UI_BoxRec rec = UI_box_recurse_depth_first_post(box, &ui_g_nil_box);
    next_box = rec.next;
    
    //- Draw shadow 
    if(box->flags & UI_BoxFlag_DrawDropShadow)
    {
      F32 shift = 3.0f; // TODO make relative precent, is pixelsn ow
      Rng2_F32 shadow_rect = shift2_F32(pad2_F32(box->rect, 2), vec2_F32(shift, shift));

      
      R_Rect2DInst *rect = D_rect2D(shadow_rect,
                                     .color  = vec4_F32(0, 0, 0, 1.f),
                                     .corner_radius = 1,
                                     .softness = 3.f,
                                     .omit_texture = 1);
    }
    
    //- Draw background 
    if(box->flags & UI_BoxFlag_DrawBackground)
    {
      
      R_Rect2DInst *rect = D_rect2D(box->rect, 
                                    .color = box->background_color,
                                    .corner_radius = 0.0f,
                                    .softness = 0.0f,
                                    .omit_texture = 1);
      
      if(box->flags & UI_BoxFlag_DrawHotEffects) 
      {
        if(UI_key_match(ui_state->hot_box_key, box->key))
        {
          
          rect->colors[Corner_00] = box->overlay_color;
          rect->colors[Corner_10] = box->overlay_color;
          rect->colors[Corner_01] = box->background_color;
          rect->colors[Corner_11] = box->background_color;
        }
      }
        
    }
    
    //- Draw text 
    if(box->flags & UI_BoxFlag_DrawText)
    {
      // The stb assumes that the supplied start position will give 
      // the _BASELINE_ of the text that is to be produced.
      // So the text position we give here is adjusted to x of the box rect's p0,
      // and to the y of the box rect's p1.
      Vec2_F32 text_pos = UI_text_pos_from_box(box);
      String8 display_string = UI_display_string_from_box(box);
      B32 truncated = 0;
      if(!(box->flags & UI_BoxFlag_DisableTextTruncate))
      {
        // TODO(anton): Do stuff for truncating
        D_text2D(text_pos, display_string, box->text_color);
      }
    }
    
    //- Draw border 
    if(box->flags & UI_BoxFlag_DrawBorder)
    {
      Rng2_F32 border_rect = pad2_F32(box->rect, 0);
      R_Rect2DInst *rect = D_rect2D(border_rect);
      Vec4_F32 border_top_color = box->border_color;
      Vec4_F32 border_bot_color = box->background_color;
      rect->colors[Corner_00] = border_top_color;
      rect->colors[Corner_10] = border_top_color;
      rect->colors[Corner_01] = border_bot_color;
      rect->colors[Corner_11] = border_bot_color;
      rect->corner_radii[Corner_00] = 1;
      rect->corner_radii[Corner_10] = 1;
      rect->corner_radii[Corner_01] = 1;
      rect->corner_radii[Corner_11] = 1;
      rect->border_thickness = 1.f;
      rect->softness = 0.f;
      rect->omit_texture = 1;
    }
    
  }
}
