Skip to content

Event handling: design problem #1

Description

@merces

In the current design, adding a new feature usually needs three things:

  • A renderer function.
  • An event handler function.
  • Some data stored in struct App:

    dz6/src/app.rs

    Line 124 in 918d9a4

    pub struct App {

I was able to use a function pointer for the render function:

dz6/src/app.rs

Line 127 in 918d9a4

pub dialog_renderer: Option<fn(&mut App, &mut Frame)>,

So, the new feature under hex/, text/ or global/ sets this pointer and the main drawing function executes it here:

if let Some(f) = app.dialog_renderer {

But I couldn't find a way to do the same for event handlers functions such as

pub fn dialog_strings_regex_events(app: &mut App, event: &Event) -> Result<bool> {

so I ended up creating a match arm for every dialog and explicitly calling the event handler function for the right feature in

pub fn handle_events(app: &mut App) -> Result<bool> {

but I'm sure there's a better way to do this I just don't know about. Maybe using traits? Not a Rust expert here, so I'd appreciate proposals to make the code smarter. :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    Fields

    No fields configured for Task.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions