Skip to content

Commit

Permalink
Apply magic value suggestion
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Daniel McNab <[email protected]>
  • Loading branch information
tomcur and DJMcNab committed Dec 11, 2024
1 parent 254d1ef commit 7b287e6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions masonry/src/render_root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ use crate::text::BrushIndex;
use crate::widget::{WidgetArena, WidgetMut, WidgetRef, WidgetState};
use crate::{AccessEvent, Action, CursorIcon, Handled, QueryCtx, Widget, WidgetId, WidgetPod};

/// We ensure that any valid initial IME area is sent to the platform by storing an invalid initial
/// IME area as the last sent ime area.
const INVALID_IME_AREA: Rect = Rect::new(f64::NAN, f64::NAN, f64::NAN, f64::NAN);

// --- MARK: STRUCTS ---

pub struct RenderRoot {
Expand Down Expand Up @@ -74,6 +78,9 @@ pub(crate) struct RenderRootState {
pub(crate) text_layout_context: LayoutContext<BrushIndex>,
pub(crate) mutate_callbacks: Vec<MutateCallback>,
pub(crate) is_ime_active: bool,
/// The IME area last sent to the platform.
///
/// This allows only sending the area to the platform when the area has changed.
pub(crate) last_sent_ime_area: Rect,
pub(crate) scenes: HashMap<WidgetId, Scene>,
/// Whether data set in the pointer pass has been invalidated.
Expand Down Expand Up @@ -171,7 +178,7 @@ impl RenderRoot {
text_layout_context: LayoutContext::new(),
mutate_callbacks: Vec::new(),
is_ime_active: false,
last_sent_ime_area: Rect::new(f64::NAN, f64::NAN, f64::NAN, f64::NAN),
last_sent_ime_area: INVALID_IME_AREA,
scenes: HashMap::new(),
needs_pointer_pass: false,
trace: PassTracing::from_env(),
Expand Down Expand Up @@ -269,8 +276,7 @@ impl RenderRoot {
if matches!(event, TextEvent::Ime(winit::event::Ime::Enabled)) {
// Reset the last sent IME area, as the platform reset the IME state and may have
// forgotten it.
self.global_state.last_sent_ime_area =
Rect::new(f64::NAN, f64::NAN, f64::NAN, f64::NAN);
self.global_state.last_sent_ime_area = INVALID_IME_AREA;
}
self.run_rewrite_passes();

Expand Down

0 comments on commit 7b287e6

Please sign in to comment.