Improve misc documentation

Closes https://github.com/emilk/egui/issues/229
This commit is contained in:
Emil Ernerfeldt 2021-03-21 17:13:58 +01:00
parent c1d5bda143
commit ed0d406698
6 changed files with 60 additions and 10 deletions

View file

@ -215,6 +215,11 @@
//! ui.radio_value(&mut some_bool, true, "On");
//! });
//!
//! ui.group(|ui|{
//! ui.label("Within a frame");
//! ui.set_min_height(200.0);
//! });
//!
//! // Change test color on subsequent widgets:
//! ui.visuals_mut().override_text_color = Some(egui::Color32::RED);
//!

View file

@ -161,15 +161,15 @@ impl Response {
}
/// The widget had keyboard focus and lost it,
/// perhaps because the user pressed enter.
/// If you want to do an action when a user presses enter in a text field,
/// use this.
/// either because the user pressed tab or clicked somewhere else,
/// or (in case of a [`TextEdit`]) because the user pressed enter.
///
/// ```
/// # let mut ui = egui::Ui::__test();
/// # let mut my_text = String::new();
/// # fn do_request(_: &str) {}
/// if ui.text_edit_singleline(&mut my_text).lost_focus() {
/// let response = ui.text_edit_singleline(&mut my_text);
/// if response.lost_focus() && ui.input().key_pressed(egui::Key::Enter) {
/// do_request(&my_text);
/// }
/// ```

View file

@ -463,6 +463,7 @@ impl Ui {
/// # Interaction
impl Ui {
/// Check for clicks, drags and/or hover on a specific region of this `Ui`.
pub fn interact(&self, rect: Rect, id: Id, sense: Sense) -> Response {
self.ctx().interact(
self.clip_rect(),
@ -1112,7 +1113,14 @@ impl Ui {
/// # Adding Containers / Sub-uis:
impl Ui {
/// Put into a `Frame::group`, visually grouping the contents together
/// Put into a [`Frame::group`], visually grouping the contents together
///
/// ```
/// # let ui = &mut egui::Ui::__test();
/// ui.group(|ui|{
/// ui.label("Within a frame");
/// });
/// ```
pub fn group<R>(&mut self, add_contents: impl FnOnce(&mut Ui) -> R) -> R {
crate::Frame::group(self.style()).show(self, add_contents)
}
@ -1213,6 +1221,14 @@ impl Ui {
/// The returned `Response` will only have checked for mouse hover
/// but can be used for tooltips (`on_hover_text`).
/// It also contains the `Rect` used by the horizontal layout.
///
/// ```
/// # let ui = &mut egui::Ui::__test();
/// ui.horizontal(|ui|{
/// ui.label("Same");
/// ui.label("row");
/// });
/// ```
pub fn horizontal<R>(&mut self, add_contents: impl FnOnce(&mut Ui) -> R) -> InnerResponse<R> {
self.horizontal_with_main_wrap(false, add_contents)
}
@ -1309,12 +1325,28 @@ impl Ui {
/// Start a ui with vertical layout.
/// Widgets will be left-justified.
///
/// ```
/// # let ui = &mut egui::Ui::__test();
/// ui.vertical(|ui|{
/// ui.label("over");
/// ui.label("under");
/// });
/// ```
pub fn vertical<R>(&mut self, add_contents: impl FnOnce(&mut Ui) -> R) -> InnerResponse<R> {
self.with_layout(Layout::top_down(Align::Min), add_contents)
}
/// Start a ui with vertical layout.
/// Widgets will be horizontally centered.
///
/// ```
/// # let ui = &mut egui::Ui::__test();
/// ui.vertical_centered(|ui|{
/// ui.label("over");
/// ui.label("under");
/// });
/// ```
pub fn vertical_centered<R>(
&mut self,
add_contents: impl FnOnce(&mut Ui) -> R,
@ -1324,6 +1356,14 @@ impl Ui {
/// Start a ui with vertical layout.
/// Widgets will be horizontally centered and justified (fill full width).
///
/// ```
/// # let ui = &mut egui::Ui::__test();
/// ui.vertical_centered_justified(|ui|{
/// ui.label("over");
/// ui.label("under");
/// });
/// ```
pub fn vertical_centered_justified<R>(
&mut self,
add_contents: impl FnOnce(&mut Ui) -> R,

View file

@ -114,8 +114,11 @@ impl CCursorPair {
/// # let mut ui = egui::Ui::__test();
/// # let mut my_string = String::new();
/// let response = ui.add(egui::TextEdit::singleline(&mut my_string));
/// if response.lost_focus() {
/// // use my_string
/// if response.changed() {
/// // …
/// }
/// if response.lost_focus() && ui.input().key_pressed(egui::Key::Enter) {
/// // …
/// }
/// ```
#[must_use = "You should put this widget in an ui with `ui.add(widget);`"]

View file

@ -128,8 +128,8 @@ impl Widgets {
ui.horizontal(|ui| {
ui.label("Single line text input:");
let response = ui.text_edit_singleline(&mut self.single_line_text_input);
if response.lost_focus() {
// The user pressed enter.
if response.lost_focus() && ui.input().key_pressed(egui::Key::Enter) {
//
}
});

View file

@ -4,9 +4,11 @@ set -eu
# Starts a local web-server that serves the contents of the `doc/` folder,
# i.e. the web-version of `egui_demo_app`.
echo "ensuring basic-http-server is installed..."
cargo install basic-http-server
echo "open http://localhost:8888"
echo "staritng server..."
echo "serving at http://localhost:8888"
(cd docs && basic-http-server --addr 127.0.0.1:8888 .)
# (cd docs && python3 -m http.server 8888 --bind 127.0.0.1)