/*------------------------------------------------------------------------------
 src/lib/djWidget/floatWidget.cxx

 Copyright (c) 2004-2006 Darby Johnston.
 All rights reserved.
 Use is subject to license terms.
------------------------------------------------------------------------------*/

//#define DJ_DBG
#include "djNumWidget.h"
#include <djTextWidget.h>

namespace dj {

FloatWidget::FloatWidget() :
  _value(0.0),
  _min(-1000000.0), _max(1000000.0),
  _inc(0.1), _dec(-0.1)
{
  widgetUpdate();
}

void FloatWidget::set(double in)
{
  const double tmp = clamp(in, _min, _max);
  if (compare(tmp, _value)) return;
  _value = tmp;
  _sig.emit(_value);
  widgetUpdate();
}

void FloatWidget::range(double min, double max)
{
  if (compare(min, _min) && compare(max, _max)) return;
  _min = min;
  _max = max;
  set(_value);
}

void FloatWidget::min(double in)
{
  if (compare(in, _min)) return;
  _min = in;
  set(_value);
}

void FloatWidget::max(double in)
{
  if (compare(in, _max)) return;
  _max = in;
  set(_value);
}

void FloatWidget::inc(double inc, double dec)
{
  _inc = inc;
  _dec = dec;
}

void FloatWidget::inc() { set(_value + _inc); }
void FloatWidget::incBig() { set(_value + _inc * 10.0); }
void FloatWidget::dec() { set(_value + _dec); }
void FloatWidget::decBig() { set(_value + _dec * 10.0); }

void FloatWidget::widgetCallback(const Str & in) { set(toFloat(in)); }
void FloatWidget::widgetUpdate() { NumWidget::widgetUpdate(toStr(_value, 3)); }

}
