2
0

WidgetSlider.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. /*
  2. * This source file is part of RmlUi, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://github.com/mikke89/RmlUi
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. * Copyright (c) 2019 The RmlUi Team, and contributors
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. * THE SOFTWARE.
  26. *
  27. */
  28. #include "WidgetSlider.h"
  29. #include "../../Include/RmlUi/Controls/ElementFormControl.h"
  30. #include "../../Include/RmlUi/Core/ElementUtilities.h"
  31. #include "../../Include/RmlUi/Core/Factory.h"
  32. #include "../../Include/RmlUi/Core/Input.h"
  33. #include "../Core/Clock.h"
  34. namespace Rml {
  35. namespace Controls {
  36. static const float DEFAULT_REPEAT_DELAY = 0.5f;
  37. static const float DEFAULT_REPEAT_PERIOD = 0.1f;
  38. WidgetSlider::WidgetSlider(ElementFormControl* _parent)
  39. {
  40. parent = _parent;
  41. orientation = HORIZONTAL;
  42. track = nullptr;
  43. bar = nullptr;
  44. arrows[0] = nullptr;
  45. arrows[1] = nullptr;
  46. bar_position = 0;
  47. bar_drag_anchor = 0;
  48. arrow_timers[0] = -1;
  49. arrow_timers[1] = -1;
  50. last_update_time = 0;
  51. }
  52. WidgetSlider::~WidgetSlider()
  53. {
  54. if (bar != nullptr)
  55. {
  56. parent->RemoveChild(bar);
  57. }
  58. if (track != nullptr)
  59. {
  60. parent->RemoveChild(track);
  61. }
  62. using Core::EventId;
  63. parent->RemoveEventListener(EventId::Blur, this);
  64. parent->RemoveEventListener(EventId::Focus, this);
  65. parent->RemoveEventListener(EventId::Keydown, this, true);
  66. parent->RemoveEventListener(EventId::Mousedown, this);
  67. parent->RemoveEventListener(EventId::Mouseup, this);
  68. parent->RemoveEventListener(EventId::Mouseout, this);
  69. parent->RemoveEventListener(EventId::Drag, this);
  70. parent->RemoveEventListener(EventId::Dragstart, this);
  71. parent->RemoveEventListener(EventId::Dragend, this);
  72. for (int i = 0; i < 2; i++)
  73. {
  74. if (arrows[i] != nullptr)
  75. {
  76. parent->RemoveChild(arrows[i]);
  77. }
  78. }
  79. }
  80. // Initialises the slider to a given orientation.
  81. bool WidgetSlider::Initialise()
  82. {
  83. Core::Property drag_property = Core::Property(Core::Style::Drag::Drag);
  84. parent->SetProperty(Core::PropertyId::Drag, drag_property);
  85. // Create all of our child elements as standard elements, and abort if we can't create them.
  86. Core::ElementPtr track_element = Core::Factory::InstanceElement(parent, "*", "slidertrack", Core::XMLAttributes());
  87. Core::ElementPtr bar_element = Core::Factory::InstanceElement(parent, "*", "sliderbar", Core::XMLAttributes());
  88. Core::ElementPtr arrow0_element = Core::Factory::InstanceElement(parent, "*", "sliderarrowdec", Core::XMLAttributes());
  89. Core::ElementPtr arrow1_element = Core::Factory::InstanceElement(parent, "*", "sliderarrowinc", Core::XMLAttributes());
  90. if (!track_element || !bar_element || !arrow0_element || !arrow1_element)
  91. {
  92. return false;
  93. }
  94. // Add them as non-DOM elements.
  95. track = parent->AppendChild(std::move(track_element), false);
  96. bar = parent->AppendChild(std::move(bar_element), false);
  97. arrows[0] = parent->AppendChild(std::move(arrow0_element), false);
  98. arrows[1] = parent->AppendChild(std::move(arrow1_element), false);
  99. arrows[0]->SetProperty(Core::PropertyId::Drag, drag_property);
  100. arrows[1]->SetProperty(Core::PropertyId::Drag, drag_property);
  101. // Attach the listeners
  102. // All listeners are attached to parent, ensuring that we don't get duplicate events when it bubbles from child to parent
  103. using Core::EventId;
  104. parent->AddEventListener(EventId::Blur, this);
  105. parent->AddEventListener(EventId::Focus, this);
  106. parent->AddEventListener(EventId::Keydown, this, true);
  107. parent->AddEventListener(EventId::Mousedown, this);
  108. parent->AddEventListener(EventId::Mouseup, this);
  109. parent->AddEventListener(EventId::Mouseout, this);
  110. parent->AddEventListener(EventId::Drag, this);
  111. parent->AddEventListener(EventId::Dragstart, this);
  112. parent->AddEventListener(EventId::Dragend, this);
  113. return true;
  114. }
  115. // Updates the key repeats for the increment / decrement arrows.
  116. void WidgetSlider::Update()
  117. {
  118. for (int i = 0; i < 2; i++)
  119. {
  120. bool updated_time = false;
  121. float delta_time = 0;
  122. if (arrow_timers[i] > 0)
  123. {
  124. if (!updated_time)
  125. {
  126. double current_time = Core::Clock::GetElapsedTime();
  127. delta_time = float(current_time - last_update_time);
  128. last_update_time = current_time;
  129. }
  130. arrow_timers[i] -= delta_time;
  131. while (arrow_timers[i] <= 0)
  132. {
  133. arrow_timers[i] += DEFAULT_REPEAT_PERIOD;
  134. SetBarPosition(i == 0 ? OnLineDecrement() : OnLineIncrement());
  135. }
  136. }
  137. }
  138. }
  139. // Sets the position of the bar.
  140. void WidgetSlider::SetBarPosition(float _bar_position)
  141. {
  142. bar_position = Rml::Core::Math::Clamp(_bar_position, 0.0f, 1.0f);
  143. PositionBar();
  144. }
  145. // Returns the current position of the bar.
  146. float WidgetSlider::GetBarPosition()
  147. {
  148. return bar_position;
  149. }
  150. // Sets the orientation of the slider.
  151. void WidgetSlider::SetOrientation(Orientation _orientation)
  152. {
  153. orientation = _orientation;
  154. }
  155. // Returns the slider's orientation.
  156. WidgetSlider::Orientation WidgetSlider::GetOrientation() const
  157. {
  158. return orientation;
  159. }
  160. // Sets the dimensions to the size of the slider.
  161. void WidgetSlider::GetDimensions(Rml::Core::Vector2f& dimensions) const
  162. {
  163. switch (orientation)
  164. {
  165. case VERTICAL: dimensions.x = 16; dimensions.y = 256; break;
  166. case HORIZONTAL: dimensions.x = 256; dimensions.y = 16; break;
  167. }
  168. }
  169. // Lays out and resizes the internal elements.
  170. void WidgetSlider::FormatElements(const Rml::Core::Vector2f& containing_block, float slider_length, float bar_length)
  171. {
  172. int length_axis = orientation == VERTICAL ? 1 : 0;
  173. // Build the box for the containing slider element. As the containing block is not guaranteed to have a defined
  174. // height, we must use the width for both axes.
  175. Core::Box parent_box;
  176. Core::ElementUtilities::BuildBox(parent_box, Rml::Core::Vector2f(containing_block.x, containing_block.x), parent);
  177. // Set the length of the slider.
  178. Rml::Core::Vector2f content = parent_box.GetSize();
  179. content[length_axis] = slider_length;
  180. parent_box.SetContent(content);
  181. // Generate the initial dimensions for the track. It'll need to be cut down to fit the arrows.
  182. Core::Box track_box;
  183. Core::ElementUtilities::BuildBox(track_box, parent_box.GetSize(), track);
  184. content = track_box.GetSize();
  185. content[length_axis] = slider_length -= orientation == VERTICAL ? (track_box.GetCumulativeEdge(Core::Box::CONTENT, Core::Box::TOP) + track_box.GetCumulativeEdge(Core::Box::CONTENT, Core::Box::BOTTOM)) :
  186. (track_box.GetCumulativeEdge(Core::Box::CONTENT, Core::Box::LEFT) + track_box.GetCumulativeEdge(Core::Box::CONTENT, Core::Box::RIGHT));
  187. // If no height has been explicitly specified for the track, it'll be initialised to -1 as per normal block
  188. // elements. We'll fix that up here.
  189. if (orientation == HORIZONTAL &&
  190. content.y < 0)
  191. content.y = parent_box.GetSize().y;
  192. // Now we size the arrows.
  193. for (int i = 0; i < 2; i++)
  194. {
  195. Core::Box arrow_box;
  196. Core::ElementUtilities::BuildBox(arrow_box, parent_box.GetSize(), arrows[i]);
  197. // Clamp the size to (0, 0).
  198. Rml::Core::Vector2f arrow_size = arrow_box.GetSize();
  199. if (arrow_size.x < 0 ||
  200. arrow_size.y < 0)
  201. arrow_box.SetContent(Rml::Core::Vector2f(0, 0));
  202. arrows[i]->SetBox(arrow_box);
  203. // Shrink the track length by the arrow size.
  204. content[length_axis] -= arrow_box.GetSize(Core::Box::MARGIN)[length_axis];
  205. }
  206. // Now the track has been sized, we can fix everything into position.
  207. track_box.SetContent(content);
  208. track->SetBox(track_box);
  209. if (orientation == VERTICAL)
  210. {
  211. Rml::Core::Vector2f offset(arrows[0]->GetBox().GetEdge(Core::Box::MARGIN, Core::Box::LEFT), arrows[0]->GetBox().GetEdge(Core::Box::MARGIN, Core::Box::TOP));
  212. arrows[0]->SetOffset(offset, parent);
  213. offset.x = track->GetBox().GetEdge(Core::Box::MARGIN, Core::Box::LEFT);
  214. offset.y += arrows[0]->GetBox().GetSize(Core::Box::BORDER).y + arrows[0]->GetBox().GetEdge(Core::Box::MARGIN, Core::Box::BOTTOM) + track->GetBox().GetEdge(Core::Box::MARGIN, Core::Box::TOP);
  215. track->SetOffset(offset, parent);
  216. offset.x = arrows[1]->GetBox().GetEdge(Core::Box::MARGIN, Core::Box::LEFT);
  217. offset.y += track->GetBox().GetSize(Core::Box::BORDER).y + track->GetBox().GetEdge(Core::Box::MARGIN, Core::Box::BOTTOM) + arrows[1]->GetBox().GetEdge(Core::Box::MARGIN, Core::Box::TOP);
  218. arrows[1]->SetOffset(offset, parent);
  219. }
  220. else
  221. {
  222. Rml::Core::Vector2f offset(arrows[0]->GetBox().GetEdge(Core::Box::MARGIN, Core::Box::LEFT), arrows[0]->GetBox().GetEdge(Core::Box::MARGIN, Core::Box::TOP));
  223. arrows[0]->SetOffset(offset, parent);
  224. offset.x += arrows[0]->GetBox().GetSize(Core::Box::BORDER).x + arrows[0]->GetBox().GetEdge(Core::Box::MARGIN, Core::Box::RIGHT) + track->GetBox().GetEdge(Core::Box::MARGIN, Core::Box::LEFT);
  225. offset.y = track->GetBox().GetEdge(Core::Box::MARGIN, Core::Box::TOP);
  226. track->SetOffset(offset, parent);
  227. offset.x += track->GetBox().GetSize(Core::Box::BORDER).x + track->GetBox().GetEdge(Core::Box::MARGIN, Core::Box::RIGHT) + arrows[1]->GetBox().GetEdge(Core::Box::MARGIN, Core::Box::LEFT);
  228. offset.y = arrows[1]->GetBox().GetEdge(Core::Box::MARGIN, Core::Box::TOP);
  229. arrows[1]->SetOffset(offset, parent);
  230. }
  231. FormatBar(bar_length);
  232. if (parent->IsDisabled())
  233. {
  234. // Propagate disabled state to child elements
  235. bar->SetPseudoClass("disabled", true);
  236. track->SetPseudoClass("disabled", true);
  237. arrows[0]->SetPseudoClass("disabled", true);
  238. arrows[1]->SetPseudoClass("disabled", true);
  239. }
  240. }
  241. // Lays out and positions the bar element.
  242. void WidgetSlider::FormatBar(float bar_length)
  243. {
  244. Core::Box bar_box;
  245. Core::ElementUtilities::BuildBox(bar_box, parent->GetBox().GetSize(), bar);
  246. auto& computed = bar->GetComputedValues();
  247. Rml::Core::Vector2f bar_box_content = bar_box.GetSize();
  248. if (orientation == HORIZONTAL)
  249. {
  250. if (computed.height.value == Core::Style::Height::Auto)
  251. bar_box_content.y = parent->GetBox().GetSize().y;
  252. }
  253. if (bar_length >= 0)
  254. {
  255. Rml::Core::Vector2f track_size = track->GetBox().GetSize();
  256. if (orientation == VERTICAL)
  257. {
  258. float track_length = track_size.y - (bar_box.GetCumulativeEdge(Core::Box::CONTENT, Core::Box::TOP) + bar_box.GetCumulativeEdge(Core::Box::CONTENT, Core::Box::BOTTOM));
  259. if (computed.height.value == Core::Style::Height::Auto)
  260. {
  261. bar_box_content.y = track_length * bar_length;
  262. // Check for 'min-height' restrictions.
  263. float min_track_length = Core::ResolveValue(computed.min_height, track_length);
  264. bar_box_content.y = Rml::Core::Math::Max(min_track_length, bar_box_content.y);
  265. // Check for 'max-height' restrictions.
  266. float max_track_length = Core::ResolveValue(computed.max_height, track_length);
  267. if (max_track_length > 0)
  268. bar_box_content.y = Rml::Core::Math::Min(max_track_length, bar_box_content.y);
  269. }
  270. // Make sure we haven't gone further than we're allowed to (min-height may have made us too big).
  271. bar_box_content.y = Rml::Core::Math::Min(bar_box_content.y, track_length);
  272. }
  273. else
  274. {
  275. float track_length = track_size.x - (bar_box.GetCumulativeEdge(Core::Box::CONTENT, Core::Box::LEFT) + bar_box.GetCumulativeEdge(Core::Box::CONTENT, Core::Box::RIGHT));
  276. if (computed.width.value == Core::Style::Width::Auto)
  277. {
  278. bar_box_content.x = track_length * bar_length;
  279. // Check for 'min-width' restrictions.
  280. float min_track_length = Core::ResolveValue(computed.min_width, track_length);
  281. bar_box_content.x = Rml::Core::Math::Max(min_track_length, bar_box_content.x);
  282. // Check for 'max-width' restrictions.
  283. float max_track_length = Core::ResolveValue(computed.max_width, track_length);
  284. if (max_track_length > 0)
  285. bar_box_content.x = Rml::Core::Math::Min(max_track_length, bar_box_content.x);
  286. }
  287. // Make sure we haven't gone further than we're allowed to (min-width may have made us too big).
  288. bar_box_content.x = Rml::Core::Math::Min(bar_box_content.x, track_length);
  289. }
  290. }
  291. // Set the new dimensions on the bar to re-decorate it.
  292. bar_box.SetContent(bar_box_content);
  293. bar->SetBox(bar_box);
  294. // Now that it's been resized, re-position it.
  295. PositionBar();
  296. }
  297. // Returns the widget's parent element.
  298. Core::Element* WidgetSlider::GetParent() const
  299. {
  300. return parent;
  301. }
  302. // Handles events coming through from the slider's components.
  303. void WidgetSlider::ProcessEvent(Core::Event& event)
  304. {
  305. if (parent->IsDisabled())
  306. return;
  307. using Rml::Core::EventId;
  308. switch (event.GetId())
  309. {
  310. case EventId::Mousedown:
  311. {
  312. if (event.GetTargetElement() == parent || event.GetTargetElement() == track)
  313. {
  314. float mouse_position, bar_halfsize;
  315. if (orientation == HORIZONTAL)
  316. {
  317. mouse_position = event.GetParameter< float >("mouse_x", 0);
  318. bar_halfsize = 0.5f * bar->GetBox().GetSize(Core::Box::BORDER).x;
  319. }
  320. else
  321. {
  322. mouse_position = event.GetParameter< float >("mouse_y", 0);
  323. bar_halfsize = 0.5f * bar->GetBox().GetSize(Core::Box::BORDER).y;
  324. }
  325. float new_bar_position = AbsolutePositionToBarPosition(mouse_position - bar_halfsize);
  326. SetBarPosition(OnBarChange(new_bar_position));
  327. }
  328. else if (event.GetTargetElement() == arrows[0])
  329. {
  330. arrow_timers[0] = DEFAULT_REPEAT_DELAY;
  331. last_update_time = Core::Clock::GetElapsedTime();
  332. SetBarPosition(OnLineDecrement());
  333. }
  334. else if (event.GetTargetElement() == arrows[1])
  335. {
  336. arrow_timers[1] = DEFAULT_REPEAT_DELAY;
  337. last_update_time = Core::Clock::GetElapsedTime();
  338. SetBarPosition(OnLineIncrement());
  339. }
  340. }
  341. break;
  342. case EventId::Mouseup:
  343. case EventId::Mouseout:
  344. {
  345. if (event.GetTargetElement() == arrows[0])
  346. arrow_timers[0] = -1;
  347. else if (event.GetTargetElement() == arrows[1])
  348. arrow_timers[1] = -1;
  349. }
  350. break;
  351. case EventId::Dragstart:
  352. {
  353. if (event.GetTargetElement() == parent)
  354. {
  355. bar->SetPseudoClass("active", true);
  356. if (orientation == HORIZONTAL)
  357. bar_drag_anchor = event.GetParameter< float >("mouse_x", 0) - bar->GetAbsoluteOffset().x;
  358. else
  359. bar_drag_anchor = event.GetParameter< float >("mouse_y", 0) - bar->GetAbsoluteOffset().y;
  360. }
  361. }
  362. break;
  363. case EventId::Drag:
  364. {
  365. if (event.GetTargetElement() == parent)
  366. {
  367. float new_bar_offset = event.GetParameter< float >((orientation == HORIZONTAL ? "mouse_x" : "mouse_y"), 0) - bar_drag_anchor;
  368. float new_bar_position = AbsolutePositionToBarPosition(new_bar_offset);
  369. SetBarPosition(OnBarChange(new_bar_position));
  370. }
  371. }
  372. break;
  373. case EventId::Dragend:
  374. {
  375. if (event.GetTargetElement() == parent)
  376. {
  377. bar->SetPseudoClass("active", false);
  378. }
  379. }
  380. break;
  381. case EventId::Keydown:
  382. {
  383. Core::Input::KeyIdentifier key_identifier = (Core::Input::KeyIdentifier) event.GetParameter< int >("key_identifier", 0);
  384. switch (key_identifier)
  385. {
  386. case Core::Input::KI_LEFT:
  387. if (orientation == HORIZONTAL) SetBarPosition(OnLineDecrement());
  388. break;
  389. case Core::Input::KI_UP:
  390. if (orientation == VERTICAL) SetBarPosition(OnLineDecrement());
  391. break;
  392. case Core::Input::KI_RIGHT:
  393. if (orientation == HORIZONTAL) SetBarPosition(OnLineIncrement());
  394. break;
  395. case Core::Input::KI_DOWN:
  396. if (orientation == VERTICAL) SetBarPosition(OnLineIncrement());
  397. break;
  398. default:
  399. break;
  400. }
  401. }
  402. break;
  403. case EventId::Focus:
  404. {
  405. if (event.GetTargetElement() == parent)
  406. bar->SetPseudoClass("focus", true);
  407. }
  408. break;
  409. case EventId::Blur:
  410. {
  411. if (event.GetTargetElement() == parent)
  412. bar->SetPseudoClass("focus", false);
  413. }
  414. break;
  415. default:
  416. break;
  417. }
  418. }
  419. float WidgetSlider::AbsolutePositionToBarPosition(float absolute_position) const
  420. {
  421. float new_bar_position = bar_position;
  422. if (orientation == HORIZONTAL)
  423. {
  424. const float edge_left = bar->GetBox().GetEdge(Core::Box::MARGIN, Core::Box::LEFT);
  425. const float edge_right = bar->GetBox().GetEdge(Core::Box::MARGIN, Core::Box::RIGHT);
  426. float traversable_track_length = track->GetBox().GetSize(Core::Box::CONTENT).x - bar->GetBox().GetSize(Core::Box::BORDER).x - edge_left - edge_right;
  427. if (traversable_track_length > 0)
  428. {
  429. float traversable_track_origin = track->GetAbsoluteOffset().x + edge_left;
  430. new_bar_position = (absolute_position - traversable_track_origin) / traversable_track_length;
  431. new_bar_position = Rml::Core::Math::Clamp(new_bar_position, 0.0f, 1.0f);
  432. }
  433. }
  434. else
  435. {
  436. const float edge_top = bar->GetBox().GetEdge(Core::Box::MARGIN, Core::Box::TOP);
  437. const float edge_bottom = bar->GetBox().GetEdge(Core::Box::MARGIN, Core::Box::BOTTOM);
  438. float traversable_track_length = track->GetBox().GetSize(Core::Box::CONTENT).y - bar->GetBox().GetSize(Core::Box::BORDER).y - edge_top - edge_bottom;
  439. if (traversable_track_length > 0)
  440. {
  441. float traversable_track_origin = track->GetAbsoluteOffset().y + edge_top;
  442. new_bar_position = (absolute_position - traversable_track_origin) / traversable_track_length;
  443. new_bar_position = Rml::Core::Math::Clamp(new_bar_position, 0.0f, 1.0f);
  444. }
  445. }
  446. return new_bar_position;
  447. }
  448. void WidgetSlider::PositionBar()
  449. {
  450. const Rml::Core::Vector2f track_dimensions = track->GetBox().GetSize();
  451. const Rml::Core::Vector2f bar_dimensions = bar->GetBox().GetSize(Core::Box::BORDER);
  452. if (orientation == VERTICAL)
  453. {
  454. const float edge_top = bar->GetBox().GetEdge(Core::Box::MARGIN, Core::Box::TOP);
  455. const float edge_bottom = bar->GetBox().GetEdge(Core::Box::MARGIN, Core::Box::BOTTOM);
  456. float traversable_track_length = track_dimensions.y - bar_dimensions.y - edge_top - edge_bottom;
  457. bar->SetOffset(
  458. Core::Vector2f(
  459. bar->GetBox().GetEdge(Core::Box::MARGIN, Core::Box::LEFT),
  460. track->GetRelativeOffset().y + edge_top + traversable_track_length * bar_position
  461. ),
  462. parent
  463. );
  464. }
  465. else
  466. {
  467. const float edge_left = bar->GetBox().GetEdge(Core::Box::MARGIN, Core::Box::LEFT);
  468. const float edge_right = bar->GetBox().GetEdge(Core::Box::MARGIN, Core::Box::RIGHT);
  469. float traversable_track_length = track_dimensions.x - bar_dimensions.x - edge_left - edge_right;
  470. bar->SetOffset(
  471. Core::Vector2f(
  472. track->GetRelativeOffset().x + edge_left + traversable_track_length * bar_position,
  473. bar->GetBox().GetEdge(Core::Box::MARGIN, Core::Box::TOP)
  474. ),
  475. parent
  476. );
  477. }
  478. }
  479. }
  480. }