mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-29 01:34:29 +01:00
Merge pull request #9951 from dotCooCoo/fix/ui-sweep-title-window
App bar: Discord, search and workspace switcher stand an item gap apart
This commit is contained in:
2 files changed
+33
-8
No files matched your search
@@ -6,7 +6,7 @@ use std::cell::RefCell;
|
||||
use craft::behavior::IconId;
|
||||
use craft::menu::MenuBarUi;
|
||||
use craft::ui::buttons::{Button, IconButton, ToggleButton};
|
||||
use craft::ui::contract::{Bind, BodyCx, Props, Show, ShowContainer};
|
||||
use craft::ui::contract::{Bind, BodyCx, Gap, Props, Show, ShowContainer};
|
||||
use craft::ui::display::Picture;
|
||||
use craft::ui::layout_components::Row;
|
||||
use craft::ui::primitives::IconSpec;
|
||||
@@ -114,17 +114,20 @@ fn leading(ui: &mut Ui, app: &mut VectorcraftApp) {
|
||||
}
|
||||
|
||||
/// The end of the bar: each ranked control in a row of its own, which the fitted title bar gives up whole, lowest rank
|
||||
/// first, before the menus narrow.
|
||||
/// first, before the menus narrow. The controls are `space.gap.item` apart, the gap between neighboring controls in a
|
||||
/// bar.
|
||||
fn trailing(ui: &mut Ui, app: &mut VectorcraftApp) {
|
||||
let safe = vectorcraft_plugins::safe_mode::active();
|
||||
for t in Trailing::SHOWN.into_iter().filter(|t| safe || *t != Trailing::Safe) {
|
||||
match t.rank() {
|
||||
Some(rank) => {
|
||||
Row::new().fit_rank(rank).show(ui, |ui, _| t.show(app, ui));
|
||||
Row::new().gap(Gap::Item).show(ui, |ui, _| {
|
||||
for t in Trailing::SHOWN.into_iter().filter(|t| safe || *t != Trailing::Safe) {
|
||||
match t.rank() {
|
||||
Some(rank) => {
|
||||
Row::new().fit_rank(rank).show(ui, |ui, _| t.show(app, ui));
|
||||
}
|
||||
None => t.show(app, ui),
|
||||
}
|
||||
None => t.show(app, ui),
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// The application bar, the body of the shell's title bar: brand mark, Home and menus, then Discord,
|
||||
|
||||
@@ -473,6 +473,28 @@ fn the_app_bar_gives_up_its_right_hand_controls_in_order() {
|
||||
assert!(widest.zip(narrowest).is_some_and(|(w, n)| n >= w - 0.5), "the search keeps its width until it goes: {search_widths:?}");
|
||||
}
|
||||
|
||||
/// The app bar's right-hand controls stand at least `space.gap.item` apart, the gap between neighboring controls in a
|
||||
/// bar, so a hovered control's highlight does not touch the one beside it.
|
||||
#[test]
|
||||
fn the_app_bar_keeps_its_right_hand_controls_an_item_gap_apart() {
|
||||
crate::i18n::set_current(crate::i18n::Lang::EN);
|
||||
let app = crate::VectorcraftApp::new(Session::new(), Default::default());
|
||||
let gap = Rc::new(std::cell::Cell::new(0.0_f32));
|
||||
let read = Rc::clone(&gap);
|
||||
let mut bar = Shown::new(app, egui::vec2(1600.0, 600.0), move |app, ui| {
|
||||
read.set(craft::ui::runtime::env::Env::of(ui).tokens.space.gap.item);
|
||||
app.ui(ui);
|
||||
});
|
||||
bar.frame(Vec::new()).frame(Vec::new());
|
||||
assert!(gap.get() > 0.0, "the item gap is read from the theme");
|
||||
let controls = ["Discord", "Search commands", "Choose a workspace"];
|
||||
let rects: Vec<egui::Rect> = controls.iter().map(|c| bar.starting(c).unwrap_or_else(|| panic!("{c} shows")).rect).collect();
|
||||
for pair in rects.windows(2) {
|
||||
let between = pair[1].left() - pair[0].right();
|
||||
assert!(between >= gap.get() - 0.5, "neighboring controls {pair:?} are {between} apart, under the item gap {}", gap.get());
|
||||
}
|
||||
}
|
||||
|
||||
/// A text the status bar painted, with where it lies.
|
||||
#[derive(Debug)]
|
||||
struct StatusText {
|
||||
|
||||
Reference in new issue
Block a user