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
31#ifndef SPIN_BOX_H
32#define SPIN_BOX_H
33
34#include "scene/gui/line_edit.h"
35#include "scene/gui/range.h"
36#include "scene/main/timer.h"
37
38class SpinBox : public Range {
39 GDCLASS(SpinBox, Range);
40
41 LineEdit *line_edit = nullptr;
42 int last_w = 0;
43 bool update_on_text_changed = false;
44
45 Timer *range_click_timer = nullptr;
46 void _range_click_timeout();
47 void _release_mouse();
48
49 void _update_text();
50 void _text_submitted(const String &p_string);
51 void _text_changed(const String &p_string);
52
53 String prefix;
54 String suffix;
55 double custom_arrow_step = 0.0;
56
57 void _line_edit_input(const Ref<InputEvent> &p_event);
58
59 struct Drag {
60 double base_val = 0.0;
61 bool allowed = false;
62 bool enabled = false;
63 Vector2 capture_pos;
64 double diff_y = 0.0;
65 } drag;
66
67 void _line_edit_focus_enter();
68 void _line_edit_focus_exit();
69
70 inline void _adjust_width_for_icon(const Ref<Texture2D> &icon);
71
72 struct ThemeCache {
73 Ref<Texture2D> updown_icon;
74 } theme_cache;
75
76protected:
77 virtual void gui_input(const Ref<InputEvent> &p_event) override;
78
79 void _notification(int p_what);
80 static void _bind_methods();
81
82public:
83 LineEdit *get_line_edit();
84
85 virtual Size2 get_minimum_size() const override;
86
87 void set_horizontal_alignment(HorizontalAlignment p_alignment);
88 HorizontalAlignment get_horizontal_alignment() const;
89
90 void set_editable(bool p_enabled);
91 bool is_editable() const;
92
93 void set_suffix(const String &p_suffix);
94 String get_suffix() const;
95
96 void set_prefix(const String &p_prefix);
97 String get_prefix() const;
98
99 void set_update_on_text_changed(bool p_enabled);
100 bool get_update_on_text_changed() const;
101
102 void set_select_all_on_focus(bool p_enabled);
103 bool is_select_all_on_focus() const;
104
105 void apply();
106 void set_custom_arrow_step(const double p_custom_arrow_step);
107 double get_custom_arrow_step() const;
108
109 SpinBox();
110};
111
112#endif // SPIN_BOX_H
113