From eec217a5c5a57d7d3db9515aab9f5ee53adb658a Mon Sep 17 00:00:00 2001 From: Pedro Larouca Date: Mon, 29 Jan 2018 13:39:29 +0000 Subject: [PATCH] =?UTF-8?q?[Samples]=C2=A0some=20more=20widgets=20(#13)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [Samples] Label, LevelBar, ProgressBar and Spinner sections --- .../Samples/Sections/Widgets/LabelSection.cs | 47 +++++++++ .../Sections/Widgets/LevelBarSection.cs | 31 ++++++ .../Sections/Widgets/ProgressBarSection.cs | 95 +++++++++++++++++++ .../Sections/Widgets/SpinnerSection.cs | 28 ++++++ 4 files changed, 201 insertions(+) create mode 100644 Source/Samples/Sections/Widgets/LabelSection.cs create mode 100644 Source/Samples/Sections/Widgets/LevelBarSection.cs create mode 100644 Source/Samples/Sections/Widgets/ProgressBarSection.cs create mode 100644 Source/Samples/Sections/Widgets/SpinnerSection.cs diff --git a/Source/Samples/Sections/Widgets/LabelSection.cs b/Source/Samples/Sections/Widgets/LabelSection.cs new file mode 100644 index 000000000..da0900459 --- /dev/null +++ b/Source/Samples/Sections/Widgets/LabelSection.cs @@ -0,0 +1,47 @@ +// This is free and unencumbered software released into the public domain. +// Happy coding!!! - GtkSharp Team + +using Gtk; + +namespace Samples +{ + [Section(ContentType = typeof(Label), Category = Category.Widgets)] + class LabelSection : ListSection + { + public LabelSection() + { + AddItem(CreateSimpleLabel()); + AddItem(CreateMarkupLabel()); + } + + public (string, Widget) CreateSimpleLabel() + { + var label = new Label(); + + // can be defined at constructor + label.LabelProp = "This is a label"; + + // right align text, center is default + label.Xalign = 1f; + + return ("Label :", label); + } + + public (string, Widget) CreateMarkupLabel() + { + var label = new Label(); + + // activate markup, default is false + label.UseMarkup = true; + + // define label with pango markup + label.LabelProp = "This is a label with custom markup"; + + // right align text, center is default + label.Xalign = 1f; + + return ("Label Markup:", label); + } + + } +} diff --git a/Source/Samples/Sections/Widgets/LevelBarSection.cs b/Source/Samples/Sections/Widgets/LevelBarSection.cs new file mode 100644 index 000000000..048958054 --- /dev/null +++ b/Source/Samples/Sections/Widgets/LevelBarSection.cs @@ -0,0 +1,31 @@ +// This is free and unencumbered software released into the public domain. +// Happy coding!!! - GtkSharp Team + +using Gtk; + +namespace Samples +{ + [Section(ContentType = typeof(LevelBar), Category = Category.Widgets)] + class LevelBarSection : ListSection + { + public LevelBarSection() + { + AddItem(CreateSimpleLevelBar()); + } + + public (string, Widget) CreateSimpleLevelBar() + { + // constructor takes MinValue, MaxValue + var lb = new LevelBar(0, 100); + + // lets add a visible request size in our example + lb.WidthRequest = 100; + + // set the value to 75% + lb.Value = 75d; + + return ("Level Bar:", lb); + } + + } +} diff --git a/Source/Samples/Sections/Widgets/ProgressBarSection.cs b/Source/Samples/Sections/Widgets/ProgressBarSection.cs new file mode 100644 index 000000000..26933fc8a --- /dev/null +++ b/Source/Samples/Sections/Widgets/ProgressBarSection.cs @@ -0,0 +1,95 @@ +// This is free and unencumbered software released into the public domain. +// Happy coding!!! - GtkSharp Team + +using Gtk; +using System; +using System.Timers; + +namespace Samples +{ + [Section(ContentType = typeof(ProgressBar), Category = Category.Widgets)] + class ProgressBarSection : ListSection + { + public ProgressBarSection() + { + AddItem(CreateSimpleProgressBar()); + AddItem(CreateFractionProgressBar()); + AddItem(CreatePulseProgressBar()); + } + + public (string, Widget) CreateSimpleProgressBar() + { + var pb = new ProgressBar(); + + // lets add a visible request size in our example + pb.WidthRequest = 100; + + // add a text + pb.Text = "Some progress..."; + + // to show text it must be set to true + pb.ShowText = true; + + // progressbar is used in percentage mode values between 0.0 and 1.0 + pb.Fraction = 0.60d; + + return ("Progress Bar:", pb); + } + + public (string, Widget) CreateFractionProgressBar() + { + // this is used when application can report progress + + var pb = new ProgressBar(); + + pb.WidthRequest = 200; + + pb.Text = "0%"; + pb.ShowText = true; + pb.Fraction = 0d; + + // lets add a timer to demo it + var timer = new Timer(); + timer.Interval = 1000; + + timer.Elapsed += (sender, e) => + { + pb.Fraction += 0.1d; + if (pb.Fraction >= 1d) + pb.Fraction = 0d; + + pb.Text = $"{Math.Truncate(pb.Fraction * 100)}%"; + }; + + timer.Start(); + + return ("Progress Bar with fraction:", pb); + } + + public (string, Widget) CreatePulseProgressBar() + { + // this is used when application can report progress + + var pb = new ProgressBar(); + + pb.WidthRequest = 200; + + pb.Text = "Task time is unknown"; + pb.ShowText = true; + + // define how much is the pulse step + pb.PulseStep = 0.1d; + + // lets add a timer to demo it + var timer = new Timer(); + timer.Interval = 200; + + timer.Elapsed += (sender, e) => pb.Pulse(); + + timer.Start(); + + return ("Progress Bar with pulse:", pb); + } + + } +} diff --git a/Source/Samples/Sections/Widgets/SpinnerSection.cs b/Source/Samples/Sections/Widgets/SpinnerSection.cs new file mode 100644 index 000000000..ceef78537 --- /dev/null +++ b/Source/Samples/Sections/Widgets/SpinnerSection.cs @@ -0,0 +1,28 @@ +// This is free and unencumbered software released into the public domain. +// Happy coding!!! - GtkSharp Team + +using Gtk; + +namespace Samples +{ + [Section(ContentType = typeof(Spinner), Category = Category.Widgets)] + class SpinnerSection : ListSection + { + public SpinnerSection() + { + AddItem(CreateSimpleSpinner()); + } + + public (string, Widget) CreateSimpleSpinner() + { + var sp = new Spinner(); + + sp.Start(); + + // can be stopped with + // Stop() + + return ("Simple Spinner:", sp); + } + } +}