|
1 | | -use iced::widget::{column, pick_list, row, scrollable, text}; |
| 1 | +use iced::widget::{checkbox, column, pick_list, row, scrollable, text}; |
2 | 2 | use iced::{Element, Length}; |
| 3 | +use wayscriber::config::{ |
| 4 | + ResolvedToolbarItems, ToolbarItemCategory, ToolbarItemDefinition, ToolbarItemSurface, |
| 5 | + ToolbarItemsConfig, toolbar_item_definitions, |
| 6 | +}; |
3 | 7 |
|
4 | 8 | use crate::app::scroll::CONTENT_SCROLL_ID; |
5 | 9 | use crate::app::state::ConfiguratorApp; |
@@ -215,4 +219,109 @@ impl ConfiguratorApp { |
215 | 219 |
|
216 | 220 | scrollable(column).id(CONTENT_SCROLL_ID).into() |
217 | 221 | } |
| 222 | + |
| 223 | + pub(super) fn ui_toolbar_visibility_tab(&self) -> Element<'_, Message> { |
| 224 | + let column = column![ |
| 225 | + text("Toolbar Visibility").size(18), |
| 226 | + text("Checked items are shown. Uncheck an item to hide it from toolbar sizing, drawing, and hit testing. Existing section toggles and mode overrides can still hide checked items.").size(12), |
| 227 | + toolbar_item_visibility_section( |
| 228 | + &self.draft.ui_toolbar_items, |
| 229 | + &self.defaults.ui_toolbar_items, |
| 230 | + ), |
| 231 | + ] |
| 232 | + .spacing(12); |
| 233 | + |
| 234 | + scrollable(column).id(CONTENT_SCROLL_ID).into() |
| 235 | + } |
| 236 | +} |
| 237 | + |
| 238 | +fn toolbar_item_visibility_section<'a>( |
| 239 | + items: &ToolbarItemsConfig, |
| 240 | + defaults: &ToolbarItemsConfig, |
| 241 | +) -> Element<'a, Message> { |
| 242 | + let resolved = items.resolved(); |
| 243 | + let default_resolved = defaults.resolved(); |
| 244 | + let mut rows = column![text("Items").size(16)].spacing(8); |
| 245 | + let mut current_surface = None; |
| 246 | + let mut current_category = None; |
| 247 | + |
| 248 | + if !resolved.unknown_hidden.is_empty() { |
| 249 | + rows = rows.push( |
| 250 | + text(format!( |
| 251 | + "Preserving {} unknown toolbar item id(s) from config.", |
| 252 | + resolved.unknown_hidden.len() |
| 253 | + )) |
| 254 | + .size(12), |
| 255 | + ); |
| 256 | + } |
| 257 | + |
| 258 | + for definition in toolbar_item_definitions() { |
| 259 | + if current_surface != Some(definition.surface) { |
| 260 | + current_surface = Some(definition.surface); |
| 261 | + current_category = None; |
| 262 | + rows = rows.push(text(toolbar_item_surface_label(definition.surface)).size(14)); |
| 263 | + } |
| 264 | + if current_category != Some(definition.category) { |
| 265 | + current_category = Some(definition.category); |
| 266 | + rows = rows.push(text(toolbar_item_category_label(definition.category)).size(13)); |
| 267 | + } |
| 268 | + |
| 269 | + rows = rows.push(toolbar_item_visibility_row( |
| 270 | + definition, |
| 271 | + &resolved, |
| 272 | + &default_resolved, |
| 273 | + )); |
| 274 | + } |
| 275 | + |
| 276 | + rows.into() |
| 277 | +} |
| 278 | + |
| 279 | +fn toolbar_item_visibility_row<'a>( |
| 280 | + definition: &ToolbarItemDefinition, |
| 281 | + resolved: &ResolvedToolbarItems, |
| 282 | + defaults: &ResolvedToolbarItems, |
| 283 | +) -> Element<'a, Message> { |
| 284 | + let id = definition.id; |
| 285 | + let visible = !resolved.is_hidden(id); |
| 286 | + let default = format!( |
| 287 | + "default: {}", |
| 288 | + visibility_override_label(!defaults.is_hidden(id)) |
| 289 | + ); |
| 290 | + |
| 291 | + row![ |
| 292 | + checkbox(visible) |
| 293 | + .label(definition.label) |
| 294 | + .on_toggle(move |value| Message::ToolbarItemVisibilityChanged(id, value)), |
| 295 | + text(definition.id.as_str()).size(12).width(Length::Fill), |
| 296 | + text(default).size(12), |
| 297 | + ] |
| 298 | + .spacing(12) |
| 299 | + .align_y(iced::Alignment::Center) |
| 300 | + .into() |
| 301 | +} |
| 302 | + |
| 303 | +fn visibility_override_label(visible: bool) -> &'static str { |
| 304 | + if visible { "shown" } else { "hidden" } |
| 305 | +} |
| 306 | + |
| 307 | +fn toolbar_item_surface_label(surface: ToolbarItemSurface) -> &'static str { |
| 308 | + match surface { |
| 309 | + ToolbarItemSurface::Top => "Top toolbar", |
| 310 | + ToolbarItemSurface::Side => "Side toolbar", |
| 311 | + } |
| 312 | +} |
| 313 | + |
| 314 | +fn toolbar_item_category_label(category: ToolbarItemCategory) -> &'static str { |
| 315 | + match category { |
| 316 | + ToolbarItemCategory::Chrome => "Toolbar controls", |
| 317 | + ToolbarItemCategory::Tool => "Tools", |
| 318 | + ToolbarItemCategory::Utility => "Utilities", |
| 319 | + ToolbarItemCategory::Group => "Sections", |
| 320 | + ToolbarItemCategory::Action => "Actions", |
| 321 | + ToolbarItemCategory::Page => "Pages", |
| 322 | + ToolbarItemCategory::Board => "Boards", |
| 323 | + ToolbarItemCategory::Setting => "Settings", |
| 324 | + ToolbarItemCategory::Session => "Sessions", |
| 325 | + ToolbarItemCategory::ToolOption => "Tool options", |
| 326 | + } |
218 | 327 | } |
0 commit comments