mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 02:09:00 +00:00
fw sync: TaskBar::compact opt-in (small members in a tight frame, Pad::Tight, Bar::compact) for PdfCraft's text box Done/Discard bar
This commit is contained in:
@@ -88,6 +88,10 @@ pub struct TaskBar<'a> {
|
||||
/// What an outside press does to the bar.
|
||||
#[prop]
|
||||
dismiss: TaskBarDismiss,
|
||||
/// The bar is compact: its members at the small control size in a tight frame, as PdfCraft's text box bar shows
|
||||
/// Done and Discard (production's 24-point buttons in a 2-point frame). Off by default.
|
||||
#[prop]
|
||||
compact: bool,
|
||||
}
|
||||
|
||||
/// What a bar hangs from: the screen bounds of document points, or the canvas view's top edge, aligned in reading
|
||||
@@ -204,7 +208,15 @@ impl MoreMenu {
|
||||
impl<'a> TaskBar<'a> {
|
||||
/// A bar named `label` hung below the screen bounds of `anchor` (document points) until `place` moves it.
|
||||
pub fn new(label: impl Into<Label>, anchor: &'a [Point], place: Bind<'a, TaskBarPlace>) -> Self {
|
||||
TaskBar { label: label.into(), hang: Hang::Points(anchor), place, kind: TaskBarKind::Task, side: None, dismiss: TaskBarDismiss::Close }
|
||||
TaskBar {
|
||||
label: label.into(),
|
||||
hang: Hang::Points(anchor),
|
||||
place,
|
||||
kind: TaskBarKind::Task,
|
||||
side: None,
|
||||
dismiss: TaskBarDismiss::Close,
|
||||
compact: false,
|
||||
}
|
||||
}
|
||||
|
||||
/// A fixed bar named `label` hung below the screen bounds of `anchor`, above them when there is no room below.
|
||||
@@ -226,6 +238,7 @@ impl<'a> TaskBar<'a> {
|
||||
kind,
|
||||
side: None,
|
||||
dismiss: TaskBarDismiss::Close,
|
||||
compact: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,7 +250,7 @@ impl<'a> TaskBar<'a> {
|
||||
|
||||
/// Shows the bar inside `area`; `body` fills its members.
|
||||
pub fn show<R>(self, ui: &mut Ui, area: Rect, mut body: impl FnMut(&mut Ui, &mut TaskBarCx<'_>) -> R) -> Inner<TaskBarOutput, R> {
|
||||
let TaskBar { label, hang, mut place, kind, side, dismiss } = self;
|
||||
let TaskBar { label, hang, mut place, kind, side, dismiss, compact } = self;
|
||||
let side = side.unwrap_or(match kind {
|
||||
TaskBarKind::Task | TaskBarKind::Fixed => Side::Below,
|
||||
TaskBarKind::Selection => Side::Above,
|
||||
@@ -277,7 +290,9 @@ impl<'a> TaskBar<'a> {
|
||||
let grip = movable.then(|| words.task_bar_move.clone());
|
||||
let mut shown = layer.show(ui, |ui, _| {
|
||||
// The bar is the one surface: the grip is its first member, on the members' line inside its padding.
|
||||
Bar::new(Label::Empty, BarKind::Tool).surface(SurfaceKind::Floating).show(ui, |ui, _| {
|
||||
let bar = Bar::new(Label::Empty, BarKind::Tool).surface(SurfaceKind::Floating);
|
||||
let bar = if compact { bar.compact() } else { bar };
|
||||
bar.show(ui, |ui, _| {
|
||||
if let Some(grip) = &grip {
|
||||
let _ = Icon::new(IconSpec::svg(IconId::new("grip"))).label(grip.clone()).show(ui);
|
||||
}
|
||||
|
||||
@@ -378,3 +378,43 @@ fn a_dragged_task_bar_stands_under_the_pointer_in_each_frame_and_writes_its_plac
|
||||
fixture.settle();
|
||||
assert!((seen(&scene).rect.min - dropped_at).length() < SLACK, "the written place keeps the bar there: {:?}", seen(&scene).rect);
|
||||
}
|
||||
|
||||
/// A fixed bar of two icon buttons (production's text box Done and Discard), compact or not: its rect, and each
|
||||
/// button's rect by name.
|
||||
fn two_buttons(compact: bool) -> (Rect, Vec<Rect>) {
|
||||
use craft_behavior::IconId;
|
||||
use craft_ui::buttons::IconButton;
|
||||
use craft_ui::contract::Props as _;
|
||||
let scene = Rc::new(RefCell::new(Rect::NOTHING));
|
||||
let shared = Rc::clone(&scene);
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let _ = on_canvas(ui, |ui, area, _| {
|
||||
let anchor = frame(DocVec::ZERO);
|
||||
let shown = TaskBar::fixed("Text box actions", &anchor).compact(compact).show(ui, area, |ui, _| {
|
||||
let _ = IconButton::new(IconId::new("check")).label("Done adding text").show(ui);
|
||||
let _ = IconButton::new(IconId::new("close")).label("Discard this text").show(ui);
|
||||
});
|
||||
*shared.borrow_mut() = shown.output.rect;
|
||||
shown.output
|
||||
});
|
||||
});
|
||||
fixture.room(Vec2::new(1120.0, 720.0));
|
||||
fixture.settle();
|
||||
let buttons = ["Done adding text", "Discard this text"].map(|name| fixture.by_label(name).map_or(Rect::NOTHING, |button| button.rect));
|
||||
let bar = *scene.borrow();
|
||||
(bar, buttons.to_vec())
|
||||
}
|
||||
|
||||
/// A compact bar holds its members at the small control size in a tight frame: smaller than the standard bar, with
|
||||
/// every member whole inside it.
|
||||
#[trial]
|
||||
fn a_compact_task_bar_is_smaller_and_shows_every_member_whole() {
|
||||
let (standard, _) = two_buttons(false);
|
||||
let (compact, buttons) = two_buttons(true);
|
||||
assert!(compact.is_positive() && standard.is_positive(), "both bars show: {standard:?} {compact:?}");
|
||||
assert!(compact.height() + 4.0 < standard.height(), "the compact bar is lower: {compact:?} against {standard:?}");
|
||||
assert!(compact.width() + 4.0 < standard.width(), "the compact bar is narrower: {compact:?} against {standard:?}");
|
||||
for button in buttons {
|
||||
assert!(button.is_positive() && compact.expand(SLACK).contains_rect(button), "each member shows whole in {compact:?}: {button:?}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ pub(super) fn shared_line(props: &ContainerProps, sizes: RegionSizes) -> Option<
|
||||
pub fn pad_of(tokens: &UiTokens, pad: Pad) -> f32 {
|
||||
let pads = &tokens.tokens().space.pad;
|
||||
match pad {
|
||||
Pad::Tight => tokens.tokens().space.gap.tight,
|
||||
Pad::Control => pads.control,
|
||||
Pad::Regular => pads.regular,
|
||||
Pad::Roomy => pads.roomy,
|
||||
|
||||
@@ -132,6 +132,8 @@ pub enum Pad {
|
||||
/// No padding.
|
||||
#[default]
|
||||
None,
|
||||
/// `space.gap.tight`: a hairline frame around a compact group, as a small floating action bar's.
|
||||
Tight,
|
||||
/// `space.pad.control`.
|
||||
Control,
|
||||
/// `space.pad.regular`.
|
||||
|
||||
@@ -160,6 +160,14 @@ impl<'a> Bar<'a> {
|
||||
self
|
||||
}
|
||||
|
||||
/// Makes the bar compact: its members at the small control size and a tight pad around them, as a small floating
|
||||
/// action bar beside an edit (PdfCraft's text box Done and Discard).
|
||||
#[must_use]
|
||||
pub fn compact(mut self) -> Self {
|
||||
self.props = self.props.child_size(ControlSize::Sm).pad(Pad::Tight);
|
||||
self
|
||||
}
|
||||
|
||||
/// Paints `kind` behind the bar instead of the chrome: a bar that floats on its own, as a canvas's task bar does,
|
||||
/// is a floating surface with its corners and shadow.
|
||||
#[must_use]
|
||||
|
||||
Reference in New Issue
Block a user