GithubHelp home page GithubHelp logo

truthiswill / skiasharp.components Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dotnet-ad/skiasharp.components

0.0 1.0 0.0 29.05 MB

Rendered components for an easier declaration of SkiaSharp rendering.

License: MIT License

C# 100.00%

skiasharp.components's Introduction

SkiaSharp.Components

NuGet Donate

Producing rendering code for SkiaSharp can be extremely verbose and repetitive. SkiaSharp.Components are higher level views that make declarations more concise.

Quickstart

var result = new Grid();

this.Title = new Label
{
    TextSize = 30,
    Text = "Title of the view",
    VerticalAlignment = Alignment.Center,
};

this.Description = new Label
{
    TextSize = 16,
    Spans = new[]
    {
        new Span
        {
            Text = "Nam ut imperdiet nibh. Ut sollicitudin varius nibh,"
        },
        new Span
        {
            ForegroundBrush = new ColorBrush(new SKColor(0xFFF44336)),
            Decorations = TextDecoration.Bold,
            Text = "id ornare tortor convallis sed"
        },
        new Span
        {
            Text = ". Morbi volutpat, lacus efficitur volutpat lacinia, nibh velit ultricies neque, vel faucibus tellus neque at nibh. Nullam vitae tincidunt metus. Vestibulum nec nisl quis lorem tincidunt maximus eu vel lectus. Proin posuere augue molestie imperdiet scelerisque. Phasellus quis suscipit neque."
        },
    },
};

var gradient = new GradientBrush(new SKPoint(0, 0), new SKPoint(0, 1), new[]
{
    new Tuple<float, SKColor>(0, new SKColor(255,255,255,255)),
    new Tuple<float, SKColor>(1, new SKColor(238,238,238,255)),
});

var shadow = new Shadow()
{
    Blur = new SKPoint(10, 10),
    Color = SKColors.Black.WithAlpha(80),
};

this.Image = new Image()
{
    Source = "https://source.unsplash.com/random",
    Fill = new ColorBrush(SKColors.LightGray),
    CornerRadius = 5.0f,
    Shadow = shadow,
};

this.Box = new Box()
{
    Fill = gradient,
    CornerRadius = 5.0f,
    Shadow = shadow,
};

var iconGradient = new GradientBrush(new SKPoint(0, 0), new SKPoint(1, 1), new[]
{
    new Tuple<float, SKColor>(0, new SKColor(0xFFF44336)),
    new Tuple<float, SKColor>(1, new SKColor(0xFF3F51B5)),
});

this.Icon = new Path
{
    Source = IconPath.Aperture,
    ViewBox = SKRect.Create(0, 0, 24, 24),
    Stroke = new Stroke()
    {
        Size = 5,
        Brush = iconGradient,
    },
};

// Setting grid column and rows
result.ColumnDefinitions = new[]
{
    Grid.Definition.Points(100),
    Grid.Definition.Stars(1),
};

result.RowDefinitions = new[]
{
    Grid.Definition.Points(100),
    Grid.Definition.Points(200),
    Grid.Definition.Stars(1),
};

// Setting child positions
result.AddView(this.Icon, 0, 0);
result.AddView(this.Title, 1, 0);
result.AddView(this.Box, 0, 1, 2);
result.AddView(this.Description, 0, 1, 2);

result.Layout(SKRect.Create(0,0,500,500));
result.Render(canvas);

Advanced usage

Invalidation

Each time a property of a view changes, the Invalidated event of a view is raised. This is useful to know when to re-render a view.

Interactions

Basic interactions are available through the Tap control which raises events when the user touches its frame. It is a view like any other components.

this.Button = new Tap()
{
    BackgroundBrush = new ColorBrush(SKColors.DeepPink),
    CornerRadius = 5,
};

this.Button.Tapped += (s,e) => Debug.WriteLine("Tapped");
this.Button.Pressed += (s, e) => ((Tap)s).BackgroundBrush = new ColorBrush(SKColors.LightPink);
this.Button.Released += (s, e) => ((Tap)s).BackgroundBrush = new ColorBrush(SKColors.DeepPink);

If you use provided Renderer, touches will be wired up automatically.

Contributions

Contributions are welcome! If you find a bug please report it and if you want a feature please report it.

If you want to contribute code please file an issue and create a branch off of the current dev branch and file a pull request.

License

MIT © Aloïs Deniel

skiasharp.components's People

Contributors

nedlanon avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.