+// High level controls
+// ====================================================================
+
+struct ui_window
+{
+ const char *title;
+ ui_rect transform;
+
+ int drag;
+ ui_px drag_offset[2];
+};
+
+static int ui_button( ui_ctx *ctx, u32 id )
+{
+ ui_new_node( ctx );
+ {
+ ui_capture_mouse( ctx, id );
+
+ if( ui_hasmouse(ctx) )
+ {
+ if( ctx->click_state == 1 )
+ ctx->capture_lock = 1;
+ else if( ctx->capture_lock && ctx->click_state == 3 )
+ {
+ return 1;
+ }
+ }
+ }
+
+ return 0;
+}
+
+static int ui_window( ui_ctx *ctx, struct ui_window *window, u32 control_group )
+{
+ ctx->id_base = control_group << 16;
+
+ if( window->drag )
+ {
+ window->transform[0] = ctx->mouse[0]+window->drag_offset[0];
+ window->transform[1] = ctx->mouse[1]+window->drag_offset[1];
+
+ ui_clamp_rect( ctx->stack[0].rect, window->transform );
+
+ if( ctx->click_state == 0 || ctx->click_state == 3 )
+ {
+ window->drag = 0;
+ }
+ }
+
+ ui_rect_copy( window->transform, ctx->cursor );
+
+ ui_new_node( ctx );
+ {
+ ui_capture_mouse( ctx, __COUNTER__ );
+
+ // Drag bar
+ ctx->cursor[3] = 25;
+ ui_new_node( ctx );
+ {
+ ui_capture_mouse( ctx, __COUNTER__ );
+
+ // title..
+
+ // Close button
+ ctx->cursor[2] = 25;
+ ui_align_right( ctx );
+ ui_rect_pad( ctx, ctx->cursor, 4 );
+
+ if( ui_button( ctx, __COUNTER__ ) )
+ {
+ vg_info( "Click clacked\n" );
+ }
+ ui_end( ctx );
+
+ if( ui_hasmouse( ctx ) )
+ {
+ // start drag
+ if( ctx->click_state == 1 )
+ {
+ window->drag = 1;
+ window->drag_offset[0] = window->transform[0]-ctx->mouse[0];
+ window->drag_offset[1] = window->transform[1]-ctx->mouse[1];
+ }
+ }
+ }
+ ui_end( ctx );
+ }
+
+ return 1;
+}
+