mirror of
				https://codeberg.org/adnano/wmenu.git
				synced 2025-11-03 09:01:46 -05:00 
			
		
		
		
	Simplify match scrolling
This commit is contained in:
		
							parent
							
								
									906b55019e
								
							
						
					
					
						commit
						d23a2c563a
					
				
					 1 changed files with 28 additions and 60 deletions
				
			
		
							
								
								
									
										80
									
								
								main.c
									
										
									
									
									
								
							
							
						
						
									
										80
									
								
								main.c
									
										
									
									
									
								
							| 
						 | 
					@ -183,79 +183,47 @@ void scroll_matches(struct menu_state *state) {
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (state->leftmost == NULL && state->rightmost == NULL) {
 | 
				
			||||||
 | 
							state->leftmost = state->matches;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (state->vertical) {
 | 
						if (state->vertical) {
 | 
				
			||||||
		if (state->leftmost == NULL) {
 | 
							if (state->leftmost == NULL) {
 | 
				
			||||||
			state->leftmost = state->matches;
 | 
								struct menu_item *item = state->rightmost;
 | 
				
			||||||
			if (state->rightmost == NULL) {
 | 
								for (int i = 1; item->left && i < state->lines; i++) {
 | 
				
			||||||
				int offs = 0;
 | 
									item = item->left;
 | 
				
			||||||
				struct menu_item *item;
 | 
					 | 
				
			||||||
				for (item = state->matches; item->left != state->selection; item = item->right) {
 | 
					 | 
				
			||||||
					offs += state->line_height;
 | 
					 | 
				
			||||||
					if (offs >= state->height) {
 | 
					 | 
				
			||||||
						state->leftmost = item->left;
 | 
					 | 
				
			||||||
						offs = state->height - offs;
 | 
					 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
				}
 | 
								state->leftmost = item;
 | 
				
			||||||
			} else {
 | 
							} else if (state->rightmost == NULL) {
 | 
				
			||||||
				int offs = 0;
 | 
								struct menu_item *item = state->leftmost;
 | 
				
			||||||
				struct menu_item *item;
 | 
								for (int i = 1; item->right && i < state->lines; i++) {
 | 
				
			||||||
				for (item = state->rightmost; item; item = item->left) {
 | 
									item = item->right;
 | 
				
			||||||
					offs += state->line_height;
 | 
					 | 
				
			||||||
					if (offs >= state->height) {
 | 
					 | 
				
			||||||
						state->leftmost = item->right;
 | 
					 | 
				
			||||||
						break;
 | 
					 | 
				
			||||||
					}
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if (state->rightmost == NULL) {
 | 
					 | 
				
			||||||
			state->rightmost = state->matches;
 | 
					 | 
				
			||||||
			int offs = 0;
 | 
					 | 
				
			||||||
			struct menu_item *item;
 | 
					 | 
				
			||||||
			for (item = state->leftmost; item; item = item->right) {
 | 
					 | 
				
			||||||
				offs += state->line_height;
 | 
					 | 
				
			||||||
				if (offs >= state->height) {
 | 
					 | 
				
			||||||
					break;
 | 
					 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			state->rightmost = item;
 | 
								state->rightmost = item;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		// Calculate available space
 | 
							// Calculate available space
 | 
				
			||||||
		int padding = state->padding;
 | 
							int max_width = state->width - state->inputw - state->promptw
 | 
				
			||||||
		int width = state->width - state->inputw - state->promptw
 | 
					 | 
				
			||||||
			- state->left_arrow - state->right_arrow;
 | 
								- state->left_arrow - state->right_arrow;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (state->leftmost == NULL) {
 | 
							if (state->leftmost == NULL) {
 | 
				
			||||||
			state->leftmost = state->matches;
 | 
								state->leftmost = state->rightmost;
 | 
				
			||||||
			if (state->rightmost == NULL) {
 | 
								int total_width = 0;
 | 
				
			||||||
				int offs = 0;
 | 
					 | 
				
			||||||
				struct menu_item *item;
 | 
					 | 
				
			||||||
				for (item = state->matches; item->left != state->selection; item = item->right) {
 | 
					 | 
				
			||||||
					offs += item->width + 2 * padding;
 | 
					 | 
				
			||||||
					if (offs >= width) {
 | 
					 | 
				
			||||||
						state->leftmost = item->left;
 | 
					 | 
				
			||||||
						offs = width - offs;
 | 
					 | 
				
			||||||
					}
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			} else {
 | 
					 | 
				
			||||||
				int offs = 0;
 | 
					 | 
				
			||||||
			struct menu_item *item;
 | 
								struct menu_item *item;
 | 
				
			||||||
			for (item = state->rightmost; item; item = item->left) {
 | 
								for (item = state->rightmost; item; item = item->left) {
 | 
				
			||||||
					offs += item->width + 2 * padding;
 | 
									total_width += item->width + 2 * state->padding;
 | 
				
			||||||
					if (offs >= width) {
 | 
									if (total_width > max_width) {
 | 
				
			||||||
						state->leftmost = item->right;
 | 
					 | 
				
			||||||
					break;
 | 
										break;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
									state->leftmost = item;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			}
 | 
							} else if (state->rightmost == NULL) {
 | 
				
			||||||
		}
 | 
								state->rightmost = state->leftmost;
 | 
				
			||||||
		if (state->rightmost == NULL) {
 | 
								int total_width = 0;
 | 
				
			||||||
			state->rightmost = state->matches;
 | 
					 | 
				
			||||||
			int offs = 0;
 | 
					 | 
				
			||||||
			struct menu_item *item;
 | 
								struct menu_item *item;
 | 
				
			||||||
			for (item = state->leftmost; item; item = item->right) {
 | 
								for (item = state->leftmost; item; item = item->right) {
 | 
				
			||||||
				offs += item->width + 2 * padding;
 | 
									total_width += item->width + 2 * state->padding;
 | 
				
			||||||
				if (offs >= width) {
 | 
									if (total_width > max_width) {
 | 
				
			||||||
					break;
 | 
										break;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				state->rightmost = item;
 | 
									state->rightmost = item;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue