Line data Source code
1 : /* File: gui_sketch_result_list.inl; Copyright and License: see below */ 2 : 3 : #include "u8/u8_log.h" 4 : 5 0 : static inline void gui_sketch_result_list_load_data( gui_sketch_result_list_t *this_, 6 : const pos_scroll_page_t *requested_page, 7 : uint32_t result_buffer_start, 8 : const data_search_result_list_t *result_list, 9 : bool result_buffer_more_after, 10 : data_database_reader_t *db_reader ) 11 : { 12 0 : assert( requested_page != NULL ); 13 0 : assert( result_list != NULL ); 14 0 : assert( db_reader != NULL ); 15 : 16 : /* reset page */ 17 0 : pos_search_result_page_reinit( &((*this_).page), result_buffer_start ); 18 0 : (*this_).requested_page = *requested_page; 19 : 20 : /* fill page */ 21 0 : u8_error_t err = U8_ERROR_NONE; 22 0 : const uint_fast32_t length = data_search_result_list_get_length( result_list ); 23 0 : for ( uint_fast32_t index = 0; index < length; index ++ ) 24 : { 25 0 : data_search_result_t const *const src_res = data_search_result_list_get_const( result_list, index ); 26 0 : err |= pos_search_result_page_add_search_result( &((*this_).page), src_res ); 27 : } 28 0 : if ( err != U8_ERROR_NONE ) 29 : { 30 0 : U8_LOG_ERROR( "Not all search results taken over by gui_sketch_result_list_t widget." ); 31 : } 32 : 33 : /* store if there is more list-entries after this page */ 34 0 : pos_search_result_page_set_buffer_more_after( &((*this_).page), result_buffer_more_after ); 35 0 : } 36 : 37 0 : static inline void gui_sketch_result_list_invalidate_data( gui_sketch_result_list_t *this_ ) 38 : { 39 : /* reset page */ 40 0 : pos_search_result_page_reinit( &((*this_).page), 0 /* buffer_start */ ); 41 0 : } 42 : 43 0 : static inline pos_scroll_page_t gui_sketch_result_list_get_prev_page( gui_sketch_result_list_t *this_ ) 44 : { 45 0 : const int_fast32_t start = pos_search_result_page_get_page_start( &((*this_).page) ); 46 0 : return pos_scroll_page_new( u8_i32_max2( 0, start - 1 ), true /*backwards*/ ); 47 : } 48 : 49 0 : static inline pos_scroll_page_t gui_sketch_result_list_get_next_page( gui_sketch_result_list_t *this_ ) 50 : { 51 0 : const int_fast32_t start = pos_search_result_page_get_page_start( &((*this_).page) ); 52 0 : const uint_fast32_t length = pos_search_result_page_get_page_length( &((*this_).page) ); 53 0 : return pos_scroll_page_new( start + length, false /*backwards*/ ); 54 : } 55 : 56 : static inline shape_int_rectangle_t gui_sketch_result_list_get_bounds( gui_sketch_result_list_t *this_ ) 57 : { 58 : return (*this_).bounds; 59 : } 60 : 61 0 : static inline void gui_sketch_result_list_set_bounds( gui_sketch_result_list_t *this_, shape_int_rectangle_t bounds ) 62 : { 63 0 : (*this_).bounds = bounds; 64 0 : } 65 : 66 0 : static inline bool gui_sketch_result_list_is_visible( gui_sketch_result_list_t *this_ ) 67 : { 68 0 : return (*this_).visible; 69 : } 70 : 71 0 : static inline void gui_sketch_result_list_set_visible( gui_sketch_result_list_t *this_, bool visible ) 72 : { 73 0 : (*this_).visible = visible; 74 0 : } 75 : 76 0 : static inline void gui_sketch_result_list_get_visible_diagrams( const gui_sketch_result_list_t *this_, 77 : data_small_set_t *out_diagram_id_list ) 78 : { 79 0 : data_small_set_reinit( out_diagram_id_list ); 80 0 : const uint_fast32_t page_start = pos_search_result_page_get_page_start( &((*this_).page) ); 81 0 : const uint_fast32_t page_length = pos_search_result_page_get_page_length( &((*this_).page) ); 82 0 : assert( page_length <= POS_SEARCH_RESULT_PAGE_MAX_PAGE_SIZE ); 83 0 : for ( uint_fast32_t idx = 0; idx < page_length; idx ++ ) 84 : { 85 0 : const pos_search_result_t *const pos_element = pos_search_result_page_get_search_result_layout_const( &((*this_).page), page_start + idx ); 86 0 : const data_search_result_t *const data_element = pos_search_result_get_data_const( pos_element ); 87 0 : const data_id_t element_diag_id = data_search_result_get_diagram_id( data_element ); 88 0 : const u8_error_t set_full = data_small_set_add_obj( out_diagram_id_list, element_diag_id ); 89 0 : if ( U8_ERROR_NONE != set_full ) 90 : { 91 0 : U8_LOG_ANOMALY("A search result contains more elements than data_small_set_t can contain."); 92 : } 93 : } 94 0 : } 95 : 96 0 : static inline void gui_sketch_result_list_get_button_at_pos( const gui_sketch_result_list_t *this_, 97 : int32_t x, 98 : int32_t y, 99 : gui_sketch_action_t *out_action_id ) 100 : { 101 0 : assert ( NULL != out_action_id ); 102 : 103 : const shape_int_rectangle_t *const prev_box 104 0 : = pos_search_result_page_get_button_prev_box_const( &((*this_).page) ); 105 : const shape_int_rectangle_t *const next_box 106 0 : = pos_search_result_page_get_button_next_box_const( &((*this_).page) ); 107 : 108 0 : if ( shape_int_rectangle_contains( prev_box, x, y ) && pos_search_result_page_has_prev_page( &((*this_).page) ) ) 109 : { 110 0 : *out_action_id = GUI_SKETCH_ACTION_PREVIOUS_PAGE; 111 : } 112 0 : else if ( shape_int_rectangle_contains( next_box, x, y ) && pos_search_result_page_has_next_page( &((*this_).page) ) ) 113 : { 114 0 : *out_action_id = GUI_SKETCH_ACTION_NEXT_PAGE; 115 : } 116 : else 117 : { 118 0 : *out_action_id = GUI_SKETCH_ACTION_NONE; 119 : } 120 0 : } 121 : 122 0 : static inline void gui_sketch_result_list_get_object_id_at_pos( const gui_sketch_result_list_t *this_, 123 : int32_t x, 124 : int32_t y, 125 : data_id_t* out_selected_id, 126 : data_id_t* out_diagram_id ) 127 : { 128 0 : assert( out_selected_id != NULL ); 129 0 : assert( out_diagram_id != NULL ); 130 : 131 : /* default in case no object found */ 132 0 : data_id_init_void( out_selected_id ); 133 0 : data_id_init_void( out_diagram_id ); 134 : 135 : /* search object */ 136 0 : if ( shape_int_rectangle_contains( &((*this_).bounds), x, y ) ) 137 : { 138 0 : const uint_fast32_t page_start = pos_search_result_page_get_page_start( &((*this_).page) ); 139 0 : const uint_fast32_t page_length = pos_search_result_page_get_page_length( &((*this_).page) ); 140 0 : assert( page_length <= POS_SEARCH_RESULT_PAGE_MAX_PAGE_SIZE ); 141 0 : for ( uint_fast32_t idx = 0; idx < page_length; idx ++ ) 142 : { 143 0 : const pos_search_result_t *const element = pos_search_result_page_get_search_result_layout_const( &((*this_).page), page_start + idx ); 144 0 : const shape_int_rectangle_t *icon_box = pos_search_result_get_icon_box_const( element ); 145 0 : const shape_int_rectangle_t *label_box = pos_search_result_get_label_box_const( element ); 146 : 147 0 : if ( shape_int_rectangle_contains( icon_box, x, y ) || shape_int_rectangle_contains( label_box, x, y ) ) 148 : { 149 0 : const data_search_result_t *const at_pos = pos_search_result_get_data_const( element ); 150 0 : data_id_copy( out_selected_id, data_search_result_get_match_id_const( at_pos ) ); 151 0 : data_id_copy( out_diagram_id, data_search_result_get_diagram_id_const( at_pos ) ); 152 0 : break; 153 : } 154 : } 155 : } 156 0 : } 157 : 158 : 159 : /* 160 : Copyright 2018-2025 Andreas Warnke 161 : 162 : Licensed under the Apache License, Version 2.0 (the "License"); 163 : you may not use this file except in compliance with the License. 164 : You may obtain a copy of the License at 165 : 166 : http://www.apache.org/licenses/LICENSE-2.0 167 : 168 : Unless required by applicable law or agreed to in writing, software 169 : distributed under the License is distributed on an "AS IS" BASIS, 170 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 171 : See the License for the specific language governing permissions and 172 : limitations under the License. 173 : */