Code updates for egui 0.21

This commit is contained in:
Mike Dilger 2023-02-10 20:57:17 +13:00
parent f5f6a90be4
commit a40051ea55
6 changed files with 48 additions and 28 deletions

View File

@ -169,7 +169,7 @@ fn render_post_maybe_fake(
let maybe_person = GLOBALS.people.get(&event.pubkey.into());
let screen_rect = ctx.input().screen_rect; // Rect
let screen_rect = ctx.input(|i| i.screen_rect); // Rect
let pos2 = ui.next_widget_position();
// If too far off of the screen, don't actually render the post, just make some space
@ -416,10 +416,10 @@ fn render_post_inner(
}));
}
if ui.button("Copy ID").clicked() {
ui.output().copied_text = event.id.try_as_bech32_string().unwrap();
ui.output_mut(|o| o.copied_text = event.id.try_as_bech32_string().unwrap());
}
if ui.button("Copy ID as hex").clicked() {
ui.output().copied_text = event.id.as_hex_string();
ui.output_mut(|o| o.copied_text = event.id.as_hex_string());
}
if ui.button("Dismiss").clicked() {
GLOBALS.dismissed.blocking_write().push(event.id);
@ -506,9 +506,9 @@ fn render_post_inner(
.clicked()
{
if app.render_raw == Some(event.id) {
ui.output().copied_text = serde_json::to_string(&event).unwrap();
ui.output_mut(|o| o.copied_text = serde_json::to_string(&event).unwrap());
} else {
ui.output().copied_text = event.content.clone();
ui.output_mut(|o| o.copied_text = event.content.clone());
}
}

View File

@ -65,7 +65,7 @@ fn real_posting_area(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram
let mut layouter = |ui: &Ui, text: &str, wrap_width: f32| {
let mut layout_job = textarea_highlighter(text.to_owned(), ui.visuals().dark_mode);
layout_job.wrap.max_width = wrap_width;
ui.fonts().layout_job(layout_job)
ui.fonts(|f| f.layout_job(layout_job))
};
if app.include_subject && app.replying_to.is_none() {

View File

@ -47,11 +47,13 @@ pub fn run() -> Result<(), Error> {
..Default::default()
};
eframe::run_native(
if let Err(e) = eframe::run_native(
"gossip",
options,
Box::new(|cc| Box::new(GossipUi::new(cc))),
);
) {
tracing::error!("Eframe error: {}", e);
}
Ok(())
}
@ -158,14 +160,14 @@ impl GossipUi {
);
{
let mut to = cctx.egui_ctx.tessellation_options();
cctx.egui_ctx.tessellation_options_mut(|to| {
// Less feathering
to.feathering = true;
to.feathering_size_in_pixels = 0.667;
// Less feathering
to.feathering = true;
to.feathering_size_in_pixels = 0.667;
// Sharper text
to.round_text_to_pixels = true;
// Sharper text
to.round_text_to_pixels = true;
});
}
if !settings.light_mode {
@ -508,7 +510,7 @@ impl GossipUi {
.on_hover_text("Copy Public Key")
.clicked()
{
ui.output().copied_text = person.pubkey.try_as_bech32_string().unwrap();
ui.output_mut(|o| o.copied_text = person.pubkey.try_as_bech32_string().unwrap());
}
});
}

View File

@ -85,7 +85,7 @@ fn content(
ui.label(RichText::new("Name: ").strong());
ui.label(name);
if ui.add(CopyButton {}).on_hover_text("Copy Name").clicked() {
ui.output().copied_text = name.to_owned();
ui.output_mut(|o| o.copied_text = name.to_owned());
}
});
}
@ -96,7 +96,7 @@ fn content(
ui.horizontal_wrapped(|ui| {
ui.label(about);
if ui.add(CopyButton {}).on_hover_text("Copy About").clicked() {
ui.output().copied_text = about.to_owned();
ui.output_mut(|o| o.copied_text = about.to_owned());
}
});
});
@ -111,7 +111,7 @@ fn content(
.on_hover_text("Copy Picture")
.clicked()
{
ui.output().copied_text = picture.to_owned();
ui.output_mut(|o| o.copied_text = picture.to_owned());
}
});
}
@ -121,7 +121,7 @@ fn content(
ui.label(RichText::new("nip05: ").strong());
ui.label(nip05);
if ui.add(CopyButton {}).on_hover_text("Copy nip05").clicked() {
ui.output().copied_text = nip05.to_owned();
ui.output_mut(|o| o.copied_text = nip05.to_owned());
}
});
}
@ -143,7 +143,7 @@ fn content(
.on_hover_text(format!("Copy {}", key))
.clicked()
{
ui.output().copied_text = svalue.clone();
ui.output_mut(|o| o.copied_text = svalue.clone());
}
if key == "lud06" {
lud06 = svalue.to_owned();

View File

@ -13,6 +13,7 @@ pub(super) fn dark_mode_visuals() -> Visuals {
dark_mode: true,
widgets: Widgets {
noninteractive: WidgetVisuals {
weak_bg_fill: Color32::from_gray(27),
bg_fill: Color32::from_white_alpha(8),
bg_stroke: Stroke::new(1.0, Color32::from_gray(72)), // separators, borders
fg_stroke: Stroke::new(1.0, Color32::from_gray(190)), // normal text color
@ -20,6 +21,7 @@ pub(super) fn dark_mode_visuals() -> Visuals {
expansion: 0.0,
},
inactive: WidgetVisuals {
weak_bg_fill: Color32::from_gray(60),
bg_fill: Color32::from_white_alpha(8),
bg_stroke: Stroke::new(1.0, Color32::from_gray(72)), // separators, borders
fg_stroke: Stroke::new(1.0, Color32::from_gray(190)), // button text
@ -27,6 +29,7 @@ pub(super) fn dark_mode_visuals() -> Visuals {
expansion: 0.0,
},
hovered: WidgetVisuals {
weak_bg_fill: Color32::from_gray(70),
bg_fill: Color32::from_gray(70),
bg_stroke: Stroke::new(1.0, Color32::from_gray(150)), // e.g. hover over window edge or button
fg_stroke: Stroke::new(1.5, Color32::from_gray(240)),
@ -34,6 +37,7 @@ pub(super) fn dark_mode_visuals() -> Visuals {
expansion: 1.0,
},
active: WidgetVisuals {
weak_bg_fill: Color32::from_gray(55),
bg_fill: Color32::from_gray(55),
bg_stroke: Stroke::new(1.0, Color32::WHITE),
fg_stroke: Stroke::new(2.0, Color32::WHITE),
@ -41,6 +45,7 @@ pub(super) fn dark_mode_visuals() -> Visuals {
expansion: 1.0,
},
open: WidgetVisuals {
weak_bg_fill: Color32::from_gray(27),
bg_fill: Color32::from_gray(27),
bg_stroke: Stroke::new(1.0, Color32::from_gray(60)),
fg_stroke: Stroke::new(1.0, Color32::from_gray(210)),
@ -71,6 +76,10 @@ pub(super) fn dark_mode_visuals() -> Visuals {
window_shadow: Shadow::big_dark(),
popup_shadow: Shadow::small_dark(),
indent_has_left_vline: false,
menu_rounding: Rounding::same(2.0),
slider_trailing_fill: true,
striped: true,
window_rounding: Rounding::same(6.0),
resize_corner_size: 12.0,
text_cursor_width: 2.0,
@ -86,6 +95,7 @@ pub(super) fn light_mode_visuals() -> Visuals {
dark_mode: false,
widgets: Widgets {
noninteractive: WidgetVisuals {
weak_bg_fill: Color32::from_gray(248),
bg_fill: Color32::from_black_alpha(20),
bg_stroke: Stroke::new(1.0, Color32::from_gray(192)),
fg_stroke: Stroke::new(1.0, Color32::from_gray(80)), // normal text color
@ -93,6 +103,7 @@ pub(super) fn light_mode_visuals() -> Visuals {
expansion: 0.0,
},
inactive: WidgetVisuals {
weak_bg_fill: Color32::from_gray(230),
bg_fill: Color32::from_black_alpha(20),
bg_stroke: Stroke::new(1.0, Color32::from_gray(192)),
fg_stroke: Stroke::new(1.0, Color32::from_gray(60)), // button text
@ -100,6 +111,7 @@ pub(super) fn light_mode_visuals() -> Visuals {
expansion: 0.0,
},
hovered: WidgetVisuals {
weak_bg_fill: Color32::from_gray(220),
bg_fill: Color32::from_gray(220),
bg_stroke: Stroke::new(1.0, Color32::from_gray(105)), // e.g. hover over window edge or button
fg_stroke: Stroke::new(1.5, Color32::BLACK),
@ -107,6 +119,7 @@ pub(super) fn light_mode_visuals() -> Visuals {
expansion: 1.0,
},
active: WidgetVisuals {
weak_bg_fill: Color32::from_gray(165),
bg_fill: Color32::from_gray(165),
bg_stroke: Stroke::new(1.0, Color32::BLACK),
fg_stroke: Stroke::new(2.0, Color32::BLACK),
@ -114,6 +127,7 @@ pub(super) fn light_mode_visuals() -> Visuals {
expansion: 1.0,
},
open: WidgetVisuals {
weak_bg_fill: Color32::from_gray(220),
bg_fill: Color32::from_gray(220),
bg_stroke: Stroke::new(1.0, Color32::from_gray(160)),
fg_stroke: Stroke::new(1.0, Color32::BLACK),
@ -144,6 +158,10 @@ pub(super) fn light_mode_visuals() -> Visuals {
window_shadow: Shadow::big_light(),
popup_shadow: Shadow::small_light(),
indent_has_left_vline: false,
menu_rounding: Rounding::same(2.0),
slider_trailing_fill: true,
striped: true,
window_rounding: Rounding::same(6.0),
resize_corner_size: 12.0,
text_cursor_width: 2.0,

View File

@ -127,7 +127,7 @@ fn show_pub_key_detail(app: &mut GossipUi, ctx: &Context, ui: &mut Ui) {
ui.horizontal_wrapped(|ui| {
ui.label(&format!("Public Key (Hex): {}", pkhex.as_str()));
if ui.add(CopyButton {}).clicked() {
ui.output().copied_text = pkhex.into_string();
ui.output_mut(|o| o.copied_text = pkhex.into_string());
}
});
@ -135,7 +135,7 @@ fn show_pub_key_detail(app: &mut GossipUi, ctx: &Context, ui: &mut Ui) {
ui.horizontal_wrapped(|ui| {
ui.label(&format!("Public Key (bech32): {}", bech32));
if ui.add(CopyButton {}).clicked() {
ui.output().copied_text = bech32.clone();
ui.output_mut(|o| o.copied_text = bech32.clone());
}
});
ui.add_space(10.0);
@ -154,7 +154,7 @@ fn show_pub_key_detail(app: &mut GossipUi, ctx: &Context, ui: &mut Ui) {
ui.horizontal_wrapped(|ui| {
ui.label(&format!("Your Profile: {}", &nprofile));
if ui.add(CopyButton {}).clicked() {
ui.output().copied_text = nprofile.clone();
ui.output_mut(|o| o.copied_text = nprofile.clone());
}
});
ui.add_space(10.0);
@ -169,7 +169,7 @@ fn offer_unlock_priv_key(app: &mut GossipUi, ui: &mut Ui) {
ui.horizontal(|ui| {
ui.label("Passphrase: ");
let response = ui.add(TextEdit::singleline(&mut app.password).password(true));
if response.lost_focus() && ui.input().key_pressed(egui::Key::Enter) {
if response.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter)) {
let _ = GLOBALS
.to_overlord
.send(ToOverlordMessage::UnlockKey(app.password.clone()));
@ -195,7 +195,7 @@ fn show_priv_key_detail(_app: &mut GossipUi, ui: &mut Ui) {
ui.horizontal_wrapped(|ui| {
ui.label(&epk.0);
if ui.add(CopyButton {}).clicked() {
ui.output().copied_text = epk.to_string();
ui.output_mut(|o| o.copied_text = epk.to_string());
}
});
@ -302,7 +302,7 @@ fn offer_import_pub_key(app: &mut GossipUi, ui: &mut Ui) {
ui.horizontal(|ui| {
ui.label(&format!("Public Key (Hex): {}", pkhex.as_str()));
if ui.add(CopyButton {}).clicked() {
ui.output().copied_text = pkhex.into_string();
ui.output_mut(|o| o.copied_text = pkhex.into_string());
}
});
@ -310,7 +310,7 @@ fn offer_import_pub_key(app: &mut GossipUi, ui: &mut Ui) {
ui.horizontal(|ui| {
ui.label(&format!("Public Key (bech32): {}", bech32));
if ui.add(CopyButton {}).clicked() {
ui.output().copied_text = bech32;
ui.output_mut(|o| o.copied_text = bech32);
}
});
}