Skip to content

Commit

Permalink
Merge branch 'emilk:master' into patch45
Browse files Browse the repository at this point in the history
  • Loading branch information
rustbasic authored Apr 21, 2024
2 parents f82a61d + d68c8d7 commit 41f1d7a
Show file tree
Hide file tree
Showing 12 changed files with 212 additions and 70 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
/.*.json
/.vscode
/media/*
.idea/
120 changes: 92 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/ecolor/src/hex_color_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#[macro_export]
macro_rules! hex_color {
($s:literal) => {{
let array = color_hex::color_from_hex!($s);
let array = $crate::color_hex::color_from_hex!($s);
if array.len() == 3 {
$crate::Color32::from_rgb(array[0], array[1], array[2])
} else {
Expand Down
3 changes: 3 additions & 0 deletions crates/ecolor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ pub use hsva::*;

#[cfg(feature = "color-hex")]
mod hex_color_macro;
#[cfg(feature = "color-hex")]
#[doc(hidden)]
pub use color_hex;

mod rgba;
pub use rgba::*;
Expand Down
12 changes: 6 additions & 6 deletions crates/egui/src/containers/popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,13 +333,13 @@ pub fn popup_below_widget<R>(
/// # });
/// ```
pub fn popup_above_or_below_widget<R>(
ui: &Ui,
parent_ui: &Ui,
popup_id: Id,
widget_response: &Response,
above_or_below: AboveOrBelow,
add_contents: impl FnOnce(&mut Ui) -> R,
) -> Option<R> {
if ui.memory(|mem| mem.is_popup_open(popup_id)) {
if parent_ui.memory(|mem| mem.is_popup_open(popup_id)) {
let (pos, pivot) = match above_or_below {
AboveOrBelow::Above => (widget_response.rect.left_top(), Align2::LEFT_BOTTOM),
AboveOrBelow::Below => (widget_response.rect.left_bottom(), Align2::LEFT_TOP),
Expand All @@ -350,8 +350,8 @@ pub fn popup_above_or_below_widget<R>(
.constrain(true)
.fixed_pos(pos)
.pivot(pivot)
.show(ui.ctx(), |ui| {
let frame = Frame::popup(ui.style());
.show(parent_ui.ctx(), |ui| {
let frame = Frame::popup(parent_ui.style());
let frame_margin = frame.total_margin();
frame
.show(ui, |ui| {
Expand All @@ -365,8 +365,8 @@ pub fn popup_above_or_below_widget<R>(
})
.inner;

if ui.input(|i| i.key_pressed(Key::Escape)) || widget_response.clicked_elsewhere() {
ui.memory_mut(|mem| mem.close_popup());
if parent_ui.input(|i| i.key_pressed(Key::Escape)) || widget_response.clicked_elsewhere() {
parent_ui.memory_mut(|mem| mem.close_popup());
}
Some(inner)
} else {
Expand Down
2 changes: 1 addition & 1 deletion crates/egui/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ impl Ui {
pub fn allocate_painter(&mut self, desired_size: Vec2, sense: Sense) -> (Response, Painter) {
let response = self.allocate_response(desired_size, sense);
let clip_rect = self.clip_rect().intersect(response.rect); // Make sure we don't paint out of bounds
let painter = Painter::new(self.ctx().clone(), self.layer_id(), clip_rect);
let painter = self.painter().with_clip_rect(clip_rect);
(response, painter)
}

Expand Down
25 changes: 24 additions & 1 deletion crates/egui/src/util/undoer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Default for Settings {
///
/// Rule 1) will make sure an undo point is not created until you _stop_ dragging that slider.
/// Rule 2) will make sure that you will get some undo points even if you are constantly changing the state.
#[derive(Clone, Default)]
#[derive(Clone)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct Undoer<State> {
settings: Settings,
Expand Down Expand Up @@ -77,6 +77,21 @@ impl<State> std::fmt::Debug for Undoer<State> {
}
}

impl<State> Default for Undoer<State>
where
State: Clone + PartialEq,
{
#[inline]
fn default() -> Self {
Self {
settings: Settings::default(),
undos: VecDeque::new(),
redos: Vec::new(),
flux: None,
}
}
}

/// Represents how the current state is changing
#[derive(Clone)]
struct Flux<State> {
Expand All @@ -89,6 +104,14 @@ impl<State> Undoer<State>
where
State: Clone + PartialEq,
{
/// Create a new [`Undoer`] with the given [`Settings`].
pub fn with_settings(settings: Settings) -> Self {
Self {
settings,
..Default::default()
}
}

/// Do we have an undo point different from the given state?
pub fn has_undo(&self, current_state: &State) -> bool {
match self.undos.len() {
Expand Down
Loading

0 comments on commit 41f1d7a

Please sign in to comment.