Options bar: icon-only buttons draw at the tool size (photocraft#15536)

This commit is contained in:
aiongg
2026-11-21 08:05:19 +00:00
parent 57a1de2594
commit 03cf32f21b
2 changed files with 25 additions and 1 deletions
+4 -1
View File
@@ -11,7 +11,7 @@ use crate::layout_components::Row;
use crate::runtime::access::Name;
use crate::runtime::commands::{CommandSet as _, Commands as _};
use crate::runtime::env::Label;
use crate::style::{ComponentStyle, StyleCx, SurfaceKind};
use crate::style::{ComponentStyle, GlyphRole, StyleCx, SurfaceKind};
use craft_behavior::{IconId, Metrics, NavShape, Roving, Sense};
use craft_theme::ControlSize;
use egui::{Response, Ui};
@@ -129,6 +129,9 @@ impl<'a> Bar<'a> {
if kind == BarKind::Status {
props = props.live(Politeness::Polite);
}
if kind == BarKind::Options {
props = props.child_glyphs(GlyphRole::Tool);
}
Bar { common: Common::new(), props, kind, commit_cancel: None, committed: false, cancelled: false, trailing: None }.label(label)
}
+21
View File
@@ -14,6 +14,7 @@ use craft_ui::display::Text;
use craft_ui::form::Field;
use craft_ui::layout_components::{Row, Stack};
use craft_ui::pickers::Select;
use craft_ui::style::GlyphRole;
use craft_ui::testing::focus::AccessActionKind;
use craft_ui::testing::layout::Block;
use craft_ui::testing::{Fixture, shrink_least_runs, trial};
@@ -449,6 +450,26 @@ fn a_labelled_check_box_in_a_row_in_a_bar_lays_out_under_rtl() {
assert!(label.max.x <= alpha.min.x + SLACK, "the check box {label:?} follows Alpha {alpha:?} from the right");
}
/// An icon-only button in an options bar draws its icon at the tool size, as the align strip's buttons do.
#[trial]
fn an_icon_button_in_an_options_bar_draws_its_icon_at_the_tool_size() {
let mut fixture = Fixture::new(|ui| {
Bar::new("Options", BarKind::Options).show(ui, |ui, _| {
IconButton::new(IconId::new("settings")).label("Plain").show(ui);
IconButton::new(IconId::new("settings")).label("Tool").glyphs(GlyphRole::Tool).show(ui);
});
});
fixture.room(Vec2::new(400.0, 80.0)).settle();
let sides: Vec<f32> = fixture
.styles_of(std::any::type_name::<IconButton<'static>>())
.iter()
.flat_map(|seen| seen.looks.icons.iter().map(|icon| icon.side))
.collect();
// Buttons that resolve the same looks share one recorded style, so a single side means they agree.
assert!(!sides.is_empty(), "the buttons resolved a style");
assert!(sides.iter().all(|side| (side - sides[0]).abs() <= 0.01), "the options bar's button and the tool button differ: {sides:?}");
}
/// Each pass's stops, each with the roving group it registered in.
type StopGroups = Rc<std::cell::RefCell<Vec<Vec<(egui::Id, Option<egui::Id>)>>>>;