mirror of
https://github.com/Ryujinx/GtkSharp.git
synced 2024-12-22 15:35:37 +00:00
Setup Samples base
This commit is contained in:
parent
1e626abda2
commit
31e120a9de
57
.vscode/launch.json
vendored
Normal file
57
.vscode/launch.json
vendored
Normal file
|
@ -0,0 +1,57 @@
|
|||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": ".NET Core Launch (console)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
"program": "BuildOutput/Samples/Samples.dll",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"console": "internalConsole",
|
||||
"stopAtEntry": false,
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Launch (web)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceFolder}/bin/Debug/<insert-target-framework-here>/<insert-project-name-here>.dll",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"stopAtEntry": false,
|
||||
"internalConsoleOptions": "openOnSessionStart",
|
||||
"launchBrowser": {
|
||||
"enabled": true,
|
||||
"args": "${auto-detect-url}",
|
||||
"windows": {
|
||||
"command": "cmd.exe",
|
||||
"args": "/C start ${auto-detect-url}"
|
||||
},
|
||||
"osx": {
|
||||
"command": "open"
|
||||
},
|
||||
"linux": {
|
||||
"command": "xdg-open"
|
||||
}
|
||||
},
|
||||
"env": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"sourceFileMap": {
|
||||
"/Views": "${workspaceFolder}/Views"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Attach",
|
||||
"type": "coreclr",
|
||||
"request": "attach",
|
||||
"processId": "${command:pickProcess}"
|
||||
}
|
||||
]
|
||||
}
|
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"files.exclude": {
|
||||
"**/obj/": true
|
||||
}
|
||||
}
|
17
.vscode/tasks.json
vendored
Normal file
17
.vscode/tasks.json
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||
// for the documentation about the tasks.json format
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "build",
|
||||
"command": "dotnet build Source/Samples/Samples.csproj",
|
||||
"type": "shell",
|
||||
"group": "build",
|
||||
"presentation": {
|
||||
"reveal": "silent"
|
||||
},
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
]
|
||||
}
|
9
Source/Samples/Category.cs
Normal file
9
Source/Samples/Category.cs
Normal file
|
@ -0,0 +1,9 @@
|
|||
|
||||
namespace Samples
|
||||
{
|
||||
enum Category
|
||||
{
|
||||
Widgets,
|
||||
Dialogs
|
||||
}
|
||||
}
|
|
@ -1,37 +1,116 @@
|
|||
using System;
|
||||
using Gtk;
|
||||
using UI = Gtk.Builder.ObjectAttribute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Samples
|
||||
{
|
||||
class MainWindow : Window
|
||||
{
|
||||
#pragma warning disable 0649
|
||||
[UI] private Label _label1;
|
||||
[UI] private Button _button1;
|
||||
#pragma warning restore 0649
|
||||
private HeaderBar _headerBar;
|
||||
private HPaned _panned;
|
||||
private TreeView _treeView;
|
||||
private Box _boxContent;
|
||||
private TreeStore _store;
|
||||
private Dictionary<string, (Type type, Widget widget)> _items;
|
||||
|
||||
private int _counter;
|
||||
|
||||
public MainWindow() : this(new Builder("MainWindow.glade")) { }
|
||||
|
||||
private MainWindow(Builder builder) : base(builder.GetObject("MainWindow").Handle)
|
||||
public MainWindow() : base(WindowType.Toplevel)
|
||||
{
|
||||
builder.Autoconnect(this);
|
||||
// Setup GUI
|
||||
WindowPosition = WindowPosition.Center;
|
||||
DefaultSize = new Gdk.Size(800, 600);
|
||||
|
||||
DeleteEvent += Window_DeleteEvent;
|
||||
_button1.Clicked += Button1_Clicked;
|
||||
_headerBar = new HeaderBar();
|
||||
_headerBar.ShowCloseButton = true;
|
||||
_headerBar.Title = "GtkSharp Sample Application";
|
||||
|
||||
var btnClickMe = new Button();
|
||||
btnClickMe.AlwaysShowImage = true;
|
||||
btnClickMe.Image = Image.NewFromIconName("document-new-symbolic", IconSize.Button);
|
||||
_headerBar.PackStart(btnClickMe);
|
||||
|
||||
Titlebar = _headerBar;
|
||||
|
||||
_panned = new HPaned();
|
||||
_panned.Position = 200;
|
||||
|
||||
_treeView = new TreeView();
|
||||
_treeView.HeadersVisible = false;
|
||||
_panned.Pack1(_treeView, false, true);
|
||||
|
||||
_boxContent = new Box(Orientation.Vertical, 0);
|
||||
_panned.Pack2(_boxContent, true, true);
|
||||
|
||||
Child = _panned;
|
||||
|
||||
// Fill up data
|
||||
FillUpTreeView();
|
||||
|
||||
// Connect events
|
||||
_treeView.Selection.Changed += Selection_Changed;
|
||||
Destroyed += (sender, e) => Application.Quit();
|
||||
}
|
||||
|
||||
private void Window_DeleteEvent(object sender, DeleteEventArgs a)
|
||||
private void Selection_Changed(object sender, EventArgs e)
|
||||
{
|
||||
Application.Quit();
|
||||
if (_treeView.Selection.GetSelected(out TreeIter iter))
|
||||
{
|
||||
var s = _store.GetValue(iter, 0).ToString();
|
||||
|
||||
while (_boxContent.Children.Length > 0)
|
||||
_boxContent.Remove(_boxContent.Children[0]);
|
||||
|
||||
if (_items.TryGetValue(s, out var item))
|
||||
{
|
||||
if (item.widget == null)
|
||||
_items[s] = item = (item.type, Activator.CreateInstance(item.type) as Widget);
|
||||
|
||||
_boxContent.PackStart(item.widget, true, true, 0);
|
||||
_boxContent.ShowAll();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void Button1_Clicked(object sender, EventArgs a)
|
||||
private void FillUpTreeView()
|
||||
{
|
||||
_counter++;
|
||||
_label1.Text = "Hello World! This button has been clicked " + _counter + " time(s).";
|
||||
// Init cells
|
||||
var cellName = new CellRendererText();
|
||||
|
||||
// Init columns
|
||||
var columeSections = new TreeViewColumn();
|
||||
columeSections.Title = "Sections";
|
||||
columeSections.PackStart(cellName, true);
|
||||
|
||||
columeSections.AddAttribute(cellName, "text", 0);
|
||||
|
||||
_treeView.AppendColumn(columeSections);
|
||||
|
||||
// Init treeview
|
||||
_store = new TreeStore(typeof(string));
|
||||
_treeView.Model = _store;
|
||||
|
||||
// Setup category base
|
||||
var dict = new Dictionary<Category, TreeIter>();
|
||||
foreach (var category in Enum.GetValues(typeof(Category)))
|
||||
dict[(Category)category] = _store.AppendValues(category.ToString());
|
||||
|
||||
// Fill up categories
|
||||
_items = new Dictionary<string, (Type type, Widget widget)>();
|
||||
var maintype = typeof(SectionAttribute);
|
||||
|
||||
foreach (var type in maintype.Assembly.GetTypes())
|
||||
{
|
||||
foreach (var attribute in type.GetCustomAttributes(true))
|
||||
{
|
||||
if (attribute is SectionAttribute a)
|
||||
{
|
||||
_store.AppendValues(dict[a.Category], a.Name);
|
||||
_items[a.Name] = (type, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_treeView.ExpandAll();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.18"/>
|
||||
<object class="GtkWindow" id="MainWindow">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="title" translatable="yes">Example Window</property>
|
||||
<property name="default_width">480</property>
|
||||
<property name="default_height">240</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_left">4</property>
|
||||
<property name="margin_right">4</property>
|
||||
<property name="margin_top">4</property>
|
||||
<property name="margin_bottom">4</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="_label1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Hello World!</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="_button1">
|
||||
<property name="label" translatable="yes">Click me!</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="receives_default">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
|
@ -5,19 +5,67 @@ namespace Samples
|
|||
{
|
||||
class Program
|
||||
{
|
||||
public static Application App;
|
||||
|
||||
public static Window Win;
|
||||
|
||||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Application.Init();
|
||||
|
||||
var app = new Application("org.Samples.Samples", GLib.ApplicationFlags.None);
|
||||
app.Register(GLib.Cancellable.Current);
|
||||
App = new Application("org.Samples.Samples", GLib.ApplicationFlags.None);
|
||||
App.Register(GLib.Cancellable.Current);
|
||||
|
||||
var win = new MainWindow();
|
||||
app.AddWindow(win);
|
||||
Win = new MainWindow();
|
||||
App.AddWindow(Win);
|
||||
|
||||
win.Show();
|
||||
var menu = new GLib.Menu();
|
||||
menu.AppendItem(new GLib.MenuItem("Help", "app.help"));
|
||||
menu.AppendItem(new GLib.MenuItem("About", "app.about"));
|
||||
menu.AppendItem(new GLib.MenuItem("Quit", "app.quit"));
|
||||
App.AppMenu = menu;
|
||||
|
||||
var helpAction = new GLib.SimpleAction("help", null);
|
||||
helpAction.Activated += HelpActivated;
|
||||
App.AddAction(helpAction);
|
||||
|
||||
var aboutAction = new GLib.SimpleAction("about", null);
|
||||
aboutAction.Activated += AboutActivated;
|
||||
App.AddAction(aboutAction);
|
||||
|
||||
var quitAction = new GLib.SimpleAction("quit", null);
|
||||
quitAction.Activated += QuitActivated;
|
||||
App.AddAction(quitAction);
|
||||
|
||||
Win.ShowAll();
|
||||
Application.Run();
|
||||
}
|
||||
|
||||
private static void HelpActivated(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
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";
|
||||
|
||||
dialog.Run();
|
||||
dialog.Hide();
|
||||
}
|
||||
|
||||
private static void QuitActivated(object sender, EventArgs e)
|
||||
{
|
||||
Application.Quit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
11
Source/Samples/SectionAttribute.cs
Normal file
11
Source/Samples/SectionAttribute.cs
Normal file
|
@ -0,0 +1,11 @@
|
|||
using System;
|
||||
|
||||
namespace Samples
|
||||
{
|
||||
class SectionAttribute : Attribute
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public Category Category { get; set; }
|
||||
}
|
||||
}
|
14
Source/Samples/Sections/Dialogs/AboutDialogCategory.cs
Normal file
14
Source/Samples/Sections/Dialogs/AboutDialogCategory.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
using System;
|
||||
using Gtk;
|
||||
|
||||
namespace Samples
|
||||
{
|
||||
[SectionAttribute(Name = "AboutDialog", Category = Category.Dialogs)]
|
||||
class AboutDialogCategory : Box
|
||||
{
|
||||
public AboutDialogCategory() : base(Orientation.Vertical, 0)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
15
Source/Samples/Sections/Widgets/ButtonCategory.cs
Normal file
15
Source/Samples/Sections/Widgets/ButtonCategory.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue