/**
 * @file    label.c
 * @brief   The clickable LABEL (flags=ACTIVATABLE); a plain LABEL has no runtime API.
 *          A reading aid for the tutorial page "widget-types", not a complete
 *          plugin: the functions below would be wired into an IcPlugin
 *          (on_widget_event) or called from init()/a Worker callback.
 *
 * @note    ASCII-only and C89 on purpose (VC6 / CP950 safe, and it must pass
 *          the syntax-only guard). The widget ids match label.nxlay.
 */

#include <string.h>

#include "nexus_plugin_api.h"

/** @brief The HostAPI table, saved by init() (not shown here). */
static const NxHostApi *s_host = (const NxHostApi *)0;

/** @brief widget id of the clickable label ([w.2] in label.nxlay). */
#define WID_DATASHEET 2

/**
 * @brief  Widget event handler.
 * @param[in] ctx       This mount's context.
 * @param[in] panel_id  Always 0 for now.
 * @param[in] widget_id Which widget.
 * @param[in] evt       The event, valid during the call only. For ACTIVATED,
 *                      evt->val is an NX_WKIND_U64 that packs the click
 *                      position (high 16 bits vertical, low 16 bits horizontal,
 *                      0..65535; a key press gives NX_WPOS_KEYBOARD).
 * @note   I2C Worker Thread. A LABEL has no value to set: its text comes from
 *         the layout file.
 */
void NX_CALL label_on_event(NxPluginCtx ctx, NxByte panel_id, NxWord widget_id,
                    const NxWidgetEvent *evt)
{
    NX_UNUSED_ARG(panel_id);
    if (widget_id == WID_DATASHEET && evt->kind == NX_WEVT_ACTIVATED)
    {
        s_host->LogWrite(ctx, NX_LOG_INFO, "label: datasheet link clicked");
    }
}
