Improve and expand documentation tests
This commit is contained in:
parent
8787eb77cf
commit
cbdfc03378
6 changed files with 46 additions and 11 deletions
|
@ -7,10 +7,12 @@
|
||||||
//! With it you can then get access to an `Ui` where you can put widgets.
|
//! With it you can then get access to an `Ui` where you can put widgets.
|
||||||
//! Use one of `SidePanel`, `TopPanel`, `CentralPanel`, `Window` or `Area`. For instace:
|
//! Use one of `SidePanel`, `TopPanel`, `CentralPanel`, `Window` or `Area`. For instace:
|
||||||
//!
|
//!
|
||||||
//! ``` ignore
|
//! ```
|
||||||
//! egui::CentralPanel::default().show(ctx, |ui| {
|
//! # let mut ctx = egui::Context::new();
|
||||||
|
//! # ctx.begin_frame(Default::default());
|
||||||
|
//! egui::CentralPanel::default().show(&ctx, |ui| {
|
||||||
//! ui.label("Hello");
|
//! ui.label("Hello");
|
||||||
//! })
|
//! });
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
//!
|
//!
|
||||||
|
|
|
@ -144,6 +144,11 @@ impl Memory {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Stop editing of active `TextEdit` (if any).
|
||||||
|
pub fn stop_text_input(&mut self) {
|
||||||
|
self.interaction.kb_focus_id = None;
|
||||||
|
}
|
||||||
|
|
||||||
/// Forget window positions, sizes etc.
|
/// Forget window positions, sizes etc.
|
||||||
/// Can be used to auto-layout windows.
|
/// Can be used to auto-layout windows.
|
||||||
pub fn reset_areas(&mut self) {
|
pub fn reset_areas(&mut self) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//! Menu bar functionality (very basic so far).
|
//! Menu bar functionality (very basic so far).
|
||||||
//!
|
//!
|
||||||
//! Usage:
|
//! Usage:
|
||||||
//! ``` rust
|
//! ```
|
||||||
//! fn show_menu(ui: &mut egui::Ui) {
|
//! fn show_menu(ui: &mut egui::Ui) {
|
||||||
//! use egui::{menu, Button};
|
//! use egui::{menu, Button};
|
||||||
//!
|
//!
|
||||||
|
|
|
@ -153,10 +153,12 @@ impl std::ops::BitOr for Response {
|
||||||
|
|
||||||
/// To summarize the response from many widgets you can use this pattern:
|
/// To summarize the response from many widgets you can use this pattern:
|
||||||
///
|
///
|
||||||
/// ``` ignore
|
/// ```
|
||||||
/// let mut response = ui.add(some_widget);
|
/// # let mut ui = egui::Ui::__test();
|
||||||
/// response |= ui.add(some_other_widget);
|
/// # let (widget_a, widget_b, widget_c) = (egui::Label::new("a"), egui::Label::new("b"), egui::Label::new("c"));
|
||||||
/// response |= ui.add(some_widget);
|
/// let mut response = ui.add(widget_a);
|
||||||
|
/// response |= ui.add(widget_b);
|
||||||
|
/// response |= ui.add(widget_c);
|
||||||
/// if response.active { ui.label("You are interacting with one of the widgets"); }
|
/// if response.active { ui.label("You are interacting with one of the widgets"); }
|
||||||
/// ```
|
/// ```
|
||||||
impl std::ops::BitOrAssign for Response {
|
impl std::ops::BitOrAssign for Response {
|
||||||
|
|
|
@ -104,6 +104,19 @@ impl Ui {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Empty `Ui` for use in tests.
|
||||||
|
pub fn __test() -> Self {
|
||||||
|
let mut ctx = Context::new();
|
||||||
|
ctx.begin_frame(Default::default());
|
||||||
|
let id = Id::new("__test");
|
||||||
|
let layer_id = LayerId {
|
||||||
|
order: Order::Middle,
|
||||||
|
id,
|
||||||
|
};
|
||||||
|
let rect = Rect::from_min_size(Pos2::new(0.0, 0.0), vec2(1000.0, 1000.0));
|
||||||
|
Self::new(ctx, layer_id, id, rect, rect)
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------------------
|
// -------------------------------------------------
|
||||||
|
|
||||||
pub fn id(&self) -> Id {
|
pub fn id(&self) -> Id {
|
||||||
|
@ -799,10 +812,11 @@ impl Ui {
|
||||||
|
|
||||||
/// Temporarily split split an Ui into several columns.
|
/// Temporarily split split an Ui into several columns.
|
||||||
///
|
///
|
||||||
/// ``` ignore
|
/// ```
|
||||||
|
/// # let mut ui = egui::Ui::__test();
|
||||||
/// ui.columns(2, |columns| {
|
/// ui.columns(2, |columns| {
|
||||||
/// columns[0].add(egui::widgets::label!("First column"));
|
/// columns[0].label("First column");
|
||||||
/// columns[1].add(egui::widgets::label!("Second column"));
|
/// columns[1].label("Second column");
|
||||||
/// });
|
/// });
|
||||||
/// ```
|
/// ```
|
||||||
pub fn columns<F, R>(&mut self, num_columns: usize, add_contents: F) -> R
|
pub fn columns<F, R>(&mut self, num_columns: usize, add_contents: F) -> R
|
||||||
|
|
|
@ -9,6 +9,18 @@ pub(crate) struct State {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A text region that the user can edit the contents of.
|
/// A text region that the user can edit the contents of.
|
||||||
|
///
|
||||||
|
/// Example:
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// # let mut ui = egui::Ui::__test();
|
||||||
|
/// # let mut my_string = String::new();
|
||||||
|
/// let response = ui.add(egui::TextEdit::new(&mut my_string).multiline(false));
|
||||||
|
/// if response.has_kb_focus && ui.input().key_pressed(egui::Key::Enter) {
|
||||||
|
/// ui.memory().stop_text_input();
|
||||||
|
/// // use my_string
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct TextEdit<'t> {
|
pub struct TextEdit<'t> {
|
||||||
text: &'t mut String,
|
text: &'t mut String,
|
||||||
|
|
Loading…
Reference in a new issue