1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 13:20:05 -04:00

Add emath::Vec2b, replacing egui_plot::AxisBools (#3543)

Thanks to `impl From<bool> for Vec2b` one can now shorten some builder
calls, like:

Previous:
```rust
 egui::ScrollArea::vertical()
        .auto_shrink([false; 2])
```

New:
```rust
 egui::ScrollArea::vertical()
        .auto_shrink(false)
```
This commit is contained in:
Emil Ernerfeldt
2023-11-11 21:31:36 +01:00
committed by GitHub
parent 03a1471ddb
commit b27aa27e94
19 changed files with 148 additions and 119 deletions

View File

@@ -1,3 +1,5 @@
use egui::Vec2b;
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
enum Plot {
@@ -19,7 +21,7 @@ fn sigmoid(x: f64) -> f64 {
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct ContextMenus {
plot: Plot,
show_axes: [bool; 2],
show_axes: Vec2b,
allow_drag: bool,
allow_zoom: bool,
allow_scroll: bool,
@@ -33,7 +35,7 @@ impl Default for ContextMenus {
fn default() -> Self {
Self {
plot: Plot::Sin,
show_axes: [true, true],
show_axes: Vec2b::TRUE,
allow_drag: true,
allow_zoom: true,
allow_scroll: true,

View File

@@ -4,9 +4,9 @@ use std::ops::RangeInclusive;
use egui::*;
use egui_plot::{
Arrows, AxisBools, AxisHints, Bar, BarChart, BoxElem, BoxPlot, BoxSpread, CoordinatesFormatter,
Corner, GridInput, GridMark, HLine, Legend, Line, LineStyle, MarkerShape, Plot, PlotImage,
PlotPoint, PlotPoints, PlotResponse, Points, Polygon, Text, VLine,
Arrows, AxisHints, Bar, BarChart, BoxElem, BoxPlot, BoxSpread, CoordinatesFormatter, Corner,
GridInput, GridMark, HLine, Legend, Line, LineStyle, MarkerShape, Plot, PlotImage, PlotPoint,
PlotPoints, PlotResponse, Points, Polygon, Text, VLine,
};
// ----------------------------------------------------------------------------
@@ -830,8 +830,8 @@ impl Default for Chart {
struct ChartsDemo {
chart: Chart,
vertical: bool,
allow_zoom: AxisBools,
allow_drag: AxisBools,
allow_zoom: Vec2b,
allow_drag: Vec2b,
}
impl Default for ChartsDemo {

View File

@@ -146,7 +146,7 @@ impl ScrollAppearance {
ui.separator();
ScrollArea::vertical()
.auto_shrink([false; 2])
.auto_shrink(false)
.scroll_bar_visibility(*visibility)
.show(ui, |ui| {
ui.with_layout(
@@ -170,7 +170,7 @@ fn huge_content_lines(ui: &mut egui::Ui) {
let text_style = TextStyle::Body;
let row_height = ui.text_style_height(&text_style);
let num_rows = 10_000;
ScrollArea::vertical().auto_shrink([false; 2]).show_rows(
ScrollArea::vertical().auto_shrink(false).show_rows(
ui,
row_height,
num_rows,
@@ -193,7 +193,7 @@ fn huge_content_painter(ui: &mut egui::Ui) {
let num_rows = 10_000;
ScrollArea::vertical()
.auto_shrink([false; 2])
.auto_shrink(false)
.show_viewport(ui, |ui, viewport| {
ui.set_height(row_height * num_rows as f32);
@@ -292,9 +292,7 @@ impl super::View for ScrollTo {
scroll_bottom |= ui.button("Scroll to bottom").clicked();
});
let mut scroll_area = ScrollArea::vertical()
.max_height(200.0)
.auto_shrink([false; 2]);
let mut scroll_area = ScrollArea::vertical().max_height(200.0).auto_shrink(false);
if go_to_scroll_offset {
scroll_area = scroll_area.vertical_scroll_offset(self.offset);
}

View File

@@ -124,7 +124,7 @@ impl super::View for TextLayoutDemo {
};
egui::ScrollArea::vertical()
.auto_shrink([false; 2])
.auto_shrink(false)
.show(ui, |ui| {
let extra_letter_spacing = points_per_pixel * *extra_letter_spacing_pixels as f32;
let line_height = (*line_height_pixels != 0)

View File

@@ -1,3 +1,5 @@
use egui::Vec2b;
#[derive(Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct WindowOptions {
@@ -7,7 +9,7 @@ pub struct WindowOptions {
collapsible: bool,
resizable: bool,
constrain: bool,
scroll2: [bool; 2],
scroll2: Vec2b,
disabled_time: f64,
anchored: bool,
@@ -24,7 +26,7 @@ impl Default for WindowOptions {
collapsible: true,
resizable: true,
constrain: true,
scroll2: [true; 2],
scroll2: Vec2b::TRUE,
disabled_time: f64::NEG_INFINITY,
anchored: false,
anchor: egui::Align2::RIGHT_TOP,