🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

HTLLeonding.Utility.LeoBoard

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

HTLLeonding.Utility.LeoBoard

A utility library for drawing a grid on a canvas with click handler support to e.g. implement Minesweeper

3.2.2
NuGet
Version published
Maintainers
1
Created
Source

LeoBoard

A utility library for creating simple, grid-based UI application like Minesweeper, Chess, etc.

Allows drawing a grid with specified size, optional row and column numbers, and content for each cell. Left- and right-click events are captured and can be handled to update the cell content.

sample_run.png

Sample usage

using System.Text;
using Avalonia.Media;
using LeoBoard;

Board.Initialize(Run, "Foo", 10, 20,
                 clickHandler: HandleClick,
                 drawGridNumbers: true);

return;

void Run()
{
    Console.OutputEncoding = Encoding.UTF8;
    
    Board.SetCellContent(0, 0, "X");
    Board.SetCellContent(1, 1, "Y", Brushes.Red);
    Board.SetCellContent(2, 2, "Z", Brushes.Blue);
    
    Console.WriteLine(Board.GetCellContent(2, 2));
    
    Board.ShowMessageBox("Hello World!");
    
    Console.ReadKey();
}

void HandleClick(int row, int col, bool leftClick, bool ctrlKeyPressed)
{
    string ctrlState = ctrlKeyPressed ? " while pressing the Ctrl key" : string.Empty;
    Console.WriteLine($"Clicked cell ({row}, {col}) with {(leftClick ? "left" : "right")} mouse button{ctrlState}");
    if (leftClick)
    {
        Board.SetCellContent(row, col, "A", Brushes.Green);
    }
    else
    {
        Board.SetCellContent(row, col, "B", Brushes.Purple);
    }
}
  • It is necessary to pass a method reference (Run in the above sample) to the initialization method, because to also support macOS we have to use the main thread as UI thread and spin up a second thread for the console interaction and actual 'main' logic. This complexity is hidden from the students as good as possible, but this small requirement remains for technical reasons.
  • The Console.ReadKey() call is required to keep the hosting console application alive
  • Allow for a few seconds for the window to appear (some async initialization is happening)

Keywords

skia

FAQs

Package last updated on 26 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts