mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-29 00:11:01 +00:00
parent
995ef382cd
commit
78082ae23d
@ -1660,7 +1660,9 @@ impl GossipUi {
|
||||
|
||||
fn begin_ui(&self, ui: &mut Ui) {
|
||||
// if a dialog is open, disable the rest of the UI
|
||||
ui.set_enabled(self.enable_ui());
|
||||
if !self.enable_ui() {
|
||||
ui.disable();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn richtext_from_person_nip05(person: &Person) -> RichText {
|
||||
@ -2020,7 +2022,8 @@ impl GossipUi {
|
||||
|
||||
fn open_menu(&mut self, ctx: &Context, item: SubMenu) {
|
||||
for (submenu, id) in self.submenu_ids.iter() {
|
||||
let mut cstate = egui::collapsing_header::CollapsingState::load_with_default_open(ctx, *id, false);
|
||||
let mut cstate =
|
||||
egui::collapsing_header::CollapsingState::load_with_default_open(ctx, *id, false);
|
||||
if item == SubMenu::Feeds || *submenu != SubMenu::Feeds {
|
||||
cstate.set_open(*submenu == item);
|
||||
}
|
||||
@ -2030,7 +2033,8 @@ impl GossipUi {
|
||||
|
||||
fn close_all_menus_except_feeds(&mut self, ctx: &Context) {
|
||||
for (submenu, id) in self.submenu_ids.iter() {
|
||||
let mut cstate = egui::collapsing_header::CollapsingState::load_with_default_open(ctx, *id, false);
|
||||
let mut cstate =
|
||||
egui::collapsing_header::CollapsingState::load_with_default_open(ctx, *id, false);
|
||||
if *submenu != SubMenu::Feeds {
|
||||
cstate.set_open(false);
|
||||
}
|
||||
@ -2044,8 +2048,11 @@ impl GossipUi {
|
||||
ctx: &Context,
|
||||
submenu: SubMenu,
|
||||
) -> (egui::collapsing_header::CollapsingState, Response) {
|
||||
let mut cstate =
|
||||
egui::collapsing_header::CollapsingState::load_with_default_open(ctx, self.submenu_ids[&submenu], false);
|
||||
let mut cstate = egui::collapsing_header::CollapsingState::load_with_default_open(
|
||||
ctx,
|
||||
self.submenu_ids[&submenu],
|
||||
false,
|
||||
);
|
||||
let open = cstate.is_open();
|
||||
let txt = if open {
|
||||
submenu.to_string() + " \u{25BE}"
|
||||
|
@ -134,7 +134,9 @@ pub(super) fn update(
|
||||
});
|
||||
});
|
||||
|
||||
ui.set_enabled(enabled);
|
||||
if !enabled {
|
||||
ui.disable();
|
||||
}
|
||||
|
||||
ui.add_space(5.0);
|
||||
|
||||
|
@ -33,7 +33,9 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
|
||||
});
|
||||
});
|
||||
|
||||
ui.set_enabled(enabled);
|
||||
if !enabled {
|
||||
ui.disable();
|
||||
}
|
||||
|
||||
let mut all_lists = GLOBALS
|
||||
.storage
|
||||
|
@ -462,7 +462,7 @@ fn content(app: &mut GossipUi, ctx: &Context, ui: &mut Ui, pubkey: PublicKey, pe
|
||||
|
||||
// Right column, starting with avatar
|
||||
ui.allocate_ui_with_layout(
|
||||
vec2(AVATAR_COL_WIDTH, f32::INFINITY),
|
||||
vec2(AVATAR_COL_WIDTH, ui.ctx().available_rect().height()),
|
||||
egui::Layout::right_to_left(egui::Align::TOP).with_main_justify(true),
|
||||
|ui| {
|
||||
ui.vertical(|ui| {
|
||||
@ -705,8 +705,8 @@ fn profile_item_frame(
|
||||
.response
|
||||
};
|
||||
|
||||
let frame_rect = (prepared.frame.inner_margin + prepared.frame.outer_margin)
|
||||
.expand_rect(prepared.content_ui.min_rect());
|
||||
let frame_rect = prepared.content_ui.min_rect()
|
||||
+ (prepared.frame.inner_margin + prepared.frame.outer_margin);
|
||||
|
||||
let response = ui
|
||||
.interact(frame_rect, ui.auto_id_with(&label), egui::Sense::click())
|
||||
|
@ -13,7 +13,9 @@ use nostr_types::RelayUrl;
|
||||
pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Frame, ui: &mut Ui) {
|
||||
let is_editing = app.relays.edit.is_some();
|
||||
widgets::page_header(ui, Page::RelaysActivityMonitor.name(), |ui| {
|
||||
ui.set_enabled(!is_editing);
|
||||
if is_editing {
|
||||
ui.disable();
|
||||
}
|
||||
super::configure_list_btn(app, ui);
|
||||
btn_h_space!(ui);
|
||||
super::relay_filter_combo(app, ui);
|
||||
|
@ -9,7 +9,9 @@ use gossip_lib::GLOBALS;
|
||||
pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Frame, ui: &mut Ui) {
|
||||
let is_editing = app.relays.edit.is_some();
|
||||
widgets::page_header(ui, Page::RelaysKnownNetwork(None).name(), |ui| {
|
||||
ui.set_enabled(!is_editing);
|
||||
if is_editing {
|
||||
ui.disable();
|
||||
}
|
||||
super::configure_list_btn(app, ui);
|
||||
btn_h_space!(ui);
|
||||
super::relay_filter_combo(app, ui);
|
||||
|
@ -11,7 +11,9 @@ use std::sync::atomic::Ordering;
|
||||
pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Frame, ui: &mut Ui) {
|
||||
let is_editing = app.relays.edit.is_some();
|
||||
widgets::page_header(ui, Page::RelaysMine.name(), |ui| {
|
||||
ui.set_enabled(!is_editing);
|
||||
if is_editing {
|
||||
ui.disable();
|
||||
}
|
||||
super::configure_list_btn(app, ui);
|
||||
btn_h_space!(ui);
|
||||
super::relay_filter_combo(app, ui);
|
||||
|
@ -8,7 +8,6 @@ use eframe::egui::{
|
||||
use eframe::epaint::{ecolor, Color32, FontFamily, FontId, Rounding, Shadow};
|
||||
use egui_winit::egui::style::{HandleShape, NumericColorSpace};
|
||||
use std::collections::BTreeMap;
|
||||
use usvg::Text;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct DefaultTheme {}
|
||||
|
@ -414,7 +414,7 @@ fn textedit_test(app: &mut GossipUi, ui: &mut Ui) {
|
||||
ui.add_space(20.0);
|
||||
ui.horizontal(|ui| {
|
||||
ui.add_sized(CSIZE, egui::Label::new("Disabled"));
|
||||
ui.set_enabled(false);
|
||||
ui.disable();
|
||||
ui.add_space(20.0);
|
||||
ui.vertical(|ui| {
|
||||
widgets::TextEdit::singleline(theme, &mut app.theme_test.textedit_empty)
|
||||
@ -477,7 +477,7 @@ fn switch_test(app: &mut GossipUi, ui: &mut Ui) {
|
||||
ui.add_space(20.0);
|
||||
ui.horizontal(|ui| {
|
||||
ui.add_sized(CSIZE, egui::Label::new("Disabled"));
|
||||
ui.set_enabled(false);
|
||||
ui.disable();
|
||||
ui.add_space(20.0);
|
||||
ui.vertical(|ui| {
|
||||
ui.horizontal(|ui| {
|
||||
|
@ -74,9 +74,8 @@ pub(in crate::ui) fn show_contact_search(
|
||||
prepared.content_ui.set_max_width(super::TAGG_WIDTH);
|
||||
prepared.content_ui.set_min_height(27.0);
|
||||
|
||||
let frame_rect = (prepared.frame.inner_margin
|
||||
+ prepared.frame.outer_margin)
|
||||
.expand_rect(prepared.content_ui.min_rect());
|
||||
let frame_rect = prepared.content_ui.min_rect()
|
||||
+ (prepared.frame.inner_margin + prepared.frame.outer_margin);
|
||||
|
||||
let response = ui
|
||||
.interact(
|
||||
|
@ -3,7 +3,7 @@ use eframe::{
|
||||
epaint::{self, ColorMode, PathStroke},
|
||||
};
|
||||
use egui::{Color32, Pos2, Response, Sense, Shape, Ui, Vec2, Widget};
|
||||
use epaint::{PathShape, Stroke};
|
||||
use epaint::PathShape;
|
||||
|
||||
pub const COPY_SYMBOL_SIZE: Vec2 = Vec2::new(12.0, 12.0);
|
||||
|
||||
|
@ -66,7 +66,9 @@ impl<'a> MoreMenuButton<'a> {
|
||||
}
|
||||
|
||||
fn show(self, app: &mut GossipUi, ui: &mut Ui) -> Response {
|
||||
ui.set_enabled(self.enabled);
|
||||
if !self.enabled {
|
||||
ui.disable();
|
||||
}
|
||||
|
||||
let response = draw_menu_button(ui, &app.theme, self.text, None);
|
||||
|
||||
@ -132,7 +134,9 @@ impl<'a> MoreMenuSubMenu<'a> {
|
||||
}
|
||||
|
||||
fn show(self, app: &mut GossipUi, ui: &mut Ui) -> Response {
|
||||
ui.set_enabled(self.enabled);
|
||||
if !self.enabled {
|
||||
ui.disable();
|
||||
}
|
||||
|
||||
let mut open = load_state(ui, &self.id);
|
||||
|
||||
|
@ -16,6 +16,8 @@ use egui::*;
|
||||
#[must_use = "You should put this widget in an ui with `ui.add(widget);`"]
|
||||
pub struct NavItem {
|
||||
text: WidgetText,
|
||||
wrap: Option<bool>,
|
||||
truncate: bool,
|
||||
sense: Option<Sense>,
|
||||
color: Option<Color32>,
|
||||
active_color: Option<Color32>,
|
||||
@ -27,6 +29,8 @@ impl NavItem {
|
||||
pub fn new(text: impl Into<WidgetText>, active: bool) -> Self {
|
||||
Self {
|
||||
text: text.into(),
|
||||
wrap: None,
|
||||
truncate: false,
|
||||
sense: None,
|
||||
color: None,
|
||||
active_color: None,
|
||||
@ -56,6 +60,42 @@ impl NavItem {
|
||||
self
|
||||
}
|
||||
|
||||
/// If `true`, the text will wrap to stay within the max width of the [`Ui`].
|
||||
///
|
||||
/// Calling `wrap` will override [`Self::truncate`].
|
||||
///
|
||||
/// By default [`Self::wrap`] will be `true` in vertical layouts
|
||||
/// and horizontal layouts with wrapping,
|
||||
/// and `false` on non-wrapping horizontal layouts.
|
||||
///
|
||||
/// Note that any `\n` in the text will always produce a new line.
|
||||
///
|
||||
/// You can also use [`crate::Style::wrap`].
|
||||
#[inline]
|
||||
#[allow(unused)]
|
||||
pub fn wrap(mut self, wrap: bool) -> Self {
|
||||
self.wrap = Some(wrap);
|
||||
self.truncate = false;
|
||||
self
|
||||
}
|
||||
|
||||
/// If `true`, the text will stop at the max width of the [`Ui`],
|
||||
/// and what doesn't fit will be elided, replaced with `…`.
|
||||
///
|
||||
/// If the text is truncated, the full text will be shown on hover as a tool-tip.
|
||||
///
|
||||
/// Default is `false`, which means the text will expand the parent [`Ui`],
|
||||
/// or wrap if [`Self::wrap`] is set.
|
||||
///
|
||||
/// Calling `truncate` will override [`Self::wrap`].
|
||||
#[inline]
|
||||
#[allow(unused)]
|
||||
pub fn truncate(mut self, truncate: bool) -> Self {
|
||||
self.wrap = None;
|
||||
self.truncate = truncate;
|
||||
self
|
||||
}
|
||||
|
||||
/// Make the label respond to clicks and/or drags.
|
||||
///
|
||||
/// By default, a label is inert and does not respond to click or drags.
|
||||
@ -79,7 +119,15 @@ impl NavItem {
|
||||
impl NavItem {
|
||||
/// Do layout and position the galley in the ui, without painting it or adding widget info.
|
||||
pub fn layout_in_ui(self, ui: &mut Ui) -> (Pos2, Arc<Galley>, Response) {
|
||||
let sense = self.sense.unwrap_or(Sense::click());
|
||||
let sense = self.sense.unwrap_or_else(|| {
|
||||
if ui.memory(|mem| mem.options.screen_reader) {
|
||||
// We only want to focus labels if the screen reader is on.
|
||||
Sense::focusable_noninteractive()
|
||||
} else {
|
||||
Sense::hover()
|
||||
}
|
||||
});
|
||||
|
||||
if let WidgetText::Galley(galley) = self.text {
|
||||
// If the user said "use this specific galley", then just use it:
|
||||
let (rect, response) = ui.allocate_exact_size(galley.size(), sense);
|
||||
@ -92,14 +140,18 @@ impl NavItem {
|
||||
}
|
||||
|
||||
let valign = ui.layout().vertical_align();
|
||||
let mut job = self
|
||||
let mut layout_job = self
|
||||
.text
|
||||
.into_layout_job(ui.style(), FontSelection::Default, valign);
|
||||
|
||||
let should_wrap = ui.wrap_text();
|
||||
let truncate = self.truncate;
|
||||
let wrap = !truncate
|
||||
&& self
|
||||
.wrap
|
||||
.unwrap_or_else(|| ui.wrap_mode() == TextWrapMode::Wrap);
|
||||
let available_width = ui.available_width();
|
||||
|
||||
if should_wrap
|
||||
if wrap
|
||||
&& ui.layout().main_dir() == Direction::LeftToRight
|
||||
&& ui.layout().main_wrap()
|
||||
&& available_width.is_finite()
|
||||
@ -111,27 +163,17 @@ impl NavItem {
|
||||
let first_row_indentation = available_width - ui.available_size_before_wrap().x;
|
||||
debug_assert!(first_row_indentation.is_finite());
|
||||
|
||||
job.wrap.max_width = available_width;
|
||||
job.first_row_min_height = cursor.height();
|
||||
job.halign = Align::Min;
|
||||
job.justify = false;
|
||||
if let Some(first_section) = job.sections.first_mut() {
|
||||
layout_job.wrap.max_width = available_width;
|
||||
layout_job.first_row_min_height = cursor.height();
|
||||
layout_job.halign = Align::Min;
|
||||
layout_job.justify = false;
|
||||
if let Some(first_section) = layout_job.sections.first_mut() {
|
||||
first_section.leading_space = first_row_indentation;
|
||||
}
|
||||
let galley = ui.fonts(|f| f.layout_job(job));
|
||||
let galley = ui.fonts(|fonts| fonts.layout_job(layout_job));
|
||||
|
||||
let pos = pos2(ui.max_rect().left(), ui.cursor().top());
|
||||
assert!(!galley.rows.is_empty(), "Galleys are never empty");
|
||||
|
||||
// set the row height to ensure the cursor advancement is correct. when creating a child ui such as with
|
||||
// ui.horizontal_wrapped, the initial cursor will be set to the height of the child ui. this can lead
|
||||
// to the cursor not advancing to the second row but rather expanding the height of the cursor.
|
||||
//
|
||||
// note that we do not set the row height earlier in this function as we do want to allow populating
|
||||
// `first_row_min_height` above. however it is crucial the placer knows the actual row height by
|
||||
// setting the cursor height before ui.allocate_rect() gets called.
|
||||
ui.set_row_height(galley.rows[0].height());
|
||||
|
||||
// collect a response from many rows:
|
||||
let rect = galley.rows[0].rect.translate(vec2(pos.x, pos.y));
|
||||
let mut response = ui.allocate_rect(rect, sense);
|
||||
@ -141,23 +183,27 @@ impl NavItem {
|
||||
}
|
||||
(pos, galley, response)
|
||||
} else {
|
||||
if should_wrap {
|
||||
job.wrap.max_width = available_width;
|
||||
if truncate {
|
||||
layout_job.wrap.max_width = available_width;
|
||||
layout_job.wrap.max_rows = 1;
|
||||
layout_job.wrap.break_anywhere = true;
|
||||
} else if wrap {
|
||||
layout_job.wrap.max_width = available_width;
|
||||
} else {
|
||||
job.wrap.max_width = f32::INFINITY;
|
||||
layout_job.wrap.max_width = f32::INFINITY;
|
||||
};
|
||||
|
||||
job.halign = ui.layout().horizontal_placement();
|
||||
job.justify = ui.layout().horizontal_justify();
|
||||
layout_job.halign = ui.layout().horizontal_placement();
|
||||
layout_job.justify = ui.layout().horizontal_justify();
|
||||
|
||||
let galley = ui.fonts(|f| f.layout_job(job));
|
||||
let galley = ui.fonts(|fonts| fonts.layout_job(layout_job));
|
||||
let (rect, response) = ui.allocate_exact_size(galley.size(), sense);
|
||||
let pos = match galley.job.halign {
|
||||
let galley_pos = match galley.job.halign {
|
||||
Align::LEFT => rect.left_top(),
|
||||
Align::Center => rect.center_top(),
|
||||
Align::RIGHT => rect.right_top(),
|
||||
};
|
||||
(pos, galley, response)
|
||||
(galley_pos, galley, response)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user