From 0a9de15d79e9cadb9478e1ebf7f450fce978ca85 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Mon, 26 May 2025 17:00:17 +0800 Subject: [PATCH] input: Change `InputState::disabled` to as builder method. (#898) ## Break Changes - The `disabled` method now is for builder method, and `is_disabled` for get state. ```diff - pub fn disabled(mut self) -> bool + pub fn is_disabled(&self) -> bool + pub fn disabled(mut self, disabled: bool) -> Self ``` --- crates/ui/src/input/state.rs | 19 +++++++++++++++---- crates/ui/src/inspector.rs | 7 +++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/crates/ui/src/input/state.rs b/crates/ui/src/input/state.rs index ecbfdfbf..728ae15a 100644 --- a/crates/ui/src/input/state.rs +++ b/crates/ui/src/input/state.rs @@ -665,12 +665,27 @@ impl InputState { self.replace_text_in_range(Some(range), &text, window, cx); } + /// Set with disabled mode. + /// + /// See also: [`Self::set_disabled`], [`Self::is_disabled`]. + pub fn disabled(mut self, disabled: bool) -> Self { + self.disabled = disabled; + self + } + /// Set the disabled state of the input field. + /// + /// See also: [`Self::disabled`], [`Self::is_disabled`]. pub fn set_disabled(&mut self, disabled: bool, _: &mut Window, cx: &mut Context) { self.disabled = disabled; cx.notify(); } + /// Return is the input field is disabled. + pub fn is_disabled(&self) -> bool { + self.disabled + } + /// Set with password masked state. pub fn masked(mut self, masked: bool) -> Self { self.masked = masked; @@ -734,10 +749,6 @@ impl InputState { self.mask_pattern.unmask(&self.text).into() } - pub fn disabled(&self) -> bool { - self.disabled - } - /// Focus the input field. pub fn focus(&self, window: &mut Window, _: &mut Context) { self.focus_handle.focus(window); diff --git a/crates/ui/src/inspector.rs b/crates/ui/src/inspector.rs index f86d043f..bec90a0e 100644 --- a/crates/ui/src/inspector.rs +++ b/crates/ui/src/inspector.rs @@ -67,11 +67,10 @@ impl DivInspector { }; let input_state = cx.new(|cx| { - let mut state = InputState::new(window, cx) + InputState::new(window, cx) .code_editor(Some("json"), theme) - .line_number(false); - state.set_disabled(true, window, cx); - state + .line_number(false) + .disabled(true) }); Self {