RE ADD CONTEXT
This commit is contained in:
@@ -7,16 +7,16 @@ use winit::{
|
||||
keyboard::{Key, NamedKey},
|
||||
};
|
||||
|
||||
pub struct TextEdit {
|
||||
view: TextView,
|
||||
pub struct TextEdit<State> {
|
||||
view: TextView<State>,
|
||||
selection: TextSelection,
|
||||
history: Vec<(String, TextSelection)>,
|
||||
double_hit: Option<Cursor>,
|
||||
pub single_line: bool,
|
||||
}
|
||||
|
||||
impl TextEdit {
|
||||
pub fn new(view: TextView, single_line: bool) -> Self {
|
||||
impl<State: 'static> TextEdit<State> {
|
||||
pub fn new(view: TextView<State>, single_line: bool) -> Self {
|
||||
Self {
|
||||
view,
|
||||
selection: Default::default(),
|
||||
@@ -43,8 +43,8 @@ impl TextEdit {
|
||||
}
|
||||
}
|
||||
|
||||
impl Widget for TextEdit {
|
||||
fn draw(&mut self, painter: &mut Painter) {
|
||||
impl<State: 'static> Widget<State> for TextEdit<State> {
|
||||
fn draw(&mut self, painter: &mut Painter<State>) {
|
||||
let base = painter.layer;
|
||||
painter.child_layer();
|
||||
self.view.draw(painter);
|
||||
@@ -86,11 +86,11 @@ impl Widget for TextEdit {
|
||||
}
|
||||
}
|
||||
|
||||
fn desired_width(&mut self, ctx: &mut SizeCtx) -> Len {
|
||||
fn desired_width(&mut self, ctx: &mut SizeCtx<State>) -> Len {
|
||||
self.view.desired_width(ctx)
|
||||
}
|
||||
|
||||
fn desired_height(&mut self, ctx: &mut SizeCtx) -> Len {
|
||||
fn desired_height(&mut self, ctx: &mut SizeCtx<State>) -> Len {
|
||||
self.view.desired_height(ctx)
|
||||
}
|
||||
}
|
||||
@@ -174,12 +174,12 @@ fn cursor_pos(cursor: Cursor, buf: &TextBuffer) -> Option<Vec2> {
|
||||
prev
|
||||
}
|
||||
|
||||
pub struct TextEditCtx<'a> {
|
||||
pub text: &'a mut TextEdit,
|
||||
pub struct TextEditCtx<'a, State> {
|
||||
pub text: &'a mut TextEdit<State>,
|
||||
pub font_system: &'a mut FontSystem,
|
||||
}
|
||||
|
||||
impl<'a> TextEditCtx<'a> {
|
||||
impl<'a, State: 'static> TextEditCtx<'a, State> {
|
||||
pub fn take(&mut self) -> String {
|
||||
let text = self
|
||||
.text
|
||||
@@ -596,26 +596,26 @@ impl TextInputResult {
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for TextEdit {
|
||||
type Target = TextView;
|
||||
impl<State> Deref for TextEdit<State> {
|
||||
type Target = TextView<State>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.view
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for TextEdit {
|
||||
impl<State> DerefMut for TextEdit<State> {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.view
|
||||
}
|
||||
}
|
||||
|
||||
pub trait TextEditable {
|
||||
fn edit<'a>(&self, ui: &'a mut Ui) -> TextEditCtx<'a>;
|
||||
pub trait TextEditable<State> {
|
||||
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> {
|
||||
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> {
|
||||
TextEditCtx {
|
||||
text: ui.data.widgets.get_mut(self).unwrap(),
|
||||
font_system: &mut ui.data.text.font_system,
|
||||
|
||||
Reference in New Issue
Block a user