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:
I was able to use a function pointer for the render function:
|
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. :)
In the current design, adding a new feature usually needs three things:
struct App:dz6/src/app.rs
Line 124 in 918d9a4
I was able to use a function pointer for the render function:
dz6/src/app.rs
Line 127 in 918d9a4
So, the new feature under
hex/,text/orglobal/sets this pointer and the main drawing function executes it here:dz6/src/draw.rs
Line 67 in 918d9a4
But I couldn't find a way to do the same for event handlers functions such as
dz6/src/hex/strings.rs
Line 208 in 918d9a4
so I ended up creating a match arm for every dialog and explicitly calling the event handler function for the right feature in
dz6/src/events.rs
Line 22 in 918d9a4
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. :)