1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 13:20:05 -04:00

Add misc documentation

This commit is contained in:
Emil Ernerfeldt
2022-01-22 08:56:36 +01:00
parent 8138a073e7
commit 199bbef77b
11 changed files with 46 additions and 13 deletions

View File

@@ -19,7 +19,15 @@ use crate::{area, window, Id, IdMap, InputState, LayerId, Pos2, Rect, Style};
pub struct Memory {
pub options: Options,
/// This map stores current states for all widgets with custom `Id`s.
/// This map stores some superficial state for all widgets with custom `Id`s.
///
/// This includes storing if a [`crate::CollapsingHeader`] is open, how far scrolled a
/// [`crate::ScrollArea`] is, where the cursor in a [`crate::TextEdit`] is, etc.
///
/// This is NOT meant to store any important data. Store that in your own structures!
///
/// Each read clones the data, so keep your values cheap to clone.
/// If you want to store a lot of data you should wrap it in `Arc<Mutex<…>>` so it is cheap to clone.
///
/// This will be saved between different program runs if you use the `persistence` feature.
///

View File

@@ -257,6 +257,7 @@ impl Visuals {
self.widgets.active.text_color()
}
/// Window background color.
#[inline(always)]
pub fn window_fill(&self) -> Color32 {
self.widgets.noninteractive.bg_fill

View File

@@ -294,7 +294,10 @@ use crate::Id;
// TODO: make IdTypeMap generic over the key (`Id`), and make a library of IdTypeMap.
/// Stores values identified by an [`Id`] AND a the [`std::any::TypeId`] of the value.
///
/// so it maps `(Id, TypeId)` to any value you want.
/// In other words, it maps `(Id, TypeId)` to any value you want.
///
/// Values are cloned when read, so keep them small and light.
/// If you want to store something bigger, wrap them in `Arc<Mutex<…>>`.
///
/// Values can either be "persisted" (serializable) or "temporary" (cleared when egui is shut down).
///
@@ -346,6 +349,8 @@ impl IdTypeMap {
}
/// Read a value without trying to deserialize a persisted value.
///
/// The call clones the value (if found), so make sure it is cheap to clone!
#[inline]
pub fn get_temp<T: 'static + Clone>(&mut self, id: Id) -> Option<T> {
let hash = hash(TypeId::of::<T>(), id);
@@ -356,6 +361,8 @@ impl IdTypeMap {
}
/// Read a value, optionally deserializing it if available.
///
/// The call clones the value (if found), so make sure it is cheap to clone!
#[inline]
pub fn get_persisted<T: SerializableAny>(&mut self, id: Id) -> Option<T> {
let hash = hash(TypeId::of::<T>(), id);

View File

@@ -337,19 +337,19 @@ pub fn color_picker_color32(ui: &mut Ui, srgba: &mut Color32, alpha: Alpha) -> b
}
pub fn color_edit_button_hsva(ui: &mut Ui, hsva: &mut Hsva, alpha: Alpha) -> Response {
let pupup_id = ui.auto_id_with("popup");
let open = ui.memory().is_popup_open(pupup_id);
let popup_id = ui.auto_id_with("popup");
let open = ui.memory().is_popup_open(popup_id);
let mut button_response = color_button(ui, (*hsva).into(), open);
if ui.style().explanation_tooltips {
button_response = button_response.on_hover_text("Click to edit color");
}
if button_response.clicked() {
ui.memory().toggle_popup(pupup_id);
ui.memory().toggle_popup(popup_id);
}
// TODO: make it easier to show a temporary popup that closes when you click outside it
if ui.memory().is_popup_open(pupup_id) {
let area_response = Area::new(pupup_id)
if ui.memory().is_popup_open(popup_id) {
let area_response = Area::new(popup_id)
.order(Order::Foreground)
.default_pos(button_response.rect.max)
.show(ui.ctx(), |ui| {