Skip to content

Commit

Permalink
Eguis buttons now report their intrinsic size so we can get rid of th…
Browse files Browse the repository at this point in the history
…e custom flex_button struct
  • Loading branch information
lucasmerlin committed Sep 6, 2024
1 parent deda6cb commit 1c7bc1b
Show file tree
Hide file tree
Showing 11 changed files with 828 additions and 826 deletions.
1,391 changes: 722 additions & 669 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ egui_extras = { version = "0.28.0", default-features = false }
[patch.crates-io]
#wry = { path = "../../RustroverProjects/github/wry" }
#
#egui = { path = "../../IdeaProjects/egui/crates/egui" }
#eframe = { path = "../../IdeaProjects/egui/crates/eframe" }
#egui-wgpu = { path = "../../IdeaProjects/egui/crates/egui-wgpu" }
#egui_extras = { path = "../../IdeaProjects/egui/crates/egui_extras" }
egui = { path = "../../IdeaProjects/egui/crates/egui" }
eframe = { path = "../../IdeaProjects/egui/crates/eframe" }
egui-wgpu = { path = "../../IdeaProjects/egui/crates/egui-wgpu" }
egui_extras = { path = "../../IdeaProjects/egui/crates/egui_extras" }
#winit = { path = "../../IdeaProjects/github/winit" }
24 changes: 12 additions & 12 deletions crates/egui_flex/examples/debug_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ fn main() -> eframe::Result {
FlexItem::default().grow(1.0),
Flex::vertical()
.align_content(egui_flex::FlexAlignContent::Stretch)
.grow_items(),
.grow_items(1.0),
|flex| {
flex.add_widget(
flex.add(
FlexItem::default().grow(1.0),
egui::Label::new("Hello"),
);
flex.add_widget(
flex.add(
FlexItem::default().grow(1.0),
egui::Label::new("World"),
);
Expand All @@ -41,14 +41,14 @@ fn main() -> eframe::Result {
FlexItem::default().grow(1.0),
Flex::vertical()
.align_content(egui_flex::FlexAlignContent::Stretch)
.grow_items(),
.grow_items(1.0),
frame,
|flex| {
flex.add_widget(
flex.add(
FlexItem::default().grow(1.0),
egui::Label::new("Hello"),
);
flex.add_widget(
flex.add(
FlexItem::default().grow(1.0),
egui::Label::new("World"),
);
Expand All @@ -57,13 +57,13 @@ fn main() -> eframe::Result {
FlexItem::default().grow(1.0),
Flex::horizontal()
.align_content(egui_flex::FlexAlignContent::Stretch)
.grow_items(),
.grow_items(1.0),
|flex| {
flex.add_widget(
flex.add(
FlexItem::default().grow(1.0),
egui::Label::new("Hello"),
);
flex.add_widget(
flex.add(
FlexItem::default().grow(1.0),
egui::Label::new("World"),
);
Expand All @@ -76,13 +76,13 @@ fn main() -> eframe::Result {
FlexItem::default().grow(1.0),
Flex::vertical()
.align_content(egui_flex::FlexAlignContent::Stretch)
.grow_items(),
.grow_items(1.0),
|flex| {
flex.add_widget(
flex.add(
FlexItem::default().grow(1.0),
egui::Label::new("Hello"),
);
flex.add_widget(
flex.add(
FlexItem::default().grow(1.0),
egui::Label::new("World"),
);
Expand Down
9 changes: 4 additions & 5 deletions crates/egui_flex/examples/flex_customize_example.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use eframe::NativeOptions;
use egui::{Ui, Window};
use egui_flex::flex_button::FlexButton;
use egui::{Button, Ui, Window};
use egui_flex::{Flex, FlexDirection, FlexInstance, FlexItem};

#[derive(Clone, Debug)]
Expand All @@ -24,7 +23,7 @@ struct Item {
impl Item {
pub fn show(&mut self, ui: &mut FlexInstance) {
let response = match &self.kind {
ItemKind::Button(text) => ui.add(self.flex.clone(), FlexButton::new(text)).inner,
ItemKind::Button(text) => ui.add(self.flex.clone(), Button::new(text)).inner,
ItemKind::Label(text) => ui.add_simple(self.flex.clone(), |ui| ui.label(text)).inner,
};

Expand All @@ -37,7 +36,7 @@ impl Item {
let response = flex
.add(
FlexItem::new().grow(1.0),
FlexButton::new("Label")
Button::new("Label")
.selected(matches!(self.kind, ItemKind::Label(_))),
)
.inner;
Expand All @@ -49,7 +48,7 @@ impl Item {
let response = flex
.add(
FlexItem::new().grow(1.0),
FlexButton::new("Button")
Button::new("Button")
.selected(matches!(self.kind, ItemKind::Button(_))),
)
.inner;
Expand Down
8 changes: 3 additions & 5 deletions crates/egui_flex/examples/flex_demos.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use egui::{Align2, CentralPanel, ComboBox, Frame};
use egui_flex::flex_button::FlexButton;
use egui::{Align2, Button, CentralPanel, ComboBox, Frame};
use egui_flex::{Flex, FlexAlign, FlexAlignContent, FlexDirection, FlexInstance, FlexItem};

fn main() -> eframe::Result {
Expand All @@ -20,8 +19,7 @@ fn main() -> eframe::Result {
if flex
.add(
FlexItem::new(),
FlexButton::new("Horizontal")
.selected(demo_dir == FlexDirection::Horizontal),
Button::new("Horizontal").selected(demo_dir == FlexDirection::Horizontal),
)
.inner
.clicked()
Expand All @@ -31,7 +29,7 @@ fn main() -> eframe::Result {
if flex
.add(
FlexItem::new(),
FlexButton::new("Vertical").selected(demo_dir == FlexDirection::Vertical),
Button::new("Vertical").selected(demo_dir == FlexDirection::Vertical),
)
.inner
.clicked()
Expand Down
35 changes: 14 additions & 21 deletions crates/egui_flex/examples/flex_example.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use eframe::NativeOptions;
use egui::{Button, CentralPanel, Checkbox, Frame, Label, Slider, TextEdit, Widget};
use egui_flex::flex_button::FlexButton;
use egui_flex::{Flex, FlexAlign, FlexItem};

fn main() -> eframe::Result {
Expand Down Expand Up @@ -105,11 +104,8 @@ fn main() -> eframe::Result {
.grow_items(1.0),
egui::Frame::group(flex.ui().style()),
|flex| {
flex.add(FlexItem::default().grow(1.0), FlexButton::new("btn"));
flex.add(
FlexItem::default(),
FlexButton::new("Very long button"),
);
flex.add(FlexItem::default().grow(1.0), Button::new("btn"));
flex.add(FlexItem::default(), Button::new("Very long button"));
flex.add_flex(
FlexItem::default().grow(1.0),
Flex::horizontal()
Expand All @@ -118,31 +114,28 @@ fn main() -> eframe::Result {
|flex| {
flex.add(
FlexItem::default().grow(1.0),
FlexButton::new("btn"),
Button::new("btn"),
);
flex.add(
FlexItem::default(),
FlexButton::new("Very long button"),
Button::new("Very long button"),
);
},
);
},
);

flex.add(
FlexItem::new().grow(1.0),
FlexButton::new("Very long button"),
);
flex.add(FlexItem::new().grow(1.0), Button::new("Very long button"));

flex.add(FlexItem::new().grow(1.0), FlexButton::new("Button"));
flex.add(FlexItem::new().grow(1.0), Button::new("Button"));
flex.add(
FlexItem::new().grow(1.0),
FlexButton::new("Button wefoijfgiweopjg"),
Button::new("Button wefoijfgiweopjg"),
);
flex.add(FlexItem::new().grow(1.0), FlexButton::new("Button"));
flex.add_widget(FlexItem::new(), Button::new("Simple Button"));
flex.add(FlexItem::new().grow(1.0), Button::new("Button"));
flex.add(FlexItem::new(), Button::new("Simple Button"));

flex.add_widget(FlexItem::new(), Checkbox::new(&mut false, "Checkbox"));
flex.add(FlexItem::new(), Checkbox::new(&mut false, "Checkbox"));

// flex.add_container(
// FlexItem::default().grow(1.0).basis(100.0),
Expand All @@ -153,17 +146,17 @@ fn main() -> eframe::Result {
// Flex::new().show(ui, |flex| {
// flex.add(
// FlexItem::new(),
// FlexButton::new("Button"),
// Button::new("Button"),
// );
//
// flex.add(
// FlexItem::new(),
// FlexButton::new("Longer Button"),
// Button::new("Longer Button"),
// );
//
// flex.add(
// FlexItem::new(),
// FlexButton::new(
// Button::new(
// "Button\nwith\nmultiple\nlines",
// ),
// );
Expand Down Expand Up @@ -191,7 +184,7 @@ fn main() -> eframe::Result {
ui.horizontal_wrapped(|ui| {
ui.button("Normal Button");
Flex::horizontal().show(ui, |flex| {
flex.add(FlexItem::new(), FlexButton::new("Hello"));
flex.add(FlexItem::new(), Button::new("Hello"));
});
ui.button("Normal Button");
});
Expand Down
49 changes: 29 additions & 20 deletions crates/egui_flex/examples/flex_nested.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use egui::{CentralPanel, Frame, Vec2};
use egui_flex::flex_button::FlexButton;
use egui::{Button, CentralPanel, Checkbox, DragValue, Frame, Slider, TextEdit, Vec2};
use egui_flex::{Flex, FlexAlignContent, FlexItem};

fn main() -> eframe::Result {
eframe::run_simple_native("flex nested", Default::default(), |ctx, _frame| {
let mut flt = 0.0;

let mut txt = String::new();

eframe::run_simple_native("flex nested", Default::default(), move |ctx, _frame| {
CentralPanel::default().show(ctx, |ui| {
ui.spacing_mut().item_spacing = Vec2::splat(10.0);
let frame = Frame::group(ui.style());
Expand All @@ -18,12 +21,21 @@ fn main() -> eframe::Result {
.grow_items(1.0),
Frame::group(flex.ui().style()),
|flex| {
flex.add(FlexItem::new(), FlexButton::new("btn"));
flex.add(FlexItem::new(), FlexButton::new("Very long button"));
flex.add(FlexItem::new(), Button::new("btn"));
// flex.add(
// FlexItem::new(),
// Slider::new(&mut flt, 0.0..=1000.0).show_value(false),
// );
flex.add(
FlexItem::new().grow(0.0),
TextEdit::singleline(&mut txt).desired_width(100.0),
);
flex.add(FlexItem::new(), DragValue::new(&mut flt));
flex.add(FlexItem::new(), Checkbox::new(&mut false, "Checkbox"));
},
);

flex.add(FlexItem::new().grow(1.0), FlexButton::new("Single Button"));
flex.add(FlexItem::new().grow(1.0), Button::new("Single Button"));

flex.add_flex_frame(
FlexItem::new().grow(1.0),
Expand All @@ -32,8 +44,8 @@ fn main() -> eframe::Result {
.grow_items(1.0),
frame,
|flex| {
flex.add(FlexItem::new().grow(1.0), FlexButton::new("btn"));
flex.add(FlexItem::new(), FlexButton::new("Very long button"));
flex.add(FlexItem::new().grow(1.0), Button::new("btn"));
flex.add(FlexItem::new(), Button::new("Very long button"));
},
);

Expand All @@ -51,8 +63,8 @@ fn main() -> eframe::Result {
.grow_items(1.0),
frame,
|flex| {
flex.add(FlexItem::new().grow(1.0), FlexButton::new("btn"));
flex.add(FlexItem::new(), FlexButton::new("Very long button"));
flex.add(FlexItem::new().grow(1.0), Button::new("btn"));
flex.add(FlexItem::new(), Button::new("Very long button"));

flex.add_flex_frame(
FlexItem::new().grow(1.0),
Expand All @@ -61,22 +73,19 @@ fn main() -> eframe::Result {
.grow_items(1.0),
Frame::group(flex.ui().style()),
|flex| {
flex.add(
FlexItem::new().grow(1.0),
FlexButton::new("btn"),
);
flex.add(FlexItem::new().grow(1.0), Button::new("btn"));
flex.add(
FlexItem::new(),
FlexButton::new("Very long button"),
Button::new("Very long button"),
);
},
);
},
);

flex.add(FlexItem::new().grow(1.0), FlexButton::new("btn"));
flex.add(FlexItem::new(), FlexButton::new("Very long button"));
flex.add(FlexItem::new(), FlexButton::new("btn"));
flex.add(FlexItem::new().grow(1.0), Button::new("btn"));
flex.add(FlexItem::new(), Button::new("Very long button"));
flex.add(FlexItem::new(), Button::new("btn"));
},
);
});
Expand All @@ -89,8 +98,8 @@ fn main() -> eframe::Result {
.grow_items(1.0),
Frame::group(flex.ui().style()),
|flex| {
flex.add(FlexItem::new().grow(1.0), FlexButton::new("btn"));
flex.add(FlexItem::new(), FlexButton::new("Very long button"));
flex.add(FlexItem::new().grow(1.0), Button::new("btn"));
flex.add(FlexItem::new(), Button::new("Very long button"));
},
);
})
Expand Down
Loading

0 comments on commit 1c7bc1b

Please sign in to comment.