Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added setting to make the NumberSelection TextInput non-editable. #281

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions native-windows-gui/src/controls/number_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ pub struct NumberSelect {
edit: TextInput,
btn_up: Button,
btn_down: Button,
handler: Option<RawEventHandler>
handler: Option<RawEventHandler>,
keyboard_editable: Rc<RefCell<bool>>,
}

impl NumberSelect {
Expand All @@ -133,7 +134,8 @@ impl NumberSelect {
enabled: true,
flags: None,
font: None,
parent: None
parent: None,
keyboard_editable: false,
}
}

Expand Down Expand Up @@ -244,6 +246,11 @@ impl NumberSelect {
WS_CHILD | WS_BORDER | WS_CLIPCHILDREN
}

pub fn set_keyboard_editable(&self, editable: bool){
*self.keyboard_editable.borrow_mut() = editable;
self.edit.set_readonly(!editable);
}

}

impl Drop for NumberSelect {
Expand All @@ -265,7 +272,8 @@ pub struct NumberSelectBuilder<'a> {
enabled: bool,
flags: Option<NumberSelectFlags>,
font: Option<&'a Font>,
parent: Option<ControlHandle>
parent: Option<ControlHandle>,
keyboard_editable: bool,
}

impl<'a> NumberSelectBuilder<'a> {
Expand Down Expand Up @@ -369,6 +377,11 @@ impl<'a> NumberSelectBuilder<'a> {
self
}

pub fn keyboard_editable(mut self, editable: bool) -> NumberSelectBuilder<'a> {
self.keyboard_editable = editable;
self
}

pub fn parent<C: Into<ControlHandle>>(mut self, p: C) -> NumberSelectBuilder<'a> {
self.parent = Some(p.into());
self
Expand Down Expand Up @@ -397,6 +410,7 @@ impl<'a> NumberSelectBuilder<'a> {

*out = NumberSelect::default();
*out.data.borrow_mut() = self.data;
*out.keyboard_editable.borrow_mut() = self.keyboard_editable;

out.handle = ControlBase::build_hwnd()
.class_name(out.class_name())
Expand All @@ -413,6 +427,7 @@ impl<'a> NumberSelectBuilder<'a> {
.size((w-19, h))
.parent(&out.handle)
.flags(text_flags)
.readonly(!self.keyboard_editable)
.build(&mut out.edit)?;

Button::builder()
Expand Down