From 482921f39544d0af9bc48c687ba54ae7f4166d96 Mon Sep 17 00:00:00 2001 From: Lucas Meurer Date: Wed, 23 Oct 2024 15:49:57 +0200 Subject: [PATCH] Add more doc comments --- crates/egui_kittest/src/builder.rs | 19 ++++++++++++++++++- crates/egui_kittest/src/lib.rs | 21 ++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/crates/egui_kittest/src/builder.rs b/crates/egui_kittest/src/builder.rs index 381cea1e625..704e2caf8c1 100644 --- a/crates/egui_kittest/src/builder.rs +++ b/crates/egui_kittest/src/builder.rs @@ -36,7 +36,9 @@ impl HarnessBuilder { /// Create a new Harness with the given app closure. /// - /// The ui closure will immediately be called once to create the initial ui. + /// The app closure will immediately be called once to create the initial ui. + /// + /// If you don't need to create Windows / Panels, you can use [`HarnessBuilder::build_ui`] instead. /// /// # Example /// ```rust @@ -54,6 +56,21 @@ impl HarnessBuilder { Harness::from_builder(&self, AppKind::Context(Box::new(app))) } + /// Create a new Harness with the given ui closure. + /// + /// The ui closure will immediately be called once to create the initial ui. + /// + /// If you need to create Windows / Panels, you can use [`HarnessBuilder::build`] instead. + /// + /// # Example + /// ```rust + /// # use egui_kittest::Harness; + /// let mut harness = Harness::builder() + /// .with_size(egui::Vec2::new(300.0, 200.0)) + /// .build_ui(|ui| { + /// ui.label("Hello, world!"); + /// }); + /// ``` pub fn build_ui<'a>(self, app: impl FnMut(&mut egui::Ui) + 'a) -> Harness<'a> { Harness::from_builder(&self, AppKind::Ui(Box::new(app))) } diff --git a/crates/egui_kittest/src/lib.rs b/crates/egui_kittest/src/lib.rs index c7cdf5fcbb4..dc18e7a7843 100644 --- a/crates/egui_kittest/src/lib.rs +++ b/crates/egui_kittest/src/lib.rs @@ -91,7 +91,9 @@ impl<'a> Harness<'a> { /// Create a new Harness with the given app closure. /// - /// The ui closure will immediately be called once to create the initial ui. + /// The app closure will immediately be called once to create the initial ui. + /// + /// If you don't need to create Windows / Panels, you can use [`Harness::new_ui`] instead. /// /// If you e.g. want to customize the size of the window, you can use [`Harness::builder`]. /// @@ -109,6 +111,21 @@ impl<'a> Harness<'a> { Self::builder().build(app) } + /// Create a new Harness with the given ui closure. + /// + /// The ui closure will immediately be called once to create the initial ui. + /// + /// If you need to create Windows / Panels, you can use [`Harness::new`] instead. + /// + /// If you e.g. want to customize the size of the ui, you can use [`Harness::builder`]. + /// + /// # Example + /// ```rust + /// # use egui_kittest::Harness; + /// let mut harness = Harness::new_ui(|ui| { + /// ui.label("Hello, world!"); + /// }); + /// ``` pub fn new_ui(app: impl FnMut(&mut egui::Ui) + 'a) -> Self { Self::builder().build_ui(app) } @@ -163,6 +180,8 @@ impl<'a> Harness<'a> { self.output = output; } + /// Resize the test harness to fit the contents. This only works when creating the Harness via + /// [`Harness::new_ui`] or [`HarnessBuilder::build_ui`]. pub fn fit_contents(&mut self) { self._step(true); if let Some(response) = &self.response {