Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into lucas/kittest-efram…
Browse files Browse the repository at this point in the history
…e-app
  • Loading branch information
Wumpf committed Jan 2, 2025
2 parents 19d5d60 + ee4ab08 commit 4cf924d
Show file tree
Hide file tree
Showing 39 changed files with 2,264 additions and 1,558 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ egui_extras::install_image_loaders(egui_ctx);
* [Tweaked the default visuals style](https://github.com/emilk/egui/pull/450).
* Plot: Renamed `Curve` to `Line`.
* `TopPanel::top` is now `TopBottomPanel::top`.
* `SidePanel::left` no longet takes the default width by argument, but by a builder call.
* `SidePanel::left` no longer takes the default width by argument, but by a builder call.
* `SidePanel::left` is resizable by default.

### 🐛 Fixed
Expand Down
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ For small things, just go ahead an open a PR. For bigger things, please file an
Browse through [`ARCHITECTURE.md`](ARCHITECTURE.md) to get a sense of how all pieces connects.

You can test your code locally by running `./scripts/check.sh`.
There are snapshots test that might need to be updated.
There are snapshots test that might need to be updated.
Run the tests with `UPDATE_SNAPSHOTS=true cargo test --workspace --all-features` to update all of them.
For more info about the tests see [egui_kittest](./crates/egui_kittest/README.md).

Expand Down Expand Up @@ -102,6 +102,7 @@ While using an immediate mode gui is simple, implementing one is a lot more tric
* Avoid double negatives
* Flip `if !condition {} else {}`
* Sets of things should be lexicographically sorted (e.g. crate dependencies in `Cargo.toml`)
* Put each type in their own file, unless they are trivial (e.g. a `struct` with no `impl`)
* Break the above rules when it makes sense


Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,10 @@ use_self = "warn"
useless_transmute = "warn"
verbose_file_reads = "warn"
wildcard_dependencies = "warn"
wildcard_imports = "warn"
zero_sized_map_values = "warn"


# TODO(emilk): enable more of these lints:
# TODO(emilk): maybe enable more of these lints?
iter_over_hash_type = "allow"
missing_assert_message = "allow"
should_panic_without_expect = "allow"
Expand All @@ -284,3 +283,4 @@ let_underscore_untyped = "allow"
manual_range_contains = "allow" # this one is just worse imho
self_named_module_files = "allow" # Disabled waiting on https://github.com/rust-lang/rust-clippy/issues/9602
significant_drop_tightening = "allow" # Too many false positives
wildcard_imports = "allow" # `use crate::*` is useful to avoid merge conflicts when adding/removing imports
72 changes: 37 additions & 35 deletions crates/egui-winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,43 +333,45 @@ impl State {
}

WindowEvent::Ime(ime) => {
if cfg!(target_os = "linux") {
// We ignore IME events on linux, because of https://github.com/emilk/egui/issues/5008
} else {
// on Mac even Cmd-C is pressed during ime, a `c` is pushed to Preedit.
// So no need to check is_mac_cmd.
//
// How winit produce `Ime::Enabled` and `Ime::Disabled` differs in MacOS
// and Windows.
//
// - On Windows, before and after each Commit will produce an Enable/Disabled
// event.
// - On MacOS, only when user explicit enable/disable ime. No Disabled
// after Commit.
//
// We use input_method_editor_started to manually insert CompositionStart
// between Commits.
match ime {
winit::event::Ime::Enabled => {
self.ime_event_enable();
}
winit::event::Ime::Preedit(text, Some(_cursor)) => {
// on Mac even Cmd-C is pressed during ime, a `c` is pushed to Preedit.
// So no need to check is_mac_cmd.
//
// How winit produce `Ime::Enabled` and `Ime::Disabled` differs in MacOS
// and Windows.
//
// - On Windows, before and after each Commit will produce an Enable/Disabled
// event.
// - On MacOS, only when user explicit enable/disable ime. No Disabled
// after Commit.
//
// We use input_method_editor_started to manually insert CompositionStart
// between Commits.
match ime {
winit::event::Ime::Enabled => {
if cfg!(target_os = "linux") {
// This event means different things in X11 and Wayland, but we can just
// ignore it and enable IME on the preedit event.
// See <https://github.com/rust-windowing/winit/issues/2498>
} else {
self.ime_event_enable();
self.egui_input
.events
.push(egui::Event::Ime(egui::ImeEvent::Preedit(text.clone())));
}
winit::event::Ime::Commit(text) => {
self.egui_input
.events
.push(egui::Event::Ime(egui::ImeEvent::Commit(text.clone())));
self.ime_event_disable();
}
winit::event::Ime::Disabled | winit::event::Ime::Preedit(_, None) => {
self.ime_event_disable();
}
};
}
}
winit::event::Ime::Preedit(text, Some(_cursor)) => {
self.ime_event_enable();
self.egui_input
.events
.push(egui::Event::Ime(egui::ImeEvent::Preedit(text.clone())));
}
winit::event::Ime::Commit(text) => {
self.egui_input
.events
.push(egui::Event::Ime(egui::ImeEvent::Commit(text.clone())));
self.ime_event_disable();
}
winit::event::Ime::Disabled | winit::event::Ime::Preedit(_, None) => {
self.ime_event_disable();
}
};

EventResponse {
repaint: true,
Expand Down
28 changes: 20 additions & 8 deletions crates/egui/src/containers/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
epaint, layers::ShapeIdx, InnerResponse, Response, Sense, Style, Ui, UiBuilder, UiKind,
UiStackInfo,
};
use epaint::{Color32, Margin, Rect, Rounding, Shadow, Shape, Stroke};
use epaint::{Color32, Margin, Marginf, Rect, Rounding, Shadow, Shape, Stroke};

/// Add a background, frame and/or margin to a rectangular background of a [`Ui`].
///
Expand Down Expand Up @@ -73,6 +73,18 @@ pub struct Frame {
pub stroke: Stroke,
}

#[test]
fn frame_size() {
assert_eq!(
std::mem::size_of::<Frame>(), 32,
"Frame changed size! If it shrank - good! Update this test. If it grew - bad! Try to find a way to avoid it."
);
assert!(
std::mem::size_of::<Frame>() <= 64,
"Frame is getting way too big!"
);
}

impl Frame {
pub fn none() -> Self {
Self::default()
Expand All @@ -81,7 +93,7 @@ impl Frame {
/// For when you want to group a few widgets together within a frame.
pub fn group(style: &Style) -> Self {
Self {
inner_margin: Margin::same(6.0), // same and symmetric looks best in corners when nesting groups
inner_margin: Margin::same(6), // same and symmetric looks best in corners when nesting groups
rounding: style.visuals.widgets.noninteractive.rounding,
stroke: style.visuals.widgets.noninteractive.bg_stroke,
..Default::default()
Expand All @@ -90,15 +102,15 @@ impl Frame {

pub fn side_top_panel(style: &Style) -> Self {
Self {
inner_margin: Margin::symmetric(8.0, 2.0),
inner_margin: Margin::symmetric(8, 2),
fill: style.visuals.panel_fill,
..Default::default()
}
}

pub fn central_panel(style: &Style) -> Self {
Self {
inner_margin: Margin::same(8.0),
inner_margin: Margin::same(8),
fill: style.visuals.panel_fill,
..Default::default()
}
Expand Down Expand Up @@ -143,7 +155,7 @@ impl Frame {
/// and in dark mode this will be very dark.
pub fn canvas(style: &Style) -> Self {
Self {
inner_margin: Margin::same(2.0),
inner_margin: Margin::same(2),
rounding: style.visuals.widgets.noninteractive.rounding,
fill: style.visuals.extreme_bg_color,
stroke: style.visuals.window_stroke(),
Expand Down Expand Up @@ -213,10 +225,10 @@ impl Frame {
}

impl Frame {
/// inner margin plus outer margin.
/// Inner margin plus outer margin.
#[inline]
pub fn total_margin(&self) -> Margin {
self.inner_margin + self.outer_margin
pub fn total_margin(&self) -> Marginf {
Marginf::from(self.inner_margin) + Marginf::from(self.outer_margin)
}
}

Expand Down
18 changes: 11 additions & 7 deletions crates/egui/src/containers/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ use crate::{
TextStyle, Ui, UiKind, Vec2b, WidgetInfo, WidgetRect, WidgetText, WidgetType,
};
use emath::GuiRounding as _;
use epaint::{emath, pos2, vec2, Galley, Pos2, Rect, RectShape, Rounding, Shape, Stroke, Vec2};
use epaint::{
emath, pos2, vec2, Galley, Pos2, Rect, RectShape, Rounding, Roundingf, Shape, Stroke, Vec2,
};

use super::scroll_area::ScrollBarVisibility;
use super::{area, resize, Area, Frame, Resize, ScrollArea};
Expand Down Expand Up @@ -484,10 +486,11 @@ impl<'open> Window<'open> {
// Calculate roughly how much larger the window size is compared to the inner rect
let (title_bar_height, title_content_spacing) = if with_title_bar {
let style = ctx.style();
let spacing = window_margin.top + window_margin.bottom;
let spacing = window_margin.sum().y;
let height = ctx.fonts(|f| title.font_height(f, &style)) + spacing;
window_frame.rounding.ne = window_frame.rounding.ne.clamp(0.0, height / 2.0);
window_frame.rounding.nw = window_frame.rounding.nw.clamp(0.0, height / 2.0);
let half_height = (height / 2.0).round() as _;
window_frame.rounding.ne = window_frame.rounding.ne.clamp(0, half_height);
window_frame.rounding.nw = window_frame.rounding.nw.clamp(0, half_height);
(height, spacing)
} else {
(0.0, 0.0)
Expand Down Expand Up @@ -603,8 +606,8 @@ impl<'open> Window<'open> {
let mut round = window_frame.rounding;

if !is_collapsed {
round.se = 0.0;
round.sw = 0.0;
round.se = 0;
round.sw = 0;
}

area_content_ui.painter().set(
Expand Down Expand Up @@ -682,6 +685,7 @@ fn paint_resize_corner(
};

// Adjust the corner offset to accommodate for window rounding
let radius = radius as f32;
let offset =
((2.0_f32.sqrt() * (1.0 + radius) - radius) * 45.0_f32.to_radians().cos()).max(2.0);

Expand Down Expand Up @@ -1022,7 +1026,7 @@ fn paint_frame_interaction(ui: &Ui, rect: Rect, interaction: ResizeInteraction)
bottom = interaction.bottom.hover;
}

let rounding = ui.visuals().window_rounding;
let rounding = Roundingf::from(ui.visuals().window_rounding);
let Rect { min, max } = rect;

let mut points = Vec::new();
Expand Down
Loading

0 comments on commit 4cf924d

Please sign in to comment.