scroll_bar.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. /**************************************************************************/
  2. /* scroll_bar.cpp */
  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. #include "scroll_bar.h"
  31. #include "core/os/keyboard.h"
  32. #include "core/os/os.h"
  33. #include "core/string/print_string.h"
  34. #include "scene/main/window.h"
  35. bool ScrollBar::focus_by_default = false;
  36. void ScrollBar::set_can_focus_by_default(bool p_can_focus) {
  37. focus_by_default = p_can_focus;
  38. }
  39. void ScrollBar::gui_input(const Ref<InputEvent> &p_event) {
  40. ERR_FAIL_COND(p_event.is_null());
  41. Ref<InputEventMouseMotion> m = p_event;
  42. if (!m.is_valid() || drag.active) {
  43. emit_signal(SNAME("scrolling"));
  44. }
  45. Ref<InputEventMouseButton> b = p_event;
  46. if (b.is_valid()) {
  47. accept_event();
  48. if (b->get_button_index() == MouseButton::WHEEL_DOWN && b->is_pressed()) {
  49. double change = get_page() != 0.0 ? get_page() / 4.0 : (get_max() - get_min()) / 16.0;
  50. set_value(get_value() + MAX(change, get_step()));
  51. accept_event();
  52. }
  53. if (b->get_button_index() == MouseButton::WHEEL_UP && b->is_pressed()) {
  54. double change = get_page() != 0.0 ? get_page() / 4.0 : (get_max() - get_min()) / 16.0;
  55. set_value(get_value() - MAX(change, get_step()));
  56. accept_event();
  57. }
  58. if (b->get_button_index() != MouseButton::LEFT) {
  59. return;
  60. }
  61. if (b->is_pressed()) {
  62. double ofs = orientation == VERTICAL ? b->get_position().y : b->get_position().x;
  63. Ref<Texture2D> decr = theme_cache.decrement_icon;
  64. Ref<Texture2D> incr = theme_cache.increment_icon;
  65. double decr_size = orientation == VERTICAL ? decr->get_height() : decr->get_width();
  66. double incr_size = orientation == VERTICAL ? incr->get_height() : incr->get_width();
  67. double grabber_ofs = get_grabber_offset();
  68. double grabber_size = get_grabber_size();
  69. double total = orientation == VERTICAL ? get_size().height : get_size().width;
  70. if (ofs < decr_size) {
  71. decr_active = true;
  72. set_value(get_value() - (custom_step >= 0 ? custom_step : get_step()));
  73. queue_redraw();
  74. return;
  75. }
  76. if (ofs > total - incr_size) {
  77. incr_active = true;
  78. set_value(get_value() + (custom_step >= 0 ? custom_step : get_step()));
  79. queue_redraw();
  80. return;
  81. }
  82. ofs -= decr_size;
  83. if (ofs < grabber_ofs) {
  84. if (scrolling) {
  85. target_scroll = CLAMP(target_scroll - get_page(), get_min(), get_max() - get_page());
  86. } else {
  87. double change = get_page() != 0.0 ? get_page() : (get_max() - get_min()) / 16.0;
  88. target_scroll = CLAMP(get_value() - change, get_min(), get_max() - get_page());
  89. }
  90. if (smooth_scroll_enabled) {
  91. scrolling = true;
  92. set_physics_process_internal(true);
  93. } else {
  94. set_value(target_scroll);
  95. }
  96. return;
  97. }
  98. ofs -= grabber_ofs;
  99. if (ofs < grabber_size) {
  100. drag.active = true;
  101. drag.pos_at_click = grabber_ofs + ofs;
  102. drag.value_at_click = get_as_ratio();
  103. queue_redraw();
  104. } else {
  105. if (scrolling) {
  106. target_scroll = CLAMP(target_scroll + get_page(), get_min(), get_max() - get_page());
  107. } else {
  108. double change = get_page() != 0.0 ? get_page() : (get_max() - get_min()) / 16.0;
  109. target_scroll = CLAMP(get_value() + change, get_min(), get_max() - get_page());
  110. }
  111. if (smooth_scroll_enabled) {
  112. scrolling = true;
  113. set_physics_process_internal(true);
  114. } else {
  115. set_value(target_scroll);
  116. }
  117. }
  118. } else {
  119. incr_active = false;
  120. decr_active = false;
  121. drag.active = false;
  122. queue_redraw();
  123. }
  124. }
  125. if (m.is_valid()) {
  126. accept_event();
  127. if (drag.active) {
  128. double ofs = orientation == VERTICAL ? m->get_position().y : m->get_position().x;
  129. Ref<Texture2D> decr = theme_cache.decrement_icon;
  130. double decr_size = orientation == VERTICAL ? decr->get_height() : decr->get_width();
  131. ofs -= decr_size;
  132. double diff = (ofs - drag.pos_at_click) / get_area_size();
  133. set_as_ratio(drag.value_at_click + diff);
  134. } else {
  135. double ofs = orientation == VERTICAL ? m->get_position().y : m->get_position().x;
  136. Ref<Texture2D> decr = theme_cache.decrement_icon;
  137. Ref<Texture2D> incr = theme_cache.increment_icon;
  138. double decr_size = orientation == VERTICAL ? decr->get_height() : decr->get_width();
  139. double incr_size = orientation == VERTICAL ? incr->get_height() : incr->get_width();
  140. double total = orientation == VERTICAL ? get_size().height : get_size().width;
  141. HighlightStatus new_hilite;
  142. if (ofs < decr_size) {
  143. new_hilite = HIGHLIGHT_DECR;
  144. } else if (ofs > total - incr_size) {
  145. new_hilite = HIGHLIGHT_INCR;
  146. } else {
  147. new_hilite = HIGHLIGHT_RANGE;
  148. }
  149. if (new_hilite != highlight) {
  150. highlight = new_hilite;
  151. queue_redraw();
  152. }
  153. }
  154. }
  155. if (p_event->is_pressed()) {
  156. if (p_event->is_action("ui_left", true)) {
  157. if (orientation != HORIZONTAL) {
  158. return;
  159. }
  160. set_value(get_value() - (custom_step >= 0 ? custom_step : get_step()));
  161. } else if (p_event->is_action("ui_right", true)) {
  162. if (orientation != HORIZONTAL) {
  163. return;
  164. }
  165. set_value(get_value() + (custom_step >= 0 ? custom_step : get_step()));
  166. } else if (p_event->is_action("ui_up", true)) {
  167. if (orientation != VERTICAL) {
  168. return;
  169. }
  170. set_value(get_value() - (custom_step >= 0 ? custom_step : get_step()));
  171. } else if (p_event->is_action("ui_down", true)) {
  172. if (orientation != VERTICAL) {
  173. return;
  174. }
  175. set_value(get_value() + (custom_step >= 0 ? custom_step : get_step()));
  176. } else if (p_event->is_action("ui_home", true)) {
  177. set_value(get_min());
  178. } else if (p_event->is_action("ui_end", true)) {
  179. set_value(get_max());
  180. }
  181. }
  182. }
  183. void ScrollBar::_update_theme_item_cache() {
  184. Range::_update_theme_item_cache();
  185. theme_cache.scroll_style = get_theme_stylebox(SNAME("scroll"));
  186. theme_cache.scroll_focus_style = get_theme_stylebox(SNAME("scroll_focus"));
  187. theme_cache.scroll_offset_style = get_theme_stylebox(SNAME("hscroll"));
  188. theme_cache.grabber_style = get_theme_stylebox(SNAME("grabber"));
  189. theme_cache.grabber_hl_style = get_theme_stylebox(SNAME("grabber_highlight"));
  190. theme_cache.grabber_pressed_style = get_theme_stylebox(SNAME("grabber_pressed"));
  191. theme_cache.increment_icon = get_theme_icon(SNAME("increment"));
  192. theme_cache.increment_hl_icon = get_theme_icon(SNAME("increment_highlight"));
  193. theme_cache.increment_pressed_icon = get_theme_icon(SNAME("increment_pressed"));
  194. theme_cache.decrement_icon = get_theme_icon(SNAME("decrement"));
  195. theme_cache.decrement_hl_icon = get_theme_icon(SNAME("decrement_highlight"));
  196. theme_cache.decrement_pressed_icon = get_theme_icon(SNAME("decrement_pressed"));
  197. }
  198. void ScrollBar::_notification(int p_what) {
  199. switch (p_what) {
  200. case NOTIFICATION_DRAW: {
  201. RID ci = get_canvas_item();
  202. Ref<Texture2D> decr, incr;
  203. if (decr_active) {
  204. decr = theme_cache.decrement_pressed_icon;
  205. } else if (highlight == HIGHLIGHT_DECR) {
  206. decr = theme_cache.decrement_hl_icon;
  207. } else {
  208. decr = theme_cache.decrement_icon;
  209. }
  210. if (incr_active) {
  211. incr = theme_cache.increment_pressed_icon;
  212. } else if (highlight == HIGHLIGHT_INCR) {
  213. incr = theme_cache.increment_hl_icon;
  214. } else {
  215. incr = theme_cache.increment_icon;
  216. }
  217. Ref<StyleBox> bg = has_focus() ? theme_cache.scroll_focus_style : theme_cache.scroll_style;
  218. Ref<StyleBox> grabber;
  219. if (drag.active) {
  220. grabber = theme_cache.grabber_pressed_style;
  221. } else if (highlight == HIGHLIGHT_RANGE) {
  222. grabber = theme_cache.grabber_hl_style;
  223. } else {
  224. grabber = theme_cache.grabber_style;
  225. }
  226. Point2 ofs;
  227. decr->draw(ci, Point2());
  228. if (orientation == HORIZONTAL) {
  229. ofs.x += decr->get_width();
  230. } else {
  231. ofs.y += decr->get_height();
  232. }
  233. Size2 area = get_size();
  234. if (orientation == HORIZONTAL) {
  235. area.width -= incr->get_width() + decr->get_width();
  236. } else {
  237. area.height -= incr->get_height() + decr->get_height();
  238. }
  239. bg->draw(ci, Rect2(ofs, area));
  240. if (orientation == HORIZONTAL) {
  241. ofs.width += area.width;
  242. } else {
  243. ofs.height += area.height;
  244. }
  245. incr->draw(ci, ofs);
  246. Rect2 grabber_rect;
  247. if (orientation == HORIZONTAL) {
  248. grabber_rect.size.width = get_grabber_size();
  249. grabber_rect.size.height = get_size().height;
  250. grabber_rect.position.y = 0;
  251. grabber_rect.position.x = get_grabber_offset() + decr->get_width() + bg->get_margin(SIDE_LEFT);
  252. } else {
  253. grabber_rect.size.width = get_size().width;
  254. grabber_rect.size.height = get_grabber_size();
  255. grabber_rect.position.y = get_grabber_offset() + decr->get_height() + bg->get_margin(SIDE_TOP);
  256. grabber_rect.position.x = 0;
  257. }
  258. grabber->draw(ci, grabber_rect);
  259. } break;
  260. case NOTIFICATION_ENTER_TREE: {
  261. if (has_node(drag_node_path)) {
  262. Node *n = get_node(drag_node_path);
  263. drag_node = Object::cast_to<Control>(n);
  264. }
  265. if (drag_node) {
  266. drag_node->connect("gui_input", callable_mp(this, &ScrollBar::_drag_node_input));
  267. drag_node->connect("tree_exiting", callable_mp(this, &ScrollBar::_drag_node_exit), CONNECT_ONE_SHOT);
  268. }
  269. } break;
  270. case NOTIFICATION_EXIT_TREE: {
  271. if (drag_node) {
  272. drag_node->disconnect("gui_input", callable_mp(this, &ScrollBar::_drag_node_input));
  273. drag_node->disconnect("tree_exiting", callable_mp(this, &ScrollBar::_drag_node_exit));
  274. }
  275. drag_node = nullptr;
  276. } break;
  277. case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
  278. if (scrolling) {
  279. if (get_value() != target_scroll) {
  280. double target = target_scroll - get_value();
  281. double dist = abs(target);
  282. double vel = ((target / dist) * 500) * get_physics_process_delta_time();
  283. if (Math::abs(vel) >= dist) {
  284. set_value(target_scroll);
  285. scrolling = false;
  286. set_physics_process_internal(false);
  287. } else {
  288. set_value(get_value() + vel);
  289. }
  290. } else {
  291. scrolling = false;
  292. set_physics_process_internal(false);
  293. }
  294. } else if (drag_node_touching) {
  295. if (drag_node_touching_deaccel) {
  296. Vector2 pos = Vector2(orientation == HORIZONTAL ? get_value() : 0, orientation == VERTICAL ? get_value() : 0);
  297. pos += drag_node_speed * get_physics_process_delta_time();
  298. bool turnoff = false;
  299. if (orientation == HORIZONTAL) {
  300. if (pos.x < 0) {
  301. pos.x = 0;
  302. turnoff = true;
  303. }
  304. if (pos.x > (get_max() - get_page())) {
  305. pos.x = get_max() - get_page();
  306. turnoff = true;
  307. }
  308. set_value(pos.x);
  309. float sgn_x = drag_node_speed.x < 0 ? -1 : 1;
  310. float val_x = Math::abs(drag_node_speed.x);
  311. val_x -= 1000 * get_physics_process_delta_time();
  312. if (val_x < 0) {
  313. turnoff = true;
  314. }
  315. drag_node_speed.x = sgn_x * val_x;
  316. } else {
  317. if (pos.y < 0) {
  318. pos.y = 0;
  319. turnoff = true;
  320. }
  321. if (pos.y > (get_max() - get_page())) {
  322. pos.y = get_max() - get_page();
  323. turnoff = true;
  324. }
  325. set_value(pos.y);
  326. float sgn_y = drag_node_speed.y < 0 ? -1 : 1;
  327. float val_y = Math::abs(drag_node_speed.y);
  328. val_y -= 1000 * get_physics_process_delta_time();
  329. if (val_y < 0) {
  330. turnoff = true;
  331. }
  332. drag_node_speed.y = sgn_y * val_y;
  333. }
  334. if (turnoff) {
  335. set_physics_process_internal(false);
  336. drag_node_touching = false;
  337. drag_node_touching_deaccel = false;
  338. }
  339. } else {
  340. if (time_since_motion == 0 || time_since_motion > 0.1) {
  341. Vector2 diff = drag_node_accum - last_drag_node_accum;
  342. last_drag_node_accum = drag_node_accum;
  343. drag_node_speed = diff / get_physics_process_delta_time();
  344. }
  345. time_since_motion += get_physics_process_delta_time();
  346. }
  347. }
  348. } break;
  349. case NOTIFICATION_MOUSE_EXIT: {
  350. highlight = HIGHLIGHT_NONE;
  351. queue_redraw();
  352. } break;
  353. }
  354. }
  355. double ScrollBar::get_grabber_min_size() const {
  356. Ref<StyleBox> grabber = theme_cache.grabber_style;
  357. Size2 gminsize = grabber->get_minimum_size();
  358. return (orientation == VERTICAL) ? gminsize.height : gminsize.width;
  359. }
  360. double ScrollBar::get_grabber_size() const {
  361. float range = get_max() - get_min();
  362. if (range <= 0) {
  363. return 0;
  364. }
  365. float page = (get_page() > 0) ? get_page() : 0;
  366. double area_size = get_area_size();
  367. double grabber_size = page / range * area_size;
  368. return grabber_size + get_grabber_min_size();
  369. }
  370. double ScrollBar::get_area_size() const {
  371. switch (orientation) {
  372. case VERTICAL: {
  373. double area = get_size().height;
  374. area -= theme_cache.scroll_style->get_minimum_size().height;
  375. area -= theme_cache.increment_icon->get_height();
  376. area -= theme_cache.decrement_icon->get_height();
  377. area -= get_grabber_min_size();
  378. return area;
  379. } break;
  380. case HORIZONTAL: {
  381. double area = get_size().width;
  382. area -= theme_cache.scroll_style->get_minimum_size().width;
  383. area -= theme_cache.increment_icon->get_width();
  384. area -= theme_cache.decrement_icon->get_width();
  385. area -= get_grabber_min_size();
  386. return area;
  387. } break;
  388. default: {
  389. return 0.0;
  390. }
  391. }
  392. }
  393. double ScrollBar::get_area_offset() const {
  394. double ofs = 0.0;
  395. if (orientation == VERTICAL) {
  396. ofs += theme_cache.scroll_offset_style->get_margin(SIDE_TOP);
  397. ofs += theme_cache.decrement_icon->get_height();
  398. }
  399. if (orientation == HORIZONTAL) {
  400. ofs += theme_cache.scroll_offset_style->get_margin(SIDE_LEFT);
  401. ofs += theme_cache.decrement_icon->get_width();
  402. }
  403. return ofs;
  404. }
  405. double ScrollBar::get_grabber_offset() const {
  406. return (get_area_size()) * get_as_ratio();
  407. }
  408. Size2 ScrollBar::get_minimum_size() const {
  409. Ref<Texture2D> incr = theme_cache.increment_icon;
  410. Ref<Texture2D> decr = theme_cache.decrement_icon;
  411. Ref<StyleBox> bg = theme_cache.scroll_style;
  412. Size2 minsize;
  413. if (orientation == VERTICAL) {
  414. minsize.width = MAX(incr->get_size().width, bg->get_minimum_size().width);
  415. minsize.height += incr->get_size().height;
  416. minsize.height += decr->get_size().height;
  417. minsize.height += bg->get_minimum_size().height;
  418. minsize.height += get_grabber_min_size();
  419. }
  420. if (orientation == HORIZONTAL) {
  421. minsize.height = MAX(incr->get_size().height, bg->get_minimum_size().height);
  422. minsize.width += incr->get_size().width;
  423. minsize.width += decr->get_size().width;
  424. minsize.width += bg->get_minimum_size().width;
  425. minsize.width += get_grabber_min_size();
  426. }
  427. return minsize;
  428. }
  429. void ScrollBar::set_custom_step(float p_custom_step) {
  430. custom_step = p_custom_step;
  431. }
  432. float ScrollBar::get_custom_step() const {
  433. return custom_step;
  434. }
  435. void ScrollBar::_drag_node_exit() {
  436. if (drag_node) {
  437. drag_node->disconnect("gui_input", callable_mp(this, &ScrollBar::_drag_node_input));
  438. }
  439. drag_node = nullptr;
  440. }
  441. void ScrollBar::_drag_node_input(const Ref<InputEvent> &p_input) {
  442. if (!drag_node_enabled) {
  443. return;
  444. }
  445. Ref<InputEventMouseButton> mb = p_input;
  446. if (mb.is_valid()) {
  447. if (mb->get_button_index() != MouseButton::LEFT) {
  448. return;
  449. }
  450. if (mb->is_pressed()) {
  451. drag_node_speed = Vector2();
  452. drag_node_accum = Vector2();
  453. last_drag_node_accum = Vector2();
  454. drag_node_from = Vector2(orientation == HORIZONTAL ? get_value() : 0, orientation == VERTICAL ? get_value() : 0);
  455. drag_node_touching = DisplayServer::get_singleton()->is_touchscreen_available();
  456. drag_node_touching_deaccel = false;
  457. time_since_motion = 0;
  458. if (drag_node_touching) {
  459. set_physics_process_internal(true);
  460. time_since_motion = 0;
  461. }
  462. } else {
  463. if (drag_node_touching) {
  464. if (drag_node_speed == Vector2()) {
  465. drag_node_touching_deaccel = false;
  466. drag_node_touching = false;
  467. set_physics_process_internal(false);
  468. } else {
  469. drag_node_touching_deaccel = true;
  470. }
  471. }
  472. }
  473. }
  474. Ref<InputEventMouseMotion> mm = p_input;
  475. if (mm.is_valid()) {
  476. if (drag_node_touching && !drag_node_touching_deaccel) {
  477. Vector2 motion = mm->get_relative();
  478. drag_node_accum -= motion;
  479. Vector2 diff = drag_node_from + drag_node_accum;
  480. if (orientation == HORIZONTAL) {
  481. set_value(diff.x);
  482. }
  483. if (orientation == VERTICAL) {
  484. set_value(diff.y);
  485. }
  486. time_since_motion = 0;
  487. }
  488. }
  489. }
  490. void ScrollBar::set_drag_node(const NodePath &p_path) {
  491. if (is_inside_tree()) {
  492. if (drag_node) {
  493. drag_node->disconnect("gui_input", callable_mp(this, &ScrollBar::_drag_node_input));
  494. drag_node->disconnect("tree_exiting", callable_mp(this, &ScrollBar::_drag_node_exit));
  495. }
  496. }
  497. drag_node = nullptr;
  498. drag_node_path = p_path;
  499. if (is_inside_tree()) {
  500. if (has_node(p_path)) {
  501. Node *n = get_node(p_path);
  502. drag_node = Object::cast_to<Control>(n);
  503. }
  504. if (drag_node) {
  505. drag_node->connect("gui_input", callable_mp(this, &ScrollBar::_drag_node_input));
  506. drag_node->connect("tree_exiting", callable_mp(this, &ScrollBar::_drag_node_exit), CONNECT_ONE_SHOT);
  507. }
  508. }
  509. }
  510. NodePath ScrollBar::get_drag_node() const {
  511. return drag_node_path;
  512. }
  513. void ScrollBar::set_drag_node_enabled(bool p_enable) {
  514. drag_node_enabled = p_enable;
  515. }
  516. void ScrollBar::set_smooth_scroll_enabled(bool p_enable) {
  517. smooth_scroll_enabled = p_enable;
  518. }
  519. bool ScrollBar::is_smooth_scroll_enabled() const {
  520. return smooth_scroll_enabled;
  521. }
  522. void ScrollBar::_bind_methods() {
  523. ClassDB::bind_method(D_METHOD("set_custom_step", "step"), &ScrollBar::set_custom_step);
  524. ClassDB::bind_method(D_METHOD("get_custom_step"), &ScrollBar::get_custom_step);
  525. ADD_SIGNAL(MethodInfo("scrolling"));
  526. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "custom_step", PROPERTY_HINT_RANGE, "-1,4096,suffix:px"), "set_custom_step", "get_custom_step");
  527. }
  528. ScrollBar::ScrollBar(Orientation p_orientation) {
  529. orientation = p_orientation;
  530. if (focus_by_default) {
  531. set_focus_mode(FOCUS_ALL);
  532. }
  533. set_step(0);
  534. }
  535. ScrollBar::~ScrollBar() {
  536. }