Toolbar separators between tool groups

AnnotationToolbar puts a vertical divider before each group button, as a
Bar separates its groups. GraphEditor's bottom bar draws a divider rule in
each gap between two button groups, inset from the bar's edges.
This commit is contained in:
aiongg
2026-11-12 14:32:51 +00:00
parent 2e64f951b8
commit 3da412f36b
2 changed files with 18 additions and 6 deletions
+6 -4
View File
@@ -4,6 +4,7 @@ use craft_behavior::Mixed;
use craft_ui::bars::{Bar, BarKind};
use craft_ui::choice::{RadioGroup, Swatch};
use craft_ui::contract::{Bind, BodyCx, NoValue, Outcome, Props as _, Remember as _, Show as _, ShowContainer as _};
use craft_ui::display::Divider;
use craft_ui::layout_components::Row;
use craft_ui::popover::Popover;
use craft_ui::rails::{FlyoutButton, LastUsed, RailTool, SlotId, ToolSlot, remembered, shown_tool};
@@ -44,10 +45,10 @@ impl Outcome for AnnotationToolbarOutput {
#[derive(Clone, Copy, Debug, Default)]
struct PaletteOpen(bool);
/// Acrobat's quick bar: Select, then the three groups (Comment, Highlight, Draw), each a button showing its
/// last-used tool with a flyout of the group's tools, then the colour well and the line width of the tool's new
/// annotations ([`AnnotateTool::color`], [`AnnotateTool::width`]); both are disabled for tools that draw nothing
/// (Select, Eraser) and the width for markups. The colour well opens a palette popover.
/// Acrobat's quick bar: Select, then the three groups (Comment, Highlight, Draw), a rule before each, each a button
/// showing its last-used tool with a flyout of the group's tools, then the colour well and the line width of the
/// tool's new annotations ([`AnnotateTool::color`], [`AnnotateTool::width`]); both are disabled for tools that draw
/// nothing (Select, Eraser) and the width for markups. The colour well opens a palette popover.
#[derive(craft_ui::contract::Pattern)]
pub struct AnnotationToolbar<'a> {
tool: &'a mut AnnotateTool,
@@ -83,6 +84,7 @@ impl<'a> AnnotationToolbar<'a> {
annotate.tool = tool;
}
for (slot, group) in slots.iter().zip(AnnotationGroup::ALL) {
Divider::vertical().show(ui);
let tools: Vec<&RailTool<AnnotationTool>> = slot.tools.iter().collect();
let shown = shown_tool(&current, slot.id, &tools, &last, |_| true).map_or(current, |tool| tool.id);
let out = FlyoutButton::new(&slot.tools, &shown)
+12 -2
View File
@@ -263,7 +263,7 @@ enum Button {
}
impl Button {
/// The buttons in reading order; a wider gap separates neighbours of different groups.
/// The buttons in reading order; a wider gap with a rule in it separates neighbours of different groups.
const ALL: [Button; 14] = [
Button::Value,
Button::Speed,
@@ -537,6 +537,12 @@ impl<'a> GraphEditor<'a> {
cells
}
/// Where a rule separates two groups of the shown buttons `cells`: the middle of the gap between them. A group
/// past the bar's end leaves no rule after the last shown button.
fn bar_rules(cells: &[(usize, Button, Rect)]) -> Vec<f32> {
cells.windows(2).filter(|pair| pair[0].1.group() != pair[1].1.group()).map(|pair| (pair[0].2.right() + pair[1].2.left()) / 2.0).collect()
}
/// The keys: a click picks, a drag moves the selected keys.
fn press_keys(&mut self, cx: &mut Cx<'_, Self>, axis: &TimeAxis, frame: &Frame, left: f32, shown_range: (f64, f64)) {
let keys: Vec<(usize, KeyframeId)> = self.keys_in_order().map(|(n, key)| (n, key.id)).collect();
@@ -999,8 +1005,12 @@ impl Component for GraphEditor<'_> {
// The bottom bar, over whatever the curves drew past the plot.
draw.fill(&PaintShape::Rect(bar, CornerRadius::ZERO), style.bar_fill);
draw.rule(RuleKind::Divider, bar.left_top(), bar.right_top());
let cells = Self::bar_cells(bar, style);
for x in Self::bar_rules(&cells) {
draw.rule(RuleKind::Divider, Pos2::new(x, bar.top() + style.gap), Pos2::new(x, bar.bottom() - style.gap));
}
let words = cx.words::<GraphEditorWords>();
for (at, button, _) in Self::bar_cells(bar, style) {
for (at, button, _) in cells {
let icon = IconSpec::svg(IconId::new(button.icon()));
let name = Label::from(button.name(&words).to_owned());
match button.on(&range) {