framework-01-w6: net change of 2 commits

- framework-01-w6: written from its sheet
- framework-01-w6: the edit-menu trials right-click outside the focusing click's click run (top run round)
This commit is contained in:
aiongg
2026-11-15 04:46:05 +00:00
parent 6be6c241b1
commit bb9d7745b6
3 changed files with 63 additions and 14 deletions
+3 -1
View File
@@ -317,6 +317,7 @@ impl Component for ColorWheel<'_> {
fn parts(&mut self, rect: Rect, cx: &mut PartsCx<'_, Self>) {
let geometry = ColorWheel::geometry(cx.style, rect);
let reach = cx.style.grab;
let hue = finite(cx.value().copied().unwrap_or_else(blank).values[0]);
// The ring takes every press within its reach; the triangle takes the circle inside the ring's reach.
cx.part(RING, HitShape::circle(geometry.center, geometry.outer + reach))
.sense(Sense::DRAG | Sense::SETS_ON_PRESS | Sense::CLICK)
@@ -326,7 +327,8 @@ impl Component for ColorWheel<'_> {
.sense(Sense::DRAG | Sense::SETS_ON_PRESS | Sense::CLICK)
.priority(HitPriority::new(HitLevel::Handle, 0))
.focusable()
.focus_shape(FocusShape::Circle);
// The triangle turns with the hue, so its ring is rebuilt each pass.
.focus_shape(FocusShape::Polygon(geometry.corners(hue, 0.0).to_vec()));
}
fn bind(&mut self) -> Option<BindMut<'_, ModelValues>> {
@@ -3,7 +3,8 @@
use super::draw::PaintShape;
use crate::style::{Flags, FocusLook};
use egui::emath::GuiRounding as _;
use egui::{CornerRadius, Shape, Stroke, StrokeKind};
use crate::runtime::focus::FocusShape;
use egui::{CornerRadius, Pos2, Rect, Shape, Stroke, StrokeKind, Vec2};
/// How a focus indication is drawn.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
@@ -28,10 +29,12 @@ impl FocusRing {
/// The shape the ring is drawn around for a part declared with `shape` and laid out in `rect`: the rect, the circle
/// inside it, or the polygon's points.
#[allow(dead_code)] // P3(framework-01-w6): fx.F33
pub(crate) fn outline(shape: &crate::runtime::focus::FocusShape, rect: egui::Rect) -> PaintShape {
let _ = (shape, rect);
todo!("fx.F33")
pub(crate) fn outline(shape: &FocusShape, rect: Rect) -> PaintShape {
match shape {
FocusShape::Rect => PaintShape::Rect(rect, CornerRadius::ZERO),
FocusShape::Circle => PaintShape::Circle(rect.center(), rect.width().min(rect.height()) / 2.0),
FocusShape::Polygon(points) => PaintShape::Polygon(points.clone()),
}
}
/// The shapes of the ring around `shape`, grown by `look.offset`. A halo adds a stroke twice as wide at a
@@ -60,8 +63,34 @@ impl FocusRing {
Shape::rect_stroke(grown, radius, stroke, StrokeKind::Inside)
}
PaintShape::Circle(center, r) => Shape::circle_stroke(*center, r + offset, stroke),
PaintShape::Polygon(points) => Shape::closed_line(points.clone(), stroke),
PaintShape::Polygon(points) => Shape::closed_line(grow_polygon(points, offset), stroke),
PaintShape::Path(points) => Shape::line(points.clone(), stroke),
}
}
}
/// `points` moved outward by `offset`: each vertex slides along the bisector of its two edge normals by
/// `offset / cos(half angle)`, so every edge ends up `offset` from where it was (a mitred outline). Fewer than three
/// points, or an offset of zero, leave the polygon as it is.
fn grow_polygon(points: &[Pos2], offset: f32) -> Vec<Pos2> {
let count = points.len();
if count < 3 || offset == 0.0 {
return points.to_vec();
}
// The sign of the area says which side of an edge is outside, whatever the winding.
let area: f32 = (0..count).map(|i| points[i].x * points[(i + 1) % count].y - points[(i + 1) % count].x * points[i].y).sum();
let side = if area < 0.0 { -1.0 } else { 1.0 };
let normal = |from: Pos2, to: Pos2| -> Vec2 {
let along = (to - from).normalized();
Vec2::new(along.y, -along.x) * side
};
(0..count)
.map(|i| {
let (before, here, after) = (points[(i + count - 1) % count], points[i], points[(i + 1) % count]);
let (n1, n2) = (normal(before, here), normal(here, after));
// 1 + n1.n2 = 2 cos^2(half angle); it vanishes only where the edges fold back on themselves.
let miter = 1.0 + n1.dot(n2);
if miter < 1e-3 { here + n1 * offset } else { here + (n1 + n2) * (offset / miter) }
})
.collect()
}
+25 -7
View File
@@ -32,7 +32,10 @@ fn rig() -> Rig {
}
impl Rig {
/// A right click well after the click that focused the field: egui counts presses of any button into one click
/// run, and a second press of a run selects the word under it.
fn right_click_in_the_field(&mut self) {
self.fixture.advance(1.0);
let at = self.fixture.by_label("Name").expect("the field").center();
self.fixture.frame(vec![pointer::secondary(at, true)]);
self.fixture.frame(vec![pointer::secondary(at, false)]);
@@ -109,16 +112,31 @@ fn an_edit_command_fired_from_elsewhere_reaches_the_focused_field() {
assert_eq!(*rig.text.borrow(), "");
}
/// The Delete row deletes the field's selection: the command reaches the focused text part as its edit, not the app.
/// Cut, Copy and Delete need a selection; Paste, Undo and Select All do not.
#[trial]
fn the_edit_menus_delete_deletes_the_selection_in_the_field() {
fn the_edit_menu_offers_cut_copy_and_delete_only_with_a_selection() {
let mut rig = rig();
let selection_rows = ["Cut", "Copy", "Delete"];
let always_rows = ["Paste", "Undo", "Select All"];
let disabled = |rig: &Rig, row: &str| {
let target = rig.fixture.by_label(row).unwrap_or_else(|| panic!("the edit menu has {row}"));
rig.fixture.tree().is_disabled_key(target.node)
};
rig.right_click_in_the_field();
assert!(rig.menu_open(), "the edit menu is open");
for row in selection_rows {
assert!(disabled(&rig, row), "{row} is disabled while the selection is empty");
}
for row in always_rows {
assert!(!disabled(&rig, row), "{row} stays enabled without a selection");
}
rig.fixture.key(Key::Escape, Modifiers::NONE);
rig.fixture.settle();
rig.fixture.key(Key::A, Modifiers::COMMAND);
rig.fixture.settle();
rig.right_click_in_the_field();
let delete = rig.fixture.by_label("Delete").expect("the Delete row");
rig.fixture.click(&delete);
rig.fixture.settle();
assert_eq!(*rig.text.borrow(), "", "Delete takes the selection out of the field");
assert!(rig.focus_in_the_field(), "the focus is back in the field");
assert!(rig.menu_open(), "the edit menu opens again");
for row in selection_rows {
assert!(!disabled(&rig, row), "{row} is enabled with a selection");
}
}