diff --git a/egui/src/lib.rs b/egui/src/lib.rs index 83c66460..5c2fa144 100644 --- a/egui/src/lib.rs +++ b/egui/src/lib.rs @@ -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); //! diff --git a/egui/src/response.rs b/egui/src/response.rs index 3b018495..068b5fae 100644 --- a/egui/src/response.rs +++ b/egui/src/response.rs @@ -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); /// } /// ``` diff --git a/egui/src/ui.rs b/egui/src/ui.rs index 7ed0f294..c0c22843 100644 --- a/egui/src/ui.rs +++ b/egui/src/ui.rs @@ -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(&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(&mut self, add_contents: impl FnOnce(&mut Ui) -> R) -> InnerResponse { 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(&mut self, add_contents: impl FnOnce(&mut Ui) -> R) -> InnerResponse { 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( &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( &mut self, add_contents: impl FnOnce(&mut Ui) -> R, diff --git a/egui/src/widgets/text_edit.rs b/egui/src/widgets/text_edit.rs index 76571c65..5ff57571 100644 --- a/egui/src/widgets/text_edit.rs +++ b/egui/src/widgets/text_edit.rs @@ -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);`"] diff --git a/egui_demo_lib/src/apps/demo/widgets.rs b/egui_demo_lib/src/apps/demo/widgets.rs index 53b40c4a..ed49903d 100644 --- a/egui_demo_lib/src/apps/demo/widgets.rs +++ b/egui_demo_lib/src/apps/demo/widgets.rs @@ -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) { + // … } }); diff --git a/start_server.sh b/start_server.sh index e88022b0..78553169 100755 --- a/start_server.sh +++ b/start_server.sh @@ -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)