1 #ifndef GRAPHICS_SCROLLBAR_H 2 #define GRAPHICS_SCROLLBAR_H 3 4 #include "graphics/color.h" 5 #include "graphics/font.h" 6 #include "input/mouse.h" 7 8 typedef struct { 9 int x; 10 int y; 11 int height; 12 void (*on_scroll_callback)(void); 13 int dot_padding; 14 int always_visible; 15 int max_scroll_position; 16 int scroll_position; 17 int is_dragging_scroll; 18 int scroll_position_drag; 19 } scrollbar_type; 20 21 /** 22 * Initializes the scrollbar 23 * @param scrollbar Scrollbar 24 * @param scroll_position Scroll position to set 25 * @param max_scroll_position Max position 26 */ 27 void scrollbar_init(scrollbar_type *scrollbar, int scroll_position, int max_scroll_position); 28 29 /** 30 * Resets the text to the specified scroll position and forces recalculation of lines 31 * @param scrollbar Scrollbar 32 * @param scroll_position Scroll position to set 33 */ 34 void scrollbar_reset(scrollbar_type *scrollbar, int scroll_position); 35 36 /** 37 * Update the max position, adjusting the scroll position if necessary 38 * @param scrollbar Scrollbar 39 * @param max_scroll_position New max position 40 */ 41 void scrollbar_update_max(scrollbar_type *scrollbar, int max_scroll_position); 42 43 /** 44 * Draws the scrollbar 45 * @param scrollbar Scrollbar 46 */ 47 void scrollbar_draw(scrollbar_type *scrollbar); 48 49 /** 50 * Handles mouse interaction with the scrollbar and scroll wheel 51 * @param scrollbar Scrollbar 52 * @param m Mouse state 53 * @return True if any interaction was handled 54 */ 55 int scrollbar_handle_mouse(scrollbar_type *scrollbar, const mouse *m); 56 57 #endif // GRAPHICS_SCROLLBAR_H 58