panels-w2: review fixes (review-2)

This commit is contained in:
aiongg
2026-11-14 17:56:00 +00:00
parent d7ed431c5c
commit 80f8719cd4
3 changed files with 19 additions and 8 deletions
+9 -7
View File
@@ -339,14 +339,16 @@ impl<T: Value + 'static> Component for FlyoutButton<'_, T> {
}
}
fn access(&self, access: &mut Access, _: &Cx<'_, Self>) {
fn access(&self, access: &mut Access, cx: &Cx<'_, Self>) {
let resolved = self.laid.as_ref().and_then(|laid| self.lead(laid));
let name = resolved.map(|resolved| resolved.label.as_ref().to_owned());
if let Some(resolved) = resolved {
access.name(Name::Text(resolved.label.as_ref().to_owned()));
if let Some(hint) = &resolved.hint {
access.description(hint.as_ref().to_owned());
}
// A command that does not resolve leaves the button's own label as its name.
let own = (!cx.resolved.label.is_empty()).then(|| cx.resolved.label.to_owned());
let name = resolved.map(|resolved| resolved.label.as_ref().to_owned()).or(own);
if let Some(name) = &name {
access.name(Name::Text(name.clone()));
}
if let Some(hint) = resolved.and_then(|resolved| resolved.hint.as_ref()) {
access.description(hint.as_ref().to_owned());
}
// The face covers the whole button, so the button's own node is the face's node.
access.node(FACE, Role::None);
+5
View File
@@ -135,6 +135,11 @@ fn a_click_command_cycles_and_a_hold_lists_the_tools_without_firing_it() {
clicked.fixture.click(&target);
clicked.fixture.idle(3);
assert_eq!(fired(&clicked), 1, "a click fires the click command");
// A pointer click need not leave focus on the button; the keys act on the focused one.
if clicked.fixture.focused_stop().is_none() {
clicked.fixture.key(Key::Tab, Modifiers::NONE);
}
assert!(clicked.fixture.focused_stop().is_some(), "the button has focus for the keys");
clicked.fixture.key(Key::Enter, Modifiers::NONE);
assert_eq!(fired(&clicked), 1, "Enter fires it");
clicked.fixture.key(Key::Space, Modifiers::NONE);
@@ -1,8 +1,10 @@
//! `ScreenModeButton`: the status bar's screen mode button, a flyout of the three modes.
use super::screen_mode::{ScreenMode, ScreenModeCommands};
use super::words::ShellWords;
use crate::contract::{NoValue, Outcome, Props as _, Show as _};
use crate::rails::{FlyoutButton, RailTool};
use crate::runtime::env::Env;
use egui::{Response, Ui};
#[cfg(feature = "testing")]
@@ -43,7 +45,9 @@ impl ScreenModeButton {
pub fn show(self, ui: &mut Ui) -> ScreenModeButtonOutput {
let modes = [ScreenMode::Standard, ScreenMode::FullScreenWithMenuBar, ScreenMode::FullScreen];
let tools: Vec<RailTool<ScreenMode>> = modes.iter().map(|mode| RailTool::new(*mode, ScreenModeCommands::of(*mode))).collect();
let out = FlyoutButton::new(&tools, &self.mode).hold_selects(false).click(ScreenModeCommands::Cycle).show(ui);
// The shell's own word names the button when the Cycle command does not resolve.
let name = Env::of(ui).words::<ShellWords>().screen_mode.clone();
let out = FlyoutButton::new(&tools, &self.mode).label(name).hold_selects(false).click(ScreenModeCommands::Cycle).show(ui);
ScreenModeButtonOutput { response: out.response }
}
}