1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-31 22:00:03 -04:00

Add a dummy warm-up frame to the demo app to pre-cache emojis

This commit is contained in:
Emil Ernerfeldt
2021-01-02 14:42:43 +01:00
parent 4202c4b6a9
commit 14a96ca5d0
14 changed files with 144 additions and 55 deletions

View File

@@ -35,7 +35,7 @@ impl State {
// Helper
pub fn is_open(ctx: &Context, id: Id) -> Option<bool> {
if ctx.memory().all_collpasing_are_open {
if ctx.memory().everything_is_visible() {
Some(true)
} else {
ctx.memory()
@@ -52,7 +52,11 @@ impl State {
/// 0 for closed, 1 for open, with tweening
pub fn openness(&self, ctx: &Context, id: Id) -> f32 {
ctx.animate_bool(id, self.open || ctx.memory().all_collpasing_are_open)
if ctx.memory().everything_is_visible() {
1.0
} else {
ctx.animate_bool(id, self.open)
}
}
/// Show contents if we are open, with a nice animation between closed and open

View File

@@ -25,6 +25,8 @@ pub fn show_tooltip(ctx: &CtxRef, add_contents: impl FnOnce(&mut Ui)) {
let position = position.min(ctx.input().screen_rect().right_bottom() - expected_size);
let position = position.max(ctx.input().screen_rect().left_top());
position
} else if ctx.memory().everything_is_visible() {
Pos2::default()
} else {
return; // No good place for a tooltip :(
};

View File

@@ -209,7 +209,7 @@ impl<'open> Window<'open> {
with_title_bar,
} = self;
if matches!(open, Some(false)) && !ctx.memory().all_windows_are_open {
if matches!(open, Some(false)) && !ctx.memory().everything_is_visible() {
return None;
}

View File

@@ -38,6 +38,7 @@ pub(crate) struct FrameState {
/// How much space is used by panels.
used_by_panels: Rect,
pub(crate) scroll_delta: Vec2,
pub(crate) scroll_target: Option<(f32, Align)>,
// TODO: move some things from `Memory` to here
@@ -56,7 +57,7 @@ impl Default for FrameState {
}
impl FrameState {
pub fn begin_frame(&mut self, input: &InputState) {
fn begin_frame(&mut self, input: &InputState) {
self.available_rect = input.screen_rect();
self.unused_rect = input.screen_rect();
self.used_by_panels = Rect::nothing();
@@ -717,6 +718,11 @@ impl Context {
}
animated_value
}
/// Clear memory of any animations.
pub fn clear_animations(&self) {
*self.animation_manager.lock() = Default::default();
}
}
impl Context {

View File

@@ -60,12 +60,8 @@ pub struct Memory {
#[cfg_attr(feature = "serde", serde(skip))]
pub(crate) tooltip_rect: Option<Rect>,
/// Useful for debugging, benchmarking etc.
pub all_collpasing_are_open: bool,
/// Useful for debugging, benchmarking etc.
pub all_menus_are_open: bool,
/// Useful for debugging, benchmarking etc.
pub all_windows_are_open: bool,
#[cfg_attr(feature = "serde", serde(skip))]
everything_is_visible: bool,
}
/// Say there is a button in a scroll area.
@@ -258,7 +254,7 @@ impl Memory {
/// Only one can be be open at a time.
impl Memory {
pub fn is_popup_open(&mut self, popup_id: Id) -> bool {
self.popup == Some(popup_id)
self.popup == Some(popup_id) || self.everything_is_visible()
}
pub fn open_popup(&mut self, popup_id: Id) {
@@ -276,6 +272,24 @@ impl Memory {
self.open_popup(popup_id);
}
}
/// If true, all windows, menus, tooltips etc are to be visible at once.
///
/// This is useful for testing, benchmarking, pre-caching, etc.
///
/// Experimental feature!
pub fn everything_is_visible(&self) -> bool {
self.everything_is_visible
}
/// If true, all windows, menus, tooltips etc are to be visible at once.
///
/// This is useful for testing, benchmarking, pre-caching, etc.
///
/// Experimental feature!
pub fn set_everything_is_visible(&mut self, value: bool) {
self.everything_is_visible = value;
}
}
// ----------------------------------------------------------------------------

View File

@@ -94,7 +94,7 @@ fn menu_impl<'c>(
bar_state.open_menu = Some(menu_id);
}
if bar_state.open_menu == Some(menu_id) || ui.memory().all_menus_are_open {
if bar_state.open_menu == Some(menu_id) || ui.ctx().memory().everything_is_visible() {
let area = Area::new(menu_id)
.order(Order::Foreground)
.fixed_pos(button_response.rect.left_bottom());

View File

@@ -139,7 +139,7 @@ impl Response {
/// Show this UI if the item was hovered (i.e. a tooltip).
/// If you call this multiple times the tooltips will stack underneath the previous ones.
pub fn on_hover_ui(self, add_contents: impl FnOnce(&mut Ui)) -> Self {
if self.hovered {
if self.hovered || self.ctx.memory().everything_is_visible() {
crate::containers::show_tooltip(&self.ctx, add_contents);
}
self