small QOL
This commit is contained in:
@@ -104,16 +104,16 @@ impl DefaultAppState for Client {
|
|||||||
.add(ui);
|
.add(ui);
|
||||||
|
|
||||||
let texts = Span::empty(Dir::DOWN).gap(10).handles(ui);
|
let texts = Span::empty(Dir::DOWN).gap(10).handles(ui);
|
||||||
let msg_area = texts.h.scroll().masked().background(rect(Color::SKY));
|
let msg_area = texts.h.scrollable().masked().background(rect(Color::SKY));
|
||||||
let add_text = wtext("add")
|
let add_text = wtext("add")
|
||||||
.editable(false)
|
.editable(EditMode::MultiLine)
|
||||||
.text_align(Align::LEFT)
|
.text_align(Align::LEFT)
|
||||||
.size(30)
|
.size(30)
|
||||||
.attr::<Selectable>(())
|
.attr::<Selectable>(())
|
||||||
.on(Submit, move |mut ctx| {
|
.on(Submit, move |mut ctx| {
|
||||||
let content = ctx.widget.edit(ctx.state.ui()).take();
|
let content = ctx.widget.edit(ctx.state.ui()).take();
|
||||||
let text = wtext(content)
|
let text = wtext(content)
|
||||||
.editable(false)
|
.editable(EditMode::MultiLine)
|
||||||
.size(30)
|
.size(30)
|
||||||
.text_align(Align::LEFT)
|
.text_align(Align::LEFT)
|
||||||
.wrap(true)
|
.wrap(true)
|
||||||
|
|||||||
@@ -40,12 +40,12 @@ impl<State, O, H: WidgetOption<State>> TextBuilder<State, O, H> {
|
|||||||
self.attrs.wrap = wrap;
|
self.attrs.wrap = wrap;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
pub fn editable(self, single_line: bool) -> TextBuilder<State, TextEditOutput, H> {
|
pub fn editable(self, mode: EditMode) -> TextBuilder<State, TextEditOutput, H> {
|
||||||
TextBuilder {
|
TextBuilder {
|
||||||
content: self.content,
|
content: self.content,
|
||||||
attrs: self.attrs,
|
attrs: self.attrs,
|
||||||
hint: self.hint,
|
hint: self.hint,
|
||||||
output: TextEditOutput { single_line },
|
output: TextEditOutput { mode },
|
||||||
state: PhantomData,
|
state: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -100,7 +100,7 @@ impl<State: 'static> TextBuilderOutput<State> for TextOutput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct TextEditOutput {
|
pub struct TextEditOutput {
|
||||||
single_line: bool,
|
mode: EditMode,
|
||||||
}
|
}
|
||||||
impl<State: 'static> TextBuilderOutput<State> for TextEditOutput {
|
impl<State: 'static> TextBuilderOutput<State> for TextEditOutput {
|
||||||
type Output = TextEdit<State>;
|
type Output = TextEdit<State>;
|
||||||
@@ -115,7 +115,7 @@ impl<State: 'static> TextBuilderOutput<State> for TextEditOutput {
|
|||||||
));
|
));
|
||||||
let mut text = TextEdit::new(
|
let mut text = TextEdit::new(
|
||||||
TextView::new(buf, builder.attrs, builder.hint.get(ui)),
|
TextView::new(buf, builder.attrs, builder.hint.get(ui)),
|
||||||
builder.output.single_line,
|
builder.output.mode,
|
||||||
);
|
);
|
||||||
let font_system = &mut ui.text.font_system;
|
let font_system = &mut ui.text.font_system;
|
||||||
text.buf
|
text.buf
|
||||||
|
|||||||
@@ -12,17 +12,23 @@ pub struct TextEdit<State> {
|
|||||||
selection: TextSelection,
|
selection: TextSelection,
|
||||||
history: Vec<(String, TextSelection)>,
|
history: Vec<(String, TextSelection)>,
|
||||||
double_hit: Option<Cursor>,
|
double_hit: Option<Cursor>,
|
||||||
pub single_line: bool,
|
pub mode: EditMode,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, PartialEq)]
|
||||||
|
pub enum EditMode {
|
||||||
|
SingleLine,
|
||||||
|
MultiLine,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<State: 'static> TextEdit<State> {
|
impl<State: 'static> TextEdit<State> {
|
||||||
pub fn new(view: TextView<State>, single_line: bool) -> Self {
|
pub fn new(view: TextView<State>, mode: EditMode) -> Self {
|
||||||
Self {
|
Self {
|
||||||
view,
|
view,
|
||||||
selection: Default::default(),
|
selection: Default::default(),
|
||||||
history: Default::default(),
|
history: Default::default(),
|
||||||
double_hit: None,
|
double_hit: None,
|
||||||
single_line,
|
mode,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn select_content(&self, start: Cursor, end: Cursor) -> String {
|
pub fn select_content(&self, start: Cursor, end: Cursor) -> String {
|
||||||
@@ -246,7 +252,7 @@ impl<'a, State: 'static> TextEditCtx<'a, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn string(&self, text: &str) -> String {
|
fn string(&self, text: &str) -> String {
|
||||||
if self.text.single_line {
|
if self.text.mode == EditMode::SingleLine {
|
||||||
text.replace('\n', "")
|
text.replace('\n', "")
|
||||||
} else {
|
} else {
|
||||||
text.to_string()
|
text.to_string()
|
||||||
@@ -315,7 +321,7 @@ impl<'a, State: 'static> TextEditCtx<'a, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn newline(&mut self) {
|
pub fn newline(&mut self) {
|
||||||
if self.text.single_line {
|
if self.text.mode == EditMode::SingleLine {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self.clear_span();
|
self.clear_span();
|
||||||
|
|||||||
@@ -83,13 +83,13 @@ widget_trait! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scroll(self) -> impl WidgetIdFn<State, Scroll<State>> {
|
fn scrollable(self) -> impl WidgetIdFn<State, Scroll<State>> {
|
||||||
use eventable::*;
|
use eventable::*;
|
||||||
move |ui| {
|
move |ui| {
|
||||||
Scroll::new(self.add(ui), Axis::Y)
|
Scroll::new(self.add(ui), Axis::Y)
|
||||||
.on(CursorSense::Scroll, |ctx| {
|
.on(CursorSense::Scroll, |mut ctx| {
|
||||||
let s = &mut ctx.state.ui()[ctx.widget];
|
let delta = ctx.data.scroll_delta.y * 50.0;
|
||||||
s.scroll(ctx.data.scroll_delta.y * 50.0);
|
ctx.widget().scroll(delta);
|
||||||
})
|
})
|
||||||
.add(ui)
|
.add(ui)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user