no more submodule

This commit is contained in:
2024-09-15 22:40:48 +02:00
parent df3b8a3135
commit 0234b33671
5804 changed files with 943618 additions and 1 deletions

View File

@@ -0,0 +1,147 @@
using System;
using Gtk;
namespace Samples
{
[Section(ContentType = typeof(ContainerChildProperties), Category = Category.Miscellaneous)]
class ContainerChildPropertiesSection : Box
{
public ContainerChildPropertiesSection() : base(Orientation.Vertical, 3)
{
ContainerChildProperties.CreateBoxProperties(this);
ContainerChildProperties.CreateGridProperties(this);
ContainerChildProperties.CreateStackProperties(this);
}
}
static class ContainerChildProperties
{
public static void CreateBoxProperties(Box parent)
{
var title = new Label { Text = "Box child properties" };
parent.PackStart(title, false, true, 0);
var box1 = new Box(Orientation.Horizontal, 3);
var btn1 = new Button() { Label = "Expand" };
btn1.Clicked += delegate
{
var child = (Box.BoxChild)box1[btn1];
child.Expand = !child.Expand;
ApplicationOutput.WriteLine(child, "Expand changed to " + child.Expand);
};
box1.PackStart(btn1, true, true, 0);
parent.PackStart(box1, false, true, 0);
var box2 = new Box(Orientation.Horizontal, 3);
var btn2 = new Button() { Label = "PackType" };
btn2.Clicked += delegate
{
var child = (Box.BoxChild)box2[btn2];
child.PackType = child.PackType == PackType.Start ? PackType.End : PackType.Start;
ApplicationOutput.WriteLine(child, "PackType changed to " + child.PackType);
};
box2.PackStart(btn2, false, false, 0);
parent.PackStart(box2, false, true, 0);
var box3 = new Box(Orientation.Horizontal, 3);
var btn3 = new Button() { Label = "Position" };
btn3.Clicked += delegate
{
var child = (Box.BoxChild)box3[btn3];
child.Position = child.Position == 0 ? 1 : 0;
ApplicationOutput.WriteLine(child, "Position changed to " + child.Position);
};
box3.PackStart(btn3, false, false, 0);
box3.PackStart(new Label { Text = "Neighbor" }, false, false, 0);
parent.PackStart(box3, false, true, 0);
}
public static void CreateGridProperties(Box parent)
{
var title = new Label { Text = "Grid child properties" };
parent.PackStart(title, false, true, 0);
var grid = new Grid { ColumnSpacing = 3, RowSpacing = 3 };
var btn1 = new Button { Label = "LeftAttach" };
var lbl = new Label { Text = "Neighbor" };
btn1.Clicked += delegate
{
var child1 = (Grid.GridChild)grid[btn1];
var child2 = (Grid.GridChild)grid[lbl];
if (child1.LeftAttach == 0)
{
child1.LeftAttach = 1;
child2.LeftAttach = 0;
}
else
{
child1.LeftAttach = 0;
child2.LeftAttach = 1;
}
ApplicationOutput.WriteLine(child1, "Child 1 LeftAttach changed to " + child1.LeftAttach);
ApplicationOutput.WriteLine(child1, "Child 2 LeftAttach changed to " + child2.LeftAttach);
};
var btn2 = new Button { Label = "Width (column span)", Hexpand = true };
btn2.Clicked += delegate
{
var child = (Grid.GridChild)grid[btn2];
child.Width = child.Width == 1 ? 2 : 1;
ApplicationOutput.WriteLine(child, "Width changed to " + child.Width);
};
grid.Attach(btn1, 0, 0, 1, 1);
grid.Attach(lbl, 1, 0, 1, 1);
grid.Attach(btn2, 0, 1, 1, 1);
parent.PackStart(grid, false, true, 0);
}
public static void CreateStackProperties(Box parent)
{
var title = new Label { Text = "Stack child properties" };
parent.PackStart(title, false, true, 0);
var stack = new Stack();
var box = new Box(Orientation.Horizontal, 3);
var btn1 = new Button { Label = "Title" };
btn1.Clicked += delegate
{
var child = (Stack.StackChild)stack[box];
child.Title = child.Title == "Page 1" ? "Page 1 abc" : "Page 1";
ApplicationOutput.WriteLine(child, "Title changed to " + child.Title);
};
box.PackStart(btn1, false, false, 0);
var btn2 = new Button { Label = "Position" };
var lbl = new Label { Text = "Page 2 label", Halign = Align.Start };
btn2.Clicked += delegate
{
var child1 = (Stack.StackChild)stack[box];
var child2 = (Stack.StackChild)stack[lbl];
if (child1.Position == 0)
{
child1.Position = 1;
child2.Position = 0;
}
else
{
child1.Position = 0;
child2.Position = 1;
}
ApplicationOutput.WriteLine(child1, "Child 1 Position changed to " + child1.Position);
ApplicationOutput.WriteLine(child1, "Child 2 Position changed to " + child2.Position);
};
box.PackStart(btn2, false, false, 0);
stack.AddTitled(box, "1", "Page 1");
stack.AddTitled(lbl, "2", "Page 2");
var switcher = new StackSwitcher();
switcher.Stack = stack;
parent.PackStart(switcher, false, true, 0);
parent.PackStart(stack, false, true, 0);
}
}
}

View File

@@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using Gtk;
namespace Samples
{
[Section(ContentType = typeof(CssNameDemo), Category = Category.Miscellaneous)]
class CssNameSection : Box
{
public CssNameSection() : base(Orientation.Vertical, 3)
{
CssNameDemo.Create(this);
}
}
class CssNameDemo
{
// inherited label has same css name as parent
internal class MyLabel : Label
{
}
// css name can be set by [CssName]
[CssName("my-label-attrib")]
internal class MyLabelWithAttrib : Label
{
}
// css name can be set in class initializer method
[GLib.TypeInitializer(typeof(MyLabelWithInit), nameof(MyLabelWithInit.ClassInit))]
internal class MyLabelWithInit : Label
{
static void ClassInit(GLib.GType gtype, Type type)
{
SetCssName(gtype, "my-label-init");
}
}
public static void Create(Box box)
{
var css = new CssProvider();
css.LoadFromData(@"
label.x {
background: LightCoral;
}
my-label-attrib {
background: LightGreen;
}
my-label-init {
background: LightSkyBlue;
}
my-label-init.x {
background: LightBlue;
}
");
StyleContext.AddProviderForScreen(Gdk.Screen.Default, css, StyleProviderPriority.Application);
string name;
name = Widget.GetCssName(Label.GType);
var label1 = new Label { Text = "Label, css name: " + name };
label1.StyleContext.AddClass("x");
name = Widget.GetCssName((GLib.GType)typeof(MyLabel));
var label2 = new MyLabel { Text = "Inherited Label, css name: " + name };
label2.StyleContext.AddClass("x");
name = Widget.GetCssName((GLib.GType)typeof(MyLabelWithAttrib));
var label3 = new MyLabelWithAttrib { Text = "Inherited Label with [CssName], css name: " + name };
name = Widget.GetCssName((GLib.GType)typeof(MyLabelWithInit));
var label4 = new MyLabelWithInit { Text = "Inherited Label with class initializer, css name: " + name };
name = Widget.GetCssName((GLib.GType)typeof(MyLabelWithInit));
var label5 = new MyLabelWithInit { Text = "Inherited Label with class initializer and css class, css name: " + name };
label5.StyleContext.AddClass("x");
box.PackStart(label1, false, false, 0);
box.PackStart(label2, false, false, 0);
box.PackStart(label3, false, false, 0);
box.PackStart(label4, false, false, 0);
box.PackStart(label5, false, false, 0);
}
}
}

View File

@@ -0,0 +1,43 @@
using System;
using Gtk;
namespace Samples
{
[Section(ContentType = typeof(MonitorDemo), Category = Category.Miscellaneous)]
class MonitorSection : ListSection
{
public MonitorSection()
{
AddItem("Press button to get monitors information:", new MonitorDemo("Press me"));
}
}
class MonitorDemo : Button
{
public MonitorDemo(string text) : base(text)
{
}
protected override void OnPressed()
{
base.OnPressed();
Gdk.Display display = Gdk.Display.Default;
int monitorsCount = display.NMonitors;
ApplicationOutput.WriteLine($"Monitors count: {monitorsCount}");
for (int i = 0; i < monitorsCount; i++)
{
Gdk.Monitor monitor = display.GetMonitor(i);
ApplicationOutput.WriteLine($"Monitor {i}:");
ApplicationOutput.WriteLine($"\tIsPrimary: {monitor.IsPrimary}");
ApplicationOutput.WriteLine($"\tManufacturer: {monitor.Manufacturer}");
ApplicationOutput.WriteLine($"\tModel: {monitor.Model}");
ApplicationOutput.WriteLine($"\tRefreshRate: {monitor.RefreshRate}");
ApplicationOutput.WriteLine($"\tScaleFactor: {monitor.ScaleFactor}");
ApplicationOutput.WriteLine($"\tWidthMm x HeightMm: {monitor.WidthMm} x {monitor.HeightMm}");
ApplicationOutput.WriteLine($"\tGeometry: {monitor.Geometry}");
ApplicationOutput.WriteLine($"\tWorkarea: {monitor.Workarea}");
}
}
}
}

View File

@@ -0,0 +1,95 @@
using System;
using System.IO;
using System.Threading;
using Gdk;
using Gtk;
namespace Samples
{
[Section (ContentType = typeof(PixbufDemo), Category = Category.Miscellaneous)]
class PixbufSection : ListSection
{
public PixbufSection ()
{
AddItem ($"Press button to run / stop {nameof(PixbufDemo)} :", new PixbufDemo ("Press me"));
}
}
class PixbufDemo : Button
{
public PixbufDemo (string text) : base (text) { }
private bool running = false;
public void DispatchPendingEvents ()
{
// The loop is limited to 1000 iterations as a workaround for an issue that some users
// have experienced. Sometimes EventsPending starts return 'true' for all iterations,
// causing the loop to never end.
int n = 1000;
Gdk.Threads.Enter ();
while (Gtk.Application.EventsPending () && --n > 0) {
Gtk.Application.RunIteration (false);
}
Gdk.Threads.Leave ();
}
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}");
}
}
}

View File

@@ -0,0 +1,64 @@
using System;
using Gtk;
namespace Samples
{
[Section(ContentType = typeof(PolarFixed), Category = Category.Miscellaneous)]
class PolarFixedSection : ListSection
{
public PolarFixedSection()
{
AddItem(CreateClock());
AddItem(CreateSpiral());
}
public (string, Widget) CreateClock()
{
double theta;
// Clock
PolarFixed pf = new PolarFixed();
for (int hour = 1; hour <= 12; hour++)
{
theta = (Math.PI / 2) - hour * (Math.PI / 6);
if (theta < 0)
theta += 2 * Math.PI;
Label l = new Label("<big><b>" + hour.ToString() + "</b></big>");
l.UseMarkup = true;
pf.Put(l, theta, 50);
}
return ("Clock", pf);
}
public (string, Widget) CreateSpiral()
{
uint r;
double theta;
var pf = new PolarFixed();
r = 0;
theta = 0.0;
foreach (string id in Gtk.Stock.ListIds())
{
StockItem item = Gtk.Stock.Lookup(id);
if (item.Label == null)
continue;
var icon = Gtk.Image.NewFromIconName(item.StockId, IconSize.SmallToolbar);
pf.Put(icon, theta, r);
// Logarithmic spiral: r = a*e^(b*theta)
r += 1;
theta = 10 * Math.Log(10 * r);
}
return ("Spiral", pf);
}
}
}

View File

@@ -0,0 +1,32 @@
using System;
using Gtk;
namespace Samples
{
[Section(ContentType=typeof(SeatDemo), Category = Category.Miscellaneous)]
class SeatSection : ListSection
{
public SeatSection()
{
AddItem("Press button to output mouse location:", new SeatDemo("Press me"));
}
}
class SeatDemo : Button
{
public SeatDemo(string text) : base(text)
{
}
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})");
}
}
}

View File

@@ -0,0 +1,30 @@
using System;
using Gtk;
namespace Samples
{
[Section(ContentType = typeof(StyleContext), Category = Category.Miscellaneous)]
class StyleContextSection : ListSection
{
public StyleContextSection()
{
var btn = new Button() { Label = "Press me" };
btn.Clicked += OnBtnClicked;
AddItem("Press button to output style context properties:", btn);
}
private void OnBtnClicked(object sender, EventArgs e)
{
var styleCtx = ((Button)sender).StyleContext;
var props = new[] { "padding-left", "padding-right", "padding-top", "padding-bottom", "min-width", "min-height", "color", "background-color", "font-size", "font-style" };
foreach (var prop in props)
{
GLib.Value val = styleCtx.GetProperty(prop, styleCtx.State);
string msg = string.Format("Property {0}, type {1}, value {2}", prop, val.Val.GetType().Name, val.Val.ToString());
ApplicationOutput.WriteLine(msg);
}
}
}
}

View File

@@ -0,0 +1,84 @@
using System;
using System.Collections.Generic;
using Gtk;
namespace Samples
{
[Section(ContentType = typeof(TimerDemo), Category = Category.Miscellaneous)]
class TimerSection : Box
{
public TimerSection() : base(Orientation.Horizontal, 3)
{
Valign = Align.Start;
TimerDemo.Create(this);
}
}
static class TimerDemo
{
public static void Create(Box box)
{
List<uint> timers = new List<uint>();
bool removeByHandler = false;
var btnAddTimer = new Button() { Label = "Add timer" };
btnAddTimer.Clicked += delegate
{
uint id = 0;
id = GLib.Timeout.Add(500, () =>
{
ApplicationOutput.WriteLine("Timer tick " + id);
if (removeByHandler)
{
removeByHandler = false;
timers.Remove(id);
ApplicationOutput.WriteLine("Remove timer from handler " + id);
return false;
}
return true;
});
timers.Add(id);
ApplicationOutput.WriteLine("Add timer " + id);
};
var btnRemoveTimer = new Button() { Label = "Remove timer" };
btnRemoveTimer.Clicked += delegate
{
if (timers.Count == 0)
return;
uint id = timers[0];
timers.RemoveAt(0);
GLib.Timeout.Remove(id);
ApplicationOutput.WriteLine("Remove timer " + id);
};
var btnRemoveTimerByHandler = new Button() { Label = "Remove timer by handler" };
btnRemoveTimerByHandler.Clicked += delegate
{
if (timers.Count == 0)
return;
removeByHandler = true;
ApplicationOutput.WriteLine("Remove timer by handler");
};
var btnGc = new Button() { Label = "GC" };
btnGc.Clicked += delegate
{
ApplicationOutput.WriteLine("GC");
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
};
box.PackStart(btnAddTimer, false, false, 0);
box.PackStart(btnRemoveTimer, false, false, 0);
box.PackStart(btnRemoveTimerByHandler, false, false, 0);
box.PackStart(btnGc, false, false, 0);
}
}
}