ui/column: remove move/remove column buttons on narrow

It doesn't make sense to move columns in narrow mode

Fixes: https://github.com/damus-io/notedeck/issues/960
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2025-07-15 08:26:53 -07:00
parent a714bef690
commit 443d356cc7
2 changed files with 52 additions and 2 deletions

View File

@@ -788,6 +788,8 @@ pub fn render_nav(
ctx: &mut AppContext<'_>, ctx: &mut AppContext<'_>,
ui: &mut egui::Ui, ui: &mut egui::Ui,
) -> RenderNavResponse { ) -> RenderNavResponse {
let narrow = is_narrow(ui.ctx());
if let Some(sheet_route) = app if let Some(sheet_route) = app
.columns(ctx.accounts) .columns(ctx.accounts)
.column(col) .column(col)
@@ -822,6 +824,8 @@ pub fn render_nav(
&[route.clone()], &[route.clone()],
col, col,
) )
.show_move_button(!narrow)
.show_delete_button(!narrow)
.show(ui), .show(ui),
NavUiType::Body => render_nav_body(ui, app, ctx, route, 1, col, inner_rect), NavUiType::Body => render_nav_body(ui, app, ctx, route, 1, col, inner_rect),
}); });
@@ -858,7 +862,10 @@ pub fn render_nav(
nav.routes(), nav.routes(),
col, col,
) )
.show_move_button(!narrow)
.show_delete_button(!narrow)
.show(ui), .show(ui),
NavUiType::Body => { NavUiType::Body => {
if let Some(top) = nav.routes().last() { if let Some(top) = nav.routes().last() {
render_nav_body(ui, app, ctx, top, nav.routes().len(), col, inner_rect) render_nav_body(ui, app, ctx, top, nav.routes().len(), col, inner_rect)

View File

@@ -25,9 +25,14 @@ pub struct NavTitle<'a> {
columns: &'a Columns, columns: &'a Columns,
routes: &'a [Route], routes: &'a [Route],
col_id: usize, col_id: usize,
options: u32,
} }
impl<'a> NavTitle<'a> { impl<'a> NavTitle<'a> {
// options
const SHOW_MOVE: u32 = 1 << 0;
const SHOW_DELETE: u32 = 1 << 1;
pub fn new( pub fn new(
ndb: &'a Ndb, ndb: &'a Ndb,
img_cache: &'a mut Images, img_cache: &'a mut Images,
@@ -35,12 +40,14 @@ impl<'a> NavTitle<'a> {
routes: &'a [Route], routes: &'a [Route],
col_id: usize, col_id: usize,
) -> Self { ) -> Self {
let options = Self::SHOW_MOVE | Self::SHOW_DELETE;
NavTitle { NavTitle {
ndb, ndb,
img_cache, img_cache,
columns, columns,
routes, routes,
col_id, col_id,
options,
} }
} }
@@ -519,6 +526,34 @@ impl<'a> NavTitle<'a> {
}; };
} }
pub fn show_move_button(&mut self, enable: bool) -> &mut Self {
if enable {
self.options |= Self::SHOW_MOVE;
} else {
self.options &= !Self::SHOW_MOVE;
}
self
}
pub fn show_delete_button(&mut self, enable: bool) -> &mut Self {
if enable {
self.options |= Self::SHOW_DELETE;
} else {
self.options &= !Self::SHOW_DELETE;
}
self
}
fn should_show_move_button(&self) -> bool {
(self.options & Self::SHOW_MOVE) == Self::SHOW_MOVE
}
fn should_show_delete_button(&self) -> bool {
(self.options & Self::SHOW_DELETE) == Self::SHOW_DELETE
}
fn title(&mut self, ui: &mut egui::Ui, top: &Route, navigating: bool) -> Option<TitleResponse> { fn title(&mut self, ui: &mut egui::Ui, top: &Route, navigating: bool) -> Option<TitleResponse> {
let title_r = if !navigating { let title_r = if !navigating {
self.title_presentation(ui, top, 32.0) self.title_presentation(ui, top, 32.0)
@@ -530,8 +565,16 @@ impl<'a> NavTitle<'a> {
if navigating { if navigating {
self.title_presentation(ui, top, 32.0) self.title_presentation(ui, top, 32.0)
} else { } else {
let move_col = self.move_button_section(ui); let mut move_col: Option<usize> = None;
let remove_col = self.delete_button_section(ui); let mut remove_col = false;
if self.should_show_move_button() {
move_col = self.move_button_section(ui);
}
if self.should_show_delete_button() {
remove_col = self.delete_button_section(ui);
}
if let Some(col) = move_col { if let Some(col) = move_col {
Some(TitleResponse::MoveColumn(col)) Some(TitleResponse::MoveColumn(col))
} else if remove_col { } else if remove_col {