Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Ui::columns_const() #4764

Merged
merged 3 commits into from
Jul 15, 2024
Merged

Add Ui::columns_const() #4764

merged 3 commits into from
Jul 15, 2024

Conversation

v0x0g
Copy link
Contributor

@v0x0g v0x0g commented Jul 3, 2024

Changes

  • Adds a new function egui::Ui::columns_const(), which is the same as egui::Ui::columns() except that it uses a const parameter for the column count.
  • Backed by an array [Ui; NUM_COL] instead of a Vec`, so fewer allocations
  • Inner closure takes in an array reference, instead of a slice reference. This makes it possible to use pattern destructuring on the columns, as shown in the example, and makes it more ergonomic to use

Example

// ORIGINAL
ui.columns(2, |cols| {
    cols[0].label("one");
    cols[1].label("two");
});


// NEW
ui.columns_const(|[a,b]| {
    a.label("one");
    b.label("two");
});

Checks

  • cargo fmt
  • cargo clippy
  • ./scripts/check.sh
  • Docs
  • Review

@emilk emilk added the egui label Jul 15, 2024
@emilk emilk changed the title Add egui::Ui::columns_const() Add Ui::columns_const() Jul 15, 2024
@emilk emilk merged commit 1bee7bf into emilk:master Jul 15, 2024
18 of 20 checks passed
lucasmerlin pushed a commit to lucasmerlin/egui that referenced this pull request Jul 30, 2024
# Changes

- Adds a new function `egui::Ui::columns_const()`, which is the same as
`egui::Ui::columns()` except that it uses a `const` parameter for the
column count.
- Backed by an array `[Ui; NUM_COL] instead of a `Vec<Ui>`, so fewer
allocations
- Inner closure takes in an array reference, instead of a slice
reference. This makes it possible to use pattern destructuring on the
columns, as shown in the example, and makes it more ergonomic to use

# Example

```rust
// ORIGINAL
ui.columns(2, |cols| {
    cols[0].label("one");
    cols[1].label("two");
});


// NEW
ui.columns_const(|[a,b]| {
    a.label("one");
    b.label("two");
});

```

# Checks

- [X] `cargo fmt`
- [X] `cargo clippy`
- [X] `./scripts/check.sh`
- [X] Docs
- [ ] Review
@v0x0g v0x0g deleted the feat/ui_columns_const branch September 6, 2024 02:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants