/// Returns if it's repeating or not
Returns if it's repeating or not
Returns if it ' s repeating or not
fn update(&mut self, state: RawButtonState, dt: Duration) -> bool {
        match state {
            RawButtonState::Up | RawButtonState::Released => {
                self.accum_repeat = Duration::new(0, 0);
                self.accum_down = Duration::new(0, 0);
                self.is_on_first_repeat = false;
                false
            }
            RawButtonState::Pressed => {
                self.accum_repeat = Duration::new(0, 0);
                self.accum_down = Duration::new(0, 0);
                self.is_on_first_repeat = true;
                false
            }
            // Down state may be repeating
            RawButtonState::Down => {
                let repeat_duration = match self.config {
                    KeyRepeatConfig::NoRepeat => return false,
                    KeyRepeatConfig::Repeat { first, multi } => {
                        if self.is_on_first_repeat {
                            first
                        } else {
                            multi
                        }
                    }
                };
                self.accum_repeat += dt;
                self.accum_down += dt;
                let mut is_repeating = false;
                // basically it's just an if branch but in case too long time passed
                while self.accum_repeat > repeat_duration {
                    is_repeating = true;
                    self.is_on_first_repeat = false;
                    self.accum_repeat -= repeat_duration;
                }
                is_repeating
            }
        }
    }
fn update ( & mut self , state : RawButtonState , dt : Duration ) -> bool { match state { RawButtonState :: Up | RawButtonState :: Released => { self . accum_repeat = Duration :: new ( 0 , 0 ) ; self . accum_down = Duration :: new ( 0 , 0 ) ; self . is_on_first_repeat = false ; false } RawButtonState :: Pressed => { self . accum_repeat = Duration :: new ( 0 , 0 ) ; self . accum_down = Duration :: new ( 0 , 0 ) ; self . is_on_first_repeat = true ; false } // Down state may be repeating RawButtonState :: Down => { let repeat_duration = match self . config { KeyRepeatConfig :: NoRepeat => return false , KeyRepeatConfig :: Repeat { first , multi } => { if self . is_on_first_repeat { first } else { multi } } } ; self . accum_repeat += dt ; self . accum_down += dt ; let mut is_repeating = false ; // basically it's just an if branch but in case too long time passed while self . accum_repeat > repeat_duration { is_repeating = true ; self . is_on_first_repeat = false ; self . accum_repeat -= repeat_duration ; } is_repeating } } }
Returns if it's repeating or not
Returns if it ' s repeating or not
&mut self
state
RawButtonState
dt
Duration