Skip to content

Added observers for SubmitText and ModifyText#44

Open
Sigma-dev wants to merge 1 commit into
ickshonpe:masterfrom
Sigma-dev:feat/add-submit-and-modify-observers
Open

Added observers for SubmitText and ModifyText#44
Sigma-dev wants to merge 1 commit into
ickshonpe:masterfrom
Sigma-dev:feat/add-submit-and-modify-observers

Conversation

@Sigma-dev

Copy link
Copy Markdown

Observers have made writing UI much better, so I thought I'd add the observers I've needed when using text inputs.

If you don't like the implementation tell me and I will change it.

Comment thread src/lib.rs
/// The text input entity that submitted the text
pub entity: Entity,
/// The submitted text
pub text: String,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest removal of text field.

If text is very long, raising EntityEvents on each change with text when text is modified is costly.

Instead users can retrieve text from the text edit entity manually when entity event is raised and text retrieval is needed.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This avoids a lot of other changes that can be now reverted in this PR.

@MuongKimhong

Copy link
Copy Markdown

How is this PR? I also want to use observers.

@coolcatcoder

Copy link
Copy Markdown

While we wait for the fate of this pull request, we can use this snippet to get us observers in the mean time:

#[derive(EntityEvent)]
pub struct TextInputModified {
    #[event_target]
    pub text_input: Entity,
}

impl TextInputModified {
    pub fn plugin(app: &mut App) {
        app.add_systems(
            Update,
            |text_inputs: Query<Entity, Changed<TextInputContents>>, mut commands: Commands| {
                for text_input in text_inputs {
                    commands.trigger(TextInputModified { text_input });
                }
            },
        );
    }
}

(Don't forget to add TextInputModified::plugin to your App, and make sure to add TextInputContents to your text input entities.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants