[web] minor fixes for reactive mode
This commit is contained in:
+2
-1
@@ -51,6 +51,7 @@ This is the core library crate Egui. It is fully platform independent without an
|
||||
* [x] Change to resize cursor on hover
|
||||
* [ ] Make it a JS library for easily creating your own stuff
|
||||
* [x] Read url fragment and redirect to a subpage (e.g. different examples apps)
|
||||
* [ ] Read https://www.html5rocks.com/en/mobile/mobifying/#toc-meta-viewport
|
||||
|
||||
### Visuals
|
||||
* [x] Simplify button style to make for nicer collapsible headers. Maybe weak outline? Or just subtle different text color?
|
||||
@@ -101,7 +102,7 @@ Add extremely quick animations for some things, maybe 2-3 frames. For instance:
|
||||
* [x] Solve which parts of Context are behind a mutex
|
||||
* [x] Rename Region to Ui
|
||||
* [ ] Move Path and Triangles to own crate
|
||||
* [ ] Maybe find a shorter name for the library like `egui`?
|
||||
* [x] Maybe find a shorter name for the library like `egui`?
|
||||
|
||||
### Global widget search
|
||||
Ability to do a search for any widget. The search works even for collapsed regions and closed windows and menus. This is implemented like this: while searching, all region are layed out and their add_content functions are run. If none of the contents matches the search, the layout is reverted and nothing is shown. So windows will get temporarily opened and run, but if the search is not a match in the window it is closed again. This means then when searching your whole GUI is being run, which may be a bit slower, but it would be a really awesome feature.
|
||||
|
||||
@@ -185,16 +185,18 @@ impl Prepared {
|
||||
if move_interact.active {
|
||||
state.pos += input.mouse.delta;
|
||||
state.vel = input.mouse.velocity;
|
||||
ctx.request_repaint();
|
||||
} else {
|
||||
let stop_speed = 20.0; // Pixels per second.
|
||||
let friction_coeff = 1000.0; // Pixels per second squared.
|
||||
let dt = input.unstable_dt;
|
||||
|
||||
let friction = friction_coeff * input.dt;
|
||||
let friction = friction_coeff * dt;
|
||||
if friction > state.vel.length() || state.vel.length() < stop_speed {
|
||||
state.vel = Vec2::zero();
|
||||
} else {
|
||||
state.vel -= friction * state.vel.normalized();
|
||||
state.pos += state.vel * input.dt;
|
||||
state.pos += state.vel * dt;
|
||||
ctx.request_repaint();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,13 +50,14 @@ impl State {
|
||||
pub fn toggle(&mut self, ui: &Ui) {
|
||||
self.open = !self.open;
|
||||
self.toggle_time = ui.input().time;
|
||||
ui.ctx().request_repaint();
|
||||
}
|
||||
|
||||
/// 0 for closed, 1 for open, with tweening
|
||||
pub fn openness(&self, ui: &Ui) -> f32 {
|
||||
let animation_time = ui.style().animation_time;
|
||||
let time_since_toggle = (ui.input().time - self.toggle_time) as f32;
|
||||
let time_since_toggle = time_since_toggle + ui.input().dt; // Instant feedback
|
||||
let time_since_toggle = time_since_toggle + ui.input().predicted_dt; // Instant feedback
|
||||
if time_since_toggle <= animation_time {
|
||||
ui.ctx().request_repaint();
|
||||
}
|
||||
@@ -103,6 +104,7 @@ impl State {
|
||||
let openness = self.openness(ui);
|
||||
let animate = 0.0 < openness && openness < 1.0;
|
||||
if animate {
|
||||
ui.ctx().request_repaint();
|
||||
Some(ui.add_custom(|child_ui| {
|
||||
let max_height = if self.open {
|
||||
if let Some(full_height) = self.open_height {
|
||||
|
||||
@@ -193,7 +193,7 @@ impl Prepared {
|
||||
if show_scroll_this_frame && current_scroll_bar_width <= 0.0 {
|
||||
// Avoid frame delay; start shwoing scroll bar right away:
|
||||
current_scroll_bar_width = remap_clamp(
|
||||
ui.input().dt,
|
||||
ui.input().predicted_dt,
|
||||
0.0..=ui.style().animation_time,
|
||||
0.0..=max_scroll_bar_width,
|
||||
);
|
||||
@@ -291,6 +291,7 @@ impl Prepared {
|
||||
|
||||
if show_scroll_this_frame != state.show_scroll {
|
||||
state.toggle_time = ui.input().time;
|
||||
ui.ctx().request_repaint();
|
||||
}
|
||||
|
||||
state.offset.y = state.offset.y.min(content_size.y - inner_rect.height());
|
||||
|
||||
+9
-4
@@ -58,7 +58,11 @@ pub struct InputState {
|
||||
pub time: f64,
|
||||
|
||||
/// Time since last frame, in seconds.
|
||||
pub dt: f32,
|
||||
/// This can be very unstable in reactive mode (when we don't paint each frame).
|
||||
pub unstable_dt: f32,
|
||||
|
||||
/// Can be used to fast-forward to next frame for instance feedback. hacky.
|
||||
pub predicted_dt: f32,
|
||||
|
||||
/// Local time. Only used for the clock in the example app.
|
||||
pub seconds_since_midnight: Option<f64>,
|
||||
@@ -177,14 +181,15 @@ impl InputState {
|
||||
#[must_use]
|
||||
pub fn begin_frame(self, new: RawInput) -> InputState {
|
||||
let mouse = self.mouse.begin_frame(&new);
|
||||
let dt = (new.time - self.raw.time) as f32;
|
||||
let unstable_dt = (new.time - self.raw.time) as f32;
|
||||
InputState {
|
||||
mouse,
|
||||
scroll_delta: new.scroll_delta,
|
||||
screen_size: new.screen_size,
|
||||
pixels_per_point: new.pixels_per_point.unwrap_or(1.0),
|
||||
time: new.time,
|
||||
dt,
|
||||
unstable_dt,
|
||||
predicted_dt: 1.0 / 60.0, // TODO: remove this hack
|
||||
seconds_since_midnight: new.seconds_since_midnight,
|
||||
events: new.events.clone(), // TODO: remove clone() and use raw.events
|
||||
raw: new,
|
||||
@@ -312,7 +317,7 @@ impl InputState {
|
||||
self.pixels_per_point
|
||||
));
|
||||
ui.add(label!("time: {:.3} s", self.time));
|
||||
ui.add(label!("dt: {:.3} s", self.dt));
|
||||
ui.add(label!("dt: {:.1} ms", 1e3 * self.unstable_dt));
|
||||
ui.add(label!(
|
||||
"seconds_since_midnight: {:?} s",
|
||||
self.seconds_since_midnight
|
||||
|
||||
@@ -142,6 +142,7 @@ impl<'t> Widget for TextEdit<'t> {
|
||||
));
|
||||
}
|
||||
}
|
||||
ui.ctx().request_repaint(); // TODO: only when cursor blinks on or off
|
||||
}
|
||||
|
||||
ui.add_galley(interact.rect.min, galley, text_style, text_color);
|
||||
|
||||
Reference in New Issue
Block a user