pub enum ThemePreference {
System,
Light,
Dark,
}Variants§
Implementations§
Source§impl ThemePreference
impl ThemePreference
pub const ALL: [Self; 3]
pub const fn as_str(self) -> &'static str
pub const fn label(self) -> &'static str
Sourcepub const fn is_dark(self) -> bool
pub const fn is_dark(self) -> bool
Examples found in repository?
examples/showcase.rs (line 1158)
965 fn update(&mut self, action: WidgetAction) {
966 let WidgetAction { binding, kind, .. } = action;
967 let WidgetActionBinding::Action(action_id) = binding else {
968 return;
969 };
970 let action_id = action_id.as_str();
971
972 let color_outcome = self.color.apply_action(
973 action_id,
974 kind.clone(),
975 ext_widgets::ColorPickerActionOptions::new("color").copy_hex("color.copy_hex"),
976 );
977 if color_outcome.update.is_some()
978 || color_outcome.effect.is_some()
979 || color_outcome.mode_changed
980 {
981 if let Some(ext_widgets::ColorPickerEffect::CopyHex(hex)) = color_outcome.effect {
982 self.copy_text_to_clipboard(&hex);
983 self.color_copied_hex = Some(hex);
984 }
985 return;
986 }
987 let color_buttons_outcome = self.color.apply_action(
988 action_id,
989 kind.clone(),
990 ext_widgets::ColorPickerActionOptions::new("color_buttons.hsva_2d"),
991 );
992 if color_buttons_outcome.update.is_some() || color_buttons_outcome.mode_changed {
993 self.color_button_status = "HSVA field";
994 return;
995 }
996 let slider_color_outcome = self.slider_trailing_picker.apply_action(
997 action_id,
998 kind.clone(),
999 ext_widgets::ColorPickerActionOptions::new("slider.trailing_picker"),
1000 );
1001 if slider_color_outcome.update.is_some() || slider_color_outcome.mode_changed {
1002 return;
1003 }
1004 let styling_stroke_outcome = self.styling_stroke_picker.apply_action(
1005 action_id,
1006 kind.clone(),
1007 ext_widgets::ColorPickerActionOptions::new("styling.stroke_picker"),
1008 );
1009 if styling_stroke_outcome.update.is_some() || styling_stroke_outcome.mode_changed {
1010 self.styling.stroke = self.styling_stroke_picker.value();
1011 return;
1012 }
1013 let styling_fill_outcome = self.styling_fill_picker.apply_action(
1014 action_id,
1015 kind.clone(),
1016 ext_widgets::ColorPickerActionOptions::new("styling.fill_picker"),
1017 );
1018 if styling_fill_outcome.update.is_some() || styling_fill_outcome.mode_changed {
1019 self.styling.fill = self.styling_fill_picker.value();
1020 return;
1021 }
1022 let styling_shadow_outcome = self.styling_shadow_picker.apply_action(
1023 action_id,
1024 kind.clone(),
1025 ext_widgets::ColorPickerActionOptions::new("styling.shadow_picker"),
1026 );
1027 if styling_shadow_outcome.update.is_some() || styling_shadow_outcome.mode_changed {
1028 self.styling.shadow = self.styling_shadow_picker.value();
1029 return;
1030 }
1031
1032 if action_id == "window.clear_all" {
1033 self.windows.clear_all();
1034 return;
1035 }
1036 if action_id == "window.add_all" {
1037 self.windows.open_all();
1038 for id in SHOWCASE_WIDGET_WINDOW_IDS {
1039 self.desktop.ensure_window(id, window_defaults(id));
1040 self.desktop.bring_to_front(id);
1041 }
1042 return;
1043 }
1044 if action_id == "window.organize_open" {
1045 self.organize_open_windows();
1046 return;
1047 }
1048 if let Some(id) = action_id.strip_prefix("window.toggle.") {
1049 if self.windows.toggle(id).unwrap_or(false) {
1050 self.desktop.ensure_window(id, window_defaults(id));
1051 self.desktop.bring_to_front(id);
1052 }
1053 return;
1054 }
1055 if let Some(id) = action_id.strip_prefix("window.close.") {
1056 self.windows.close(id);
1057 self.desktop.close(id);
1058 return;
1059 }
1060 if let Some(id) = action_id.strip_prefix("window.activate.") {
1061 self.desktop.bring_to_front(id);
1062 return;
1063 }
1064 if let Some(id) = action_id.strip_prefix("window.drag.") {
1065 if let WidgetActionKind::PointerEdit(edit) = kind {
1066 self.desktop
1067 .apply_drag(id, edit, default_window_position(id));
1068 }
1069 return;
1070 }
1071 if let Some(id) = action_id.strip_prefix("window.resize.") {
1072 if let WidgetActionKind::PointerEdit(edit) = kind {
1073 self.desktop.apply_resize(id, edit, window_defaults(id));
1074 }
1075 return;
1076 }
1077 if let Some(id) = action_id.strip_prefix("window.collapse.") {
1078 self.desktop.toggle_collapsed(id);
1079 return;
1080 }
1081 if let Some(id) = window_for_action(action_id) {
1082 self.desktop.bring_to_front(id);
1083 }
1084 if action_id == "runtime.tick" {
1085 self.progress_phase += SHOWCASE_PROGRESS_RADIANS_PER_SECOND / SHOWCASE_TICK_RATE_HZ;
1086 self.caret_phase = (self.caret_phase
1087 + std::f32::consts::TAU * TEXT_CARET_BLINK_HZ / SHOWCASE_TICK_RATE_HZ)
1088 % std::f32::consts::TAU;
1089 return;
1090 }
1091 if action_id == "command_palette.search" {
1092 if let WidgetActionKind::TextEdit(edit) = kind {
1093 self.apply_command_palette_event(edit.event);
1094 }
1095 return;
1096 }
1097 if let Some(id) = action_id.strip_prefix("command_palette.item.") {
1098 self.select_command_palette_item(id);
1099 return;
1100 }
1101 if let Some(input) = focused_text_for_action(action_id) {
1102 if let WidgetActionKind::TextEdit(edit) = kind {
1103 self.apply_text_edit(input, edit);
1104 }
1105 return;
1106 }
1107
1108 match action_id {
1109 "labels.link" => {
1110 self.label_link_visited = true;
1111 self.label_link_status = "Internal link activated";
1112 return;
1113 }
1114 "labels.hyperlink" => {
1115 self.label_hyperlink_visited = true;
1116 self.label_link_status = "Opened docs.rs/operad";
1117 self.platform.open_url("https://docs.rs/operad");
1118 return;
1119 }
1120 "button.default" => self.last_button = "Default",
1121 "button.primary" => self.last_button = "Primary",
1122 "button.secondary" => self.last_button = "Secondary",
1123 "button.destructive" => self.last_button = "Destructive",
1124 "button.small" => self.last_button = "Small",
1125 "button.icon" => self.last_button = "Settings",
1126 "button.image" => self.last_button = "Folder",
1127 "button.reset" => {
1128 self.toggle_button = false;
1129 self.last_button = "Reset";
1130 }
1131 "button.toggle" => {
1132 self.toggle_button = !self.toggle_button;
1133 self.last_button = "Toggle";
1134 }
1135 "checkbox.enabled" => self.checked = !self.checked,
1136 "labels.locale.toggle" => {
1137 self.label_locale.toggle(&label_locale_options());
1138 return;
1139 }
1140 "toggles.switch" => self.switch_enabled = !self.switch_enabled,
1141 "toggles.mixed" => self.mixed_switch = self.mixed_switch.toggled(),
1142 "toggles.radio.compact" => self.radio_choice = "compact",
1143 "toggles.radio.comfortable" => self.radio_choice = "comfortable",
1144 "toggles.radio.spacious" => self.radio_choice = "spacious",
1145 "toggles.theme.system" => {
1146 self.theme_preference = widgets::ThemePreference::System;
1147 return;
1148 }
1149 "toggles.theme.light" => {
1150 self.theme_preference = widgets::ThemePreference::Light;
1151 return;
1152 }
1153 "toggles.theme.dark" => {
1154 self.theme_preference = widgets::ThemePreference::Dark;
1155 return;
1156 }
1157 "theme.preference.dark" => {
1158 self.theme_preference = if self.theme_preference.is_dark() {
1159 widgets::ThemePreference::Light
1160 } else {
1161 widgets::ThemePreference::Dark
1162 };
1163 return;
1164 }
1165 "combo.toggle" => self.combo_open = !self.combo_open,
1166 "selection.dropdown.toggle" => {
1167 self.dropdown.toggle(&select_options());
1168 return;
1169 }
1170 "menus.menu_button" => {
1171 let button_items = menu_items(self.menu_autosave);
1172 let outcome = self.menu_button.toggle(&button_items);
1173 if outcome.opened {
1174 self.image_text_menu_button.close();
1175 self.image_menu_button.close();
1176 self.context_menu.close();
1177 }
1178 return;
1179 }
1180 "menus.image_text_menu_button" => {
1181 let button_items = menu_items(self.menu_autosave);
1182 let outcome = self.image_text_menu_button.toggle(&button_items);
1183 if outcome.opened {
1184 self.menu_button.close();
1185 self.image_menu_button.close();
1186 self.context_menu.close();
1187 }
1188 return;
1189 }
1190 "menus.image_menu_button" => {
1191 let button_items = menu_items(self.menu_autosave);
1192 let outcome = self.image_menu_button.toggle(&button_items);
1193 if outcome.opened {
1194 self.menu_button.close();
1195 self.image_text_menu_button.close();
1196 self.context_menu.close();
1197 }
1198 return;
1199 }
1200 "menus.context.open" => {
1201 self.context_menu
1202 .open_with_items(UiPoint::new(0.0, 0.0), &menu_items(self.menu_autosave));
1203 self.menu_button.close();
1204 self.image_text_menu_button.close();
1205 self.image_menu_button.close();
1206 return;
1207 }
1208 "menus.context.close" => {
1209 self.context_menu.close();
1210 return;
1211 }
1212 "menus.bar.file" => {
1213 self.menu_bar
1214 .open(&menu_bar_menus(self.menu_autosave, self.menu_grid), 0);
1215 return;
1216 }
1217 "menus.bar.edit" => {
1218 self.menu_bar
1219 .open(&menu_bar_menus(self.menu_autosave, self.menu_grid), 1);
1220 return;
1221 }
1222 "menus.bar.view" => {
1223 self.menu_bar
1224 .open(&menu_bar_menus(self.menu_autosave, self.menu_grid), 2);
1225 return;
1226 }
1227 "date.previous" => self.date.show_previous_month(),
1228 "date.next" => self.date.show_next_month(),
1229 "date.week.sunday" => {
1230 self.date.first_weekday = ext_widgets::Weekday::Sunday;
1231 return;
1232 }
1233 "date.week.monday" => {
1234 self.date.first_weekday = ext_widgets::Weekday::Monday;
1235 return;
1236 }
1237 "date.range.toggle" => {
1238 if self.date.min.is_some() || self.date.max.is_some() {
1239 self.date.min = None;
1240 self.date.max = None;
1241 } else {
1242 self.date.min = CalendarDate::new(2026, 5, 4);
1243 self.date.max = CalendarDate::new(2026, 5, 29);
1244 }
1245 return;
1246 }
1247 "toast.show" => {
1248 self.toast_visible = true;
1249 return;
1250 }
1251 "toast.hide" => {
1252 self.toast_visible = false;
1253 return;
1254 }
1255 id if id.starts_with("toast.dismiss.") => {
1256 self.toast_visible = false;
1257 return;
1258 }
1259 "toast.action.1.undo" => {
1260 self.toast_action_status = "Undo requested";
1261 return;
1262 }
1263 "popup.toggle" => {
1264 self.popup_open = !self.popup_open;
1265 return;
1266 }
1267 "popup.close" => {
1268 self.popup_open = false;
1269 return;
1270 }
1271 "layout.tab.preview" => {
1272 self.layout_tab = 0;
1273 return;
1274 }
1275 "layout.tab.settings" => {
1276 self.layout_tab = 1;
1277 return;
1278 }
1279 "forms.profile.submit" => {
1280 self.form.submit();
1281 self.form_status = "Submit requested".to_string();
1282 return;
1283 }
1284 "forms.profile.apply" => {
1285 self.form.apply();
1286 self.form_status = "Applied".to_string();
1287 return;
1288 }
1289 "forms.profile.cancel" => {
1290 self.form.cancel();
1291 self.sync_profile_form_text_fields();
1292 self.form_status = "Cancelled".to_string();
1293 return;
1294 }
1295 "forms.profile.reset" => {
1296 self.form = profile_form_state();
1297 self.form_newsletter = true;
1298 self.sync_profile_form_text_fields();
1299 self.form_status = "Reset".to_string();
1300 return;
1301 }
1302 "forms.profile.newsletter.toggle" => {
1303 self.form_newsletter = !self.form_newsletter;
1304 let _ = self.form.update_field(
1305 "newsletter",
1306 if self.form_newsletter {
1307 "true"
1308 } else {
1309 "false"
1310 },
1311 );
1312 self.validate_profile_form();
1313 self.form_status = "Editing profile".to_string();
1314 return;
1315 }
1316 "overlays.collapsing.toggle" => {
1317 self.overlay_expanded = !self.overlay_expanded;
1318 return;
1319 }
1320 "overlays.popup.toggle" => {
1321 self.overlay_popup_open = !self.overlay_popup_open;
1322 return;
1323 }
1324 "overlays.popup.close" => {
1325 self.overlay_popup_open = false;
1326 return;
1327 }
1328 "overlays.modal.open" => {
1329 self.overlay_modal_open = true;
1330 return;
1331 }
1332 "overlays.modal.close" => {
1333 self.overlay_modal_open = false;
1334 return;
1335 }
1336 "drag_drop.text_source" => {
1337 self.drag_drop_status = "Text drag started";
1338 return;
1339 }
1340 "drag_drop.file_source" => {
1341 self.drag_drop_status = "File drag started";
1342 return;
1343 }
1344 "drag_drop.bytes_source" => {
1345 self.drag_drop_status = "Image byte drag started";
1346 return;
1347 }
1348 "drag_drop.accept_text" => {
1349 self.drag_drop_status = "Text payload accepted";
1350 return;
1351 }
1352 "drag_drop.files_only" => {
1353 self.drag_drop_status = "File payload rejected";
1354 return;
1355 }
1356 "drag_drop.image_bytes" => {
1357 self.drag_drop_status = "Image bytes hovered";
1358 return;
1359 }
1360 "slider.trailing" => {
1361 self.slider_trailing_color = !self.slider_trailing_color;
1362 return;
1363 }
1364 "slider.trailing_color_button" => {
1365 self.slider_trailing_picker_open = !self.slider_trailing_picker_open;
1366 return;
1367 }
1368 "slider.thumb.circle" => {
1369 self.slider_thumb_shape = SliderThumbChoice::Circle;
1370 return;
1371 }
1372 "slider.thumb.square" => {
1373 self.slider_thumb_shape = SliderThumbChoice::Square;
1374 return;
1375 }
1376 "slider.thumb.rectangle" => {
1377 self.slider_thumb_shape = SliderThumbChoice::Rectangle;
1378 return;
1379 }
1380 "slider.steps" => {
1381 self.slider_use_steps = !self.slider_use_steps;
1382 if self.slider_use_steps {
1383 self.set_slider_value(widgets::slider::round_slider_to_step(
1384 self.slider,
1385 self.slider_step(),
1386 ));
1387 }
1388 return;
1389 }
1390 "slider.logarithmic" => {
1391 self.slider_logarithmic = !self.slider_logarithmic;
1392 return;
1393 }
1394 "slider.clamping.never" => {
1395 self.slider_clamping = widgets::SliderClamping::Never;
1396 return;
1397 }
1398 "slider.clamping.edits" => {
1399 self.slider_clamping = widgets::SliderClamping::Edits;
1400 return;
1401 }
1402 "slider.clamping.always" => {
1403 self.slider_clamping = widgets::SliderClamping::Always;
1404 self.clamp_slider_to_range();
1405 return;
1406 }
1407 "slider.smart_aim" => {
1408 self.slider_smart_aim = !self.slider_smart_aim;
1409 return;
1410 }
1411 "animation.open" => {
1412 self.animation_open = !self.animation_open;
1413 return;
1414 }
1415 "animation.timed.toggle" => {
1416 self.animation_timed_expanded = !self.animation_timed_expanded;
1417 return;
1418 }
1419 "animation.scrub.toggle" => {
1420 self.animation_scrub_expanded = !self.animation_scrub_expanded;
1421 return;
1422 }
1423 "animation.state.toggle" => {
1424 self.animation_state_expanded = !self.animation_state_expanded;
1425 return;
1426 }
1427 "animation.interaction.toggle" => {
1428 self.animation_interaction_expanded = !self.animation_interaction_expanded;
1429 return;
1430 }
1431 "animation.scrub" => {
1432 if let WidgetActionKind::PointerEdit(edit) = kind {
1433 self.animation_scrub = scaled_slider(edit.target_rect, edit.position, 0.0, 1.0);
1434 }
1435 return;
1436 }
1437 "diagnostics.animation.controls.transport.pause_toggle" => {
1438 self.diagnostics_animation_paused = !self.diagnostics_animation_paused;
1439 return;
1440 }
1441 "diagnostics.animation.controls.transport.step" => {
1442 self.diagnostics_animation_paused = true;
1443 self.diagnostics_animation_scrub =
1444 (self.diagnostics_animation_scrub + 1.0 / 12.0).min(1.0);
1445 return;
1446 }
1447 "diagnostics.animation.controls.transport.scrub" => {
1448 if let WidgetActionKind::PointerEdit(edit) = kind {
1449 self.diagnostics_animation_scrub =
1450 scaled_slider(edit.target_rect, edit.position, 0.0, 1.0);
1451 }
1452 return;
1453 }
1454 "diagnostics.animation.controls.input.active.toggle" => {
1455 self.diagnostics_animation_active = !self.diagnostics_animation_active;
1456 self.refresh_diagnostics_snapshot();
1457 return;
1458 }
1459 "diagnostics.animation.controls.input.hover.set" => {
1460 if let WidgetActionKind::PointerEdit(edit) = kind {
1461 self.diagnostics_animation_hover =
1462 scaled_slider(edit.target_rect, edit.position, 0.0, 1.0);
1463 self.refresh_diagnostics_snapshot();
1464 }
1465 return;
1466 }
1467 "diagnostics.animation.controls.input.pulse.fire" => {
1468 self.diagnostics_animation_pulse_count =
1469 self.diagnostics_animation_pulse_count.saturating_add(1);
1470 return;
1471 }
1472 "layout_widgets.float_inspector" => {
1473 let panel = ext_widgets::DockPanelDescriptor::new(
1474 "inspector",
1475 "Inspector",
1476 ext_widgets::DockSide::Left,
1477 120.0,
1478 );
1479 self.layout_dock
1480 .float_panel(&panel, UiRect::new(20.0, 58.0, 236.0, 210.0));
1481 return;
1482 }
1483 "layout_widgets.dock_inspector" => {
1484 let panel = ext_widgets::DockPanelDescriptor::new(
1485 "inspector",
1486 "Inspector",
1487 ext_widgets::DockSide::Left,
1488 120.0,
1489 );
1490 self.layout_dock
1491 .dock_panel(&panel, ext_widgets::DockSide::Left);
1492 return;
1493 }
1494 "layout_widgets.drawer.inspector" => {
1495 self.layout_dock.toggle_panel_hidden("inspector");
1496 return;
1497 }
1498 "layout_widgets.drawer.assets" => {
1499 self.layout_dock.toggle_panel_hidden("assets");
1500 return;
1501 }
1502 "layout_widgets.reorder.assets.before.inspector" => {
1503 let mut panels = base_layout_dock_panels();
1504 self.layout_dock.apply_order_to_panels(&mut panels);
1505 let payload = ext_widgets::dock_workspace::dock_panel_drag_payload("assets");
1506 self.layout_dock.apply_reorder_to_panels(
1507 &mut panels,
1508 &payload,
1509 "inspector",
1510 ext_widgets::DockPanelReorderPlacement::Before,
1511 );
1512 return;
1513 }
1514 "layout_widgets.reorder.assets.after.inspector" => {
1515 let mut panels = base_layout_dock_panels();
1516 self.layout_dock.apply_order_to_panels(&mut panels);
1517 let payload = ext_widgets::dock_workspace::dock_panel_drag_payload("assets");
1518 self.layout_dock.apply_reorder_to_panels(
1519 &mut panels,
1520 &payload,
1521 "inspector",
1522 ext_widgets::DockPanelReorderPlacement::After,
1523 );
1524 return;
1525 }
1526 "styling.stroke_color_button" => {
1527 self.styling_stroke_picker_open = !self.styling_stroke_picker_open;
1528 return;
1529 }
1530 "styling.fill_color_button" => {
1531 self.styling_fill_picker_open = !self.styling_fill_picker_open;
1532 return;
1533 }
1534 "styling.shadow_color_button" => {
1535 self.styling_shadow_picker_open = !self.styling_shadow_picker_open;
1536 return;
1537 }
1538 "styling.inner_same" => {
1539 self.styling.inner_same = !self.styling.inner_same;
1540 return;
1541 }
1542 "styling.outer_same" => {
1543 self.styling.outer_same = !self.styling.outer_same;
1544 return;
1545 }
1546 "styling.radius_same" => {
1547 self.styling.radius_same = !self.styling.radius_same;
1548 return;
1549 }
1550 _ => {}
1551 }
1552
1553 if action_id == "canvas.rotate" {
1554 if let WidgetActionKind::Drag(drag) = kind {
1555 self.cube.apply_drag(drag);
1556 }
1557 return;
1558 }
1559 if let WidgetActionKind::Scroll(scroll) = &kind {
1560 match action_id {
1561 "lists_tables.scroll_area.scroll" => self.list_scroll = scroll.offset().y,
1562 "lists_tables.virtual_list.scroll" => self.virtual_scroll = scroll.offset().y,
1563 "lists_tables.data_table.scroll" => self.table_scroll = scroll.offset().y,
1564 "lists_tables.virtualized_table.scroll" => {
1565 self.virtual_table_scroll = scroll.offset().y
1566 }
1567 "layout.preview.scroll" => self.layout_preview_scroll = scroll.offset().y,
1568 "layout.left.scroll" => self.layout_left_scroll = scroll.offset().y,
1569 "layout.right.scroll" => self.layout_right_scroll = scroll.offset().y,
1570 "layout.inspector.scroll" => self.layout_inspector_scroll = scroll.offset().y,
1571 "layout.document.scroll" => self.layout_document_scroll = scroll.offset().y,
1572 "layout.assets.scroll" => self.layout_assets_scroll = scroll.offset().y,
1573 "trees.virtual.scroll" => self.tree_virtual_scroll = scroll.offset().y,
1574 "containers.scroll_area_with_bars.scroll" => {
1575 self.containers_scroll.set_offset(scroll.offset());
1576 }
1577 "controls.widget_list.scroll" => {
1578 self.controls_scroll = *scroll;
1579 self.controls_scroll.set_offset(scroll.offset());
1580 }
1581 _ => {}
1582 }
1583 return;
1584 }
1585
1586 if let Some(date) = action_id
1587 .strip_prefix("date.day.")
1588 .and_then(parse_calendar_date)
1589 {
1590 self.date.select(date);
1591 return;
1592 }
1593
1594 if let Some(option_id) = action_id.strip_prefix("labels.locale.option.") {
1595 self.label_locale
1596 .select_id_and_close(&label_locale_options(), option_id);
1597 return;
1598 }
1599 if let Some(option_id) = action_id.strip_prefix("selection.dropdown.option.") {
1600 self.dropdown
1601 .select_id_and_close(&select_options(), option_id);
1602 return;
1603 }
1604 if let Some(option_id) = action_id.strip_prefix("selection.combo.option.") {
1605 if let Some(option) = select_options()
1606 .into_iter()
1607 .find(|option| option.id == option_id && option.enabled)
1608 {
1609 self.combo_label = option.label;
1610 self.combo_open = false;
1611 }
1612 return;
1613 }
1614 if let Some(option_id) = action_id.strip_prefix("selection.menu.option.") {
1615 self.select_menu.select_id(&select_options(), option_id);
1616 return;
1617 }
1618 if let Some(menu_id) = action_id.strip_prefix("menus.item.") {
1619 self.apply_menu_item(menu_id);
1620 return;
1621 }
1622 if let Some(menu_id) = action_id.strip_prefix("menus.context.") {
1623 self.apply_menu_item(menu_id);
1624 self.context_menu.close();
1625 return;
1626 }
1627 if let Some(kind) = action_id.strip_prefix("color_buttons.") {
1628 self.color_button_status = match kind {
1629 "compact" => "Compact",
1630 "swatch" => "Swatch",
1631 "rgb" => "RGB",
1632 "rgba" => "RGBA",
1633 "srgb" => "SRGB",
1634 "srgba" => "SRGBA",
1635 "hsva" => "HSVA",
1636 "oklch" => "OKLCH",
1637 "color32" => "Color32",
1638 "rgba_premultiplied" => "RGBA premultiplied",
1639 "rgba_unmultiplied" => "RGBA unmultiplied",
1640 "srgba_premultiplied" => "SRGBA premultiplied",
1641 "srgba_unmultiplied" => "SRGBA unmultiplied",
1642 _ => self.color_button_status,
1643 };
1644 return;
1645 }
1646 if let Some(row) = action_id
1647 .strip_prefix("lists_tables.data_table.row.")
1648 .and_then(|row| row.parse::<usize>().ok())
1649 {
1650 self.table_selection = ext_widgets::DataTableSelection::single_row(row)
1651 .with_active_cell(ext_widgets::DataTableCellIndex::new(row, 0));
1652 return;
1653 }
1654 if let Some(cell) = action_id
1655 .strip_prefix("lists_tables.data_table.cell.")
1656 .and_then(parse_table_cell)
1657 {
1658 self.table_selection =
1659 ext_widgets::DataTableSelection::single_row(cell.row).with_active_cell(cell);
1660 return;
1661 }
1662 match action_id {
1663 "lists_tables.virtualized_table.sort.name" => {
1664 self.virtual_table_descending = !self.virtual_table_descending;
1665 return;
1666 }
1667 "lists_tables.virtualized_table.filter.status" => {
1668 self.virtual_table_ready_only = !self.virtual_table_ready_only;
1669 self.virtual_table_scroll = 0.0;
1670 return;
1671 }
1672 "lists_tables.virtualized_table.resize.reset" => {
1673 self.virtual_table_value_width = 70.0;
1674 self.virtual_table_resize = None;
1675 return;
1676 }
1677 _ => {}
1678 }
1679 if let Some(row) = action_id
1680 .strip_prefix("lists_tables.virtualized_table.row.")
1681 .and_then(|row| row.parse::<usize>().ok())
1682 {
1683 self.table_selection = ext_widgets::DataTableSelection::single_row(row)
1684 .with_active_cell(ext_widgets::DataTableCellIndex::new(row, 0));
1685 return;
1686 }
1687 if let Some(cell) = action_id
1688 .strip_prefix("lists_tables.virtualized_table.cell.")
1689 .and_then(parse_table_cell)
1690 {
1691 self.table_selection =
1692 ext_widgets::DataTableSelection::single_row(cell.row).with_active_cell(cell);
1693 return;
1694 }
1695 if let Some(id) = action_id.strip_prefix("trees.tree.row.") {
1696 self.apply_tree_row(id, false);
1697 return;
1698 }
1699 if let Some(id) = action_id.strip_prefix("trees.outliner.row.") {
1700 self.apply_tree_row(id, true);
1701 return;
1702 }
1703
1704 let WidgetActionKind::PointerEdit(edit) = kind else {
1705 return;
1706 };
1707 match action_id {
1708 "numeric.drag_value" => {
1709 self.numeric_value = scaled_slider(edit.target_rect, edit.position, 0.0, 100.0);
1710 }
1711 "numeric.drag_angle" => {
1712 self.numeric_angle =
1713 scaled_slider(edit.target_rect, edit.position, 0.0, 360.0).to_radians();
1714 }
1715 "numeric.drag_angle_tau" => {
1716 self.numeric_tau = scaled_slider(edit.target_rect, edit.position, 0.0, 1.0)
1717 * std::f32::consts::TAU;
1718 }
1719 "layout_widgets.split_pane.handle" => {
1720 let total_extent = self
1721 .desktop
1722 .size("layout_widgets", default_window_size("layout_widgets"))
1723 .width
1724 - 48.0;
1725 let total_extent = total_extent.max(1.0);
1726 let handle_center = edit.target_rect.x + edit.target_rect.width * 0.5;
1727 self.layout_split
1728 .resize_by(edit.position.x - handle_center, total_extent, 6.0);
1729 }
1730 "slider.value" => {
1731 self.set_slider_value(
1732 self.slider_value_spec()
1733 .value_from_control_point(edit.target_rect, edit.position),
1734 );
1735 }
1736 "slider.range_left" => {
1737 let value = widgets::slider::SliderValueSpec::new(0.0, self.slider_right.max(1.0))
1738 .value_from_control_point(edit.target_rect, edit.position);
1739 self.set_slider_left(value.min(self.slider_right - 1.0));
1740 }
1741 "slider.range_right" => {
1742 let value = widgets::slider::SliderValueSpec::new(self.slider_left + 1.0, 10000.0)
1743 .value_from_control_point(edit.target_rect, edit.position);
1744 self.set_slider_right(value.max(self.slider_left + 1.0));
1745 }
1746 "lists_tables.scroll_area.scrollbar" => {
1747 let scroll = scroll_state(self.list_scroll, 92.0, 6.0 * 26.0);
1748 self.list_scroll = self
1749 .scrollbars
1750 .apply_drag_for_target_rect(
1751 "list",
1752 scroll,
1753 scrollbar_widgets::ScrollAxis::Vertical,
1754 edit,
1755 )
1756 .y;
1757 }
1758 "lists_tables.virtual_list.scrollbar" => {
1759 let scroll = scroll_state(self.virtual_scroll, 112.0, 24.0 * 28.0);
1760 self.virtual_scroll = self
1761 .scrollbars
1762 .apply_drag_for_target_rect(
1763 "virtual",
1764 scroll,
1765 scrollbar_widgets::ScrollAxis::Vertical,
1766 edit,
1767 )
1768 .y;
1769 }
1770 "lists_tables.data_table.scrollbar" => {
1771 let scroll = scroll_state(self.table_scroll, 128.0, 16.0 * 28.0);
1772 self.table_scroll = self
1773 .scrollbars
1774 .apply_drag_for_target_rect(
1775 "table",
1776 scroll,
1777 scrollbar_widgets::ScrollAxis::Vertical,
1778 edit,
1779 )
1780 .y;
1781 }
1782 "lists_tables.virtualized_table.scrollbar" => {
1783 let row_count = virtual_table_visible_rows(self).len() as f32;
1784 let scroll = scroll_state(self.virtual_table_scroll, 128.0, row_count * 28.0);
1785 self.virtual_table_scroll = self
1786 .scrollbars
1787 .apply_drag_for_target_rect(
1788 "virtual_table",
1789 scroll,
1790 scrollbar_widgets::ScrollAxis::Vertical,
1791 edit,
1792 )
1793 .y;
1794 }
1795 "lists_tables.virtualized_table.resize.value" => match edit.phase.edit_phase() {
1796 EditPhase::Preview => {}
1797 EditPhase::BeginEdit => {
1798 self.virtual_table_resize =
1799 Some((self.virtual_table_value_width, edit.position.x));
1800 }
1801 EditPhase::UpdateEdit | EditPhase::CommitEdit => {
1802 let (origin_width, origin_x) = self
1803 .virtual_table_resize
1804 .unwrap_or((self.virtual_table_value_width, edit.position.x));
1805 self.virtual_table_value_width =
1806 (origin_width + edit.position.x - origin_x).clamp(56.0, 180.0);
1807 if edit.phase.edit_phase() == EditPhase::CommitEdit {
1808 self.virtual_table_resize = None;
1809 }
1810 }
1811 EditPhase::CancelEdit => {
1812 if let Some((origin_width, _)) = self.virtual_table_resize.take() {
1813 self.virtual_table_value_width = origin_width;
1814 }
1815 }
1816 },
1817 "containers.scroll_area_with_bars.vertical-scrollbar" => {
1818 let offset = self.scrollbars.apply_drag_for_target_rect(
1819 "containers.vertical",
1820 self.containers_scroll,
1821 scrollbar_widgets::ScrollAxis::Vertical,
1822 edit,
1823 );
1824 self.containers_scroll.set_offset(offset);
1825 }
1826 "containers.scroll_area_with_bars.horizontal-scrollbar" => {
1827 let offset = self.scrollbars.apply_drag_for_target_rect(
1828 "containers.horizontal",
1829 self.containers_scroll,
1830 scrollbar_widgets::ScrollAxis::Horizontal,
1831 edit,
1832 );
1833 self.containers_scroll.set_offset(offset);
1834 }
1835 "controls.widget_list.scrollbar" => {
1836 let mut scroll =
1837 controls_scroll_state_for_view(self.controls_scroll, edit.target_rect.height);
1838 let offset = self.scrollbars.apply_drag_for_target_rect(
1839 "controls.widget_list",
1840 scroll,
1841 scrollbar_widgets::ScrollAxis::Vertical,
1842 edit,
1843 );
1844 scroll.set_offset(offset);
1845 self.controls_scroll = scroll;
1846 }
1847 "styling.inner" => {
1848 self.styling.inner_margin =
1849 scaled_slider(edit.target_rect, edit.position, 0.0, 32.0);
1850 if self.styling.inner_same {
1851 self.styling.inner_right = self.styling.inner_margin;
1852 self.styling.inner_top = self.styling.inner_margin;
1853 self.styling.inner_bottom = self.styling.inner_margin;
1854 }
1855 }
1856 "styling.inner_right" => {
1857 self.styling.inner_right =
1858 scaled_slider(edit.target_rect, edit.position, 0.0, 32.0);
1859 }
1860 "styling.inner_top" => {
1861 self.styling.inner_top = scaled_slider(edit.target_rect, edit.position, 0.0, 32.0);
1862 }
1863 "styling.inner_bottom" => {
1864 self.styling.inner_bottom =
1865 scaled_slider(edit.target_rect, edit.position, 0.0, 32.0);
1866 }
1867 "styling.outer" => {
1868 self.styling.outer_margin =
1869 scaled_slider(edit.target_rect, edit.position, 0.0, 40.0);
1870 if self.styling.outer_same {
1871 self.styling.outer_right = self.styling.outer_margin;
1872 self.styling.outer_top = self.styling.outer_margin;
1873 self.styling.outer_bottom = self.styling.outer_margin;
1874 }
1875 }
1876 "styling.outer_right" => {
1877 self.styling.outer_right =
1878 scaled_slider(edit.target_rect, edit.position, 0.0, 40.0);
1879 }
1880 "styling.outer_top" => {
1881 self.styling.outer_top = scaled_slider(edit.target_rect, edit.position, 0.0, 40.0);
1882 }
1883 "styling.outer_bottom" => {
1884 self.styling.outer_bottom =
1885 scaled_slider(edit.target_rect, edit.position, 0.0, 40.0);
1886 }
1887 "styling.radius" => {
1888 self.styling.corner_radius =
1889 scaled_slider(edit.target_rect, edit.position, 0.0, 28.0);
1890 if self.styling.radius_same {
1891 self.styling.corner_ne = self.styling.corner_radius;
1892 self.styling.corner_sw = self.styling.corner_radius;
1893 self.styling.corner_se = self.styling.corner_radius;
1894 }
1895 }
1896 "styling.radius_ne" => {
1897 self.styling.corner_ne = scaled_slider(edit.target_rect, edit.position, 0.0, 28.0);
1898 }
1899 "styling.radius_sw" => {
1900 self.styling.corner_sw = scaled_slider(edit.target_rect, edit.position, 0.0, 28.0);
1901 }
1902 "styling.radius_se" => {
1903 self.styling.corner_se = scaled_slider(edit.target_rect, edit.position, 0.0, 28.0);
1904 }
1905 "styling.shadow_x" => {
1906 self.styling.shadow_x = scaled_slider(edit.target_rect, edit.position, -24.0, 24.0);
1907 }
1908 "styling.shadow_y" => {
1909 self.styling.shadow_y = scaled_slider(edit.target_rect, edit.position, -24.0, 24.0);
1910 }
1911 "styling.shadow" => {
1912 self.styling.shadow_blur =
1913 scaled_slider(edit.target_rect, edit.position, 0.0, 32.0);
1914 }
1915 "styling.shadow_spread" => {
1916 self.styling.shadow_spread =
1917 scaled_slider(edit.target_rect, edit.position, 0.0, 16.0);
1918 }
1919 "styling.stroke" => {
1920 self.styling.stroke_width =
1921 scaled_slider(edit.target_rect, edit.position, 0.0, 4.0);
1922 }
1923 _ => {}
1924 }
1925 }Trait Implementations§
Source§impl Clone for ThemePreference
impl Clone for ThemePreference
Source§fn clone(&self) -> ThemePreference
fn clone(&self) -> ThemePreference
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ThemePreference
impl Debug for ThemePreference
Source§impl Hash for ThemePreference
impl Hash for ThemePreference
Source§impl PartialEq for ThemePreference
impl PartialEq for ThemePreference
Source§fn eq(&self, other: &ThemePreference) -> bool
fn eq(&self, other: &ThemePreference) -> bool
Tests for
self and other values to be equal, and is used by ==.impl Copy for ThemePreference
impl Eq for ThemePreference
impl StructuralPartialEq for ThemePreference
Auto Trait Implementations§
impl Freeze for ThemePreference
impl RefUnwindSafe for ThemePreference
impl Send for ThemePreference
impl Sync for ThemePreference
impl Unpin for ThemePreference
impl UnsafeUnpin for ThemePreference
impl UnwindSafe for ThemePreference
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.