engine icon indicating copy to clipboard operation
engine copied to clipboard

Examples - code block highlights

Open Maksims opened this issue 1 year ago • 2 comments

It would be great to label a block of code (line ranges), so that it would highlight it and show nice UI. As many examples have repeating code, and relevant blocks of code are lost in long files.

Maksims avatar Jun 11 '24 18:06 Maksims

Monaco supports for instance // #region App Creation with a closing // #endregion:

async function example({ canvas, deviceType, glslangPath, twgslPath }) {

    // #region App Creation
    const gfxOptions = {
        deviceTypes: [deviceType],
        glslangUrl: glslangPath + 'glslang.js',
        twgslUrl: twgslPath + 'twgsl.js'
    };
    
    
    const device = await pc.createGraphicsDevice(canvas, gfxOptions);
    const createOptions = new pc.AppOptions();
    createOptions.graphicsDevice = device;

    createOptions.componentSystems = [
        pc.RenderComponentSystem,
        pc.CameraComponentSystem,
        pc.LightComponentSystem
    ];
    createOptions.resourceHandlers = [
        // @ts-ignore
        pc.TextureHandler,
        // @ts-ignore
        pc.ContainerHandler
    ];

    const app = new pc.AppBase(canvas);
    app.init(createOptions);
    app.start();

    // Set the canvas to fill the window and automatically change resolution to be the same as the canvas size
    app.setCanvasFillMode(pc.FILLMODE_FILL_WINDOW);
    app.setCanvasResolution(pc.RESOLUTION_AUTO);

    // Ensure canvas is resized when window changes size
    const resize = () => app.resizeCanvas();
    window.addEventListener('resize', resize);
    app.on('destroy', () => {
        window.removeEventListener('resize', resize);
    });
    // #endregion

    // create box entity
    const box = new pc.Entity('cube');
    box.addComponent('render', {
        type: 'box'
    });
    app.root.addChild(box);

    // create camera entity
    const camera = new pc.Entity('camera');
    camera.addComponent('camera', {
        clearColor: new pc.Color(0.5, 0.6, 0.9)
    });
    app.root.addChild(camera);
    camera.setPosition(0, 0, 3);

    // create directional light entity
    const light = new pc.Entity('light');
    light.addComponent('light');
    app.root.addChild(light);
    light.setEulerAngles(45, 0, 0);

    // rotate the box according to the delta time since the last frame
    app.on('update', (/** @type {number} */ dt) => box.rotate(10 * dt, 20 * dt, 30 * dt));
    return app;
}

Then it would look like:

image

But not sure what you mean with highlight + nice UI, something else than these region code folding blocks?

kungfooman avatar Jun 12 '24 14:06 kungfooman

If it would be possible to change background (lines background) color of those blocks, to make the whole block pop out?

Maksims avatar Jun 12 '24 14:06 Maksims