Minor code tweaks
This commit is contained in:
parent
5093b67e9b
commit
4e59296cbb
9 changed files with 50 additions and 25 deletions
|
@ -91,7 +91,7 @@ pub fn canvas_element(canvas_id: &str) -> Option<web_sys::HtmlCanvasElement> {
|
|||
|
||||
pub fn canvas_element_or_die(canvas_id: &str) -> web_sys::HtmlCanvasElement {
|
||||
canvas_element(canvas_id)
|
||||
.unwrap_or_else(|| panic!("Failed to find canvas with id '{}'", canvas_id))
|
||||
.unwrap_or_else(|| panic!("Failed to find canvas with id {:?}", canvas_id))
|
||||
}
|
||||
|
||||
fn canvas_origin(canvas_id: &str) -> egui::Pos2 {
|
||||
|
|
|
@ -42,7 +42,7 @@ impl Frame {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn side_top_panel(style: &Style) -> Self {
|
||||
pub fn side_top_panel(style: &Style) -> Self {
|
||||
Self {
|
||||
inner_margin: Margin::symmetric(8.0, 2.0),
|
||||
fill: style.visuals.window_fill(),
|
||||
|
@ -50,7 +50,7 @@ impl Frame {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn central_panel(style: &Style) -> Self {
|
||||
pub fn central_panel(style: &Style) -> Self {
|
||||
Self {
|
||||
inner_margin: Margin::same(8.0),
|
||||
fill: style.visuals.window_fill(),
|
||||
|
|
|
@ -349,6 +349,8 @@ impl SidePanel {
|
|||
None
|
||||
} else if how_expanded < 1.0 {
|
||||
// Show a fake panel in this in-between animation state:
|
||||
// TODO(emilk): move the panel out-of-screen instead of changing its width.
|
||||
// Then we can actually paint it as it animates.
|
||||
let expanded_width = PanelState::load(ctx, self.id)
|
||||
.map_or(self.default_width, |state| state.rect.width());
|
||||
let fake_width = how_expanded * expanded_width;
|
||||
|
@ -382,6 +384,8 @@ impl SidePanel {
|
|||
None
|
||||
} else if how_expanded < 1.0 {
|
||||
// Show a fake panel in this in-between animation state:
|
||||
// TODO(emilk): move the panel out-of-screen instead of changing its width.
|
||||
// Then we can actually paint it as it animates.
|
||||
let expanded_width = PanelState::load(ui.ctx(), self.id)
|
||||
.map_or(self.default_width, |state| state.rect.width());
|
||||
let fake_width = how_expanded * expanded_width;
|
||||
|
@ -785,6 +789,8 @@ impl TopBottomPanel {
|
|||
None
|
||||
} else if how_expanded < 1.0 {
|
||||
// Show a fake panel in this in-between animation state:
|
||||
// TODO(emilk): move the panel out-of-screen instead of changing its height.
|
||||
// Then we can actually paint it as it animates.
|
||||
let expanded_height = PanelState::load(ctx, self.id)
|
||||
.map(|state| state.rect.height())
|
||||
.or(self.default_height)
|
||||
|
@ -820,6 +826,8 @@ impl TopBottomPanel {
|
|||
None
|
||||
} else if how_expanded < 1.0 {
|
||||
// Show a fake panel in this in-between animation state:
|
||||
// TODO(emilk): move the panel out-of-screen instead of changing its height.
|
||||
// Then we can actually paint it as it animates.
|
||||
let expanded_height = PanelState::load(ui.ctx(), self.id)
|
||||
.map(|state| state.rect.height())
|
||||
.or(self.default_height)
|
||||
|
|
|
@ -253,12 +253,13 @@ impl ScrollArea {
|
|||
self
|
||||
}
|
||||
|
||||
/// Control the scrolling behavior
|
||||
/// If `true` (default), the scroll area will respond to user scrolling
|
||||
/// If `false`, the scroll area will not respond to user scrolling
|
||||
/// Control the scrolling behavior.
|
||||
///
|
||||
/// * If `true` (default), the scroll area will respond to user scrolling.
|
||||
/// * If `false`, the scroll area will not respond to user scrolling.
|
||||
///
|
||||
/// This can be used, for example, to optionally freeze scrolling while the user
|
||||
/// is inputing text in a [`TextEdit`] widget contained within the scroll area.
|
||||
/// is typing text in a [`TextEdit`] widget contained within the scroll area.
|
||||
///
|
||||
/// This controls both scrolling directions.
|
||||
pub fn enable_scrolling(mut self, enable: bool) -> Self {
|
||||
|
@ -268,8 +269,8 @@ impl ScrollArea {
|
|||
|
||||
/// For each axis, should the containing area shrink if the content is small?
|
||||
///
|
||||
/// If true, egui will add blank space outside the scroll area.
|
||||
/// If false, egui will add blank space inside the scroll area.
|
||||
/// * If `true`, egui will add blank space outside the scroll area.
|
||||
/// * If `false`, egui will add blank space inside the scroll area.
|
||||
///
|
||||
/// Default: `[true; 2]`.
|
||||
pub fn auto_shrink(mut self, auto_shrink: [bool; 2]) -> Self {
|
||||
|
|
|
@ -1293,12 +1293,15 @@ impl Context {
|
|||
}
|
||||
|
||||
/// Like [`Self::animate_bool`] but allows you to control the animation time.
|
||||
pub fn animate_bool_with_time(&self, id: Id, value: bool, animation_time: f32) -> f32 {
|
||||
pub fn animate_bool_with_time(&self, id: Id, target_value: bool, animation_time: f32) -> f32 {
|
||||
let animated_value = {
|
||||
let ctx_impl = &mut *self.write();
|
||||
ctx_impl
|
||||
.animation_manager
|
||||
.animate_bool(&ctx_impl.input, animation_time, id, value)
|
||||
ctx_impl.animation_manager.animate_bool(
|
||||
&ctx_impl.input,
|
||||
animation_time,
|
||||
id,
|
||||
target_value,
|
||||
)
|
||||
};
|
||||
let animation_in_progress = 0.0 < animated_value && animated_value < 1.0;
|
||||
if animation_in_progress {
|
||||
|
@ -1310,14 +1313,17 @@ impl Context {
|
|||
/// Allows you to smoothly change the f32 value.
|
||||
/// At the first call the value is written to memory.
|
||||
/// When it is called with a new value, it linearly interpolates to it in the given time.
|
||||
pub fn animate_value_with_time(&self, id: Id, value: f32, animation_time: f32) -> f32 {
|
||||
pub fn animate_value_with_time(&self, id: Id, target_value: f32, animation_time: f32) -> f32 {
|
||||
let animated_value = {
|
||||
let ctx_impl = &mut *self.write();
|
||||
ctx_impl
|
||||
.animation_manager
|
||||
.animate_value(&ctx_impl.input, animation_time, id, value)
|
||||
ctx_impl.animation_manager.animate_value(
|
||||
&ctx_impl.input,
|
||||
animation_time,
|
||||
id,
|
||||
target_value,
|
||||
)
|
||||
};
|
||||
let animation_in_progress = animated_value != value;
|
||||
let animation_in_progress = animated_value != target_value;
|
||||
if animation_in_progress {
|
||||
self.request_repaint();
|
||||
}
|
||||
|
|
|
@ -2007,7 +2007,7 @@ impl Ui {
|
|||
InnerResponse::new(inner, self.interact(rect, child_ui.id, Sense::hover()))
|
||||
}
|
||||
|
||||
#[deprecated = "Use ui.vertical_centered instead"]
|
||||
#[deprecated = "Use ui.vertical_centered or ui.centered_and_justified"]
|
||||
pub fn centered<R>(&mut self, add_contents: impl FnOnce(&mut Self) -> R) -> InnerResponse<R> {
|
||||
self.vertical_centered(add_contents)
|
||||
}
|
||||
|
|
|
@ -34,11 +34,13 @@ impl Label {
|
|||
|
||||
/// If `true`, the text will wrap to stay within the max width of the [`Ui`].
|
||||
///
|
||||
/// By default [`Self::wrap`] will be true in vertical layouts
|
||||
/// By default [`Self::wrap`] will be `true` in vertical layouts
|
||||
/// and horizontal layouts with wrapping,
|
||||
/// and false on non-wrapping horizontal layouts.
|
||||
/// and `false` on non-wrapping horizontal layouts.
|
||||
///
|
||||
/// Note that any `\n` in the text will always produce a new line.
|
||||
///
|
||||
/// You can also use [`crate::Style::wrap`].
|
||||
#[inline]
|
||||
pub fn wrap(mut self, wrap: bool) -> Self {
|
||||
self.wrap = Some(wrap);
|
||||
|
|
|
@ -72,10 +72,19 @@ impl Widget for Separator {
|
|||
|
||||
if ui.is_rect_visible(response.rect) {
|
||||
let stroke = ui.visuals().widgets.noninteractive.bg_stroke;
|
||||
let painter = ui.painter();
|
||||
if is_horizontal_line {
|
||||
ui.painter().hline(rect.x_range(), rect.center().y, stroke);
|
||||
painter.hline(
|
||||
rect.x_range(),
|
||||
painter.round_to_pixel(rect.center().y),
|
||||
stroke,
|
||||
);
|
||||
} else {
|
||||
ui.painter().vline(rect.center().x, rect.y_range(), stroke);
|
||||
painter.vline(
|
||||
painter.round_to_pixel(rect.center().x),
|
||||
rect.y_range(),
|
||||
stroke,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,8 +5,7 @@ pub use ordered_float::*;
|
|||
/// Hash the given value with a predictable hasher.
|
||||
#[inline]
|
||||
pub fn hash(value: impl std::hash::Hash) -> u64 {
|
||||
use ahash::RandomState;
|
||||
RandomState::with_seeds(1, 2, 3, 4).hash_one(value)
|
||||
ahash::RandomState::with_seeds(1, 2, 3, 4).hash_one(value)
|
||||
}
|
||||
|
||||
/// Hash the given value with the given hasher.
|
||||
|
|
Loading…
Reference in a new issue