Giter Club home page Giter Club logo

pesto's Introduction

Pesto GUI

WORK IN PROGRESS.

Pesto is a high-performance GUI framework in C++ highly inspired by CSS and HTML, using Skia as rendering engine.

It's based on

  • Clang (so ready for WebAssembly)
  • C++17
  • Cmake
  • SDL2

Example

Example screenshot

#import "pesto/Base.h"
#import "pesto/Window.h"
#import "pesto/Application.h"
#import "pesto/Element.h"

#include <iostream>
#include <string>

int main(int argc, char **argv) {
    for (auto arg = argv; *arg; arg++) {
        printf("%s\n", *arg);
    }

    auto *application = new Pesto::Application;
    Pesto::utils::setupErrorListener();

    // language=HTML
    std::string xml = u8R"(
<style>
.left {
    position: absolute;
    top: 5px;
    left: 5px;
    width: 245px;
    bottom: 5px;
    padding: 5px;
    background-color: #eee;
}

sidebar-splitter {
    position: absolute;
    right: 0px;
    top: 0;
    width: 3px;
    bottom: 0;
    background-color: black;
}

content {
    position: absolute;
    left: 250px;
    padding: 5px;
    top: 5px;
    right: 55px;
    bottom: 5px;
    background-color: #bbb;
}

.right {
    position: absolute;
    width: 50px;
    background: red;
    top: 5px;
    right: 5px;
    bottom: 5px;
}

#footer {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0px;
    height: 50px;
    background: gray;
    color: white;
}
</style>
<div class="left">
    Hello Sidebar
    <sidebar-splitter>
    </sidebar-splitter>
</div>
<content>
    <div id="content" cacheRender="true">
        Hello Content
    </div>

    <button>Button 1</button>
    <button>Button 2</button>
    <div>
        Hello!
    </div>

    <div id="footer">
        Hello Footer
    </div>
</content>
<div class="right">
</div>
)";

    auto *window = application->createWindow(xml);
    window->setSize(600, 400);

    std::cout << window->document->toString();

    printf("Started\n");

    auto content = window->document->queryOne("#content");
    unsigned int counter = 0;

    application->addAnimationFrameCallback([&](float diff) {
        content->setText(std::string("Hi #").append(std::to_string(counter++)));
    });

    application->loop();

    printf("Done\n");
    return 0;
}

Supported CSS

    - position: absolute | relative | static
    - left, top, right, bottom in px and %
    - width, height in px and %
    - overflow: auto | scroll | hidden | visible
    - text-align: left | center | right
    - vertical-align: left | middle | right
    - display: block | inline
    - border, border-left, border-right, border-top
    - border-radius, border-top-left-radius, etc
    - padding, padding-left, padding-right, padding-top, padding-right
    - margin, margin-left, margin-right, margin-top, margin-right
    - max-width, max-height
    - min-width, min-height
    - font-family
    - line-height
    - font-size
    - font-weight
    - color: hex, rgba, etc
    - white-space: pre | pre-wrap | pre-line | nowrap
    - background-color

Install dependencies

Build Skia

git submodule init
export PATH="${PWD}/libs/depot_tools:${PATH}"

cd libs/skia
python tools/git-sync-deps
bin/gn gen out/Clang --args='is_official_build=true cc="clang" cxx="clang++" skia_use_dng_sdk=false skia_use_sfntly=false skia_use_libwebp=false'

# bin/gn gen out/ClangO2 --args='is_official_build=true is_debug=false extra_cflags=["-O2"] cc="/usr/local/Cellar/llvm@5/5.0.1/bin/clang" cxx="/usr/local/Cellar/llvm@5/5.0.1/bin/clang++" skia_use_dng_sdk=false skia_use_sfntly=false skia_use_libwebp=false'

ninja -C out/ClangO

OSX

Make sure to install on OSX libjpeg-turbo, webp, icu4c, sdl2 via brew.

brew install libjpeg-turbo webp icu4c

On OSX it's important to make libjpeg-turbo headers available to standard include path (which overwrite default libjpeg), so use brew link --force --overwrite libjpeg-turbo.

Same with icu4c, so call brew link icu4c --force.

Use it

Use Cmake to build examples or pesto as library and include it in your project. CLion works perfectly fine ;)

cmake --build ./src/pesto/cmake-build-debug --target pesto_demo_example_absolute -- -j 6

./src/pesto/cmake-build-debug/demo/pesto_demo_example_absolute

WebAssembly

TBD

  1. Apply patch

pesto's People

Contributors

marcj 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.