timeline: use strips instead of panels
panels grow when their childs a larger than its container. strips do not do this, which is better for timelines Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
82
src/app.rs
82
src/app.rs
@@ -8,9 +8,10 @@ use crate::timeline;
|
|||||||
use crate::ui;
|
use crate::ui;
|
||||||
use crate::ui::is_mobile;
|
use crate::ui::is_mobile;
|
||||||
use crate::Result;
|
use crate::Result;
|
||||||
use egui::containers::scroll_area::ScrollBarVisibility;
|
|
||||||
|
|
||||||
|
use egui::containers::scroll_area::ScrollBarVisibility;
|
||||||
use egui::{Context, Frame, Margin, Style};
|
use egui::{Context, Frame, Margin, Style};
|
||||||
|
use egui_extras::{Size, StripBuilder};
|
||||||
|
|
||||||
use enostr::{ClientMessage, Filter, Pubkey, RelayEvent, RelayMessage};
|
use enostr::{ClientMessage, Filter, Pubkey, RelayEvent, RelayMessage};
|
||||||
use nostrdb::{BlockType, Config, Mention, Ndb, Note, NoteKey, Subscription, Transaction};
|
use nostrdb::{BlockType, Config, Mention, Ndb, Note, NoteKey, Subscription, Transaction};
|
||||||
@@ -588,8 +589,8 @@ fn timeline_view(ui: &mut egui::Ui, app: &mut Damus, timeline: usize) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
egui::ScrollArea::vertical()
|
egui::ScrollArea::vertical()
|
||||||
.scroll_bar_visibility(ScrollBarVisibility::AlwaysHidden)
|
.scroll_bar_visibility(ScrollBarVisibility::AlwaysVisible)
|
||||||
.auto_shrink([false; 2])
|
//.auto_shrink([false; 2])
|
||||||
/*
|
/*
|
||||||
.show_viewport(ui, |ui, viewport| {
|
.show_viewport(ui, |ui, viewport| {
|
||||||
render_notes_in_viewport(ui, app, viewport, row_height, font_id);
|
render_notes_in_viewport(ui, app, viewport, row_height, font_id);
|
||||||
@@ -597,6 +598,7 @@ fn timeline_view(ui: &mut egui::Ui, app: &mut Damus, timeline: usize) {
|
|||||||
*/
|
*/
|
||||||
.show(ui, |ui| {
|
.show(ui, |ui| {
|
||||||
ui.spacing_mut().item_spacing.y = 0.0;
|
ui.spacing_mut().item_spacing.y = 0.0;
|
||||||
|
ui.spacing_mut().item_spacing.x = 4.0;
|
||||||
let _ = render_notes(ui, app, timeline);
|
let _ = render_notes(ui, app, timeline);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -681,12 +683,8 @@ fn render_damus_mobile(ctx: &egui::Context, app: &mut Damus) {
|
|||||||
#[cfg(feature = "profiling")]
|
#[cfg(feature = "profiling")]
|
||||||
puffin::profile_function!();
|
puffin::profile_function!();
|
||||||
|
|
||||||
let panel_width = ctx.screen_rect().width();
|
|
||||||
|
|
||||||
main_panel(&ctx.style()).show(ctx, |ui| {
|
main_panel(&ctx.style()).show(ctx, |ui| {
|
||||||
timeline_panel(ui, panel_width, 0, |ui| {
|
timeline_view(ui, app, 0);
|
||||||
timeline_view(ui, app, 0);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -705,53 +703,45 @@ fn render_damus_desktop(ctx: &egui::Context, app: &mut Damus) {
|
|||||||
|
|
||||||
let screen_size = ctx.screen_rect().width();
|
let screen_size = ctx.screen_rect().width();
|
||||||
let calc_panel_width = (screen_size / app.timelines.len() as f32) - 30.0;
|
let calc_panel_width = (screen_size / app.timelines.len() as f32) - 30.0;
|
||||||
let min_width = 300.0;
|
let min_width = 320.0;
|
||||||
let need_scroll = calc_panel_width < min_width;
|
let need_scroll = calc_panel_width < min_width;
|
||||||
let panel_width = if need_scroll {
|
let panel_sizes = if need_scroll {
|
||||||
min_width
|
Size::exact(min_width)
|
||||||
} else {
|
} else {
|
||||||
calc_panel_width
|
Size::remainder()
|
||||||
};
|
};
|
||||||
|
|
||||||
if app.timelines.len() == 1 {
|
if app.timelines.len() == 1 {
|
||||||
let panel_width = ctx.screen_rect().width();
|
|
||||||
main_panel(&ctx.style()).show(ctx, |ui| {
|
main_panel(&ctx.style()).show(ctx, |ui| {
|
||||||
timeline_panel(ui, panel_width, 0, |ui| {
|
timeline_view(ui, app, 0);
|
||||||
//postbox(ui, app);
|
|
||||||
timeline_view(ui, app, 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
/*
|
|
||||||
egui::Area::new("test")
|
|
||||||
.fixed_pos(egui::pos2(50.0, 50.0))
|
|
||||||
//.resizable(false)
|
|
||||||
//.title_bar(false)
|
|
||||||
.show(ctx, |ui| {
|
|
||||||
ui.label("Test");
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
main_panel(&ctx.style()).show(ctx, |ui| {
|
main_panel(&ctx.style()).show(ctx, |ui| {
|
||||||
egui::ScrollArea::horizontal()
|
ui.spacing_mut().item_spacing.x = 0.0;
|
||||||
.auto_shrink([false; 2])
|
if need_scroll {
|
||||||
.show(ui, |ui| {
|
egui::ScrollArea::horizontal().show(ui, |ui| {
|
||||||
for timeline_ind in 0..app.timelines.len() {
|
timelines_view(ui, panel_sizes, app, app.timelines.len());
|
||||||
if timeline_ind == 0 {
|
|
||||||
//postbox(ui, app);
|
|
||||||
}
|
|
||||||
timeline_panel(ui, panel_width, timeline_ind as u32, |ui| {
|
|
||||||
// TODO: add new timeline to each panel
|
|
||||||
timeline_view(ui, app, timeline_ind);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
timelines_view(ui, panel_sizes, app, app.timelines.len());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn timelines_view(ui: &mut egui::Ui, sizes: Size, app: &mut Damus, timelines: usize) {
|
||||||
|
StripBuilder::new(ui)
|
||||||
|
.sizes(sizes, timelines)
|
||||||
|
.clip(true)
|
||||||
|
.horizontal(|mut strip| {
|
||||||
|
for timeline_ind in 0..timelines {
|
||||||
|
strip.cell(|ui| timeline_view(ui, app, timeline_ind));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
fn postbox(ui: &mut egui::Ui, app: &mut Damus) {
|
fn postbox(ui: &mut egui::Ui, app: &mut Damus) {
|
||||||
let _output = egui::TextEdit::multiline(&mut app.compose)
|
let _output = egui::TextEdit::multiline(&mut app.compose)
|
||||||
@@ -771,20 +761,6 @@ fn postbox(ui: &mut egui::Ui, app: &mut Damus) {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
fn timeline_panel<R>(
|
|
||||||
ui: &mut egui::Ui,
|
|
||||||
panel_width: f32,
|
|
||||||
ind: u32,
|
|
||||||
add_contents: impl FnOnce(&mut egui::Ui) -> R,
|
|
||||||
) -> egui::InnerResponse<R> {
|
|
||||||
egui::SidePanel::left(format!("l{}", ind))
|
|
||||||
.resizable(false)
|
|
||||||
.frame(Frame::none())
|
|
||||||
.max_width(panel_width)
|
|
||||||
.min_width(panel_width)
|
|
||||||
.show_inside(ui, add_contents)
|
|
||||||
}
|
|
||||||
|
|
||||||
impl eframe::App for Damus {
|
impl eframe::App for Damus {
|
||||||
/// Called by the frame work to save state before shutdown.
|
/// Called by the frame work to save state before shutdown.
|
||||||
fn save(&mut self, _storage: &mut dyn eframe::Storage) {
|
fn save(&mut self, _storage: &mut dyn eframe::Storage) {
|
||||||
|
|||||||
Reference in New Issue
Block a user