Skip to content

Commit

Permalink
Add more doc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmerlin committed Oct 23, 2024
1 parent 7f2c2ff commit 482921f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
19 changes: 18 additions & 1 deletion crates/egui_kittest/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)))
}
Expand Down
21 changes: 20 additions & 1 deletion crates/egui_kittest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`].
///
Expand All @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 482921f

Please sign in to comment.