25 #include "eng3d/ui/scrollbar.hpp"
26 #include "eng3d/ui/button.hpp"
27 #include "eng3d/ui/ui.hpp"
28 #include "eng3d/state.hpp"
29 #include "eng3d/texture.hpp"
30 #include "eng3d/log.hpp"
36 this->
set_on_drag([
this](glm::ivec2 start_pos, glm::ivec2 current_pos) {
37 assert(this->
parent !=
nullptr);
40 const float parent_height = glm::max(
static_cast<float>(y_bounds.y - y_bounds.x), 1.f);
42 if (start_pos == current_pos) {
43 this->start_drag_scroll = scrolled;
45 const float y_diff = current_pos.y - start_pos.y;
47 const auto btn_height = 20;
49 const float track_height = this->
parent->
height - btn_height * 3;
50 const auto ratio = (-y_diff / track_height) * parent_height;
58 this->
current_texture = s.tex_man.load(s.package_man.get_unique(
"gfx/scrollbar_drag.png"));
65 this->
current_texture = s.tex_man.load(s.package_man.get_unique(
"gfx/scrollbar.png"));
71 auto& up_btn = this->make_widget<UI::Button>(0, 0, 20, 20);
75 const float ratio =
static_cast<float>(y_bounds.y - y_bounds.x) /
static_cast<float>(this->
height);
80 up_btn.current_texture = s.tex_man.load(s.package_man.get_unique(
"gfx/scrollbar_up.png"));
82 auto& down_btn = this->make_widget<UI::Button>(0, this->
height - 20, 20, 20);
86 const float ratio =
static_cast<float>(y_bounds.y - y_bounds.x) /
static_cast<float>(this->
height);
91 down_btn.current_texture = s.tex_man.load(s.package_man.get_unique(
"gfx/scrollbar_down.png"));
93 this->thumb_btn = &this->make_widget<UI::ScrollbarThumb>(0, 0);
99 const auto y_bounds = this->parent->get_y_bounds();
100 const float parent_height = glm::max(
static_cast<float>(y_bounds.y - y_bounds.x), 1.f);
101 const auto btn_height = 20;
103 const float track_height = this->height - btn_height * 2;
105 const auto scrolled = glm::abs<float>(this->parent->scrolled_y) / parent_height;
106 this->thumb_btn->set_y(btn_height + scrolled * (track_height - btn_height));
107 this->thumb_btn->height = btn_height;
static State & get_instance()
WidgetType
The type of the widget, some widgets share types between them to keep simplicity.