use mitsuami_core::{
Element, ElementBuilder, EventValue, InputPurpose, NodeId, Prop, Tweak, Ui, UiEvent, View, WidgetKind,
};
use mitsuami_reactive::{IntoValue, Signal, Value};
pub struct TextInput(Element);
widget!(TextInput);
impl Default for TextInput {
fn default() -> TextInput {
TextInput::new()
}
}
impl TextInput {
pub fn new() -> TextInput {
TextInput(Element::new(WidgetKind::TextInput))
}
pub fn value(mut self, value: impl IntoValue<String>) -> TextInput {
self.0.prop(value.into_value(), Prop::Value);
self
}
pub fn bind(self, signal: Signal<String>) -> TextInput {
self.value(signal).on_input(move |text| signal.set(text))
}
pub fn placeholder(mut self, placeholder: impl IntoValue<String>) -> TextInput {
self.0.prop(placeholder.into_value(), Prop::Placeholder);
self
}
pub fn enabled(mut self, enabled: impl IntoValue<bool>) -> TextInput {
self.0.prop(enabled.into_value(), Prop::Enabled);
self
}
pub fn read_only(mut self, read_only: impl IntoValue<bool>) -> TextInput {
self.0.prop(read_only.into_value(), Prop::ReadOnly);
self
}
pub fn input_purpose(mut self, purpose: impl IntoValue<InputPurpose>) -> TextInput {
self.0.prop(purpose.into_value(), Prop::InputPurpose);
self
}
pub fn on_input(mut self, handler: impl Fn(String) + 'static) -> TextInput {
self.0.on(move |event| {
if let UiEvent::Changed(EventValue::Text(text)) = event {
handler(text.clone());
}
});
self
}
pub fn native(mut self, tweak: Tweak<TextInput>) -> TextInput {
tweak.apply(&mut self.0);
self
}
pub fn on_submit(mut self, handler: impl Fn() + 'static) -> TextInput {
self.0.on(move |event| {
if *event == UiEvent::Submit {
handler();
}
});
self
}
}
pub struct PasswordInput(Element);
widget!(PasswordInput);
impl Default for PasswordInput {
fn default() -> PasswordInput {
PasswordInput::new()
}
}
impl PasswordInput {
pub fn new() -> PasswordInput {
PasswordInput(Element::new(WidgetKind::PasswordInput))
}
pub fn value(mut self, value: impl IntoValue<String>) -> PasswordInput {
self.0.prop(value.into_value(), Prop::Value);
self
}
pub fn bind(self, signal: Signal<String>) -> PasswordInput {
self.value(signal).on_input(move |text| signal.set(text))
}
pub fn placeholder(mut self, placeholder: impl IntoValue<String>) -> PasswordInput {
self.0.prop(placeholder.into_value(), Prop::Placeholder);
self
}
pub fn enabled(mut self, enabled: impl IntoValue<bool>) -> PasswordInput {
self.0.prop(enabled.into_value(), Prop::Enabled);
self
}
pub fn native(mut self, tweak: Tweak<PasswordInput>) -> PasswordInput {
tweak.apply(&mut self.0);
self
}
pub fn on_input(mut self, handler: impl Fn(String) + 'static) -> PasswordInput {
self.0.on(move |event| {
if let UiEvent::Changed(EventValue::Text(text)) = event {
handler(text.clone());
}
});
self
}
pub fn on_submit(mut self, handler: impl Fn() + 'static) -> PasswordInput {
self.0.on(move |event| {
if *event == UiEvent::Submit {
handler();
}
});
self
}
}
pub struct SearchInput(Element);
widget!(SearchInput);
impl Default for SearchInput {
fn default() -> SearchInput {
SearchInput::new()
}
}
impl SearchInput {
pub fn new() -> SearchInput {
SearchInput(Element::new(WidgetKind::SearchInput))
}
pub fn value(mut self, value: impl IntoValue<String>) -> SearchInput {
self.0.prop(value.into_value(), Prop::Value);
self
}
pub fn bind(self, signal: Signal<String>) -> SearchInput {
self.value(signal).on_input(move |text| signal.set(text))
}
pub fn placeholder(mut self, placeholder: impl IntoValue<String>) -> SearchInput {
self.0.prop(placeholder.into_value(), Prop::Placeholder);
self
}
pub fn enabled(mut self, enabled: impl IntoValue<bool>) -> SearchInput {
self.0.prop(enabled.into_value(), Prop::Enabled);
self
}
pub fn on_input(mut self, handler: impl Fn(String) + 'static) -> SearchInput {
self.0.on(move |event| {
if let UiEvent::Changed(EventValue::Text(text)) = event {
handler(text.clone());
}
});
self
}
pub fn on_search(mut self, handler: impl Fn(String) + 'static) -> SearchInput {
self.0.on(move |event| {
if let UiEvent::Search(text) = event {
handler(text.clone());
}
});
self
}
pub fn native(mut self, tweak: Tweak<SearchInput>) -> SearchInput {
tweak.apply(&mut self.0);
self
}
}
pub struct TextArea(Element);
widget!(TextArea);
impl Default for TextArea {
fn default() -> TextArea {
TextArea::new()
}
}
impl TextArea {
pub fn new() -> TextArea {
let mut element = Element::new(WidgetKind::TextArea);
element.prop(Value::Static(3), Prop::Lines);
TextArea(element)
}
pub fn value(mut self, value: impl IntoValue<String>) -> TextArea {
self.0.prop(value.into_value(), Prop::Value);
self
}
pub fn bind(self, signal: Signal<String>) -> TextArea {
self.value(signal).on_input(move |text| signal.set(text))
}
pub fn placeholder(mut self, placeholder: impl IntoValue<String>) -> TextArea {
self.0.prop(placeholder.into_value(), Prop::Placeholder);
self
}
pub fn enabled(mut self, enabled: impl IntoValue<bool>) -> TextArea {
self.0.prop(enabled.into_value(), Prop::Enabled);
self
}
pub fn read_only(mut self, read_only: impl IntoValue<bool>) -> TextArea {
self.0.prop(read_only.into_value(), Prop::ReadOnly);
self
}
pub fn lines(mut self, lines: impl IntoValue<u32>) -> TextArea {
self.0.prop(lines.into_value(), |n| Prop::Lines(n.max(1)));
self
}
pub fn line_wrap(mut self, wrap: impl IntoValue<bool>) -> TextArea {
self.0.prop(wrap.into_value(), Prop::LineWrap);
self
}
pub fn on_input(mut self, handler: impl Fn(String) + 'static) -> TextArea {
self.0.on(move |event| {
if let UiEvent::Changed(EventValue::Text(text)) = event {
handler(text.clone());
}
});
self
}
pub fn native(mut self, tweak: Tweak<TextArea>) -> TextArea {
tweak.apply(&mut self.0);
self
}
}
impl TextInput {
#[doc(hidden)]
pub fn __tag() -> TextInput {
TextInput::new()
}
}
impl PasswordInput {
#[doc(hidden)]
pub fn __tag() -> PasswordInput {
PasswordInput::new()
}
}
impl SearchInput {
#[doc(hidden)]
pub fn __tag() -> SearchInput {
SearchInput::new()
}
}
impl TextArea {
#[doc(hidden)]
pub fn __tag() -> TextArea {
TextArea::new()
}
}