single line textedit
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
use crate::prelude::*;
|
||||
use cosmic_text::{Attrs, Family, Metrics};
|
||||
use std::marker::{PhantomData, Sized};
|
||||
use std::marker::Sized;
|
||||
|
||||
pub struct TextBuilder<O = TextOutput, H: WidgetOption = ()> {
|
||||
pub content: String,
|
||||
pub attrs: TextAttrs,
|
||||
pub hint: H,
|
||||
_pd: PhantomData<O>,
|
||||
pub output: O,
|
||||
}
|
||||
|
||||
impl<O, H: WidgetOption> TextBuilder<O, H> {
|
||||
@@ -35,12 +35,12 @@ impl<O, H: WidgetOption> TextBuilder<O, H> {
|
||||
self.attrs.wrap = wrap;
|
||||
self
|
||||
}
|
||||
pub fn editable(self) -> TextBuilder<TextEditOutput, H> {
|
||||
pub fn editable(self, single_line: bool) -> TextBuilder<TextEditOutput, H> {
|
||||
TextBuilder {
|
||||
content: self.content,
|
||||
attrs: self.attrs,
|
||||
hint: self.hint,
|
||||
_pd: PhantomData,
|
||||
output: TextEditOutput { single_line },
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,7 @@ impl<O> TextBuilder<O> {
|
||||
content: self.content,
|
||||
attrs: self.attrs,
|
||||
hint: move |ui: &mut Ui| Some(hint.add(ui).any()),
|
||||
_pd: PhantomData,
|
||||
output: self.output,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -83,7 +83,9 @@ impl TextBuilderOutput for TextOutput {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TextEditOutput;
|
||||
pub struct TextEditOutput {
|
||||
single_line: bool,
|
||||
}
|
||||
impl TextBuilderOutput for TextEditOutput {
|
||||
type Output = TextEdit;
|
||||
|
||||
@@ -92,7 +94,10 @@ impl TextBuilderOutput for TextEditOutput {
|
||||
builder.attrs.font_size,
|
||||
builder.attrs.line_height,
|
||||
));
|
||||
let mut text = TextEdit::new(TextView::new(buf, builder.attrs, builder.hint.get(ui)));
|
||||
let mut text = TextEdit::new(
|
||||
TextView::new(buf, builder.attrs, builder.hint.get(ui)),
|
||||
builder.output.single_line,
|
||||
);
|
||||
let font_system = &mut ui.data.text.font_system;
|
||||
text.buf
|
||||
.set_text(font_system, &builder.content, &Attrs::new(), SHAPING, None);
|
||||
@@ -114,6 +119,6 @@ pub fn text(content: impl Into<String>) -> TextBuilder {
|
||||
content: content.into(),
|
||||
attrs: TextAttrs::default(),
|
||||
hint: (),
|
||||
_pd: PhantomData,
|
||||
output: TextOutput,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user