1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-02 23:00:04 -04:00

Some hacky fixes

This commit is contained in:
Konkitoman
2023-07-29 21:32:57 +03:00
parent bb0b80fb08
commit 1f5d17cfcc
3 changed files with 35 additions and 8 deletions

View File

@@ -557,7 +557,8 @@ impl<'open> Window<'open> {
}; };
let margins = frame.outer_margin.sum() let margins = frame.outer_margin.sum()
+ frame.inner_margin.sum() + frame.inner_margin.sum()
+ vec2(0.0, title_bar_height); + vec2(0.0, title_bar_height)
- vec2(0.0, 3.0); //magic number
if let Some(mut state) = resize::State::load(ctx, resize_id) { if let Some(mut state) = resize::State::load(ctx, resize_id) {
state.requested_size = Some(win_size - margins); state.requested_size = Some(win_size - margins);
@@ -700,8 +701,6 @@ impl<'open> Window<'open> {
content_inner content_inner
}; };
let size = ctx.round_vec_to_pixels(area_content_ui.min_size());
let full_response = area.end(ctx, area_content_ui); let full_response = area.end(ctx, area_content_ui);
if !collapsing.is_open() { if !collapsing.is_open() {

View File

@@ -63,7 +63,7 @@ struct Repaint {
pub repaint_after: HashMap<u64, std::time::Duration>, pub repaint_after: HashMap<u64, std::time::Duration>,
/// While positive, keep requesting repaints. Decrement at the end of each frame. /// While positive, keep requesting repaints. Decrement at the end of each frame.
repaint_requests: u32, repaint_requests: HashMap<u64, u32>,
request_repaint_callback: Option<Box<dyn Fn(RequestRepaintInfo) + Send + Sync>>, request_repaint_callback: Option<Box<dyn Fn(RequestRepaintInfo) + Send + Sync>>,
requested_repaint_last_frame: bool, requested_repaint_last_frame: bool,
@@ -73,12 +73,14 @@ impl Default for Repaint {
fn default() -> Self { fn default() -> Self {
let mut repaint_after = HashMap::default(); let mut repaint_after = HashMap::default();
repaint_after.insert(0, std::time::Duration::from_millis(100)); repaint_after.insert(0, std::time::Duration::from_millis(100));
let mut repaint_requests = HashMap::default();
repaint_requests.insert(0, 1);
Self { Self {
frame_nr: 0, frame_nr: 0,
repaint_after, repaint_after,
// Start with painting an extra frame to compensate for some widgets // Start with painting an extra frame to compensate for some widgets
// that take two frames before they "settle": // that take two frames before they "settle":
repaint_requests: 1, repaint_requests,
request_repaint_callback: None, request_repaint_callback: None,
requested_repaint_last_frame: false, requested_repaint_last_frame: false,
} }
@@ -94,7 +96,7 @@ impl Repaint {
if after == std::time::Duration::ZERO { if after == std::time::Duration::ZERO {
// Do a few extra frames to let things settle. // Do a few extra frames to let things settle.
// This is a bit of a hack, and we don't support it for `repaint_after` callbacks yet. // This is a bit of a hack, and we don't support it for `repaint_after` callbacks yet.
self.repaint_requests = 2; self.repaint_requests.insert(viewport_id, 2);
} }
// We only re-call the callback if we get a lower duration, // We only re-call the callback if we get a lower duration,
@@ -132,8 +134,23 @@ impl Repaint {
) -> Vec<(u64, std::time::Duration)> { ) -> Vec<(u64, std::time::Duration)> {
// if repaint_requests is greater than zero. just set the duration to zero for immediate // if repaint_requests is greater than zero. just set the duration to zero for immediate
// repaint. if there's no repaint requests, then we can use the actual repaint_after instead. // repaint. if there's no repaint requests, then we can use the actual repaint_after instead.
let repaint_after = if self.repaint_requests > 0 { let repaint_after = if self
self.repaint_requests -= 1; .repaint_requests
.get(&viewport_id)
.cloned()
.unwrap_or(0)
> 0
{
// This is a hack, i think
// is some thing strange with the input! We need to store a state per viewport and not per context
if let Some(requests) = self.repaint_requests.get_mut(&viewport_id) {
if *requests >= 2 {
*requests -= 2;
} else {
*requests -= 1;
}
}
std::time::Duration::ZERO std::time::Duration::ZERO
} else { } else {
self.repaint_after self.repaint_after
@@ -147,6 +164,8 @@ impl Repaint {
self.frame_nr += 1; self.frame_nr += 1;
self.repaint_after.retain(|id, _| viewports.contains(id)); self.repaint_after.retain(|id, _| viewports.contains(id));
self.repaint_requests
.retain(|id, repaints| viewports.contains(id) && *repaints != 0);
self.repaint_after self.repaint_after
.iter() .iter()

View File

@@ -5,6 +5,8 @@ use eframe::NativeOptions;
fn main() { fn main() {
env_logger::init(); // Use `RUST_LOG=debug` to see logs. env_logger::init(); // Use `RUST_LOG=debug` to see logs.
let mut to_repair = false;
let _ = eframe::run_simple_native( let _ = eframe::run_simple_native(
"Viewports Examples", "Viewports Examples",
NativeOptions { NativeOptions {
@@ -17,6 +19,7 @@ fn main() {
let mut is_desktop = ctx.is_desktop(); let mut is_desktop = ctx.is_desktop();
ui.checkbox(&mut is_desktop, "Is Desktop"); ui.checkbox(&mut is_desktop, "Is Desktop");
ctx.set_desktop(is_desktop); ctx.set_desktop(is_desktop);
ui.checkbox(&mut to_repair, "To Repair!");
egui::CollapsingHeader::new("Show Test1").show(ui, |ui| { egui::CollapsingHeader::new("Show Test1").show(ui, |ui| {
egui::Window::new("Test1").show(ctx, move |ui, id, parent_id| { egui::Window::new("Test1").show(ctx, move |ui, id, parent_id| {
@@ -30,6 +33,9 @@ fn main() {
ui.data_mut(|data| { ui.data_mut(|data| {
data.insert_persisted(Id::new("Test1").with("_embedded"), embedded) data.insert_persisted(Id::new("Test1").with("_embedded"), embedded)
}); });
if to_repair {
ui.spinner();
}
let ctx = ui.ctx().clone(); let ctx = ui.ctx().clone();
ui.label(format!( ui.label(format!(
@@ -59,6 +65,9 @@ fn main() {
ui.data_mut(|data| { ui.data_mut(|data| {
data.insert_persisted(Id::new("Test2").with("_embedded"), embedded) data.insert_persisted(Id::new("Test2").with("_embedded"), embedded)
}); });
if to_repair {
ui.spinner();
}
let ctx = ui.ctx().clone(); let ctx = ui.ctx().clone();
ui.label(format!( ui.label(format!(
"Current rendering window: {}", "Current rendering window: {}",