Skip to content

Add Ui::columns_const() - #4764

Merged
emilk merged 3 commits into
emilk:masterfrom
v0x0g:feat/ui_columns_const
Jul 15, 2024
Merged

emilk merged 3 commits into
emilk:masterfrom
v0x0g:feat/ui_columns_const

Conversation

@v0x0g

@v0x0g v0x0g commented Jul 3, 2024

Copy link
Copy Markdown
Contributor

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
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
486c pushed a commit to 486c/egui that referenced this pull request Oct 9, 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
hacknus pushed a commit to hacknus/egui that referenced this pull request Oct 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
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