Skip to content
php-baremetal REGISTRY
Publish a package

php-baremetal/ext-input

bm-ext MIT

Touch input for php-baremetal: the Touch interface, the Pressed/Moved/Released/Gesture events and a C API for touch drivers. Platform-neutral.

IDE stubs @ 1.0.0

The PHP declarations of the functions, classes and constants this package adds, with their docblocks, so PhpStorm and Intelephense can complete and type-check your firmware code.

You don't need to download them: on every composer install and composer update, conductor copies them into vendor/php-baremetal/ide-stubs/, which IDEs index without configuration. They are never loaded at runtime.

php ide/ext-input.stub
<?php
// php-baremetal/ext-input 1.0.0 — IDE helper, not loaded at runtime.

namespace Baremetal\Input {
    /**
     * Which gesture a touch controller recognised; the value of Gesture::$type.
     */
    enum GestureType: string
    {
        /** A swipe towards the top of the screen. */
        case SwipeUp = 'swipe-up';

        /** A swipe towards the bottom of the screen. */
        case SwipeDown = 'swipe-down';

        /** A swipe towards the left of the screen. */
        case SwipeLeft = 'swipe-left';

        /** A swipe towards the right of the screen. */
        case SwipeRight = 'swipe-right';

        /** A short touch. */
        case Tap = 'tap';

        /** Two short touches in a row. */
        case DoubleTap = 'double-tap';

        /** A touch held for a while. */
        case LongPress = 'long-press';
    }

    /**
     * A touch device: a driver of a touch controller implements it.
     */
    interface Touch
    {
        /**
         * The point touched now, in screen coordinates, or null with no finger.
         *
         * @return array{x: int, y: int}|null
         */
        public function point(): ?array;

        /**
         * Turns on the events of this device (Pressed, Moved, Released, Gesture) and returns the handle that
         * stops and starts them. Every call returns a new handle on the same source and turns it on.
         */
        public function events(): \Baremetal\Source;
    }

    /**
     * The base of the four touch event classes; $device is the Touch that raised it.
     */
    abstract class TouchEvent extends \Baremetal\Event
    {
        /** Horizontal position in screen coordinates. */
        public readonly int $x;

        /** Vertical position in screen coordinates. */
        public readonly int $y;
    }

    /**
     * A finger came down at ($x, $y).
     */
    final class Pressed extends TouchEvent
    {
    }

    /**
     * The finger moved to ($x, $y); no coalescing: each report that moves the point is one event.
     */
    final class Moved extends TouchEvent
    {
    }

    /**
     * The finger went up; $x and $y are the last point.
     */
    final class Released extends TouchEvent
    {
    }

    /**
     * The controller recognised a gesture, ending at ($x, $y).
     */
    final class Gesture extends TouchEvent
    {
        /** Which gesture. */
        public readonly GestureType $type;
    }

    /**
     * The handle returned by Touch::events(): stop(), start() and running() of Baremetal\Source.
     */
    final class TouchEvents extends \Baremetal\Source
    {
    }
}
Download ext-input.php