Skip to content

Commit

Permalink
android: update to latest winit/egui/android-activity
Browse files Browse the repository at this point in the history
so we can start fixing this shit

Signed-off-by: William Casarin <[email protected]>
  • Loading branch information
jb55 committed Jan 29, 2025
1 parent b57c56b commit 2a60d8b
Show file tree
Hide file tree
Showing 25 changed files with 487 additions and 432 deletions.
639 changes: 359 additions & 280 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,10 @@ lto = true # Enable link-time optimization
codegen-units = 1 # Reduce number of codegen units to increase optimizations
panic = 'abort' # Abort on panic
strip = true # Strip symbols from binary*


[patch.crates-io]
egui = { git = "https://github.com/jb55/egui", rev = "03c769a3576920d5e33e01c06167e7c67d296625" }
eframe = { git = "https://github.com/jb55/egui", rev = "03c769a3576920d5e33e01c06167e7c67d296625" }
egui-winit = { git = "https://github.com/jb55/egui", rev = "03c769a3576920d5e33e01c06167e7c67d296625" }
egui_extras = { git = "https://github.com/jb55/egui", rev = "03c769a3576920d5e33e01c06167e7c67d296625" }
29 changes: 6 additions & 23 deletions crates/notedeck/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,13 @@ pub struct Notedeck {
app_size: AppSizeHandler,
}

fn margin_top(narrow: bool) -> f32 {
#[cfg(target_os = "android")]
{
// FIXME - query the system bar height and adjust more precisely
let _ = narrow; // suppress compiler warning on android
40.0
}
#[cfg(not(target_os = "android"))]
{
if narrow {
50.0
} else {
0.0
}
}
}

/// Our chrome, which is basically nothing
fn main_panel(style: &egui::Style, narrow: bool) -> egui::CentralPanel {
fn main_panel(style: &egui::Style) -> egui::CentralPanel {
let inner_margin = egui::Margin {
top: margin_top(narrow),
left: 0.0,
right: 0.0,
bottom: 0.0,
top: 0,
left: 0,
right: 0,
bottom: 0,
};
egui::CentralPanel::default().frame(egui::Frame {
inner_margin,
Expand All @@ -71,7 +54,7 @@ impl eframe::App for Notedeck {
// handle account updates
self.accounts.update(&self.ndb, &mut self.pool, ctx);

main_panel(&ctx.style(), crate::ui::is_narrow(ctx)).show(ctx, |ui| {
main_panel(&ctx.style()).show(ctx, |ui| {
// render app
if let Some(app) = &self.app {
let app = app.clone();
Expand Down
10 changes: 5 additions & 5 deletions crates/notedeck/src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct ColorTheme {
pub inactive_weak_bg_fill: Color32,
}

const WIDGET_ROUNDING: Rounding = Rounding::same(8.0);
const WIDGET_ROUNDING: Rounding = Rounding::same(8);

pub fn create_themed_visuals(theme: ColorTheme, default: Visuals) -> Visuals {
Visuals {
Expand Down Expand Up @@ -83,12 +83,12 @@ pub fn create_themed_visuals(theme: ColorTheme, default: Visuals) -> Visuals {
},
extreme_bg_color: theme.extreme_bg_color,
error_fg_color: theme.err_fg_color,
window_rounding: Rounding::same(8.0),
window_rounding: Rounding::same(8),
window_fill: theme.window_fill,
window_shadow: Shadow {
offset: [0.0, 8.0].into(),
blur: 24.0,
spread: 0.0,
offset: [0, 8],
blur: 24,
spread: 0,
color: egui::Color32::from_rgba_unmultiplied(0x6D, 0x6D, 0x6D, 0x14),
},
window_stroke: Stroke {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class MainActivity extends GameActivity {
protected void onCreate(Bundle savedInstanceState) {
// Shrink view so it does not get covered by insets.

/*
View content = getWindow().getDecorView().findViewById(android.R.id.content);
ViewCompat.setOnApplyWindowInsetsListener(content, (v, windowInsets) -> {
Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());
Expand All @@ -39,7 +38,6 @@ protected void onCreate(Bundle savedInstanceState) {
});

WindowCompat.setDecorFitsSystemWindows(getWindow(), true);
*/

super.onCreate(savedInstanceState);
}
Expand All @@ -48,11 +46,10 @@ protected void onCreate(Bundle savedInstanceState) {
public boolean onTouchEvent(MotionEvent event) {
// Offset the location so it fits the view with margins caused by insets.

/*
int[] location = new int[2];
findViewById(android.R.id.content).getLocationOnScreen(location);
event.offsetLocation(-location[0], -location[1]);
*/

return super.onTouchEvent(event);
}
}
2 changes: 1 addition & 1 deletion crates/notedeck_chrome/src/android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub async fn android_main(app: AndroidApp) {
use tracing_subscriber::{prelude::*, EnvFilter};

std::env::set_var("RUST_BACKTRACE", "full");
std::env::set_var("RUST_LOG", "egui=trace");
std::env::set_var("RUST_LOG", "egui=trace,android_activity=debug");

//std::env::set_var(
// "RUST_LOG",
Expand Down
6 changes: 2 additions & 4 deletions crates/notedeck_columns/src/ui/account_login_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ impl<'a> AccountLoginView<'a> {
}

pub fn ui(&mut self, ui: &mut egui::Ui) -> InnerResponse<Option<AccountLoginResponse>> {
Frame::none()
.outer_margin(12.0)
.show(ui, |ui| self.show(ui))
Frame::new().outer_margin(12.0).show(ui, |ui| self.show(ui))
}

fn show(&mut self, ui: &mut egui::Ui) -> Option<AccountLoginResponse> {
Expand Down Expand Up @@ -104,7 +102,7 @@ fn login_textedit(manager: &mut AcquireKeyState) -> TextEdit {
)
.vertical_align(Align::Center)
.min_size(Vec2::new(0.0, 40.0))
.margin(Margin::same(12.0))
.margin(Margin::same(12))
})
}

Expand Down
4 changes: 2 additions & 2 deletions crates/notedeck_columns/src/ui/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl<'a> AccountsView<'a> {
}

pub fn ui(&mut self, ui: &mut Ui) -> InnerResponse<Option<AccountsViewResponse>> {
Frame::none().outer_margin(12.0).show(ui, |ui| {
Frame::new().outer_margin(12.0).show(ui, |ui| {
if let Some(resp) = Self::top_section_buttons_widget(ui).inner {
return Some(resp);
}
Expand Down Expand Up @@ -135,7 +135,7 @@ fn show_profile_card(
let mut op: Option<ProfilePreviewAction> = None;

ui.add_sized(max_size, |ui: &mut egui::Ui| {
let mut frame = Frame::none();
let mut frame = Frame::new();
if is_selected || card_resp.hovered() {
frame = frame.fill(ui.visuals().noninteractive().weak_bg_fill);
}
Expand Down
12 changes: 6 additions & 6 deletions crates/notedeck_columns/src/ui/add_column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl<'a> AddColumnView<'a> {
.vertical_align(Align::Center)
.desired_width(f32::INFINITY)
.min_size(Vec2::new(0.0, 40.0))
.margin(Margin::same(12.0))
.margin(Margin::same(12))
});

ui.add(text_edit);
Expand All @@ -208,10 +208,10 @@ impl<'a> AddColumnView<'a> {
if let Ok(profile) = self.ndb.get_profile_by_pubkey(&txn, keypair.pubkey.bytes()) {
egui::Frame::window(ui.style())
.outer_margin(Margin {
left: 4.0,
right: 4.0,
top: 12.0,
bottom: 32.0,
left: 4,
right: 4,
top: 12,
bottom: 32,
})
.show(ui, |ui| {
ProfilePreview::new(&profile, self.img_cache).ui(ui);
Expand Down Expand Up @@ -570,7 +570,7 @@ pub fn hashtag_ui(
.vertical_align(Align::Center)
.desired_width(f32::INFINITY)
.min_size(Vec2::new(0.0, 40.0))
.margin(Margin::same(12.0));
.margin(Margin::same(12));
ui.add(text_edit);

ui.add_space(8.0);
Expand Down
10 changes: 5 additions & 5 deletions crates/notedeck_columns/src/ui/column/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ impl<'a> NavTitle<'a> {
let x_range = ui.available_rect_before_wrap().x_range();
let is_dragging = egui::DragAndDrop::payload::<usize>(ui.ctx()).is_some(); // must be outside ui.dnd_drop_zone to capture properly
let (_, _) = ui.dnd_drop_zone::<usize, ()>(
egui::Frame::none().inner_margin(Margin::same(8.0)),
egui::Frame::new().inner_margin(Margin::same(8)),
|ui| {
let distances: Vec<(egui::Response, f32)> =
self.collect_column_distances(ui, id);
Expand Down Expand Up @@ -294,10 +294,10 @@ impl<'a> NavTitle<'a> {
ui: &mut egui::Ui,
id: egui::Id,
) -> Vec<(egui::Response, f32)> {
let y_margin = 4.0;
let item_frame = egui::Frame::none()
.rounding(egui::Rounding::same(8.0))
.inner_margin(Margin::symmetric(8.0, y_margin));
let y_margin: i8 = 4;
let item_frame = egui::Frame::new()
.rounding(egui::Rounding::same(8))
.inner_margin(Margin::symmetric(8, y_margin));

(0..self.columns.num_columns())
.filter_map(|col| {
Expand Down
2 changes: 1 addition & 1 deletion crates/notedeck_columns/src/ui/edit_deck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl<'a> EditDeckView<'a> {
pub fn ui(&mut self, ui: &mut egui::Ui) -> Option<EditDeckResponse> {
let mut edit_deck_resp = None;

padding(egui::Margin::symmetric(16.0, 4.0), ui, |ui| {
padding(egui::Margin::symmetric(16, 4), ui, |ui| {
if ui.add(delete_button()).clicked() {
edit_deck_resp = Some(EditDeckResponse::Delete);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/notedeck_columns/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub fn padding<R>(
ui: &mut egui::Ui,
add_contents: impl FnOnce(&mut egui::Ui) -> R,
) -> egui::InnerResponse<R> {
egui::Frame::none()
egui::Frame::new()
.inner_margin(amount)
.show(ui, add_contents)
}
Expand Down
8 changes: 4 additions & 4 deletions crates/notedeck_columns/src/ui/note/contents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ pub fn render_note_preview(
*/
};

egui::Frame::none()
egui::Frame::new()
.fill(ui.visuals().noninteractive().weak_bg_fill)
.inner_margin(egui::Margin::same(8.0))
.outer_margin(egui::Margin::symmetric(0.0, 8.0))
.rounding(egui::Rounding::same(10.0))
.inner_margin(egui::Margin::same(8))
.outer_margin(egui::Margin::symmetric(0, 8))
.rounding(egui::Rounding::same(10))
.stroke(egui::Stroke::new(
1.0,
ui.visuals().noninteractive().bg_stroke.color,
Expand Down
30 changes: 11 additions & 19 deletions crates/notedeck_columns/src/ui/note/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,22 @@ impl NoteContextSelection {
pub fn process(&self, ui: &mut egui::Ui, note: &Note<'_>) {
match self {
NoteContextSelection::CopyText => {
ui.output_mut(|w| {
w.copied_text = note.content().to_string();
});
ui.ctx().copy_text(note.content().to_string());
}
NoteContextSelection::CopyPubkey => {
ui.output_mut(|w| {
if let Some(bech) = Pubkey::new(*note.pubkey()).to_bech() {
w.copied_text = bech;
}
});
if let Some(bech) = Pubkey::new(*note.pubkey()).to_bech() {
ui.ctx().copy_text(bech);
}
}
NoteContextSelection::CopyNoteId => {
ui.output_mut(|w| {
if let Some(bech) = NoteId::new(*note.id()).to_bech() {
w.copied_text = bech;
}
});
}
NoteContextSelection::CopyNoteJSON => {
ui.output_mut(|w| match note.json() {
Ok(json) => w.copied_text = json,
Err(err) => error!("error copying note json: {err}"),
});
if let Some(bech) = NoteId::new(*note.id()).to_bech() {
ui.ctx().copy_text(bech);
}
}
NoteContextSelection::CopyNoteJSON => match note.json() {
Ok(json) => ui.ctx().copy_text(json),
Err(err) => error!("error copying note json: {err}"),
},
}
}
}
Expand Down
41 changes: 22 additions & 19 deletions crates/notedeck_columns/src/ui/note/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ impl<'a> NoteView<'a> {
.response
}

pub fn expand_size() -> f32 {
5.0
pub fn expand_size() -> i8 {
5
}

fn pfp(
Expand Down Expand Up @@ -223,8 +223,8 @@ impl<'a> NoteView<'a> {
let (rect, size, resp) = ui::anim::hover_expand(
ui,
egui::Id::new((profile_key, note_key)),
pfp_size,
ui::NoteView::expand_size(),
pfp_size as f32,
ui::NoteView::expand_size() as f32,
anim_speed,
);

Expand All @@ -246,7 +246,7 @@ impl<'a> NoteView<'a> {
None => ui
.add(
ui::ProfilePic::new(self.img_cache, ui::ProfilePic::no_pfp_url())
.size(pfp_size),
.size(pfp_size as f32),
)
.interact(sense),
}
Expand Down Expand Up @@ -360,20 +360,23 @@ impl<'a> NoteView<'a> {

let size = ui.available_size();
ui.vertical(|ui| {
ui.add_sized([size.x, self.options().pfp_size()], |ui: &mut egui::Ui| {
ui.horizontal_centered(|ui| {
selected_option = NoteView::note_header(
ui,
self.note_cache,
self.note,
&profile,
self.options(),
container_right,
)
.context_selection;
})
.response
});
ui.add_sized(
[size.x, self.options().pfp_size() as f32],
|ui: &mut egui::Ui| {
ui.horizontal_centered(|ui| {
selected_option = NoteView::note_header(
ui,
self.note_cache,
self.note,
&profile,
self.options(),
container_right,
)
.context_selection;
})
.response
},
);

let note_reply = self
.note_cache
Expand Down
2 changes: 1 addition & 1 deletion crates/notedeck_columns/src/ui/note/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl NoteOptions {
options
}

pub fn pfp_size(&self) -> f32 {
pub fn pfp_size(&self) -> i8 {
if self.has_small_pfp() {
ProfilePic::small_size()
} else if self.has_medium_pfp() {
Expand Down
Loading

0 comments on commit 2a60d8b

Please sign in to comment.