Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- global UI_PropertyGrid = {};
- function UI_PropertyGrid._create_label( text )
- {
- data = this.data;
- ctrl = UI_CreateStatic( data.OpCont, 0, 0, data.label_width_min, data.label_height, text, color(0,0.1), DT_LEFT | DT_VCENTER );
- ctrl.minWidth = data.label_width_min;
- ctrl.maxWidth = data.label_width_max;
- ctrl.q1x = data.label_width_percent;
- return ctrl;
- }
- function UI_PropertyGrid._create_checkbox( name, value, option )
- {
- data = this.data;
- optval = @option.value;
- checked = if( optval !== null, value === option.value, value );
- ctrl = UI_CreateCheckbox( data.OpCont, 0, 0, data.value_height, data.value_height, name, optval, checked );
- return ctrl;
- }
- function UI_PropertyGrid._create_textbox( name, value, option )
- {
- data = this.data;
- ctrl = UI_CreateTextbox( data.OpCont, 0, 0, data.value_width_min, name, @option.textbox_caption, value );
- ctrl.minWidth = data.label_width_min;
- ctrl.maxWidth = data.label_width_max;
- ctrl.q1x = data.label_width_percent;
- return ctrl;
- }
- function UI_PropertyGrid.getType( value, option )
- {
- if( option !== null )
- return option.type;
- if( typeid( value ) == VT_BOOL ) return "checkbox";
- return "textbox";
- }
- function UI_PropertyGrid.setData( input_values, options )
- {
- data = this.data;
- all_values = {};
- foreach( k, v : input_values )
- all_values[ k ] = v;
- data.values = all_values;
- if( options !== null )
- data.options = options;
- // Rebuild options
- data.OpCont.removeAllChildren();
- foreach( k, v : all_values )
- {
- option = @options.(k);
- this._create_label( @option.label || k );
- type = this.getType( v, option );
- this.("_create_"$type)( k, v, option );
- }
- }
- function UI_CreatePropertyGrid( parent, x, y, width, height, seed, options )
- {
- PropertyGrid = parent.frame.createControl( "propertygrid" );
- PropertyGrid.x = x;
- PropertyGrid.y = y;
- PropertyGrid.width = width;
- PropertyGrid.height = height;
- PropertyGrid._interface = UI_PropertyGrid;
- PropertyGrid.data =
- {
- label_width_min = 0,
- label_width_max = UI_MaxValue,
- label_width_percent = 0.5,
- label_height = 24,
- value_width_min = 0,
- value_width_max = UI_MaxValue,
- value_width_percent = 0.5,
- value_height = 24,
- values = {},
- options = {},
- };
- Form = UI_CreateForm( PropertyGrid );
- PropertyGrid.data.Form = Form;
- Scrollable = UI_CreateScrollable( Form, 0, 0, 0, 0, "auto", false );
- Scrollable.q1x = 1;
- Scrollable.q1y = 1;
- PropertyGrid.data.Scrollable = Scrollable;
- AutoLayout = UI_CreateAutoLayout( Scrollable, 0, 0, 0 );
- AutoLayout.q1x = 1;
- PropertyGrid.data.AutoLayout = AutoLayout;
- PropertyGrid.data.OpCont = AutoLayout;
- parent.addChild( PropertyGrid );
- PropertyGrid.setData( seed, options );
- return PropertyGrid;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement