diff --git a/@TableGridDraw/TableGridDraw.m b/@TableGridDraw/TableGridDraw.m new file mode 100644 index 0000000000000000000000000000000000000000..83a549196a51be252cbf1eb1602a60d0b4b574d5 --- /dev/null +++ b/@TableGridDraw/TableGridDraw.m @@ -0,0 +1,17 @@ +classdef TableGridDraw < handle + %TABLEGRIDDRAW Draw a TableGrid into a uipanel + % Draws a 2D Grid inside a uipanel (Yay!) + + properties + my_table_grid = [] + controls = [] + end + + methods + function object = TableGridDraw(my_table_grid) + object.my_table_grid = my_table_grid; + end + end + +end + diff --git a/@TableGridDraw/draw_onto.m b/@TableGridDraw/draw_onto.m new file mode 100644 index 0000000000000000000000000000000000000000..e1438b1f3581d44d789ecadd3568d55086688115 --- /dev/null +++ b/@TableGridDraw/draw_onto.m @@ -0,0 +1,31 @@ +function draw_onto( object, parent_handle ) +%DRAW_ONTO Draws the controls onto the parent_handle. This function needs +%to be called everytime an update happens. +% This function draws the entire handle onto the handle. This function +% needs to be called everytime the back table is updated. The class will +% notify when its necessary. + + %Need to invert y, so need total size + [x, y] = object.get_bounding_box(); + + % First delete an extra controls + assert( ~(size(object.controls, 2) > object.my_table_grid.width), 'Implment delete when necessary.'); + assert( ~(size(object.controls, 1) > object.my_table_grid.height), 'Implment delete when necessary.'); + + if size(object.controls, 2) ~= object.my_table_grid.width || size(object.controls, 1) ~= object.my_table_grid.height + object.controls(object.my_table_grid.height, object.my_table_grid.width) = 0; + end + + for i = 1:object.my_table_grid.width + for j = 1:object.my_table_grid.width + if object.controls(j,i) ~= 0 && ishandle(object.controls(j,i)) + assert( false, 'Deal with existing controls' ); + else + %Standardize this + uicontrol(parent_handle, 'Style', 'edit', 'Position', [(i-1)*120+(i-1)*5, y-((j)*80+(j-1)*5), 120, 80], 'String', ['' num2str(i) ', ' num2str(j)]); + end + end + end + +end + diff --git a/@TableGridDraw/get_bounding_box.m b/@TableGridDraw/get_bounding_box.m new file mode 100644 index 0000000000000000000000000000000000000000..a1ff3834b767afa5b76f42c1818d8a4329246a63 --- /dev/null +++ b/@TableGridDraw/get_bounding_box.m @@ -0,0 +1,11 @@ +function [x, y] = get_bounding_box( object ) +%GET_BOUNDING_BOX Gets the size in pixels of the grid. +%Returns the size of the grid (as a box) for layout purposes. + x = object.my_table_grid.height; %Store number of cells first + x = 120*x + 5*(x-1); %Then calculate the pixels. + + y = object.my_table_grid.height; + y = 80*y + 5*(y-1); %Same here. + +end +