scroll_bar.cpp 20 KB

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