pub struct Input { /* private fields */ }Expand description
Ergonomik input soyutlama katmanı.
Kullanım:
if input.is_key_pressed(KeyCode::KeyW as u32) { /* ileri git */ }
if input.is_key_just_pressed(KeyCode::Space as u32) { /* zıpla (tek sefer) */ }
if input.is_mouse_button_pressed(mouse::LEFT) { /* ateş et */ }
let (dx, dy) = input.mouse_delta(); /* fare hareketi */
let scroll = input.mouse_scroll(); /* tekerlek */Implementations§
Source§impl Input
impl Input
pub fn new() -> Input
Sourcepub fn begin_frame(&mut self)
pub fn begin_frame(&mut self)
Her frame başında çağrılmalı — “just pressed/released” setlerini temizler ve deferred tuş bırakmalarını gerçekleştirir.
Mantık:
on_key_released()aynı frame’de basılıp bırakılan tuşlar içinkeys_pressed’den silmeyi erteliyordu (fast-tap koruması).begin_frame()bu deferred silmeleri gerçekleştirir.- Ardından just_pressed ve just_released setleri temizlenir, fare deltaları sıfırlanır.
Sourcepub fn pressed_keys(&self) -> Vec<u32>
pub fn pressed_keys(&self) -> Vec<u32>
Basılı tüm tuşları döndürür (Debug için)
Sourcepub fn on_key_pressed(&mut self, key: u32)
pub fn on_key_pressed(&mut self, key: u32)
Tuş basıldığında çağır (winit KeyCode’un scan code’u)
Sourcepub fn on_key_released(&mut self, key: u32)
pub fn on_key_released(&mut self, key: u32)
Tuş bırakıldığında çağır.
Eğer tuş aynı frame’de basılıp bırakıldıysa (keys_just_pressed içindeyse),
keys_pressed’den silmeyi begin_frame()’e erteler. Böylece oyun bu “fast tap“ı
kaçırmaz — hem is_key_pressed hem is_key_just_pressed o frame boyunca true döner.
Sourcepub fn is_key_pressed(&self, key: u32) -> bool
pub fn is_key_pressed(&self, key: u32) -> bool
Tuş şu an basılı mı? (sürekli kontrol)
Sourcepub fn is_key_just_pressed(&self, key: u32) -> bool
pub fn is_key_just_pressed(&self, key: u32) -> bool
Tuş bu frame’de mi basıldı? (tek seferlik tetikleme)
Sourcepub fn is_key_just_released(&self, key: u32) -> bool
pub fn is_key_just_released(&self, key: u32) -> bool
Tuş bu frame’de mi bırakıldı?
Fare butonu basıldığında çağır (0=Left, 1=Right, 2=Middle)
Fare butonu bırakıldığında çağır
Fare butonu basılı mı?
Fare butonu bu frame’de mi basıldı?
Fare butonu bu frame’de mi bırakıldı?
Sourcepub fn on_mouse_moved(&mut self, x: f32, y: f32)
pub fn on_mouse_moved(&mut self, x: f32, y: f32)
Fare ekran pozisyonu değiştiğinde çağır.
Pozisyon farkından delta biriktirilir — DeviceEvent::MouseMotion
olmayan platformlarda (web, bazı Linux konfigürasyonları) fallback sağlar.
Sourcepub fn on_mouse_delta(&mut self, dx: f32, dy: f32)
pub fn on_mouse_delta(&mut self, dx: f32, dy: f32)
Fare delta hareketi (DeviceEvent::MouseMotion).
on_mouse_moved zaten delta biriktirdiği için, bu metot yalnızca
platform DeviceEvent::MouseMotion veriyorsa ek doğruluk sağlar.
İkisi birlikte çağrılmamalı — platform’a göre birini kullanın.
Sourcepub fn mouse_position(&self) -> (f32, f32)
pub fn mouse_position(&self) -> (f32, f32)
Fare ekran pozisyonu
Sourcepub fn mouse_delta(&self) -> (f32, f32)
pub fn mouse_delta(&self) -> (f32, f32)
Bu frame’deki fare hareketi (delta)
Sourcepub fn on_mouse_scroll(&mut self, delta: f32)
pub fn on_mouse_scroll(&mut self, delta: f32)
Fare tekerleği hareket ettiğinde çağır. Pozitif = yukarı/ileri, negatif = aşağı/geri.
Sourcepub fn mouse_scroll(&self) -> f32
pub fn mouse_scroll(&self) -> f32
Bu frame’deki fare tekerlek deltası. Pozitif = yukarı/ileri, negatif = aşağı/geri.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Input
impl<'de> Deserialize<'de> for Input
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Input, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Input, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl InputExt for Input
impl InputExt for Input
Source§fn pressed(&self, keycode: KeyCode) -> bool
fn pressed(&self, keycode: KeyCode) -> bool
Key::KeyW, Key::Space gibi KeyCode varyantlarını doğrudan alır.Source§fn just_pressed(&self, keycode: KeyCode) -> bool
fn just_pressed(&self, keycode: KeyCode) -> bool
Source§fn just_released(&self, keycode: KeyCode) -> bool
fn just_released(&self, keycode: KeyCode) -> bool
Source§impl Serialize for Input
impl Serialize for Input
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl Freeze for Input
impl RefUnwindSafe for Input
impl Send for Input
impl Sync for Input
impl Unpin for Input
impl UnsafeUnpin for Input
impl UnwindSafe for Input
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().