notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

commit 0400b9476947c11965c6faa6fa2671668a887b3a
parent a618da3ed7a0b020c77a134764dfbb343c04fad6
Author: William Casarin <jb55@jb55.com>
Date:   Sun,  9 Jul 2023 14:21:01 -0700

add padding to top panel on mobile

Diffstat:
Msrc/app.rs | 35+++++++++++++++++++++++++++++++++--
Msrc/lib.rs | 2++
Msrc/ui.rs | 4+++-
3 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/src/app.rs b/src/app.rs @@ -7,7 +7,7 @@ use crate::ui::padding; use crate::Result; use egui::containers::scroll_area::ScrollBarVisibility; use egui::widgets::Spinner; -use egui::{Context, Frame, TextureHandle, TextureId}; +use egui::{Context, Frame, Margin, TextureHandle, TextureId}; use enostr::{ClientMessage, EventId, Filter, Profile, Pubkey, RelayEvent, RelayMessage}; use poll_promise::Promise; use std::collections::{HashMap, HashSet}; @@ -410,8 +410,33 @@ fn timeline_view(ui: &mut egui::Ui, app: &mut Damus) { }); } +fn top_panel(ctx: &egui::Context) -> egui::TopBottomPanel { + // mobile needs padding, at least on android + if is_mobile(ctx) { + let mut top_margin = Margin::default(); + top_margin.top = 50.0; + + let frame = Frame { + inner_margin: top_margin, + fill: ctx.style().visuals.panel_fill, + ..Default::default() + }; + + return egui::TopBottomPanel::top("top_panel").frame(frame); + } + + egui::TopBottomPanel::top("top_panel").frame(Frame::none()) +} + +#[inline] +fn horizontal_centered() -> egui::Layout { + egui::Layout::left_to_right(egui::Align::Center) +} + fn render_panel(ctx: &egui::Context, app: &mut Damus) { - egui::TopBottomPanel::top("top_panel").show(ctx, |ui| { + top_panel(ctx).show(ctx, |ui| { + set_app_style(ui); + ui.horizontal_wrapped(|ui| { ui.visuals_mut().button_frame = false; egui::widgets::global_dark_light_mode_switch(ui); @@ -452,7 +477,13 @@ fn set_app_style(ui: &mut egui::Ui) { } fn render_damus_mobile(ctx: &egui::Context, app: &mut Damus) { + render_panel(ctx, app); + + #[cfg(feature = "profiling")] + puffin::profile_function!(); + let panel_width = ctx.screen_rect().width(); + egui::CentralPanel::default().show(ctx, |ui| { set_app_style(ui); timeline_panel(ui, app, panel_width, 0); diff --git a/src/lib.rs b/src/lib.rs @@ -13,6 +13,8 @@ mod frame_history; pub use app::Damus; pub use error::Error; + +#[cfg(target_os = "android")] use winit::platform::android::EventLoopBuilderExtAndroid; pub type Result<T> = std::result::Result<T, error::Error>; diff --git a/src/ui.rs b/src/ui.rs @@ -1,5 +1,7 @@ +use egui::style::Margin; + pub fn padding<R>( - amount: f32, + amount: impl Into<Margin>, ui: &mut egui::Ui, add_contents: impl FnOnce(&mut egui::Ui) -> R, ) -> egui::InnerResponse<R> {