remove state generic from a lot of things
This commit is contained in:
@@ -51,7 +51,7 @@ impl<State, O, H: WidgetOption<State>> TextBuilder<State, O, H> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<State: 'static, O> TextBuilder<State, O> {
|
||||
impl<State: HasUi, O> TextBuilder<State, O> {
|
||||
pub fn hint<W: WidgetLike<State, Tag>, Tag>(
|
||||
self,
|
||||
hint: W,
|
||||
@@ -59,7 +59,7 @@ impl<State: 'static, O> TextBuilder<State, O> {
|
||||
TextBuilder {
|
||||
content: self.content,
|
||||
attrs: self.attrs,
|
||||
hint: move |ui: &mut Ui<State>| Some(hint.add(ui).any()),
|
||||
hint: move |ui: &mut State| Some(hint.add(ui).any()),
|
||||
output: self.output,
|
||||
state: PhantomData,
|
||||
}
|
||||
@@ -69,25 +69,25 @@ impl<State: 'static, O> TextBuilder<State, O> {
|
||||
pub trait TextBuilderOutput<State>: Sized {
|
||||
type Output;
|
||||
fn run<H: WidgetOption<State>>(
|
||||
ui: &mut Ui<State>,
|
||||
state: &mut State,
|
||||
builder: TextBuilder<State, Self, H>,
|
||||
) -> Self::Output;
|
||||
}
|
||||
|
||||
pub struct TextOutput;
|
||||
impl<State: 'static> TextBuilderOutput<State> for TextOutput {
|
||||
type Output = Text<State>;
|
||||
impl<State: HasUi> TextBuilderOutput<State> for TextOutput {
|
||||
type Output = Text;
|
||||
|
||||
fn run<H: WidgetOption<State>>(
|
||||
ui: &mut Ui<State>,
|
||||
state: &mut State,
|
||||
builder: TextBuilder<State, Self, H>,
|
||||
) -> Self::Output {
|
||||
let mut buf = TextBuffer::new_empty(Metrics::new(
|
||||
builder.attrs.font_size,
|
||||
builder.attrs.line_height,
|
||||
));
|
||||
let hint = builder.hint.get(ui);
|
||||
let font_system = &mut ui.text.font_system;
|
||||
let hint = builder.hint.get(state);
|
||||
let font_system = &mut state.ui().text.font_system;
|
||||
buf.set_text(font_system, &builder.content, &Attrs::new(), SHAPING, None);
|
||||
let mut text = Text {
|
||||
content: builder.content.into(),
|
||||
@@ -102,11 +102,12 @@ impl<State: 'static> TextBuilderOutput<State> for TextOutput {
|
||||
pub struct TextEditOutput {
|
||||
mode: EditMode,
|
||||
}
|
||||
impl<State: 'static> TextBuilderOutput<State> for TextEditOutput {
|
||||
type Output = TextEdit<State>;
|
||||
|
||||
impl<State: HasUi> TextBuilderOutput<State> for TextEditOutput {
|
||||
type Output = TextEdit;
|
||||
|
||||
fn run<H: WidgetOption<State>>(
|
||||
ui: &mut Ui<State>,
|
||||
state: &mut State,
|
||||
builder: TextBuilder<State, Self, H>,
|
||||
) -> Self::Output {
|
||||
let buf = TextBuffer::new_empty(Metrics::new(
|
||||
@@ -114,10 +115,10 @@ impl<State: 'static> TextBuilderOutput<State> for TextEditOutput {
|
||||
builder.attrs.line_height,
|
||||
));
|
||||
let mut text = TextEdit::new(
|
||||
TextView::new(buf, builder.attrs, builder.hint.get(ui)),
|
||||
TextView::new(buf, builder.attrs, builder.hint.get(state)),
|
||||
builder.output.mode,
|
||||
);
|
||||
let font_system = &mut ui.text.font_system;
|
||||
let font_system = &mut state.ui().text.font_system;
|
||||
text.buf
|
||||
.set_text(font_system, &builder.content, &Attrs::new(), SHAPING, None);
|
||||
builder.attrs.apply(font_system, &mut text.buf, None);
|
||||
@@ -125,12 +126,12 @@ impl<State: 'static> TextBuilderOutput<State> for TextEditOutput {
|
||||
}
|
||||
}
|
||||
|
||||
impl<State, O: TextBuilderOutput<State>, H: WidgetOption<State>> FnOnce<(&mut Ui<State>,)>
|
||||
impl<State, O: TextBuilderOutput<State>, H: WidgetOption<State>> FnOnce<(&mut State,)>
|
||||
for TextBuilder<State, O, H>
|
||||
{
|
||||
type Output = O::Output;
|
||||
|
||||
extern "rust-call" fn call_once(self, args: (&mut Ui<State>,)) -> Self::Output {
|
||||
extern "rust-call" fn call_once(self, args: (&mut State,)) -> Self::Output {
|
||||
O::run(args.0, self)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user