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

SidePanel::left and TopPanel::top now takes impl Hash instead of Id

This commit is contained in:
Emil Ernerfeldt
2020-12-15 15:13:12 +01:00
parent 18ebac116f
commit 0e0beece44
3 changed files with 16 additions and 10 deletions

View File

@@ -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,
}
}

View File

@@ -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);
});