示例#1
0
        public (string, Widget) CreateCustomActionsEntry()
        {
            var entry = new Entry();

            entry.PlaceholderText = "Search";
            entry.SetIconFromIconName(EntryIconPosition.Primary, "edit-find-symbolic");
            entry.SetIconFromIconName(EntryIconPosition.Secondary, "edit-clear-symbolic");

            entry.IconRelease += (o, args) =>
            {
                switch (args.P0)
                {
                case EntryIconPosition.Primary:
                    ApplicationOutput.WriteLine(o, "Clicked Search Icon");
                    break;

                default:
                    entry.Text = string.Empty;
                    ApplicationOutput.WriteLine(o, "Clicked Clear Icon");
                    break;
                }
            };

            return("Custom actions entry:", entry);
        }
示例#2
0
        public (string, Widget) CreateSimpleButton()
        {
            var btn = new Button("Simple Button");

            btn.Clicked += (sender, e) => ApplicationOutput.WriteLine(sender, "Clicked");

            return("Simple button:", btn);
        }
示例#3
0
        public (string, Widget) CreateStockButton()
        {
            var btn = new Button(Stock.About);

            btn.Clicked += (sender, e) => ApplicationOutput.WriteLine(sender, "Clicked");

            return("Stock button:", btn);
        }
示例#4
0
        public (string, Widget) CreateLinkButton()
        {
            var btn = new LinkButton("A simple link button");

            btn.Clicked += (sender, e) => ApplicationOutput.WriteLine(sender, "Link button Clicked");

            return("Link button:", btn);
        }
示例#5
0
        public (string, Widget) CreateHorizontalRange()
        {
            var adj    = new Adjustment(0.0, 0.0, 101.0, 0.1, 1.0, 1.0);
            var hScale = new HScale(adj);

            hScale.SetSizeRequest(200, -1);
            hScale.ValueChanged += (sender, e) => ApplicationOutput.WriteLine(sender, $"Value Change: {((HScale)sender).Value}");
            return("Horizontal", hScale);
        }
示例#6
0
        public (string, Widget) CreateSwitchButton()
        {
            var btn = new Switch();

            btn.ButtonReleaseEvent += (o, args) =>
                                      ApplicationOutput.WriteLine(o, $"Switch is now: {!btn.Active}");

            return("Switch:", btn);
        }
示例#7
0
        public (string, Widget) CreateVerticalRange()
        {
            var adj    = new Adjustment(0.0, 0.0, 101.0, 0.1, 1.0, 1.0);
            var vScale = new VScale(adj);

            vScale.SetSizeRequest(-1, 200);
            vScale.ValueChanged += (sender, e) => ApplicationOutput.WriteLine(sender, $"Value Change: {((VScale)sender).Value}");
            return("Vertical", vScale);
        }
示例#8
0
        public (string, Widget) CreatePlaceholderEntry()
        {
            var entry = new Entry();

            entry.PlaceholderText = "Please fill with information";

            entry.Changed += (sender, e) => ApplicationOutput.WriteLine(sender, "Changed");

            return("Placeholder text entry:", entry);
        }
示例#9
0
        public (string, Widget) CreateSimpleRightAlignedTextEntry()
        {
            var entry = new Entry("Text is Right Aligned");

            entry.Xalign = 1f;

            entry.Changed += (sender, e) => ApplicationOutput.WriteLine(sender, "Changed");

            return("Right aligned text entry:", entry);
        }
示例#10
0
        public (string, Widget) CreateSimpleEntry()
        {
            var entry = new Entry("Initial Text");

            entry.TooltipText = "This is the tooltip!";

            entry.Changed += (sender, e) => ApplicationOutput.WriteLine(sender, "Changed");

            return("Simple entry:", entry);
        }
示例#11
0
        public (string, Widget) CreateImageButton()
        {
            var btn = new Button();

            btn.AlwaysShowImage = true;
            btn.Image           = Image.NewFromIconName("document-new-symbolic", IconSize.Button);
            btn.Clicked        += (sender, e) => ApplicationOutput.WriteLine(sender, "Clicked");

            return("Image button:", btn);
        }
示例#12
0
        public (string, Widget) CreateMaxLimitEntry()
        {
            var entry = new Entry("123");

            entry.MaxLength = 3;

            entry.Changed += (sender, e) => ApplicationOutput.WriteLine(sender, "Changed");

            return("Text length limited entry:", entry);
        }
示例#13
0
        protected override void OnPressed()
        {
            base.OnPressed();

            var seat = Display.DefaultSeat;

            ApplicationOutput.WriteLine($"Default seat: {seat}");

            seat.Pointer.GetPosition(null, out int x, out int y);
            ApplicationOutput.WriteLine($"Position: ({x}, {y})");
        }
示例#14
0
        public (string, Widget) CreateImageTextButton()
        {
            var btn = new Button();

            btn.Label           = "Some text";
            btn.ImagePosition   = PositionType.Top;
            btn.AlwaysShowImage = true;
            btn.Image           = Image.NewFromIconName("document-new-symbolic", IconSize.Button);
            btn.Clicked        += (sender, e) => ApplicationOutput.WriteLine(sender, "Clicked");

            return("Image and text button:", btn);
        }
示例#15
0
        public (string, Widget) CreateInvisibleCharEntry()
        {
            var entry = new Entry("Invisible text entry");

            entry.Visibility       = false;
            entry.InvisibleChar    = '\u2022';
            entry.InvisibleCharSet = true;

            entry.Changed += (sender, e) => ApplicationOutput.WriteLine(sender, "Changed");

            return("Invisible text entry:", entry);
        }
示例#16
0
        public (string, Widget) CreateActionButton()
        {
            var sa = new GLib.SimpleAction("SampleAction", null);

            sa.Activated += (sender, e) => ApplicationOutput.WriteLine(sender, "SampleAction Activated");
            Program.App.AddAction(sa);

            var btn = new Button();

            btn.Label      = "SampleAction Button";
            btn.ActionName = "app.SampleAction";

            return("Action button:", btn);
        }
示例#17
0
        protected override void OnPressed()
        {
            base.OnPressed();
            var count = 0;

            if (running)
            {
                running = false;

                return;
            }

            var startmem = GC.GetTotalMemory(true);
            var testfile = "Textpic.png";

            using var teststream = typeof(ImageSection).Assembly.GetManifestResourceStream("Testpic");
            using (var writeTestFile = new FileStream(testfile, FileMode.Create)) {
                teststream.CopyTo(writeTestFile);
            }

            using (var heatup = new Pixbuf(testfile)) {
                ApplicationOutput.WriteLine($"{nameof(heatup)}.{nameof(Pixbuf.ByteLength)}\t{heatup.ByteLength:N0}");
            }

            startmem = GC.GetTotalMemory(true);
            ApplicationOutput.WriteLine($"{nameof(GC.GetTotalMemory)} at start: {startmem:N}");
            running = true;

            var memAllocated = 0UL;

            while (running)
            {
                using (var source = new Pixbuf(typeof(ImageSection).Assembly, "Testpic")) {
                    memAllocated += source.ByteLength;
                    count++;
                }

                DispatchPendingEvents();

                if (!running)
                {
                    break;
                }
            }

            var endmem = GC.GetTotalMemory(true);

            ApplicationOutput.WriteLine($"Leak:\t{(endmem - startmem):N0}\t{nameof(memAllocated)}");
            ApplicationOutput.WriteLine($"{nameof(GC.GetTotalMemory)} at start: {startmem:N0}\tat end: {endmem:N0}\t{nameof(Pixbuf)} created: {count}");
        }
示例#18
0
        public (string, Widget) CreateSpinButton()
        {
            // Spinbutton constructor takes MinValue, MaxValue and StepValue
            var btn = new SpinButton(0, 1000, 1);

            // Button constructor also takes the adjustment object
            // and it can be redefined any time like CurrentVal, MinVal, MaxVal, Step, PageStep, PageSize
            btn.Adjustment.Configure(888, 0, 1000, 1, 100, 0);

            // Default values are double, use ValueAsInt method to get Int
            btn.ValueChanged += (sender, e) =>
                                ApplicationOutput.WriteLine(sender, $"Spin button changed: {btn.ValueAsInt}");

            return("Spin button:", btn);
        }
示例#19
0
        public (string, Widget) CreateToggleButton()
        {
            var btn = new ToggleButton("Toggle Me");

            btn.Toggled += (sender, e) =>
            {
                if (btn.Active)
                {
                    btn.Label = "Untoggle Me";
                }
                else
                {
                    btn.Label = "Toglle Me";
                }

                ApplicationOutput.WriteLine(sender, "Buton Toggled");
            };

            return("Toggle button:", btn);
        }
示例#20
0
        public (string, Widget) CreateMultiColumnComboBox()
        {
            // create a store for our combo
            var store = new ListStore(typeof(string), typeof(string), typeof(bool));

            // lets append some stock icons, passing the icon names, and a simple text column
            store.AppendValues("dialog-warning", "Warning", true);
            store.AppendValues("process-stop", "Stop", false);
            store.AppendValues("document-new", "New", true);
            store.AppendValues("edit-clear", "Clear", true);

            // create cells
            var imageCell = new CellRendererPixbuf();
            var textCell  = new CellRendererText();

            // create the combo and pass the values in
            var combo = new ComboBox(store);

            combo.PackStart(imageCell, true);
            combo.PackStart(textCell, true);

            // add combo attributes to show in columns
            combo.AddAttribute(imageCell, "icon-name", 0);
            combo.AddAttribute(textCell, "text", 1);

            // lets use the store bool values to control sensitive rows
            // Process-stop (store index one) should be disabled in this sample
            // For a ComboBox item to be disabled, all cell renderers for the item need to have
            // their sensitivity disabled
            combo.AddAttribute(imageCell, "sensitive", 2);
            combo.AddAttribute(textCell, "sensitive", 2);

            // listen to index changed on combo
            combo.Changed += (sender, e) =>
                             ApplicationOutput.WriteLine(sender, $"Index changed to:{((ComboBox)sender).Active}");

            // lets preselect the first option
            combo.Active = 0;

            return("Combo with Icons and Text:", combo);
        }
示例#21
0
        public (string, Widget) CreateSimpleComboBox()
        {
            // initialize with a simple string list
            var combo = new ComboBox(
                new string[]
            {
                "Combo Entry 1",
                "Combo Entry 2",
                "Combo Entry 3",
                "Combo Entry 4"
            }
                );

            // event to notify for index changes in our combo
            combo.Changed += (sender, e) =>
                             ApplicationOutput.WriteLine(sender, $"Index changed to:{((ComboBox)sender).Active}");

            // set the active selection to index 2 (Combo Entry 3)
            combo.Active = 2;

            return("Simple combo:", combo);
        }