remove state generic from a lot of things

This commit is contained in:
2025-12-17 21:37:55 -05:00
parent 7e6369029f
commit 30bc55c78e
45 changed files with 740 additions and 856 deletions

View File

@@ -7,8 +7,8 @@ use winit::{
keyboard::{Key, NamedKey},
};
pub struct TextEdit<State> {
view: TextView<State>,
pub struct TextEdit {
view: TextView,
selection: TextSelection,
history: Vec<(String, TextSelection)>,
double_hit: Option<Cursor>,
@@ -21,8 +21,8 @@ pub enum EditMode {
MultiLine,
}
impl<State: 'static> TextEdit<State> {
pub fn new(view: TextView<State>, mode: EditMode) -> Self {
impl TextEdit {
pub fn new(view: TextView, mode: EditMode) -> Self {
Self {
view,
selection: Default::default(),
@@ -49,8 +49,8 @@ impl<State: 'static> TextEdit<State> {
}
}
impl<State: 'static> Widget<State> for TextEdit<State> {
fn draw(&mut self, painter: &mut Painter<State>) {
impl Widget for TextEdit {
fn draw(&mut self, painter: &mut Painter) {
let base = painter.layer;
painter.child_layer();
self.view.draw(painter);
@@ -92,11 +92,11 @@ impl<State: 'static> Widget<State> for TextEdit<State> {
}
}
fn desired_width(&mut self, ctx: &mut SizeCtx<State>) -> Len {
fn desired_width(&mut self, ctx: &mut SizeCtx) -> Len {
self.view.desired_width(ctx)
}
fn desired_height(&mut self, ctx: &mut SizeCtx<State>) -> Len {
fn desired_height(&mut self, ctx: &mut SizeCtx) -> Len {
self.view.desired_height(ctx)
}
}
@@ -180,12 +180,12 @@ fn cursor_pos(cursor: Cursor, buf: &TextBuffer) -> Option<Vec2> {
prev
}
pub struct TextEditCtx<'a, State> {
pub text: &'a mut TextEdit<State>,
pub struct TextEditCtx<'a> {
pub text: &'a mut TextEdit,
pub font_system: &'a mut FontSystem,
}
impl<'a, State: 'static> TextEditCtx<'a, State> {
impl<'a> TextEditCtx<'a> {
pub fn take(&mut self) -> String {
let text = self
.text
@@ -602,26 +602,26 @@ impl TextInputResult {
}
}
impl<State> Deref for TextEdit<State> {
type Target = TextView<State>;
impl Deref for TextEdit {
type Target = TextView;
fn deref(&self) -> &Self::Target {
&self.view
}
}
impl<State> DerefMut for TextEdit<State> {
impl DerefMut for TextEdit {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.view
}
}
pub trait TextEditable<State> {
fn edit<'a>(&self, ui: &'a mut Ui<State>) -> TextEditCtx<'a, State>;
pub trait TextEditable {
fn edit<'a>(&self, ui: &'a mut Ui) -> TextEditCtx<'a>;
}
impl<State: 'static, I: IdLike<State, Widget = TextEdit<State>>> TextEditable<State> for I {
fn edit<'a>(&self, ui: &'a mut Ui<State>) -> TextEditCtx<'a, State> {
impl<I: IdLike<Widget = TextEdit>> TextEditable for I {
fn edit<'a>(&self, ui: &'a mut Ui) -> TextEditCtx<'a> {
TextEditCtx {
text: ui.widgets.get_mut(self).unwrap(),
font_system: &mut ui.text.font_system,