Ejemplo n.º 1
0
    void Awake()
    {
        // create the table with a specified object type
        _table = new TableView(this, typeof(FooItem));

        // setup the description for content
        _table.AddColumn("Name", "Name", 0.5f, TextAnchor.MiddleLeft);
        _table.AddColumn("Count_A", "Count_A", 0.1f);
        _table.AddColumn("Time_A", "Time_A", 0.1f, TextAnchor.MiddleCenter, "0.000");
        _table.AddColumn("Count_B", "Count_B", 0.1f);
        _table.AddColumn("Time_B", "Time_B", 0.1f, TextAnchor.MiddleCenter, "0.0");
        _table.AddColumn("Prop", "PrivateProp", 0.1f, TextAnchor.MiddleCenter, "0.0");

        // add test data
        List <object> entries = new List <object>();

        for (int i = 0; i < 100; i++)
        {
            entries.Add(FooItem.MakeRandom());
        }
        _table.RefreshData(entries);

        // register the event-handling function
        _table.OnSelected += TableView_Selected;
    }
Ejemplo n.º 2
0
    void TableView_Selected(object selected, int col)
    {
        FooItem foo = selected as FooItem;

        if (foo == null)
        {
            Debug.LogErrorFormat("the selected object is not a valid one. ({0} expected, {1} got)",
                                 typeof(FooItem).ToString(), selected.GetType().ToString());
            return;
        }

        string text = string.Format("object '{0}' selected. (col={1})", foo.Name, col);

        Debug.Log(text);
        ShowNotification(new GUIContent(text));
    }
        public void SetUpFixture()
        {
            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost        host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                IEventBindingService eventBindingService = new MockEventBindingService(host);
                Form form = (Form)host.RootComponent;
                form.ClientSize = new Size(200, 300);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                // Add custom control
                CustomUserControl userControl = (CustomUserControl)host.CreateComponent(typeof(CustomUserControl), "userControl1");
                userControl.Location   = new Point(0, 0);
                userControl.ClientSize = new Size(200, 100);

                DesignerSerializationManager  designerSerializationManager = new DesignerSerializationManager(host);
                IDesignerSerializationManager serializationManager         = (IDesignerSerializationManager)designerSerializationManager;
                using (designerSerializationManager.CreateSession()) {
                    FooItem fooItem = (FooItem)serializationManager.CreateInstance(typeof(FooItem), new object[] { "aa" }, "fooItem1", false);
                    userControl.FooItems.Add(fooItem);
                    fooItem = (FooItem)serializationManager.CreateInstance(typeof(FooItem), new object[] { "bb" }, "fooItem2", false);
                    userControl.FooItems.Add(fooItem);

                    BarItem barItem = (BarItem)serializationManager.CreateInstance(typeof(BarItem), new object[] { "cc" }, "barItem1", false);
                    userControl.ParentComponent.ParentBarItems.Add(barItem);
                    barItem = (BarItem)serializationManager.CreateInstance(typeof(BarItem), new object[] { "dd" }, "barItem2", false);
                    userControl.ParentComponent.ParentBarItems.Add(barItem);
                    form.Controls.Add(userControl);

                    PythonCodeDomSerializer serializer = new PythonCodeDomSerializer("    ");
                    generatedPythonCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, String.Empty, 1);
                }
            }
        }
 public void Add(FooItem f)
 {
     Items.Add(f);
 }