scroll_bar.cpp 20 KB

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