[7cf5ddb] | 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 UI list
|
---|
| 34 | */
|
---|
| 35 |
|
---|
| 36 | #ifndef _UI_PRIVATE_LIST_H
|
---|
| 37 | #define _UI_PRIVATE_LIST_H
|
---|
| 38 |
|
---|
| 39 | #include <adt/list.h>
|
---|
| 40 | #include <gfx/color.h>
|
---|
| 41 | #include <gfx/coord.h>
|
---|
| 42 | #include <ipc/loc.h>
|
---|
| 43 | #include <ui/window.h>
|
---|
| 44 | #include <stdint.h>
|
---|
| 45 | #include <types/ui/list.h>
|
---|
| 46 |
|
---|
| 47 | /** List entry */
|
---|
| 48 | struct ui_list_entry {
|
---|
| 49 | /** Containing list */
|
---|
| 50 | struct ui_list *list;
|
---|
| 51 | /** Link to @c flist->entries */
|
---|
| 52 | link_t lentries;
|
---|
| 53 | /** Entry caption */
|
---|
| 54 | char *caption;
|
---|
| 55 | /** User argument */
|
---|
| 56 | void *arg;
|
---|
| 57 | /** Custom color or @c NULL to use default color */
|
---|
| 58 | gfx_color_t *color;
|
---|
| 59 | /** Custom background color or @c NULL to use default color */
|
---|
| 60 | gfx_color_t *bgcolor;
|
---|
| 61 | };
|
---|
| 62 |
|
---|
| 63 | /** UI list.
|
---|
| 64 | *
|
---|
| 65 | * Displays a scrollable list of entries.
|
---|
| 66 | */
|
---|
| 67 | typedef struct ui_list {
|
---|
| 68 | /** Base control object */
|
---|
| 69 | struct ui_control *control;
|
---|
| 70 |
|
---|
| 71 | /** Containing window */
|
---|
| 72 | ui_window_t *window;
|
---|
| 73 |
|
---|
| 74 | /** Callbacks */
|
---|
| 75 | struct ui_list_cb *cb;
|
---|
| 76 |
|
---|
| 77 | /** Callback argument */
|
---|
| 78 | void *cb_arg;
|
---|
| 79 |
|
---|
| 80 | /** List rectangle */
|
---|
| 81 | gfx_rect_t rect;
|
---|
| 82 |
|
---|
| 83 | /** Scrollbar */
|
---|
| 84 | struct ui_scrollbar *scrollbar;
|
---|
| 85 |
|
---|
| 86 | /** List entries (list of ui_list_entry_t) */
|
---|
| 87 | list_t entries;
|
---|
| 88 |
|
---|
| 89 | /** Number of entries */
|
---|
| 90 | size_t entries_cnt;
|
---|
| 91 |
|
---|
| 92 | /** First entry of current page */
|
---|
| 93 | ui_list_entry_t *page;
|
---|
| 94 |
|
---|
| 95 | /** Index of first entry of current page */
|
---|
| 96 | size_t page_idx;
|
---|
| 97 |
|
---|
| 98 | /** Cursor position */
|
---|
| 99 | ui_list_entry_t *cursor;
|
---|
| 100 |
|
---|
| 101 | /** Index of entry under cursor */
|
---|
| 102 | size_t cursor_idx;
|
---|
| 103 |
|
---|
| 104 | /** @c true iff the list is active */
|
---|
| 105 | bool active;
|
---|
| 106 | } ui_list_t;
|
---|
| 107 |
|
---|
| 108 | extern gfx_coord_t ui_list_entry_height(ui_list_t *);
|
---|
| 109 | extern errno_t ui_list_entry_paint(ui_list_entry_t *, size_t);
|
---|
| 110 | extern errno_t ui_list_paint(ui_list_t *);
|
---|
| 111 | extern ui_evclaim_t ui_list_kbd_event(ui_list_t *, kbd_event_t *);
|
---|
| 112 | extern ui_evclaim_t ui_list_pos_event(ui_list_t *, pos_event_t *);
|
---|
| 113 | extern unsigned ui_list_page_size(ui_list_t *);
|
---|
| 114 | extern void ui_list_inside_rect(ui_list_t *, gfx_rect_t *);
|
---|
| 115 | extern void ui_list_scrollbar_rect(ui_list_t *, gfx_rect_t *);
|
---|
| 116 | extern gfx_coord_t ui_list_scrollbar_pos(ui_list_t *);
|
---|
| 117 | extern void ui_list_scrollbar_update(ui_list_t *);
|
---|
| 118 | extern void ui_list_clear_entries(ui_list_t *);
|
---|
| 119 | extern ui_list_entry_t *ui_list_page_nth_entry(ui_list_t *,
|
---|
| 120 | size_t, size_t *);
|
---|
| 121 | extern void ui_list_cursor_move(ui_list_t *, ui_list_entry_t *,
|
---|
| 122 | size_t);
|
---|
| 123 | extern void ui_list_cursor_up(ui_list_t *);
|
---|
| 124 | extern void ui_list_cursor_down(ui_list_t *);
|
---|
| 125 | extern void ui_list_cursor_top(ui_list_t *);
|
---|
| 126 | extern void ui_list_cursor_bottom(ui_list_t *);
|
---|
| 127 | extern void ui_list_page_up(ui_list_t *);
|
---|
| 128 | extern void ui_list_page_down(ui_list_t *);
|
---|
| 129 | extern void ui_list_scroll_up(ui_list_t *);
|
---|
| 130 | extern void ui_list_scroll_down(ui_list_t *);
|
---|
| 131 | extern void ui_list_scroll_page_up(ui_list_t *);
|
---|
| 132 | extern void ui_list_scroll_page_down(ui_list_t *);
|
---|
| 133 | extern void ui_list_scroll_pos(ui_list_t *, size_t);
|
---|
| 134 | extern void ui_list_activate_req(ui_list_t *);
|
---|
| 135 | extern void ui_list_selected(ui_list_entry_t *);
|
---|
| 136 | extern int ui_list_entry_ptr_cmp(const void *, const void *);
|
---|
| 137 | extern size_t ui_list_entry_get_idx(ui_list_entry_t *);
|
---|
[c0757e1f] | 138 | extern void ui_list_entry_destroy(ui_list_entry_t *);
|
---|
[7cf5ddb] | 139 |
|
---|
| 140 | #endif
|
---|
| 141 |
|
---|
| 142 | /** @}
|
---|
| 143 | */
|
---|