Advertisement
snake5

sgs-ui: property grid v0.2

Jun 7th, 2014
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. global UI_PropertyGrid = {};
  2.  
  3. function UI_PropertyGrid._create_label( text )
  4. {
  5.     data = this.data;
  6.     ctrl = UI_CreateStatic( data.OpCont, 0, 0, data.label_width_min, data.label_height, text, color(0,0.1), DT_LEFT | DT_VCENTER );
  7.     ctrl.minWidth = data.label_width_min;
  8.     ctrl.maxWidth = data.label_width_max;
  9.     ctrl.q1x = data.label_width_percent;
  10.     return ctrl;
  11. }
  12.  
  13. function UI_PropertyGrid._create_checkbox( name, value, option )
  14. {
  15.     data = this.data;
  16.     optval = @option.value;
  17.     checked = if( optval !== null, value === option.value, value );
  18.     ctrl = UI_CreateCheckbox( data.OpCont, 0, 0, data.value_height, data.value_height, name, optval, checked );
  19.     return ctrl;
  20. }
  21.  
  22. function UI_PropertyGrid._create_textbox( name, value, option )
  23. {
  24.     data = this.data;
  25.     ctrl = UI_CreateTextbox( data.OpCont, 0, 0, data.value_width_min, name, @option.textbox_caption, value );
  26.     ctrl.minWidth = data.label_width_min;
  27.     ctrl.maxWidth = data.label_width_max;
  28.     ctrl.q1x = data.label_width_percent;
  29.     return ctrl;
  30. }
  31.  
  32. function UI_PropertyGrid.getType( value, option )
  33. {
  34.     if( option !== null )
  35.         return option.type;
  36.     if( typeid( value ) == VT_BOOL ) return "checkbox";
  37.     return "textbox";
  38. }
  39.  
  40. function UI_PropertyGrid.setData( input_values, options )
  41. {
  42.     data = this.data;
  43.     all_values = {};
  44.     foreach( k, v : input_values )
  45.         all_values[ k ] = v;
  46.    
  47.     data.values = all_values;
  48.     if( options !== null )
  49.         data.options = options;
  50.    
  51.     // Rebuild options
  52.     data.OpCont.removeAllChildren();
  53.     foreach( k, v : all_values )
  54.     {
  55.         option = @options.(k);
  56.         this._create_label( @option.label || k );
  57.        
  58.         type = this.getType( v, option );
  59.         this.("_create_"$type)( k, v, option );
  60.     }
  61. }
  62.  
  63. function UI_CreatePropertyGrid( parent, x, y, width, height, seed, options )
  64. {
  65.     PropertyGrid = parent.frame.createControl( "propertygrid" );
  66.     PropertyGrid.x = x;
  67.     PropertyGrid.y = y;
  68.     PropertyGrid.width = width;
  69.     PropertyGrid.height = height;
  70.     PropertyGrid._interface = UI_PropertyGrid;
  71.     PropertyGrid.data =
  72.     {
  73.         label_width_min = 0,
  74.         label_width_max = UI_MaxValue,
  75.         label_width_percent = 0.5,
  76.         label_height = 24,
  77.         value_width_min = 0,
  78.         value_width_max = UI_MaxValue,
  79.         value_width_percent = 0.5,
  80.         value_height = 24,
  81.        
  82.         values = {},
  83.         options = {},
  84.     };
  85.    
  86.     Form = UI_CreateForm( PropertyGrid );
  87.     PropertyGrid.data.Form = Form;
  88.    
  89.     Scrollable = UI_CreateScrollable( Form, 0, 0, 0, 0, "auto", false );
  90.     Scrollable.q1x = 1;
  91.     Scrollable.q1y = 1;
  92.     PropertyGrid.data.Scrollable = Scrollable;
  93.    
  94.     AutoLayout = UI_CreateAutoLayout( Scrollable, 0, 0, 0 );
  95.     AutoLayout.q1x = 1;
  96.     PropertyGrid.data.AutoLayout = AutoLayout;
  97.     PropertyGrid.data.OpCont = AutoLayout;
  98.    
  99.     parent.addChild( PropertyGrid );
  100.    
  101.     PropertyGrid.setData( seed, options );
  102.    
  103.     return PropertyGrid;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement