mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-29 16:31:18 +00:00
Relay Lists: Add "reasons" string to compact view
This commit is contained in:
parent
ff6d0d5e93
commit
008d193994
@ -146,11 +146,23 @@ pub(super) fn relay_scroll_list(app: &mut GossipUi, ui: &mut Ui, relays: Vec<DbR
|
||||
db_relay // don't update
|
||||
};
|
||||
|
||||
// is this relay currently connected?
|
||||
let is_connected = if let Some(_) = GLOBALS.connected_relays.get(&db_url) {
|
||||
true
|
||||
// get details on this relay
|
||||
let (is_connected, reasons) = if let Some(entry) = GLOBALS.connected_relays.get(&db_url) {
|
||||
(
|
||||
true,
|
||||
entry.iter()
|
||||
.map(|rj| {
|
||||
if rj.persistent {
|
||||
format!("[{}]", rj.reason)
|
||||
} else {
|
||||
false
|
||||
rj.reason.to_string()
|
||||
}
|
||||
})
|
||||
.collect::<Vec<String>>()
|
||||
.join(", ")
|
||||
)
|
||||
} else {
|
||||
(false, "".into())
|
||||
};
|
||||
|
||||
let enabled = edit || !is_editing;
|
||||
@ -159,6 +171,7 @@ pub(super) fn relay_scroll_list(app: &mut GossipUi, ui: &mut Ui, relays: Vec<DbR
|
||||
widget.set_detail(false); // TODO obey settings
|
||||
widget.set_enabled(enabled);
|
||||
widget.set_connected(is_connected);
|
||||
widget.set_reasons(reasons);
|
||||
if let Some(ref assignment) = GLOBALS.relay_picker.get_relay_assignment(&db_url) {
|
||||
widget.set_user_count(assignment.pubkeys.len());
|
||||
}
|
||||
|
@ -140,6 +140,7 @@ pub struct RelayEntry {
|
||||
view: RelayEntryView,
|
||||
enabled: bool,
|
||||
connected: bool,
|
||||
reasons: String,
|
||||
user_count: Option<usize>,
|
||||
usage: UsageBits,
|
||||
accent: Color32,
|
||||
@ -160,6 +161,7 @@ impl RelayEntry {
|
||||
view: RelayEntryView::List,
|
||||
enabled: true,
|
||||
connected: false,
|
||||
reasons: "".into(),
|
||||
user_count: None,
|
||||
usage,
|
||||
accent,
|
||||
@ -193,6 +195,10 @@ impl RelayEntry {
|
||||
self.connected = connected;
|
||||
}
|
||||
|
||||
pub fn set_reasons(&mut self, reasons: String) {
|
||||
self.reasons = reasons;
|
||||
}
|
||||
|
||||
// pub fn view(&self) -> RelayEntryView {
|
||||
// self.view.clone()
|
||||
// }
|
||||
@ -441,12 +447,15 @@ impl RelayEntry {
|
||||
}
|
||||
|
||||
fn paint_usage(&self, ui: &mut Ui, rect: &Rect) {
|
||||
const RIGHT: f32 = -17.0;
|
||||
const SPACE: f32 = 23.0;
|
||||
|
||||
let right = match self.view {
|
||||
RelayEntryView::Detail => {
|
||||
pos2(rect.max.x, rect.min.y) + vec2(-TEXT_RIGHT, TEXT_TOP + 30.0)
|
||||
}
|
||||
_ => {
|
||||
pos2(rect.max.x, rect.min.y) + vec2(-TEXT_RIGHT -EDIT_BTN_SIZE - 10.0, TEXT_TOP + 4.0)
|
||||
pos2(rect.max.x, rect.min.y) + vec2(-TEXT_RIGHT -EDIT_BTN_SIZE -SPACE, TEXT_TOP + 4.0)
|
||||
}
|
||||
};
|
||||
|
||||
@ -468,8 +477,9 @@ impl RelayEntry {
|
||||
}
|
||||
}
|
||||
|
||||
const RIGHT: f32 = -17.0;
|
||||
const SPACE: f32 = 23.0;
|
||||
// ---- usage text ----
|
||||
let pos = right + vec2(RIGHT - 7.0 * SPACE, 0.0);
|
||||
draw_text_at(ui, pos, self.reasons.clone().into(), Align::RIGHT, Some(ui.visuals().text_color()), None);
|
||||
|
||||
// ---- R ----
|
||||
let pos = right + vec2(RIGHT - 5.0 * SPACE,0.0);
|
||||
|
Loading…
Reference in New Issue
Block a user