/**
 * @file    meter.c
 * @brief   Moving a METER bar.
 *          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 meter.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 METER ([w.1] in meter.nxlay). */
#define WID_LOADING 1

/**
 * @brief  Sets the bar; values outside num_min..num_max are clamped.
 * @param[in] percent 0..100 here because the declaration says num_max=100.
 * @note   Any thread. The bar is read-only for the user (no event), unless
 *         you declare flags=ACTIVATABLE.
 */
NxLong meter_set(NxPluginCtx ctx, NxDword percent)
{
    NxPropVal v;

    memset(&v, 0, sizeof(v));
    v.SizeOfStruct = (NxDword)sizeof(v);
    v.kind         = (NxWord)NX_WKIND_I64;
    v.u.i64        = (NxI64)percent;
    return s_host->SetWidgetProp(ctx, 0, WID_LOADING, NX_WP_VALUE, &v);
}
