[Samples] some more widgets (#13)

[Samples] Label, LevelBar, ProgressBar and Spinner sections
This commit is contained in:
Pedro Larouca 2018-01-29 13:39:29 +00:00 committed by Harry
parent 7640a16562
commit eec217a5c5
4 changed files with 201 additions and 0 deletions

View file

@ -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 <span foreground=\"red\" size=\"large\">label</span> with <b>custom</b> markup";
// right align text, center is default
label.Xalign = 1f;
return ("Label Markup:", label);
}
}
}

View file

@ -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);
}
}
}

View file

@ -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);
}
}
}

View file

@ -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);
}
}
}