canvas-w7: review fixes (review-2)

This commit is contained in:
Martin Ball
2026-11-18 14:18:19 +00:00
parent 8b4978b879
commit 01613f11c3
3 changed files with 23 additions and 10 deletions
+9 -8
View File
@@ -153,14 +153,15 @@ impl<'a> CommentBalloons<'a> {
} else {
pages.iter().map(|page| page.rect.right()).fold(f32::NEG_INFINITY, f32::max) + gap
};
let x_of = |page: &PlacedPage| match place {
BalloonPlace::Column => column,
BalloonPlace::Floating if rtl => (page.rect.left() - gap - width).max(room.left()),
BalloonPlace::Floating => {
let beside = page.rect.right() + gap;
// Without room beside the page the card floats over the page's edge, inside the room.
if beside + width <= room.right() { beside } else { (room.right() - width).max(room.left()) }
}
// A card always lies whole inside the room: without room beside the pages it floats over their edge, so
// its text is never cut off by the room's clip.
let x_of = |page: &PlacedPage| {
let preferred = match place {
BalloonPlace::Column => column,
BalloonPlace::Floating if rtl => page.rect.left() - gap - width,
BalloonPlace::Floating => page.rect.right() + gap,
};
preferred.min(room.right() - width).max(room.left())
};
let count = order.len();
+1 -1
View File
@@ -85,7 +85,7 @@ fn balloons_long(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
#[story(CommentBalloons<'static>, covers = [], drive = Drive::Never)]
fn balloons_right_to_left(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let threads = [thread(1, "منى", "الهامش ضيق جدا في هذه الصفحة.", false)];
let threads = [thread(1, "מיכל", "השוליים צרים מדי בעמוד הזה.", false)];
beside_page(ui, data, &threads, &[], None, BalloonPlace::Column)
}
+13 -1
View File
@@ -7,7 +7,7 @@ use craft_theme::variant::Variant;
use craft_ui::buttons::{Button, IconButton};
use craft_ui::contract::{Bind, Common, Component, Cx, MeasureCx, PaintUi, PartsCx, Props as _, Role, WordSetCx as _, clicked};
use craft_ui::controls::disclosure::DisclosureGlyph;
use craft_ui::primitives::{HAlign, IconSpec, PaintShape, TextRun, Wrap};
use craft_ui::primitives::{HAlign, IconSpec, PaintShape, StrokeWidth, TextRun, Wrap};
use craft_ui::runtime::env::Label;
use craft_ui::runtime::focus::{self, FocusTarget};
use craft_ui::style::{ComponentStyle, DataColor, Ink, StyleColor, StyleCx, TypeRole};
@@ -33,6 +33,10 @@ pub(crate) struct CommentRowStyle {
faint: StyleColor,
highlight: StyleColor,
bar: StyleColor,
/// The surface of a balloon card.
card: StyleColor,
/// The border of a balloon card.
border: StyleColor,
avatar: StyleColor,
avatar_ink: StyleColor,
/// The disc behind a card's kind icon.
@@ -677,6 +681,8 @@ impl Component for CommentRow<'_> {
faint: cx.color(color.text.faint),
highlight: cx.color(color.state.selected),
bar: cx.color(color.accent.solid),
card: cx.color(color.surface.raised),
border: cx.color(color.line.border),
avatar: cx.color(color.accent.strong),
avatar_ink: cx.color(color.text.on_strong),
sunken: cx.color(color.surface.sunken),
@@ -726,6 +732,12 @@ impl Component for CommentRow<'_> {
let rtl = cx.env.direction().is_rtl();
let now = self.now;
let age = |then: i64| age_text(&cx.env, then, now);
// A balloon card sits over the page, so it carries its own surface and border.
if self.actions == CardActions::Buttons {
let shape = PaintShape::Rect(rect, CornerRadius::ZERO);
ui.draw().fill(&shape, st.card);
ui.draw().stroke(&shape, StrokeWidth::Thin, st.border);
}
if self.selected {
ui.draw().fill(&PaintShape::Rect(rect, CornerRadius::ZERO), st.highlight);
let bar = if rtl {