[Samples] Setup more of base + add button examples
This commit is contained in:
parent
69716243b9
commit
687b070ea2
10 changed files with 162 additions and 52 deletions
|
@ -1,23 +1,23 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
|
||||||
using Gtk;
|
using Gtk;
|
||||||
|
|
||||||
namespace Samples
|
namespace Samples
|
||||||
{
|
{
|
||||||
static class ApplicationOutput
|
static class ApplicationOutput
|
||||||
{
|
{
|
||||||
public static Widget Widget { get; set; }
|
private static readonly ScrolledWindow _scrolledWindow;
|
||||||
private static ScrolledWindow _scrolledWindow;
|
private static readonly TextView _textView;
|
||||||
private static TextView _textView;
|
|
||||||
|
|
||||||
static ApplicationOutput()
|
static ApplicationOutput()
|
||||||
{
|
{
|
||||||
var vbox = new VBox();
|
var vbox = new VBox();
|
||||||
|
|
||||||
var labelTitle = new Label();
|
var labelTitle = new Label
|
||||||
labelTitle.Text = "Application Output:";
|
{
|
||||||
labelTitle.Margin = 4;
|
Text = "Application Output:",
|
||||||
labelTitle.Xalign = 0f;
|
Margin = 4,
|
||||||
|
Xalign = 0f
|
||||||
|
};
|
||||||
vbox.PackStart(labelTitle, false, true, 0);
|
vbox.PackStart(labelTitle, false, true, 0);
|
||||||
|
|
||||||
_scrolledWindow = new ScrolledWindow();
|
_scrolledWindow = new ScrolledWindow();
|
||||||
|
@ -26,18 +26,29 @@ namespace Samples
|
||||||
vbox.PackStart(_scrolledWindow, true, true, 0);
|
vbox.PackStart(_scrolledWindow, true, true, 0);
|
||||||
|
|
||||||
Widget = vbox;
|
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)
|
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)
|
public static void WriteLine(string line)
|
||||||
{
|
{
|
||||||
var enditer = _textView.Buffer.EndIter;
|
var enditer = _textView.Buffer.EndIter;
|
||||||
_textView.Buffer.Insert(ref enditer, line + Environment.NewLine);
|
if (_textView.Buffer.Text.Length > 0)
|
||||||
_textView.ScrollToIter(enditer, 0, false, 0, 0);
|
line = Environment.NewLine + line;
|
||||||
|
_textView.Buffer.Insert(ref enditer, line);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -40,6 +40,7 @@ namespace Samples
|
||||||
vpanned.Position = 400;
|
vpanned.Position = 400;
|
||||||
|
|
||||||
_boxContent = new Box(Orientation.Vertical, 0);
|
_boxContent = new Box(Orientation.Vertical, 0);
|
||||||
|
_boxContent.Margin = 8;
|
||||||
vpanned.Pack1(_boxContent, true, true);
|
vpanned.Pack1(_boxContent, true, true);
|
||||||
|
|
||||||
vpanned.Pack2(ApplicationOutput.Widget, false, true);
|
vpanned.Pack2(ApplicationOutput.Widget, false, true);
|
||||||
|
|
|
@ -48,16 +48,17 @@ namespace Samples
|
||||||
|
|
||||||
private static void AboutActivated(object sender, EventArgs e)
|
private static void AboutActivated(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var dialog = new AboutDialog();
|
var dialog = new AboutDialog
|
||||||
dialog.TransientFor = Win;
|
{
|
||||||
dialog.ProgramName = "GtkSharp Sample Application";
|
TransientFor = Win,
|
||||||
dialog.Version = "1.0.0.0";
|
ProgramName = "GtkSharp Sample Application",
|
||||||
dialog.Comments = "A sample application for the GtkSharp project.";
|
Version = "1.0.0.0",
|
||||||
dialog.LogoIconName = "system-run-symbolic";
|
Comments = "A sample application for the GtkSharp project.",
|
||||||
dialog.License = "This sample application is licensed under public domain.";
|
LogoIconName = "system-run-symbolic",
|
||||||
dialog.Website = "https://www.github.com/GtkSharp/GtkSharp";
|
License = "This sample application is licensed under public domain.",
|
||||||
dialog.WebsiteLabel = "GtkSharp Website";
|
Website = "https://www.github.com/GtkSharp/GtkSharp",
|
||||||
|
WebsiteLabel = "GtkSharp Website"
|
||||||
|
};
|
||||||
dialog.Run();
|
dialog.Run();
|
||||||
dialog.Hide();
|
dialog.Hide();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
14
Source/Samples/Sections/Dialogs/AboutDialogSection.cs
Normal file
14
Source/Samples/Sections/Dialogs/AboutDialogSection.cs
Normal 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)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
46
Source/Samples/Sections/ListSection.cs
Normal file
46
Source/Samples/Sections/ListSection.cs
Normal 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++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
68
Source/Samples/Sections/Widgets/ButtonSection.cs
Normal file
68
Source/Samples/Sections/Widgets/ButtonSection.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue