fix: wrap the editor toolbar in narrow windows
This commit is contained in:
1 parent
c833883388
commit
9d4d37f8c7
1 file changed
+14
-2
+14
-2
@@ -57,6 +57,7 @@ struct Editor {
|
|||||||
texture: egui::TextureHandle,
|
texture: egui::TextureHandle,
|
||||||
/// The `Doc::revision` the texture shows.
|
/// The `Doc::revision` the texture shows.
|
||||||
shown: u64,
|
shown: u64,
|
||||||
|
toolbar_height: f32,
|
||||||
doc: Doc,
|
doc: Doc,
|
||||||
tool: Tool,
|
tool: Tool,
|
||||||
color: usize,
|
color: usize,
|
||||||
@@ -79,6 +80,7 @@ impl Editor {
|
|||||||
base,
|
base,
|
||||||
texture,
|
texture,
|
||||||
shown: 0,
|
shown: 0,
|
||||||
|
toolbar_height: 0.0,
|
||||||
doc: Doc::new(),
|
doc: Doc::new(),
|
||||||
tool: Tool::Arrow,
|
tool: Tool::Arrow,
|
||||||
color: 0,
|
color: 0,
|
||||||
@@ -220,7 +222,8 @@ impl Editor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn toolbar(&mut self, ui: &mut egui::Ui) {
|
fn toolbar(&mut self, ui: &mut egui::Ui) {
|
||||||
ui.horizontal(|ui| {
|
// Wraps onto a second row in narrow windows (niri's half-width columns).
|
||||||
|
ui.horizontal_wrapped(|ui| {
|
||||||
for tool in Tool::ALL {
|
for tool in Tool::ALL {
|
||||||
if ui
|
if ui
|
||||||
.selectable_label(self.tool == tool, tool.label())
|
.selectable_label(self.tool == tool, tool.label())
|
||||||
@@ -405,7 +408,16 @@ impl eframe::App for Editor {
|
|||||||
let ctx = ui.ctx().clone();
|
let ctx = ui.ctx().clone();
|
||||||
self.keys(&ctx);
|
self.keys(&ctx);
|
||||||
self.guard_close(&ctx);
|
self.guard_close(&ctx);
|
||||||
egui::Panel::top("toolbar").show(ui, |ui| self.toolbar(ui));
|
let toolbar = egui::Panel::top("toolbar").show(ui, |ui| {
|
||||||
|
self.toolbar(ui);
|
||||||
|
ui.min_rect().height()
|
||||||
|
});
|
||||||
|
// The panel takes its height from the last pass: when the toolbar
|
||||||
|
// wraps or unwraps, lay out again so no row is cut off.
|
||||||
|
if toolbar.inner != self.toolbar_height {
|
||||||
|
self.toolbar_height = toolbar.inner;
|
||||||
|
ctx.request_discard("toolbar height changed");
|
||||||
|
}
|
||||||
if self.confirm_close && self.doc.is_dirty() {
|
if self.confirm_close && self.doc.is_dirty() {
|
||||||
egui::Panel::bottom("unsaved").show(ui, |ui| {
|
egui::Panel::bottom("unsaved").show(ui, |ui| {
|
||||||
ui.label("Unsaved changes — Esc to discard, Ctrl+S to save");
|
ui.label("Unsaved changes — Esc to discard, Ctrl+S to save");
|
||||||
|
|||||||
Reference in new issue
Block a user