tb_inline_select.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // ================================================================================
  2. // == This file is a part of Turbo Badger. (C) 2011-2014, Emil Segerås ==
  3. // == See tb_core.h for more information. ==
  4. // ================================================================================
  5. #ifndef TB_INLINE_SELECT_H
  6. #define TB_INLINE_SELECT_H
  7. #include "tb_widgets_listener.h"
  8. #include "tb_select_item.h"
  9. #include "tb_editfield.h"
  10. namespace tb {
  11. /** TBSelectList is a select widget with no popups. Instead it has two
  12. arrow buttons that cycle between the choices.
  13. By default it is a number widget.
  14. FIX: Should also be possible to set a list of strings that will be
  15. shown instead of numbers.
  16. */
  17. class TBInlineSelect : public TBWidget, private TBWidgetListener
  18. {
  19. public:
  20. // For safe typecasting
  21. TBOBJECT_SUBCLASS(TBInlineSelect, TBWidget);
  22. TBInlineSelect();
  23. ~TBInlineSelect();
  24. /** Set along which axis the content should layouted. */
  25. virtual void SetAxis(AXIS axis) { m_layout.SetAxis(axis); }
  26. virtual AXIS GetAxis() const { return m_layout.GetAxis(); }
  27. void SetLimits(double min, double max);
  28. double GetMinValue() const { return m_min; }
  29. double GetMaxValue() const { return m_max; }
  30. // ATOMIC BEGIN
  31. /// set the increment, decrement step size for clicking the buttons
  32. void SetStepSize(double value) { m_stepsize = value; }
  33. double GetStepSize() const { return m_stepsize; }
  34. // ATOMIC END
  35. virtual void SetValueDouble(double value) { SetValueInternal(value, true); }
  36. virtual double GetValueDouble() { return m_value; }
  37. virtual void SetValue(int value) { SetValueInternal(value, true); }
  38. virtual int GetValue() { return m_value; }
  39. void SetEditFieldLayoutParams(LayoutParams& lp);
  40. virtual void OnInflate(const INFLATE_INFO &info);
  41. virtual void OnSkinChanged();
  42. virtual bool OnEvent(const TBWidgetEvent &ev);
  43. protected:
  44. TBButton m_buttons[2];
  45. TBLayout m_layout;
  46. TBEditField m_editfield;
  47. double m_value;
  48. double m_min, m_max;
  49. bool m_modified;
  50. // ATOMIC BEGIN
  51. double m_stepsize;
  52. // ATOMIC END
  53. void SetValueInternal(double value, bool update_text);
  54. private:
  55. TBStr m_initial_edit_value;
  56. void InvokeModifiedEvent();
  57. void OnWidgetFocusChanged(TBWidget *widget, bool focused);
  58. bool OnWidgetInvokeEvent(TBWidget *widget, const TBWidgetEvent &ev);
  59. };
  60. }; // namespace tb
  61. #endif // TB_INLINE_SELECT_H