rust: apply sidebar width from Settings; egui Panel::show

This commit is contained in:
Andy Dixon
2026-10-11 17:32:39 +01:00
parent 31d8d6fdae
commit 19c5862288
2 changed files with 11 additions and 4 deletions
+9 -2
View File
@@ -80,6 +80,8 @@ pub struct App {
screenshot: Option<(PathBuf, u32)>, screenshot: Option<(PathBuf, u32)>,
shot_settle: u32, shot_settle: u32,
run_local: Option<(String, Option<String>)>, run_local: Option<(String, Option<String>)>,
/// Apply `prefs.sidebar_width` to the panel on the next frame (after Settings changed it).
resize_sidebar: bool,
} }
const fn sc(m: Modifiers, k: Key) -> KeyboardShortcut { const fn sc(m: Modifiers, k: Key) -> KeyboardShortcut {
@@ -125,6 +127,7 @@ impl App {
screenshot: opts.screenshot.map(|p| (p, 0)), screenshot: opts.screenshot.map(|p| (p, 0)),
shot_settle: 0, shot_settle: 0,
run_local: opts.run_local.map(|c| (c, None)), run_local: opts.run_local.map(|c| (c, None)),
resize_sidebar: false,
}; };
if let Some((_, sid)) = &mut app.run_local { if let Some((_, sid)) = &mut app.run_local {
let id = app.s.svc.connect_local(); let id = app.s.svc.connect_local();
@@ -488,6 +491,7 @@ impl App {
Request::ReloadProfiles => self.s.reload_profiles(), Request::ReloadProfiles => self.s.reload_profiles(),
Request::ReloadPreferences => { Request::ReloadPreferences => {
self.s.prefs = self.s.svc.preferences(); self.s.prefs = self.s.svc.preferences();
self.resize_sidebar = true;
self.theme = theme_for(&self.s.prefs.theme); self.theme = theme_for(&self.s.prefs.theme);
theme::apply(&self.s.ctx, self.theme); theme::apply(&self.s.ctx, self.theme);
} }
@@ -783,8 +787,11 @@ impl eframe::App for App {
egui::Panel::bottom("status").exact_size(26.0).frame(egui::Frame::NONE.fill(t.chrome)).show(ui, |ui| chrome::status_bar(self, ui)); egui::Panel::bottom("status").exact_size(26.0).frame(egui::Frame::NONE.fill(t.chrome)).show(ui, |ui| chrome::status_bar(self, ui));
} }
let width = self.s.prefs.sidebar_width.clamp(180, 500) as f32; let width = self.s.prefs.sidebar_width.clamp(180, 500) as f32;
let side = egui::Panel::left("sidebar") let mut panel = egui::Panel::left("sidebar").default_size(width);
.default_size(width) if std::mem::take(&mut self.resize_sidebar) {
panel = panel.exact_size(width);
}
let side = panel
.min_size(180.0) .min_size(180.0)
.max_size(500.0) .max_size(500.0)
.resizable(true) .resizable(true)
+2 -2
View File
@@ -32,7 +32,7 @@ pub fn ui(app: &mut App, ui: &mut Ui) {
ui.add_space(4.0); ui.add_space(4.0);
// Footer actions, pinned to the bottom of the sidebar. // Footer actions, pinned to the bottom of the sidebar.
egui::Panel::bottom("sidebar-footer").exact_size(36.0).frame(egui::Frame::NONE.fill(t.dock)).show_inside(ui, |ui| { egui::Panel::bottom("sidebar-footer").exact_size(36.0).frame(egui::Frame::NONE.fill(t.dock)).show(ui, |ui| {
ui.horizontal_centered(|ui| { ui.horizontal_centered(|ui| {
ui.add_space(6.0); ui.add_space(6.0);
if widgets::icon_button(ui, icon::PLUS, "New connection (Ctrl/Cmd+N)").clicked() { if widgets::icon_button(ui, icon::PLUS, "New connection (Ctrl/Cmd+N)").clicked() {
@@ -56,7 +56,7 @@ pub fn ui(app: &mut App, ui: &mut Ui) {
}); });
}); });
if !app.sidebar.selected.is_empty() { if !app.sidebar.selected.is_empty() {
egui::Panel::bottom("sidebar-bulk").frame(egui::Frame::NONE.fill(t.dock).inner_margin(6)).show_inside(ui, |ui| bulk_bar(app, ui)); egui::Panel::bottom("sidebar-bulk").frame(egui::Frame::NONE.fill(t.dock).inner_margin(6)).show(ui, |ui| bulk_bar(app, ui));
} }
egui::ScrollArea::vertical().auto_shrink([false, false]).show(ui, |ui| list(app, ui)); egui::ScrollArea::vertical().auto_shrink([false, false]).show(ui, |ui| list(app, ui));
} }