small QOL
This commit is contained in:
@@ -104,16 +104,16 @@ impl DefaultAppState for Client {
|
||||
.add(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")
|
||||
.editable(false)
|
||||
.editable(EditMode::MultiLine)
|
||||
.text_align(Align::LEFT)
|
||||
.size(30)
|
||||
.attr::<Selectable>(())
|
||||
.on(Submit, move |mut ctx| {
|
||||
let content = ctx.widget.edit(ctx.state.ui()).take();
|
||||
let text = wtext(content)
|
||||
.editable(false)
|
||||
.editable(EditMode::MultiLine)
|
||||
.size(30)
|
||||
.text_align(Align::LEFT)
|
||||
.wrap(true)
|
||||
|
||||
@@ -40,12 +40,12 @@ impl<State, O, H: WidgetOption<State>> TextBuilder<State, O, H> {
|
||||
self.attrs.wrap = wrap;
|
||||
self
|
||||
}
|
||||
pub fn editable(self, single_line: bool) -> TextBuilder<State, TextEditOutput, H> {
|
||||
pub fn editable(self, mode: EditMode) -> TextBuilder<State, TextEditOutput, H> {
|
||||
TextBuilder {
|
||||
content: self.content,
|
||||
attrs: self.attrs,
|
||||
hint: self.hint,
|
||||
output: TextEditOutput { single_line },
|
||||
output: TextEditOutput { mode },
|
||||
state: PhantomData,
|
||||
}
|
||||
}
|
||||
@@ -100,7 +100,7 @@ impl<State: 'static> TextBuilderOutput<State> for TextOutput {
|
||||
}
|
||||
|
||||
pub struct TextEditOutput {
|
||||
single_line: bool,
|
||||
mode: EditMode,
|
||||
}
|
||||
impl<State: 'static> TextBuilderOutput<State> for TextEditOutput {
|
||||
type Output = TextEdit<State>;
|
||||
@@ -115,7 +115,7 @@ impl<State: 'static> TextBuilderOutput<State> for TextEditOutput {
|
||||
));
|
||||
let mut text = TextEdit::new(
|
||||
TextView::new(buf, builder.attrs, builder.hint.get(ui)),
|
||||
builder.output.single_line,
|
||||
builder.output.mode,
|
||||
);
|
||||
let font_system = &mut ui.text.font_system;
|
||||
text.buf
|
||||
|
||||
@@ -12,17 +12,23 @@ pub struct TextEdit<State> {
|
||||
selection: TextSelection,
|
||||
history: Vec<(String, TextSelection)>,
|
||||
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> {
|
||||
pub fn new(view: TextView<State>, single_line: bool) -> Self {
|
||||
pub fn new(view: TextView<State>, mode: EditMode) -> Self {
|
||||
Self {
|
||||
view,
|
||||
selection: Default::default(),
|
||||
history: Default::default(),
|
||||
double_hit: None,
|
||||
single_line,
|
||||
mode,
|
||||
}
|
||||
}
|
||||
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 {
|
||||
if self.text.single_line {
|
||||
if self.text.mode == EditMode::SingleLine {
|
||||
text.replace('\n', "")
|
||||
} else {
|
||||
text.to_string()
|
||||
@@ -315,7 +321,7 @@ impl<'a, State: 'static> TextEditCtx<'a, State> {
|
||||
}
|
||||
|
||||
pub fn newline(&mut self) {
|
||||
if self.text.single_line {
|
||||
if self.text.mode == EditMode::SingleLine {
|
||||
return;
|
||||
}
|
||||
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::*;
|
||||
move |ui| {
|
||||
Scroll::new(self.add(ui), Axis::Y)
|
||||
.on(CursorSense::Scroll, |ctx| {
|
||||
let s = &mut ctx.state.ui()[ctx.widget];
|
||||
s.scroll(ctx.data.scroll_delta.y * 50.0);
|
||||
.on(CursorSense::Scroll, |mut ctx| {
|
||||
let delta = ctx.data.scroll_delta.y * 50.0;
|
||||
ctx.widget().scroll(delta);
|
||||
})
|
||||
.add(ui)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user