linebender / linebender/druid

Towards an unified and clean `Widget` methods?

Open
#1,176 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

discussion
Dominant language
Rust
Stars
9.7k
Forks
565
PR merge metrics
No merged PRs in 30d

Description

The `Widget` trait have many complex methods, and each has many different parameters:

```rust
fn event(&mut self, ctx: &mut EventCtx, event: &Event, data: &mut T, env: &Env);
fn lifecycle(&mut self, ctx: &mut LifeCycleCtx, event: &LifeCycle, data: &T, env: &Env);
fn update(&mut self, ctx: &mut UpdateCtx, old_data: &T, data: &T, env: &Env);
fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints, data: &T, env: &Env) -> Size;
fn paint(&mut self, ctx: &mut PaintCtx, data: &T, env: &Env);
```

Maybe some of its parameters (such as `event` `data` `env` `bc` `old_data`) can be merged into Context types? Then we will get an more unified and clean methods:

```rust
fn event(&mut self, ctx: &mut EventCtx);
fn lifecycle(&mut self, ctx: &mut LifeCycleCtx);
fn update(&mut self, ctx: &mut UpdateCtx);
fn layout(&mut self, ctx: &mut LayoutCtx) -> Size;
fn paint(&mut self, ctx: &mut PaintCtx);
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Widget trait methods shown in the issue: event, lifecycle, update, layout, and paint. Review how their context and non-context parameters are used across the toolkit; done would require an agreed and tested API redesign, but the issue names no files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
frontend
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.