|
1 | | -use iced::widget::{checkbox, column, pick_list, row, scrollable, text}; |
| 1 | +use std::collections::BTreeSet; |
| 2 | + |
| 3 | +use iced::widget::{button, checkbox, column, pick_list, row, scrollable, text}; |
2 | 4 | use iced::{Element, Length}; |
3 | 5 | use wayscriber::config::{ |
4 | | - ResolvedToolbarItems, ToolbarItemCategory, ToolbarItemDefinition, ToolbarItemSurface, |
5 | | - ToolbarItemsConfig, toolbar_item_definitions, |
| 6 | + ResolvedToolbarItems, ToolbarItemCategory, ToolbarItemDefinition, ToolbarItemOrderGroup, |
| 7 | + ToolbarItemSurface, ToolbarItemsConfig, toolbar_item_definitions, toolbar_item_order_group, |
6 | 8 | }; |
7 | 9 |
|
8 | 10 | use crate::app::scroll::CONTENT_SCROLL_ID; |
@@ -255,7 +257,7 @@ fn toolbar_item_visibility_section<'a>( |
255 | 257 | ); |
256 | 258 | } |
257 | 259 |
|
258 | | - for definition in toolbar_item_definitions() { |
| 260 | + for definition in toolbar_item_definitions_for_display(&resolved) { |
259 | 261 | if current_surface != Some(definition.surface) { |
260 | 262 | current_surface = Some(definition.surface); |
261 | 263 | current_category = None; |
@@ -287,17 +289,81 @@ fn toolbar_item_visibility_row<'a>( |
287 | 289 | "default: {}", |
288 | 290 | visibility_override_label(!defaults.is_hidden(id)) |
289 | 291 | ); |
| 292 | + let order_group = configurator_order_group(definition); |
| 293 | + let order = order_group.and_then(|group| { |
| 294 | + let index = resolved.order.index_of(group, id)?; |
| 295 | + let len = resolved.order.ordered_ids(group).len(); |
| 296 | + Some((group, index, index > 0, index + 1 < len)) |
| 297 | + }); |
290 | 298 |
|
291 | | - row![ |
| 299 | + let mut cells = row![ |
292 | 300 | checkbox(visible) |
293 | 301 | .label(definition.label) |
294 | 302 | .on_toggle(move |value| Message::ToolbarItemVisibilityChanged(id, value)), |
295 | 303 | text(definition.id.as_str()).size(12).width(Length::Fill), |
296 | | - text(default).size(12), |
297 | 304 | ] |
298 | 305 | .spacing(12) |
299 | | - .align_y(iced::Alignment::Center) |
300 | | - .into() |
| 306 | + .align_y(iced::Alignment::Center); |
| 307 | + if let Some((group, _, can_move_up, can_move_down)) = order { |
| 308 | + let up = if can_move_up { |
| 309 | + button(text("^")).on_press(Message::ToolbarItemMoveRequested(group, id, -1)) |
| 310 | + } else { |
| 311 | + button(text("^")) |
| 312 | + }; |
| 313 | + let down = if can_move_down { |
| 314 | + button(text("v")).on_press(Message::ToolbarItemMoveRequested(group, id, 1)) |
| 315 | + } else { |
| 316 | + button(text("v")) |
| 317 | + }; |
| 318 | + cells = cells |
| 319 | + .push(up) |
| 320 | + .push(down) |
| 321 | + .push(button(text("Reset")).on_press(Message::ToolbarItemOrderReset(group))); |
| 322 | + } |
| 323 | + cells.push(text(default).size(12)).into() |
| 324 | +} |
| 325 | + |
| 326 | +fn toolbar_item_definitions_for_display( |
| 327 | + resolved: &ResolvedToolbarItems, |
| 328 | +) -> Vec<&'static ToolbarItemDefinition> { |
| 329 | + let mut result = Vec::new(); |
| 330 | + let mut emitted = BTreeSet::new(); |
| 331 | + let mut emitted_groups = BTreeSet::new(); |
| 332 | + |
| 333 | + for definition in toolbar_item_definitions() { |
| 334 | + if let Some(group) = configurator_order_group(definition) { |
| 335 | + if emitted_groups.insert(group) { |
| 336 | + for id in resolved.order.ordered_ids(group) { |
| 337 | + if let Some(ordered_definition) = toolbar_item_definitions() |
| 338 | + .iter() |
| 339 | + .find(|candidate| candidate.id == *id) |
| 340 | + && configurator_order_group(ordered_definition) == Some(group) |
| 341 | + { |
| 342 | + result.push(ordered_definition); |
| 343 | + emitted.insert(ordered_definition.id); |
| 344 | + } |
| 345 | + } |
| 346 | + } |
| 347 | + if emitted.contains(&definition.id) { |
| 348 | + continue; |
| 349 | + } |
| 350 | + } |
| 351 | + result.push(definition); |
| 352 | + emitted.insert(definition.id); |
| 353 | + } |
| 354 | + |
| 355 | + result |
| 356 | +} |
| 357 | + |
| 358 | +fn configurator_order_group(definition: &ToolbarItemDefinition) -> Option<ToolbarItemOrderGroup> { |
| 359 | + let group = toolbar_item_order_group(definition)?; |
| 360 | + matches!( |
| 361 | + group, |
| 362 | + ToolbarItemOrderGroup::TopTools |
| 363 | + | ToolbarItemOrderGroup::TopControls |
| 364 | + | ToolbarItemOrderGroup::SideSections |
| 365 | + ) |
| 366 | + .then_some(group) |
301 | 367 | } |
302 | 368 |
|
303 | 369 | fn visibility_override_label(visible: bool) -> &'static str { |
|
0 commit comments