diff --git a/README.md b/README.md index ef18c526..8d7b663b 100644 --- a/README.md +++ b/README.md @@ -174,7 +174,7 @@ loop { egui_ctx.begin_frame(raw_input); my_app.ui(&mut egui_ctx); // add panels, windows and widgets to `egui_ctx` here let (output, paint_commands) = egui_ctx.end_frame(); - let paint_jobs = self.ctx.tesselate(paint_commands); // create triangles to paint + let paint_jobs = egui_ctx.tesselate(paint_commands); // create triangles to paint my_integration.paint(paint_jobs); my_integration.set_cursor_icon(output.cursor_icon); // Also see `egui::Output` for more diff --git a/egui/src/align.rs b/egui/src/align.rs index 25cbe5a0..342a9354 100644 --- a/egui/src/align.rs +++ b/egui/src/align.rs @@ -1,3 +1,5 @@ +//! One- and two-dimensional alignment ([`Align::Center`], [`LEFT_TOP`] etc). + use crate::math::{pos2, Rect}; /// left/center/right or top/center/bottom alignment for e.g. anchors and `Layout`s. @@ -5,27 +7,30 @@ use crate::math::{pos2, Rect}; #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))] pub enum Align { - /// Left/Top + /// Left or top. Min, - /// Note: requires a bounded/known available_width. + /// Horizontal or vertical center. Center, - /// Right/Bottom - /// Note: requires a bounded/known available_width. + /// Right or bottom. Max, } impl Align { + /// Convenience for [`Self::Min`] pub fn left() -> Self { Self::Min } + /// Convenience for [`Self::Max`] pub fn right() -> Self { Self::Max } + /// Convenience for [`Self::Min`] pub fn top() -> Self { Self::Min } + /// Convenience for [`Self::Max`] pub fn bottom() -> Self { Self::Max } diff --git a/egui/src/containers/area.rs b/egui/src/containers/area.rs index 142492f9..c8f7db45 100644 --- a/egui/src/containers/area.rs +++ b/egui/src/containers/area.rs @@ -29,7 +29,17 @@ impl State { /// An area on the screen that can be moved by dragging. /// -/// This forms the base of the `Window` container. +/// This forms the base of the [`Window`] container. +/// +/// ``` +/// # let mut ctx = egui::CtxRef::default(); +/// # ctx.begin_frame(Default::default()); +/// # let ctx = &ctx; +/// egui::Area::new("my_area") +/// .fixed_pos(egui::pos2(32.0, 32.0)) +/// .show(ctx, |ui| { +/// ui.label("Floating text!"); +/// }); #[derive(Clone, Copy, Debug)] pub struct Area { id: Id, diff --git a/egui/src/containers/mod.rs b/egui/src/containers/mod.rs index 1fd7ef80..d287a6a8 100644 --- a/egui/src/containers/mod.rs +++ b/egui/src/containers/mod.rs @@ -1,6 +1,6 @@ -//! Containers are pieces of the UI which wraps other pieces of UI. Examples: `Window`, `ScrollArea`, `Resize`, etc. +//! Containers are pieces of the UI which wraps other pieces of UI. Examples: [`Window`], [`ScrollArea`], [`Resize`], etc. //! -//! For instance, a `Frame` adds a frame and background to some contained UI. +//! For instance, a [`Frame`] adds a frame and background to some contained UI. pub(crate) mod area; pub(crate) mod collapsing_header; diff --git a/egui/src/containers/panel.rs b/egui/src/containers/panel.rs index e9e02a07..20d30822 100644 --- a/egui/src/containers/panel.rs +++ b/egui/src/containers/panel.rs @@ -8,7 +8,16 @@ use crate::*; /// A panel that covers the entire left side of the screen. /// -/// Panels should be added before adding any `Window`s. +/// `SidePanel`s should be added before adding any [`Window`]s. +/// +/// ``` +/// # let mut ctx = egui::CtxRef::default(); +/// # ctx.begin_frame(Default::default()); +/// # let ctx = &ctx; +/// egui::SidePanel::left("my_side_panel", 0.0).show(ctx, |ui| { +/// ui.label("Hello World!"); +/// }); +/// ``` pub struct SidePanel { id: Id, max_width: f32, @@ -56,7 +65,16 @@ impl SidePanel { /// A panel that covers the entire top side of the screen. /// -/// Panels should be added before adding any `Window`s. +/// `TopPanel`s should be added before adding any [`Window`]s. +/// +/// ``` +/// # let mut ctx = egui::CtxRef::default(); +/// # ctx.begin_frame(Default::default()); +/// # let ctx = &ctx; +/// egui::TopPanel::top("my_top_panel").show(ctx, |ui| { +/// ui.label("Hello World!"); +/// }); +/// ``` pub struct TopPanel { id: Id, max_height: Option, @@ -108,7 +126,16 @@ impl TopPanel { /// i.e. whatever area is left after adding other panels. /// /// `CentralPanel` should be added after all other panels. -/// Any `Window`s and `Area`s will cover the `CentralPanel`. +/// Any [`Window`]s and [`Area`]s will cover the `CentralPanel`. +/// +/// ``` +/// # let mut ctx = egui::CtxRef::default(); +/// # ctx.begin_frame(Default::default()); +/// # let ctx = &ctx; +/// egui::CentralPanel::default().show(ctx, |ui| { +/// ui.label("Hello World!"); +/// }); +/// ``` #[derive(Default)] pub struct CentralPanel {} diff --git a/egui/src/containers/window.rs b/egui/src/containers/window.rs index 7cf248f0..82b8b730 100644 --- a/egui/src/containers/window.rs +++ b/egui/src/containers/window.rs @@ -12,6 +12,14 @@ use super::*; /// * if the window has a scroll area (off by default) /// * if the window can be collapsed (minimized) to just the title bar (yes, by default) /// * if there should be a close button (none by default) +/// +/// ``` +/// # let mut ctx = egui::CtxRef::default(); +/// # ctx.begin_frame(Default::default()); +/// # let ctx = &ctx; +/// egui::Window::new("My Window").show(ctx, |ui| { +/// ui.label("Hello World!"); +/// }); pub struct Window<'open> { title_label: Label, open: Option<&'open mut bool>, @@ -24,7 +32,7 @@ pub struct Window<'open> { } impl<'open> Window<'open> { - /// The window title is used as a unique Id and must be unique, and should not change. + /// The window title is used as a unique [`Id`] and must be unique, and should not change. /// This is true even if you disable the title bar with `.title_bar(false)`. pub fn new(title: impl Into) -> Self { let title = title.into(); diff --git a/egui/src/context.rs b/egui/src/context.rs index 789fb1f9..87d8e44f 100644 --- a/egui/src/context.rs +++ b/egui/src/context.rs @@ -64,7 +64,7 @@ impl FrameState { pub fn available_rect(&self) -> Rect { debug_assert!( self.available_rect.is_finite(), - "Called `available_rect()` before `begin_frame()`" + "Called `available_rect()` before `CtxRef::begin_frame()`" ); self.available_rect } @@ -101,8 +101,8 @@ impl FrameState { // ---------------------------------------------------------------------------- -/// A wrapper around `CtxRef`. -/// This is how you will normally access a [`Context`]. +/// A wrapper around [`Arc`](std::sync::Arc)`<`[`Context`]`>`. +/// This is how you will normally create and access a [`Context`]. #[derive(Clone)] pub struct CtxRef(std::sync::Arc); @@ -145,7 +145,7 @@ impl Default for CtxRef { impl CtxRef { /// Call at the start of every frame. - /// Put your widgets into a `SidePanel`, `TopPanel`, `CentralPanel`, `Window` or `Area`. + /// Put your widgets into a [`SidePanel`], [`TopPanel`], [`CentralPanel`], [`Window`] or [`Area`]. pub fn begin_frame(&mut self, new_input: RawInput) { let mut self_: Context = (*self.0).clone(); self_.begin_frame_mut(new_input); @@ -154,8 +154,8 @@ impl CtxRef { // --------------------------------------------------------------------- - /// If the given `Id` is not unique, an error will be printed at the given position. - /// Call this for `Id`:s that need interaction or persistence. + /// If the given [`Id`] is not unique, an error will be printed at the given position. + /// Call this for [`Id`]:s that need interaction or persistence. pub(crate) fn register_interaction_id(&self, id: Id, new_pos: Pos2) { let prev_pos = self.memory().used_ids.insert(id, new_pos); if let Some(prev_pos) = prev_pos { @@ -352,12 +352,9 @@ impl CtxRef { // ---------------------------------------------------------------------------- -/// Thi is the first thing you need when working with Egui. +/// This is the first thing you need when working with Egui. Create using [`CtxRef`]. /// -/// Contains the input state, memory, options and output. -/// `Ui`:s keep an `Arc` pointer to this. -/// This allows us to create several child `Ui`:s at once, -/// all working against the same shared Context. +/// Contains the [`InputState`], [`Memory`], [`Output`], options and more. // TODO: too many mutexes. Maybe put it all behind one Mutex instead. #[derive(Default)] pub struct Context { @@ -442,17 +439,17 @@ impl Context { &self.input } - /// Not valid until first call to `begin_frame()` + /// Not valid until first call to [`CtxRef::begin_frame()`]. /// That's because since we don't know the proper `pixels_per_point` until then. pub fn fonts(&self) -> &Fonts { &*self .fonts .as_ref() - .expect("No fonts available until first call to Context::begin_frame()`") + .expect("No fonts available until first call to CtxRef::begin_frame()") } - /// The Egui texture, containing font characters etc.. - /// Not valid until first call to `begin_frame()` + /// The Egui texture, containing font characters etc. + /// Not valid until first call to [`CtxRef::begin_frame()`]. /// That's because since we don't know the proper `pixels_per_point` until then. pub fn texture(&self) -> Arc { self.fonts().texture() @@ -464,14 +461,17 @@ impl Context { self.options.lock().font_definitions = font_definitions; } + /// The [`Style`] used by all new windows, panels etc. pub fn style(&self) -> Arc