Skip to content

Commit 1f29d95

Browse files
committed
Various changes to comments and documentation
1 parent 67a9586 commit 1f29d95

15 files changed

+56
-120
lines changed

masonry/src/action.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use std::any::Any;
55

66
use crate::event::PointerButton;
77

8-
// TODO - Refactor - See issue https://github.com/linebender/xilem/issues/335
8+
// TODO - Replace actions with an associated type on the Widget trait
9+
// See https://github.com/linebender/xilem/issues/664
910

1011
// TODO - TextCursor changed, ImeChanged, EnterKey, MouseEnter
1112
#[non_exhaustive]

masonry/src/contexts.rs

-13
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
//! The context types that are passed into various widget methods.
55
6-
use std::time::Duration;
7-
86
use accesskit::TreeUpdate;
97
use dpi::LogicalPosition;
108
use parley::{FontContext, LayoutContext};
@@ -709,14 +707,6 @@ impl_context_method!(
709707
.push_back(RenderRootSignal::ShowWindowMenu(position));
710708
}
711709

712-
/// Request a timer event.
713-
///
714-
/// The return value is a token, which can be used to associate the
715-
/// request with the event.
716-
pub fn request_timer(&mut self, _deadline: Duration) -> TimerToken {
717-
todo!("request_timer");
718-
}
719-
720710
/// Mark child widget as stashed.
721711
///
722712
/// If `stashed` is true, the child will not be painted or listed in the accessibility tree.
@@ -737,9 +727,6 @@ impl_context_method!(
737727
}
738728
);
739729

740-
// FIXME - Remove
741-
pub struct TimerToken;
742-
743730
impl EventCtx<'_> {
744731
// TODO - clearly document all semantics of pointer capture when they've been decided on
745732
// TODO - Figure out cases where widget should be notified of pointer capture

masonry/src/event.rs

+21-13
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ impl From<PointerButton> for PointerButtons {
181181
// TODO - How can RenderRoot express "I started a drag-and-drop op"?
182182
// TODO - Touchpad, Touch, AxisMotion
183183
// TODO - How to handle CursorEntered?
184-
// Note to self: Events like "pointerenter", "pointerleave" are handled differently at the Widget level. But that's weird because WidgetPod can distribute them. Need to think about this again.
185184
#[derive(Debug, Clone)]
186185
pub enum PointerEvent {
187186
PointerDown(PointerButton, PointerState),
@@ -313,6 +312,7 @@ pub enum Update {
313312
}
314313

315314
impl PointerEvent {
315+
/// Create a [`PointerEvent::PointerLeave`] event with dummy values.
316316
pub fn new_pointer_leave() -> Self {
317317
// TODO - The fact we're creating so many dummy values might be
318318
// a sign we should refactor that struct
@@ -328,6 +328,7 @@ impl PointerEvent {
328328
PointerEvent::PointerLeave(pointer_state)
329329
}
330330

331+
/// Returns the [`PointerState`] of the event.
331332
pub fn pointer_state(&self) -> &PointerState {
332333
match self {
333334
PointerEvent::PointerDown(_, state)
@@ -343,13 +344,17 @@ impl PointerEvent {
343344
}
344345
}
345346

347+
/// Returns the position of the pointer event, except for [`PointerEvent::PointerLeave`] and [`PointerEvent::HoverFileCancel`].
346348
pub fn position(&self) -> Option<LogicalPosition<f64>> {
347349
match self {
348350
PointerEvent::PointerLeave(_) | PointerEvent::HoverFileCancel(_) => None,
349351
_ => Some(self.pointer_state().position),
350352
}
351353
}
352354

355+
/// Short name, for debug logging.
356+
///
357+
/// Returns the enum variant name.
353358
pub fn short_name(&self) -> &'static str {
354359
match self {
355360
PointerEvent::PointerDown(_, _) => "PointerDown",
@@ -365,6 +370,10 @@ impl PointerEvent {
365370
}
366371
}
367372

373+
/// Returns true if the event is likely to occur every frame.
374+
///
375+
/// Developers should avoid logging during high-density events to avoid
376+
/// cluttering the console.
368377
pub fn is_high_density(&self) -> bool {
369378
match self {
370379
PointerEvent::PointerDown(_, _) => false,
@@ -382,20 +391,25 @@ impl PointerEvent {
382391
}
383392

384393
impl TextEvent {
394+
/// Short name, for debug logging.
385395
pub fn short_name(&self) -> &'static str {
386396
match self {
387-
TextEvent::KeyboardKey(KeyEvent { repeat: true, .. }, _) => "KeyboardKey (repeat)",
397+
TextEvent::KeyboardKey(KeyEvent { repeat: true, .. }, _) => "KeyboardKey(repeat)",
388398
TextEvent::KeyboardKey(_, _) => "KeyboardKey",
389399
TextEvent::Ime(Ime::Disabled) => "Ime::Disabled",
390400
TextEvent::Ime(Ime::Enabled) => "Ime::Enabled",
391401
TextEvent::Ime(Ime::Commit(_)) => "Ime::Commit",
392402
TextEvent::Ime(Ime::Preedit(s, _)) if s.is_empty() => "Ime::Preedit(\"\")",
393-
TextEvent::Ime(Ime::Preedit(_, _)) => "Ime::Preedit",
403+
TextEvent::Ime(Ime::Preedit(_, _)) => "Ime::Preedit(\"...\")",
394404
TextEvent::ModifierChange(_) => "ModifierChange",
395405
TextEvent::FocusChange(_) => "FocusChange",
396406
}
397407
}
398408

409+
/// Returns true if the event is likely to occur every frame.
410+
///
411+
/// Developers should avoid logging during high-density events to avoid
412+
/// cluttering the console.
399413
pub fn is_high_density(&self) -> bool {
400414
match self {
401415
TextEvent::KeyboardKey(_, _) => false,
@@ -408,6 +422,9 @@ impl TextEvent {
408422
}
409423

410424
impl AccessEvent {
425+
/// Short name, for debug logging.
426+
///
427+
/// Returns the enum variant name.
411428
pub fn short_name(&self) -> &'static str {
412429
match self.action {
413430
accesskit::Action::Click => "Click",
@@ -442,15 +459,6 @@ impl AccessEvent {
442459

443460
impl PointerState {
444461
pub fn empty() -> Self {
445-
#[cfg(FALSE)]
446-
#[allow(unsafe_code)]
447-
// SAFETY: Uuuuh, unclear. Winit says the dummy id should only be used in
448-
// tests and should never be passed to winit. In principle, we're never
449-
// passing this id to winit, but it's still visible to custom widgets which
450-
// might do so if they tried really hard.
451-
// It would be a lot better if winit could just make this constructor safe.
452-
let device_id = unsafe { DeviceId::dummy() };
453-
454462
PointerState {
455463
physical_position: PhysicalPosition::new(0.0, 0.0),
456464
position: LogicalPosition::new(0.0, 0.0),
@@ -466,7 +474,7 @@ impl PointerState {
466474
impl Update {
467475
/// Short name, for debug logging.
468476
///
469-
/// Essentially returns the enum variant name.
477+
/// Returns the enum variant name.
470478
pub fn short_name(&self) -> &str {
471479
match self {
472480
Update::WidgetAdded => "WidgetAdded",

masonry/src/testing/helper_widgets.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@ use accesskit::{Node, Role};
1616
use smallvec::SmallVec;
1717
use tracing::trace_span;
1818
use vello::Scene;
19-
use widget::widget::get_child_at_pos;
20-
use widget::WidgetRef;
2119

2220
use crate::event::{PointerEvent, TextEvent};
23-
use crate::widget::SizedBox;
24-
25-
// TODO: Expect doesn't work here
26-
#[allow(clippy::wildcard_imports, reason = "Deferred: Noisy")]
27-
use crate::*;
21+
use crate::widget::widget::get_child_at_pos;
22+
use crate::widget::{SizedBox, WidgetRef};
23+
use crate::{
24+
AccessCtx, AccessEvent, AsAny, BoxConstraints, ComposeCtx, CursorIcon, EventCtx, LayoutCtx,
25+
PaintCtx, Point, QueryCtx, RegisterCtx, Size, Update, UpdateCtx, Widget, WidgetId, WidgetPod,
26+
};
2827

2928
pub type PointerEventFn<S> = dyn FnMut(&mut S, &mut EventCtx, &PointerEvent);
3029
pub type TextEventFn<S> = dyn FnMut(&mut S, &mut EventCtx, &TextEvent);
@@ -284,13 +283,13 @@ impl<S> ModularWidget<S> {
284283

285284
#[warn(clippy::missing_trait_methods)]
286285
impl<S: 'static> Widget for ModularWidget<S> {
287-
fn on_pointer_event(&mut self, ctx: &mut EventCtx, event: &event::PointerEvent) {
286+
fn on_pointer_event(&mut self, ctx: &mut EventCtx, event: &PointerEvent) {
288287
if let Some(f) = self.on_pointer_event.as_mut() {
289288
f(&mut self.state, ctx, event);
290289
}
291290
}
292291

293-
fn on_text_event(&mut self, ctx: &mut EventCtx, event: &event::TextEvent) {
292+
fn on_text_event(&mut self, ctx: &mut EventCtx, event: &TextEvent) {
294293
if let Some(f) = self.on_text_event.as_mut() {
295294
f(&mut self.state, ctx, event);
296295
}
@@ -441,9 +440,9 @@ impl Widget for ReplaceChild {
441440
self.child.on_event(ctx, event)
442441
}
443442

444-
fn on_pointer_event(&mut self, _ctx: &mut EventCtx, _event: &event::PointerEvent) {}
443+
fn on_pointer_event(&mut self, _ctx: &mut EventCtx, _event: &PointerEvent) {}
445444

446-
fn on_text_event(&mut self, _ctx: &mut EventCtx, _event: &event::TextEvent) {}
445+
fn on_text_event(&mut self, _ctx: &mut EventCtx, _event: &TextEvent) {}
447446

448447
fn on_access_event(&mut self, _ctx: &mut EventCtx, _event: &AccessEvent) {}
449448

@@ -507,12 +506,12 @@ impl Recording {
507506

508507
#[warn(clippy::missing_trait_methods)]
509508
impl<W: Widget> Widget for Recorder<W> {
510-
fn on_pointer_event(&mut self, ctx: &mut EventCtx, event: &event::PointerEvent) {
509+
fn on_pointer_event(&mut self, ctx: &mut EventCtx, event: &PointerEvent) {
511510
self.recording.push(Record::PE(event.clone()));
512511
self.child.on_pointer_event(ctx, event);
513512
}
514513

515-
fn on_text_event(&mut self, ctx: &mut EventCtx, event: &event::TextEvent) {
514+
fn on_text_event(&mut self, ctx: &mut EventCtx, event: &TextEvent) {
516515
self.recording.push(Record::TE(event.clone()));
517516
self.child.on_text_event(ctx, event);
518517
}

masonry/src/text/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! Support for text display and rendering
55
//!
66
//! There are three kinds of text commonly needed:
7-
//! 1) Entirely display text (e.g. a button)
7+
//! 1) Non interactive text (e.g. a button's label)
88
//! 2) Selectable text (e.g. a paragraph of content)
99
//! 3) Editable text (e.g. a search bar)
1010
//!

masonry/src/widget/align.rs

-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ fn log_size_warnings(size: Size) {
163163
}
164164
}
165165

166-
// --- MARK: TESTS ---
167166
// --- MARK: TESTS ---
168167
#[cfg(test)]
169168
mod tests {

masonry/src/widget/button.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::{
1818
PointerEvent, QueryCtx, Size, TextEvent, Update, UpdateCtx, Widget, WidgetId,
1919
};
2020

21-
// the minimum padding added to a button.
21+
// The minimum padding added to a button.
2222
// NOTE: these values are chosen to match the existing look of TextBox; these
2323
// should be reevaluated at some point.
2424
const LABEL_INSETS: Insets = Insets::uniform_xy(8., 2.);
@@ -207,12 +207,6 @@ impl Widget for Button {
207207
fn make_trace_span(&self, ctx: &QueryCtx<'_>) -> Span {
208208
trace_span!("Button", id = ctx.widget_id().trace())
209209
}
210-
211-
// FIXME
212-
#[cfg(FALSE)]
213-
fn get_debug_text(&self) -> Option<String> {
214-
Some(self.label.as_ref().text().as_ref().to_string())
215-
}
216210
}
217211

218212
// --- MARK: TESTS ---

masonry/src/widget/flex.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ pub struct Flex {
3232
/// Optional parameters for an item in a [`Flex`] container (row or column).
3333
///
3434
/// Generally, when you would like to add a flexible child to a container,
35-
/// you can simply call [`with_flex_child`](Flex::with_flex_child), passing the
36-
/// child and the desired flex factor as a `f64`, which has an impl of
35+
/// you can simply call [`with_flex_child`](Flex::with_flex_child) or [`add_flex_child`](Flex::add_flex_child),
36+
/// passing the child and the desired flex factor as a `f64`, which has an impl of
3737
/// `Into<FlexParams>`.
38-
// FIXME - "with_flex_child or [`add_flex_child`](FlexMut::add_flex_child)"
3938
#[derive(Default, Debug, Copy, Clone, PartialEq)]
4039
pub struct FlexParams {
4140
flex: Option<f64>,
@@ -540,7 +539,6 @@ impl Flex {
540539
this.ctx.request_layout();
541540
}
542541

543-
// FIXME - Remove Box
544542
pub fn child_mut<'t>(
545543
this: &'t mut WidgetMut<'_, Self>,
546544
idx: usize,

masonry/src/widget/scroll_bar.rs

+9-48
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,13 @@ use crate::{
1717
WidgetId,
1818
};
1919

20-
// RULES
21-
// -
22-
23-
// TODO - Document names:
24-
// - grabbybar
25-
// - empty_space
26-
// - _z
27-
// - _length
28-
29-
// TODO - Fade scrollbars? Find out how Linux/MacOS/Windows do it
30-
// TODO - Rename cursor to oval/rect/bar/grabber/grabbybar
31-
// TODO - Rename progress to ???
20+
// TODO
21+
// - Fade scrollbars? Find out how Linux/MacOS/Windows do it
22+
// - Rename cursor to oval/rect/bar/grabber/grabbybar
23+
// - Rename progress to something more descriptive
24+
// - Document names
25+
// - Document invariants
26+
3227
pub struct ScrollBar {
3328
axis: Axis,
3429
pub(crate) cursor_progress: f64,
@@ -287,41 +282,7 @@ mod tests {
287282
assert_render_snapshot!(harness, "scrollbar_horizontal_middle");
288283
}
289284

290-
// TODO - portal larger than content
291-
292-
#[cfg(FALSE)]
293-
#[test]
294-
fn edit_button() {
295-
let image_1 = {
296-
let button = Button::from_label(
297-
Label::new("The quick brown fox jumps over the lazy dog")
298-
.with_text_color(PRIMARY_LIGHT)
299-
.with_text_size(20.0),
300-
);
301-
302-
let mut harness = TestHarness::create_with_size(button, Size::new(50.0, 50.0));
303-
304-
harness.render()
305-
};
306-
307-
let image_2 = {
308-
let button = Button::new("Hello world");
285+
// TODO - Add "portal larger than content" test
309286

310-
let mut harness = TestHarness::create_with_size(button, Size::new(50.0, 50.0));
311-
312-
harness.edit_root_widget(|mut button, _| {
313-
let mut button = button.downcast::<Button>().unwrap();
314-
button.set_text("The quick brown fox jumps over the lazy dog");
315-
316-
let mut label = button.label_mut();
317-
label.set_text_color(PRIMARY_LIGHT);
318-
label.set_text_size(20.0);
319-
});
320-
321-
harness.render()
322-
};
323-
324-
// We don't use assert_eq because we don't want rich assert
325-
assert!(image_1 == image_2);
326-
}
287+
// TODO - Add WidgetMut tests
327288
}

masonry/src/widget/sized_box.rs

-2
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,6 @@ impl SizedBox {
324324
self.padding = padding.into();
325325
self
326326
}
327-
328-
// TODO - child()
329327
}
330328

331329
// --- MARK: WIDGETMUT ---

0 commit comments

Comments
 (0)