1 | /*
|
---|
2 | * Copyright (c) 2023 Jiri Svoboda
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | /** @addtogroup libui
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 | /**
|
---|
33 | * @file Scrollbar structure
|
---|
34 | *
|
---|
35 | */
|
---|
36 |
|
---|
37 | #ifndef _UI_PRIVATE_SCROLLBAR_H
|
---|
38 | #define _UI_PRIVATE_SCROLLBAR_H
|
---|
39 |
|
---|
40 | #include <gfx/coord.h>
|
---|
41 | #include <stdbool.h>
|
---|
42 | #include <types/ui/scrollbar.h>
|
---|
43 |
|
---|
44 | /** Actual structure of scrollbar.
|
---|
45 | *
|
---|
46 | * This is private to libui.
|
---|
47 | */
|
---|
48 | struct ui_scrollbar {
|
---|
49 | /** Base control object */
|
---|
50 | struct ui_control *control;
|
---|
51 | /** UI */
|
---|
52 | struct ui *ui;
|
---|
53 | /** UI window containing scrollbar */
|
---|
54 | struct ui_window *window;
|
---|
55 | /** Callbacks */
|
---|
56 | struct ui_scrollbar_cb *cb;
|
---|
57 | /** Callback argument */
|
---|
58 | void *arg;
|
---|
59 | /** Scrollbar rectangle */
|
---|
60 | gfx_rect_t rect;
|
---|
61 | /** Scrollbar direction */
|
---|
62 | ui_scrollbar_dir_t dir;
|
---|
63 | /** Thumb length */
|
---|
64 | gfx_coord_t thumb_len;
|
---|
65 | /** Up button */
|
---|
66 | struct ui_pbutton *up_btn;
|
---|
67 | /** Down button */
|
---|
68 | struct ui_pbutton *down_btn;
|
---|
69 | /** Thumb is currently held down */
|
---|
70 | bool thumb_held;
|
---|
71 | /** Upper trough is currently held down */
|
---|
72 | bool upper_trough_held;
|
---|
73 | /** Pointer is inside upper trough */
|
---|
74 | bool upper_trough_inside;
|
---|
75 | /** Lower trough is currently held down */
|
---|
76 | bool lower_trough_held;
|
---|
77 | /** Pointer is inside lower trough */
|
---|
78 | bool lower_trough_inside;
|
---|
79 | /** Position where thumb was pressed */
|
---|
80 | gfx_coord2_t press_pos;
|
---|
81 | /** Last thumb position */
|
---|
82 | gfx_coord_t last_pos;
|
---|
83 | /** Thumb position */
|
---|
84 | gfx_coord_t pos;
|
---|
85 | /** Last cursor position (when trough is held) */
|
---|
86 | gfx_coord2_t last_curs_pos;
|
---|
87 | };
|
---|
88 |
|
---|
89 | /** Scrollbar geometry.
|
---|
90 | *
|
---|
91 | * Computed rectangles of scrollbar elements.
|
---|
92 | */
|
---|
93 | typedef struct {
|
---|
94 | /** Up button rectangle */
|
---|
95 | gfx_rect_t up_btn_rect;
|
---|
96 | /** Trough rectangle */
|
---|
97 | gfx_rect_t trough_rect;
|
---|
98 | /** Upper trough rectangle */
|
---|
99 | gfx_rect_t upper_trough_rect;
|
---|
100 | /** Thumb rectangle */
|
---|
101 | gfx_rect_t thumb_rect;
|
---|
102 | /** Lower trough rectangle */
|
---|
103 | gfx_rect_t lower_trough_rect;
|
---|
104 | /** Down button rectangle */
|
---|
105 | gfx_rect_t down_btn_rect;
|
---|
106 | } ui_scrollbar_geom_t;
|
---|
107 |
|
---|
108 | extern errno_t ui_scrollbar_paint_gfx(ui_scrollbar_t *);
|
---|
109 | extern errno_t ui_scrollbar_paint_text(ui_scrollbar_t *);
|
---|
110 | extern void ui_scrollbar_get_geom(ui_scrollbar_t *, ui_scrollbar_geom_t *);
|
---|
111 |
|
---|
112 | #endif
|
---|
113 |
|
---|
114 | /** @}
|
---|
115 | */
|
---|