Improve misc documentation
Closes https://github.com/emilk/egui/issues/229
This commit is contained in:
parent
c1d5bda143
commit
ed0d406698
6 changed files with 60 additions and 10 deletions
|
@ -215,6 +215,11 @@
|
||||||
//! ui.radio_value(&mut some_bool, true, "On");
|
//! 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:
|
//! // Change test color on subsequent widgets:
|
||||||
//! ui.visuals_mut().override_text_color = Some(egui::Color32::RED);
|
//! ui.visuals_mut().override_text_color = Some(egui::Color32::RED);
|
||||||
//!
|
//!
|
||||||
|
|
|
@ -161,15 +161,15 @@ impl Response {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The widget had keyboard focus and lost it,
|
/// The widget had keyboard focus and lost it,
|
||||||
/// perhaps because the user pressed enter.
|
/// either because the user pressed tab or clicked somewhere else,
|
||||||
/// If you want to do an action when a user presses enter in a text field,
|
/// or (in case of a [`TextEdit`]) because the user pressed enter.
|
||||||
/// use this.
|
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # let mut ui = egui::Ui::__test();
|
/// # let mut ui = egui::Ui::__test();
|
||||||
/// # let mut my_text = String::new();
|
/// # let mut my_text = String::new();
|
||||||
/// # fn do_request(_: &str) {}
|
/// # 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);
|
/// do_request(&my_text);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
|
|
|
@ -463,6 +463,7 @@ impl Ui {
|
||||||
|
|
||||||
/// # Interaction
|
/// # Interaction
|
||||||
impl Ui {
|
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 {
|
pub fn interact(&self, rect: Rect, id: Id, sense: Sense) -> Response {
|
||||||
self.ctx().interact(
|
self.ctx().interact(
|
||||||
self.clip_rect(),
|
self.clip_rect(),
|
||||||
|
@ -1112,7 +1113,14 @@ impl Ui {
|
||||||
|
|
||||||
/// # Adding Containers / Sub-uis:
|
/// # Adding Containers / Sub-uis:
|
||||||
impl Ui {
|
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 {
|
pub fn group<R>(&mut self, add_contents: impl FnOnce(&mut Ui) -> R) -> R {
|
||||||
crate::Frame::group(self.style()).show(self, add_contents)
|
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
|
/// The returned `Response` will only have checked for mouse hover
|
||||||
/// but can be used for tooltips (`on_hover_text`).
|
/// but can be used for tooltips (`on_hover_text`).
|
||||||
/// It also contains the `Rect` used by the horizontal layout.
|
/// 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> {
|
pub fn horizontal<R>(&mut self, add_contents: impl FnOnce(&mut Ui) -> R) -> InnerResponse<R> {
|
||||||
self.horizontal_with_main_wrap(false, add_contents)
|
self.horizontal_with_main_wrap(false, add_contents)
|
||||||
}
|
}
|
||||||
|
@ -1309,12 +1325,28 @@ impl Ui {
|
||||||
|
|
||||||
/// Start a ui with vertical layout.
|
/// Start a ui with vertical layout.
|
||||||
/// Widgets will be left-justified.
|
/// 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> {
|
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)
|
self.with_layout(Layout::top_down(Align::Min), add_contents)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Start a ui with vertical layout.
|
/// Start a ui with vertical layout.
|
||||||
/// Widgets will be horizontally centered.
|
/// 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>(
|
pub fn vertical_centered<R>(
|
||||||
&mut self,
|
&mut self,
|
||||||
add_contents: impl FnOnce(&mut Ui) -> R,
|
add_contents: impl FnOnce(&mut Ui) -> R,
|
||||||
|
@ -1324,6 +1356,14 @@ impl Ui {
|
||||||
|
|
||||||
/// Start a ui with vertical layout.
|
/// Start a ui with vertical layout.
|
||||||
/// Widgets will be horizontally centered and justified (fill full width).
|
/// 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>(
|
pub fn vertical_centered_justified<R>(
|
||||||
&mut self,
|
&mut self,
|
||||||
add_contents: impl FnOnce(&mut Ui) -> R,
|
add_contents: impl FnOnce(&mut Ui) -> R,
|
||||||
|
|
|
@ -114,8 +114,11 @@ impl CCursorPair {
|
||||||
/// # let mut ui = egui::Ui::__test();
|
/// # let mut ui = egui::Ui::__test();
|
||||||
/// # let mut my_string = String::new();
|
/// # let mut my_string = String::new();
|
||||||
/// let response = ui.add(egui::TextEdit::singleline(&mut my_string));
|
/// let response = ui.add(egui::TextEdit::singleline(&mut my_string));
|
||||||
/// if response.lost_focus() {
|
/// if response.changed() {
|
||||||
/// // use my_string
|
/// // …
|
||||||
|
/// }
|
||||||
|
/// 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);`"]
|
#[must_use = "You should put this widget in an ui with `ui.add(widget);`"]
|
||||||
|
|
|
@ -128,8 +128,8 @@ impl Widgets {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.label("Single line text input:");
|
ui.label("Single line text input:");
|
||||||
let response = ui.text_edit_singleline(&mut self.single_line_text_input);
|
let response = ui.text_edit_singleline(&mut self.single_line_text_input);
|
||||||
if response.lost_focus() {
|
if response.lost_focus() && ui.input().key_pressed(egui::Key::Enter) {
|
||||||
// The user pressed enter.
|
// …
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,11 @@ set -eu
|
||||||
# Starts a local web-server that serves the contents of the `doc/` folder,
|
# Starts a local web-server that serves the contents of the `doc/` folder,
|
||||||
# i.e. the web-version of `egui_demo_app`.
|
# i.e. the web-version of `egui_demo_app`.
|
||||||
|
|
||||||
|
echo "ensuring basic-http-server is installed..."
|
||||||
cargo install basic-http-server
|
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 && basic-http-server --addr 127.0.0.1:8888 .)
|
||||||
# (cd docs && python3 -m http.server 8888 --bind 127.0.0.1)
|
# (cd docs && python3 -m http.server 8888 --bind 127.0.0.1)
|
||||||
|
|
Loading…
Reference in a new issue