RingDotNetfor Ring

Avalonia

A cross platform GUI library from Ring — windows, controls, layout, drawing, themes and input on Windows, Linux and macOS.

Avalonia is a GUI library for .NET that draws its own controls, so the same program looks the same on every system. RingDotNet uses it as a package: the first run restores the Avalonia packages from nuget.org and makes the Ring classes of them, then a program creates windows and controls with objects and the dot operator, like the Windows Forms and WPF programs do.

A first Avalonia window#

Ring
load "avalonia.ring"
avUse()

oWindow = avWindow("Hello Avalonia",360,160)
oText = avText("Hello from Avalonia and Ring")
oText.FontSize = 22
oText.HorizontalAlignment = "Center"
oText.VerticalAlignment = "Center"
oWindow.Content = oText

avRun(oWindow)

avalonia.ring is the helper file of the samples (samples/UsingDotNet/tests/packages/AvaloniaSamples). avUse() restores and loads Avalonia, starts the platform of the system with the Fluent theme and imports the namespaces. avRun shows the window and runs the loop of the application until the window is closed.

The helpers#

HelperDoes
avUse()restores and loads Avalonia, starts the platform, imports the namespaces
avWindow(title, w, h)a window, centered on the screen
avText(text), avButton(text, code)a TextBlock, a Button that runs Ring code when it is clicked
avStack(spacing, margin), avRow(spacing)a vertical and a horizontal StackPanel
avBrush("#336699"), avThickness(8), avMargin(l, t, r, b)a brush, a thickness for a margin or a padding
avRun(window)shows the window and runs the loop of the application
avClick(control), avPump()the checks of a program: click a button, run the events that wait in the queue

Events#

An event is connected with a method that starts with set and ends with Event, and the code is Ring code:

Ring
oButton = new Button()
oButton.Content = "Click me"
oButton.setClickEvent("clicked()")

oBox = new TextBox()
oBox.setTextChangedEvent("typed()")

oWindow.setKeyDownEvent("keyDown(aDotNetArgs[2].Key)")

aDotNetArgs has the sender and the arguments of the event: aDotNetArgs[2].Key is the key of a KeyDown event and aDotNetArgs[2].GetPosition(oCanvas) is the position of a pointer event on a control.

Layout and drawing#

The layout is made of panels: StackPanel, Grid (columns and rows such as "100,*,2*"), DockPanel, WrapPanel, UniformGrid and Canvas. Measure and Arrange let a program ask where a control goes. Shapes (Rectangle, Ellipse, Line, Polygon and a Path made from path text), gradients, transforms, a DrawingImage made of drawings and PathIcon icons draw without any image file.

Bindings connect two controls without code that runs when a value changes:

Ring
oBinding = (new Binding).@New("Value")
oBinding.Source = oSlider
oText.Bind([ :property = oText.TextProperty, :binding = oBinding ])

A method that has several forms takes a list of named arguments, and the list is empty for the form without arguments: oWindow.Show([]), oBox.Focus([]).

Samples#

The samples and the applications run themselves as a test: ring 02_button_click.ring --selftest checks the program and closes its window. See Avalonia samples for 52 short programs and Avalonia applications for 51 applications: calculators and converters, games, a notepad, an address book, a paint program and more.

On Linux the programs need a display and the system libraries libICE and libSM (Debian and Ubuntu: sudo apt install libice6 libsm6).

RingDotNet — use .NET classes and methods from Ring programs. Screenshots and output on these pages come from the real samples.