From 0e0beece44cea20e0b44257d1c4cb9c046d012da Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Tue, 15 Dec 2020 15:13:12 +0100 Subject: [PATCH] SidePanel::left and TopPanel::top now takes `impl Hash` instead of Id --- CHANGELOG.md | 7 ++++--- egui/src/containers/panel.rs | 13 +++++++++---- egui/src/demos/demo_windows.rs | 6 +++--- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6b5b52a..0b19dfd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,12 +11,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Added ⭐ -* `ImageButton` - `ui.add(ImageButton::new(...))` -* `ui.vertical_centered` and `ui.vertical_centered_justified` +* `ImageButton` - `ui.add(ImageButton::new(...))`. +* `ui.vertical_centered` and `ui.vertical_centered_justified`. ### Changed 🔧 -* `ui.image` now takes `impl Into` as a `size` argument +* `SidePanel::left` and `TopPanel::top` now takes `impl Hash` as first argument. +* `ui.image` now takes `impl Into` as a `size` argument. ## 0.5.0 - 2020-12-13 diff --git a/egui/src/containers/panel.rs b/egui/src/containers/panel.rs index 91141619..e586a0aa 100644 --- a/egui/src/containers/panel.rs +++ b/egui/src/containers/panel.rs @@ -16,9 +16,13 @@ pub struct SidePanel { } impl SidePanel { + /// `id_source`: Something unique, e.g. `"my_side_panel"`. /// The given `max_width` is a soft maximum (as always), and the actual panel may be smaller or larger. - pub fn left(id: Id, max_width: f32) -> Self { - Self { id, max_width } + pub fn left(id_source: impl std::hash::Hash, max_width: f32) -> Self { + Self { + id: Id::new(id_source), + max_width, + } } } @@ -64,11 +68,12 @@ pub struct TopPanel { } impl TopPanel { + /// `id_source`: Something unique, e.g. `"my_top_panel"`. /// Default height is that of `interact_size.y` (i.e. a button), /// but the panel will expand as needed. - pub fn top(id: Id) -> Self { + pub fn top(id_source: impl std::hash::Hash) -> Self { Self { - id, + id: Id::new(id_source), max_height: None, } } diff --git a/egui/src/demos/demo_windows.rs b/egui/src/demos/demo_windows.rs index 98c89f26..70c4ac08 100644 --- a/egui/src/demos/demo_windows.rs +++ b/egui/src/demos/demo_windows.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use crate::{ app, demos::{self, Demo}, - Context, Id, Resize, ScrollArea, Ui, Window, + Context, Resize, ScrollArea, Ui, Window, }; // ---------------------------------------------------------------------------- @@ -105,7 +105,7 @@ impl DemoWindows { self.previous_link = env.link; } - crate::SidePanel::left(Id::new("side_panel"), 200.0).show(ctx, |ui| { + crate::SidePanel::left("side_panel", 200.0).show(ctx, |ui| { ui.heading("✒ Egui Demo"); crate::demos::warn_if_debug_build(ui); ui.label("Egui is an immediate mode GUI library written in Rust."); @@ -131,7 +131,7 @@ impl DemoWindows { sidebar_ui(ui); }); - crate::TopPanel::top(Id::new("menu_bar")).show(ctx, |ui| { + crate::TopPanel::top("menu_bar").show(ctx, |ui| { show_menu_bar(ui, &mut self.open_windows, env.seconds_since_midnight); });