spin_box.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /**************************************************************************/
  2. /* spin_box.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef SPIN_BOX_H
  31. #define SPIN_BOX_H
  32. #include "scene/gui/line_edit.h"
  33. #include "scene/gui/range.h"
  34. #include "scene/main/timer.h"
  35. class SpinBox : public Range {
  36. GDCLASS(SpinBox, Range);
  37. LineEdit *line_edit = nullptr;
  38. int last_w = 0;
  39. bool update_on_text_changed = false;
  40. Timer *range_click_timer = nullptr;
  41. void _range_click_timeout();
  42. void _release_mouse();
  43. void _update_text(bool p_keep_line_edit = false);
  44. void _text_submitted(const String &p_string);
  45. void _text_changed(const String &p_string);
  46. String prefix;
  47. String suffix;
  48. String last_updated_text;
  49. double custom_arrow_step = 0.0;
  50. void _line_edit_input(const Ref<InputEvent> &p_event);
  51. struct Drag {
  52. double base_val = 0.0;
  53. bool allowed = false;
  54. bool enabled = false;
  55. Vector2 capture_pos;
  56. double diff_y = 0.0;
  57. } drag;
  58. void _line_edit_focus_enter();
  59. void _line_edit_focus_exit();
  60. inline void _adjust_width_for_icon(const Ref<Texture2D> &icon);
  61. struct ThemeCache {
  62. Ref<Texture2D> updown_icon;
  63. } theme_cache;
  64. protected:
  65. virtual void gui_input(const Ref<InputEvent> &p_event) override;
  66. void _notification(int p_what);
  67. static void _bind_methods();
  68. public:
  69. LineEdit *get_line_edit();
  70. virtual Size2 get_minimum_size() const override;
  71. void set_horizontal_alignment(HorizontalAlignment p_alignment);
  72. HorizontalAlignment get_horizontal_alignment() const;
  73. void set_editable(bool p_enabled);
  74. bool is_editable() const;
  75. void set_suffix(const String &p_suffix);
  76. String get_suffix() const;
  77. void set_prefix(const String &p_prefix);
  78. String get_prefix() const;
  79. void set_update_on_text_changed(bool p_enabled);
  80. bool get_update_on_text_changed() const;
  81. void set_select_all_on_focus(bool p_enabled);
  82. bool is_select_all_on_focus() const;
  83. void apply();
  84. void set_custom_arrow_step(const double p_custom_arrow_step);
  85. double get_custom_arrow_step() const;
  86. SpinBox();
  87. };
  88. #endif // SPIN_BOX_H