[Samples] Setup more of base + add button examples

This commit is contained in:
cra0zy 2018-01-21 19:54:58 +01:00
parent 69716243b9
commit 687b070ea2
10 changed files with 162 additions and 52 deletions

View File

@ -1,23 +1,23 @@
using System;
using System.Diagnostics;
using Gtk;
namespace Samples
{
static class ApplicationOutput
{
public static Widget Widget { get; set; }
private static ScrolledWindow _scrolledWindow;
private static TextView _textView;
private static readonly ScrolledWindow _scrolledWindow;
private static readonly TextView _textView;
static ApplicationOutput()
{
var vbox = new VBox();
var labelTitle = new Label();
labelTitle.Text = "Application Output:";
labelTitle.Margin = 4;
labelTitle.Xalign = 0f;
var labelTitle = new Label
{
Text = "Application Output:",
Margin = 4,
Xalign = 0f
};
vbox.PackStart(labelTitle, false, true, 0);
_scrolledWindow = new ScrolledWindow();
@ -26,18 +26,29 @@ namespace Samples
vbox.PackStart(_scrolledWindow, true, true, 0);
Widget = vbox;
_textView.SizeAllocated += TextView_SizeAllocated;
}
public static Widget Widget { get; set; }
private static void TextView_SizeAllocated(object o, SizeAllocatedArgs args)
{
_textView.ScrollToIter(_textView.Buffer.EndIter, 0, false, 0, 0);
}
public static void WriteLine(object o, string e)
{
WriteLine("[" + Environment.TickCount + "] " + o.GetType().ToString() + ": " + e);
WriteLine("[" + Environment.TickCount + "] " + o.GetType() + ": " + e);
}
public static void WriteLine(string line)
{
var enditer = _textView.Buffer.EndIter;
_textView.Buffer.Insert(ref enditer, line + Environment.NewLine);
_textView.ScrollToIter(enditer, 0, false, 0, 0);
if (_textView.Buffer.Text.Length > 0)
line = Environment.NewLine + line;
_textView.Buffer.Insert(ref enditer, line);
}
}
}

View File

@ -40,6 +40,7 @@ namespace Samples
vpanned.Position = 400;
_boxContent = new Box(Orientation.Vertical, 0);
_boxContent.Margin = 8;
vpanned.Pack1(_boxContent, true, true);
vpanned.Pack2(ApplicationOutput.Widget, false, true);

View File

@ -48,16 +48,17 @@ namespace Samples
private static void AboutActivated(object sender, EventArgs e)
{
var dialog = new AboutDialog();
dialog.TransientFor = Win;
dialog.ProgramName = "GtkSharp Sample Application";
dialog.Version = "1.0.0.0";
dialog.Comments = "A sample application for the GtkSharp project.";
dialog.LogoIconName = "system-run-symbolic";
dialog.License = "This sample application is licensed under public domain.";
dialog.Website = "https://www.github.com/GtkSharp/GtkSharp";
dialog.WebsiteLabel = "GtkSharp Website";
var dialog = new AboutDialog
{
TransientFor = Win,
ProgramName = "GtkSharp Sample Application",
Version = "1.0.0.0",
Comments = "A sample application for the GtkSharp project.",
LogoIconName = "system-run-symbolic",
License = "This sample application is licensed under public domain.",
Website = "https://www.github.com/GtkSharp/GtkSharp",
WebsiteLabel = "GtkSharp Website"
};
dialog.Run();
dialog.Hide();
}

View File

@ -1,14 +0,0 @@
using System;
using Gtk;
namespace Samples
{
[SectionAttribute(Name = "AboutDialog", Category = Category.Dialogs)]
class AboutDialogCategory : Box
{
public AboutDialogCategory() : base(Orientation.Vertical, 0)
{
}
}
}

View File

@ -0,0 +1,14 @@
using System;
using Gtk;
namespace Samples
{
[Section(Name = "AboutDialog", Category = Category.Dialogs)]
class AboutDialogSection : Box
{
public AboutDialogSection() : base(Orientation.Vertical, 0)
{
}
}
}

View File

@ -0,0 +1,46 @@
using System;
using Gtk;
namespace Samples
{
public class ListSection : Box
{
private Grid _grid;
private int _position;
public ListSection() : base(Orientation.Vertical, 0)
{
_position = 0;
_grid = new Grid
{
RowSpacing = 6,
ColumnSpacing = 6
};
PackStart(_grid, false, true, 0);
PackStart(new VBox(), true, true, 0);
}
public void AddItem((string, Widget) turp)
{
AddItem(turp.Item1, turp.Item2);
}
public void AddItem(string label, Widget widget)
{
_grid.Attach(new Label
{
Text = label,
Hexpand = true,
Halign = Align.Start
}, 0, _position, 1, 1);
var hbox = new HBox();
hbox.PackStart(new VBox(), true, true, 0);
hbox.PackStart(widget, false, true, 0);
_grid.Attach(hbox, 1, _position, 1, 1);
_position++;
}
}
}

View File

@ -1,17 +0,0 @@
using System;
using Gtk;
namespace Samples
{
[SectionAttribute(Name = "Button", Category = Category.Widgets)]
class ButtonCategory : Box
{
public ButtonCategory() : base(Orientation.Vertical, 0)
{
var btn = new Button("Click Me");
PackStart(btn, true, true, 0);
btn.Clicked += (sender, e) => ApplicationOutput.WriteLine(sender, "Clicked");
}
}
}

View File

@ -0,0 +1,68 @@
using Gtk;
namespace Samples
{
[Section(Name = "Button", Category = Category.Widgets)]
class ButtonSection : ListSection
{
public ButtonSection()
{
AddItem(CreateSimpleButton());
AddItem(CreateStockButton());
AddItem(CreateImageButton());
AddItem(CreateImageTextButton());
AddItem(CreateActionButton());
}
public (string, Widget) CreateSimpleButton()
{
var btn = new Button("Simple Button");
btn.Clicked += (sender, e) => ApplicationOutput.WriteLine(sender, "Clicked");
return ("Simple button:", btn);
}
public (string, Widget) CreateStockButton()
{
var btn = new Button(Stock.About);
btn.Clicked += (sender, e) => ApplicationOutput.WriteLine(sender, "Clicked");
return ("Stock button:", btn);
}
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);
}
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);
}
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);
}
}
}