Browse Source

Improve misc docs

pull/505/head
Emil Ernerfeldt 3 years ago
parent
commit
ef36cac422
  1. 2
      README.md
  2. 14
      egui/src/containers/popup.rs
  3. 10
      egui/src/lib.rs
  4. 13
      egui/src/painter.rs
  5. 4
      egui/src/ui.rs
  6. 3
      egui_demo_lib/src/apps/demo/widget_gallery.rs
  7. 14
      epi/src/lib.rs

2
README.md

@ -291,7 +291,7 @@ There is experimental support for a screen reader. In [the web demo](https://emi
Read more at <https://github.com/emilk/egui/issues/167>.
### What is the difference between egui and eframe?
### What is the difference between [egui](https://docs.rs/egui) and [eframe](https://docs.rs/eframe)?
`egui` is a 2D user interface library for laying out and interacting with buttons, sliders, etc.
`egui` has no idea if it is running on the web or natively, and does not know how to collect input or show things on screen.

14
egui/src/containers/popup.rs

@ -53,6 +53,20 @@ pub fn show_tooltip(ctx: &CtxRef, id: Id, add_contents: impl FnOnce(&mut Ui)) {
show_tooltip_at_pointer(ctx, id, add_contents)
}
/// Show a tooltip at the current pointer position (if any).
///
/// Most of the time it is easier to use [`Response::on_hover_ui`].
///
/// See also [`show_tooltip_text`].
///
/// ```
/// # let mut ui = egui::Ui::__test();
/// if ui.ui_contains_pointer() {
/// egui::show_tooltip_at_pointer(ui.ctx(), egui::Id::new("my_tooltip"), |ui| {
/// ui.label("Helpful text");
/// });
/// }
/// ```
pub fn show_tooltip_at_pointer(ctx: &CtxRef, id: Id, add_contents: impl FnOnce(&mut Ui)) {
let suggested_pos = ctx
.input()

10
egui/src/lib.rs

@ -394,7 +394,10 @@ pub fn warn_if_debug_build(ui: &mut crate::Ui) {
/// Create a [`Hyperlink`](crate::Hyperlink) to the current [`file!()`] (and line) on Github
///
/// Example: `ui.add(github_link_file_line!("https://github.com/YOUR/PROJECT/blob/master/", "(source code)"));`
/// ```
/// # let ui = &mut egui::Ui::__test();
/// ui.add(egui::github_link_file_line!("https://github.com/YOUR/PROJECT/blob/master/", "(source code)"));
/// ```
#[macro_export]
macro_rules! github_link_file_line {
($github_url:expr, $label:expr) => {{
@ -405,7 +408,10 @@ macro_rules! github_link_file_line {
/// Create a [`Hyperlink`](crate::Hyperlink) to the current [`file!()`] on github.
///
/// Example: `ui.add(github_link_file!("https://github.com/YOUR/PROJECT/blob/master/", "(source code)"));`
/// ```
/// # let ui = &mut egui::Ui::__test();
/// ui.add(egui::github_link_file!("https://github.com/YOUR/PROJECT/blob/master/", "(source code)"));
/// ```
#[macro_export]
macro_rules! github_link_file {
($github_url:expr, $label:expr) => {{

13
egui/src/painter.rs

@ -92,14 +92,15 @@ impl Painter {
/// ## Accessors etc
impl Painter {
/// Get a reference to the parent [`CtxRef`].
#[inline(always)]
pub(crate) fn ctx(&self) -> &CtxRef {
pub fn ctx(&self) -> &CtxRef {
&self.ctx
}
/// Available fonts
/// Available fonts.
#[inline(always)]
pub(crate) fn fonts(&self) -> &Fonts {
pub fn fonts(&self) -> &Fonts {
self.ctx.fonts()
}
@ -123,19 +124,19 @@ impl Painter {
self.clip_rect = clip_rect;
}
/// Useful for pixel-perfect rendering
/// Useful for pixel-perfect rendering.
#[inline(always)]
pub fn round_to_pixel(&self, point: f32) -> f32 {
self.ctx().round_to_pixel(point)
}
/// Useful for pixel-perfect rendering
/// Useful for pixel-perfect rendering.
#[inline(always)]
pub fn round_vec_to_pixels(&self, vec: Vec2) -> Vec2 {
self.ctx().round_vec_to_pixels(vec)
}
/// Useful for pixel-perfect rendering
/// Useful for pixel-perfect rendering.
#[inline(always)]
pub fn round_pos_to_pixels(&self, pos: Pos2) -> Pos2 {
self.ctx().round_pos_to_pixels(pos)

4
egui/src/ui.rs

@ -698,9 +698,9 @@ impl Ui {
widget_rect
}
/// Allocate a specific part of the `Ui.
/// Allocate a specific part of the `Ui`.
///
/// Ignore the layout of the `Ui: just put my widget here!
/// Ignore the layout of the `Ui`: just put my widget here!
/// The layout cursor will advance to past this `rect`.
pub fn allocate_rect(&mut self, rect: Rect, sense: Sense) -> Response {
let id = self.advance_cursor_after_rect(rect);

3
egui_demo_lib/src/apps/demo/widget_gallery.rs

@ -6,6 +6,7 @@ enum Enum {
Third,
}
/// Shows off one example of each major type of widget.
#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))]
pub struct WidgetGallery {
enabled: bool,
@ -141,7 +142,7 @@ impl WidgetGallery {
});
ui.end_row();
ui.add(doc_link_label("Combo box", "combo_box"));
ui.add(doc_link_label("Combo box", "ComboBox"));
egui::ComboBox::from_label("Take your pick")
.selected_text(format!("{:?}", radio))

14
epi/src/lib.rs

@ -96,8 +96,8 @@ pub trait App {
/// Called once before the first frame.
///
/// Allows you to do setup code, e.g to call `[Context::set_fonts]`,
/// `[Context::set_visuals]` etc.
/// Allows you to do setup code, e.g to call `[egui::Context::set_fonts]`,
/// `[egui::Context::set_visuals]` etc.
///
/// Also allows you to restore state, if there is a storage.
fn setup(
@ -127,7 +127,7 @@ pub trait App {
/// where `APPNAME` is what is returned by [`Self::name()`].
fn save(&mut self, _storage: &mut dyn Storage) {}
/// Called once on shutdown (before or after `save()`)
/// Called once on shutdown (before or after [`Self::save`])
fn on_exit(&mut self) {}
// ---------
@ -136,12 +136,12 @@ pub trait App {
/// The name of your App.
fn name(&self) -> &str;
/// Time between automatic calls to `save()`
/// Time between automatic calls to [`Self::save`]
fn auto_save_interval(&self) -> std::time::Duration {
std::time::Duration::from_secs(30)
}
/// The size limit of the web app canvas
/// The size limit of the web app canvas.
fn max_size_points(&self) -> egui::Vec2 {
// Some browsers get slow with huge WebGL canvases, so we limit the size:
egui::Vec2::new(1024.0, 2048.0)
@ -254,6 +254,8 @@ impl<'a> Frame<'a> {
/// Very simple Http fetch API.
/// Calls the given callback when done.
///
/// You must enable the "http" feature for this.
#[cfg(feature = "http")]
pub fn http_fetch(
&self,
@ -370,6 +372,8 @@ pub const APP_KEY: &str = "app";
#[cfg(feature = "http")]
/// `epi` supports simple HTTP requests with [`Frame::http_fetch`].
///
/// You must enable the "http" feature for this.
pub mod http {
/// A simple http requests.
pub struct Request {

Loading…
Cancel
Save