コード例 #1
0
        public ColumnishGrid()
        {
            var colinfo = new myColumnInfo(this);
            var rowinfo = new myRowInfo(this);

            var fmt = new OneValueForEachColumn <MyTextFormat> (new ValuePerCell_FromDelegates <MyTextFormat> (gv_fmt));

            IRowList <T> rowlist = new RowList_Bindable_IList <T>(this, RowsProperty);

            // TODO it would be better if these propnames were stored separately
            // from the formatting info.
            var propnames = new Dictionary <int, string>();

            this.PropertyChanged += (object sender, System.ComponentModel.PropertyChangedEventArgs e) => {
                if (e.PropertyName == ColumnsProperty.PropertyName)
                {
                    propnames.Clear();
                    for (int i = 0; i < Columns.Count; i++)
                    {
                        propnames[i] = Columns[i].PropertyName;
                    }
                }
            };

            IValuePerCell <string> vals = new ValuePerCell_RowList_Properties <string, T>(rowlist, propnames);

            IDrawCell <IGraphics> dec = new DrawCell_Text(vals, fmt);

            var padding1 = new ValuePerCell_Steady <Padding?> (new Padding(1, 1, 1, 1));
            var padding8 = new ValuePerCell_Steady <Padding?> (new Padding(8, 8, 8, 8));
            IValuePerCell <CrossGraphics.Color> bginfo = new ValuePerCell_FromDelegates <CrossGraphics.Color> (gv_clr);

            bginfo = new OneValueForEachColumn <CrossGraphics.Color> (bginfo);

            dec = new DrawCell_Chain_Padding(padding8, dec);
            dec = new DrawCell_Fill(bginfo, dec);
            dec = new DrawCell_Chain_Padding(padding1, dec);
            dec = new DrawCell_Chain_Cache(dec, colinfo, rowinfo);

            var sel = new Selection();

            var dec_selection = new DrawCell_FillRectIfSelected(sel, new CrossGraphics.Color(0, 255, 0, 120));

            var dh_layers = new DrawVisible_Layers(new IDrawVisible <IGraphics>[] {
                new DrawVisible_Adapter_DrawCell <IGraphics>(dec),
                new DrawVisible_Adapter_DrawCell <IGraphics>(dec_selection)
            });

            Main = new MainPanel(
                colinfo,
                rowinfo,
                dh_layers
                );
            Notify_DemoToggleSelections.Listen(Main, sel);
                        #if not
            // TODO the mod happens, but the notification does not
            _main.SingleTap += (object sender, CellCoords e) => {
                T          r   = Rows [e.Row];
                ColumnInfo ci  = Columns[e.Column];
                var        typ = typeof(T);
                var        ti  = typ.GetTypeInfo();
                var        p   = ti.GetDeclaredProperty(ci.PropertyName);
                if (p != null)
                {
                    var val = p.GetValue(r);
                    p.SetValue(r, val.ToString() + "*");
                }
            };
                        #endif

            var bginfo_gray = new ValuePerCell_Steady <CrossGraphics.Color> (CrossGraphics.Colors.Gray);
            Top = new FrozenRowsPanel(
                colinfo,
                new Dimension_Steady(1, 40, false),
                new DrawVisible_Adapter_DrawCell <IGraphics>(
                    new DrawCell_Chain_Padding(
                        padding1,
                        new DrawCell_Fill(
                            bginfo_gray,
                            new DrawCell_Text(
                                new myFrozenGetCellTextValue(this),
                                new ValuePerCell_Steady <MyTextFormat>(
                                    new MyTextFormat {
                TextFont  = CrossGraphics.Font.BoldSystemFontOfSize(20),
                TextColor = CrossGraphics.Colors.Red,
                HorizontalTextAlignment = CrossGraphics.TextAlignment.Center,
                VerticalTextAlignment   = CrossGraphics.TextAlignment.Center
            }
                                    )
                                )
                            )
                        )
                    )
                );
        }
コード例 #2
0
        public ColumnishGrid()
        {
            var colinfo = new myColumnInfo(this);
            var rowinfo = new myRowInfo(this);

            var fmt = new OneValueForEachColumn <MyTextFormat> (new ValuePerCell_FromDelegates <MyTextFormat> (gv_fmt));

            IRowList <T> rowlist = new RowList_Bindable_ReactiveList <T>(this, RowsProperty);

            // TODO it would be better if these propnames were stored separately
            // from the formatting info.
            var propnames = new Dictionary <int, string>();

            this.PropertyChanged += (object sender, System.ComponentModel.PropertyChangedEventArgs e) => {
                if (e.PropertyName == ColumnsProperty.PropertyName)
                {
                    propnames.Clear();
                    for (int i = 0; i < Columns.Count; i++)
                    {
                        propnames[i] = Columns[i].PropertyName;
                    }
                }
            };

            IValuePerCell <string> vals = new ValuePerCell_RowList_Properties <string, T>(rowlist, propnames);

            IDrawCell <IGraphics> dec = new DrawCell_Text(vals, fmt);

            var padding1 = new ValuePerCell_Steady <Padding?> (new Padding(1, 1, 1, 1));
            var padding8 = new ValuePerCell_Steady <Padding?> (new Padding(8, 8, 8, 8));
            IValuePerCell <Color?> bginfo = new ValuePerCell_FromDelegates <Color?> (gv_clr);

            bginfo = new OneValueForEachColumn <Color?> (bginfo);

            dec = new DrawCell_Chain_Padding(padding8, dec);
            dec = new DrawCell_Fill(bginfo, dec);
            dec = new DrawCell_Chain_Padding(padding1, dec);
            dec = new DrawCell_Chain_Cache(dec, colinfo, rowinfo);

            Main = new MainPanel(
                colinfo,
                rowinfo,
                new DrawVisible_Adapter_DrawCell <IGraphics>(dec)
                );
            Main.SingleTap += (object sender, CellCoords e) => {
                // when we get a tap on a cell, append an asterisk to its text.
                // this should automatically trigger a display update because the
                // object is a ReactiveObject which tells its ReactiveList which
                // tells its RowList and so on.
                T          r   = Rows [e.Row];
                ColumnInfo ci  = Columns[e.Column];
                var        typ = typeof(T);
                var        ti  = typ.GetTypeInfo();
                var        p   = ti.GetDeclaredProperty(ci.PropertyName);
                if (p != null)
                {
                    var val = p.GetValue(r);
                    p.SetValue(r, val.ToString() + "*");
                }
            };

            var bginfo_gray = new ValuePerCell_Steady <Color?> (Color.Gray);

            Top = new FrozenRowsPanel(
                colinfo,
                new Dimension_Steady(1, 40, false),
                new DrawVisible_Adapter_DrawCell <IGraphics>(
                    new DrawCell_Chain_Padding(
                        padding1,
                        new DrawCell_Fill(
                            bginfo_gray,
                            new DrawCell_Text(
                                new myFrozenGetCellTextValue(this),
                                new ValuePerCell_Steady <MyTextFormat>(
                                    new MyTextFormat {
                TextFont  = Font.SystemFontOfSize(20, Xamarin.Forms.FontAttributes.Bold),
                TextColor = Color.Red,
                HorizontalTextAlignment = TextAlignment.Center,
                VerticalTextAlignment   = TextAlignment.Center
            }
                                    )
                                )
                            )
                        )
                    )
                );
        }