Skip to content

Commit

Permalink
code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
aspect committed Dec 5, 2023
1 parent 7013776 commit a1c0c59
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 50 deletions.
8 changes: 6 additions & 2 deletions core/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,8 +648,12 @@ impl Core {
CoreWallet::AccountActivation { ids: _ } => {}
CoreWallet::AccountCreation { descriptor } => {
let account = Account::from(descriptor);
self.account_collection.as_mut().expect("account collection").push_unchecked(account.clone());
self.get_mut::<modules::AccountManager>().select(Some(account.clone()));
self.account_collection
.as_mut()
.expect("account collection")
.push_unchecked(account.clone());
self.get_mut::<modules::AccountManager>()
.select(Some(account.clone()));
self.select::<modules::AccountManager>();

let wallet = self.wallet().clone();
Expand Down
33 changes: 16 additions & 17 deletions core/src/egui/composite_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl<'a> Composite<'a> {
#[must_use = "You should put this widget in an ui with `ui.add(widget);`"]
pub struct CompositeButton<'a> {
image: Option<Composite<'a>>,
icon_size : Option<f32>,
icon_size: Option<f32>,
text: Option<WidgetText>,
secondary_text: Option<WidgetText>,
shortcut_text: WidgetText,
Expand Down Expand Up @@ -98,7 +98,7 @@ impl<'a> CompositeButton<'a> {
Self {
text,
image,
icon_size : None,
icon_size: None,
shortcut_text: Default::default(),
wrap: None,
fill: None,
Expand All @@ -121,14 +121,11 @@ impl<'a> CompositeButton<'a> {
self
}


pub fn icon_size(mut self, icon_size: f32) -> Self {
self.icon_size = Some(icon_size);
self
}



/// If `true`, the text will wrap to stay within the max width of the [`Ui`].
///
/// By default [`Self::wrap`] will be true in vertical layouts
Expand Down Expand Up @@ -259,14 +256,13 @@ impl Widget for CompositeButton<'_> {

let image_size = if let Some(image) = &image {
match image {
Composite::Image(image) => {
image
.load_and_calc_size(ui, space_available_for_image)
.unwrap_or(space_available_for_image)
}
Composite::Icon(_icon) => {
self.icon_size.map(|f|Vec2::splat(f)).unwrap_or(Vec2::splat(theme_style().composite_icon_size))
}
Composite::Image(image) => image
.load_and_calc_size(ui, space_available_for_image)
.unwrap_or(space_available_for_image),
Composite::Icon(_icon) => self
.icon_size
.map(|f| Vec2::splat(f))
.unwrap_or(Vec2::splat(theme_style().composite_icon_size)),
}
} else {
Vec2::ZERO
Expand Down Expand Up @@ -375,7 +371,6 @@ impl Widget for CompositeButton<'_> {
let mut cursor_x = rect.min.x + button_padding.x;

if let Some(image) = &image {

match image {
Composite::Image(image) => {
let image_rect = Rect::from_min_size(
Expand All @@ -395,14 +390,18 @@ impl Widget for CompositeButton<'_> {
response = texture_load_result_response(image.source(), &tlr, response);
}
Composite::Icon(icon) => {

let galley = WidgetText::RichText(icon.clone().size(image_size.y)).into_galley(ui, wrap, text_wrap_width, TextStyle::Button);
let galley = WidgetText::RichText(icon.clone().size(image_size.y))
.into_galley(ui, wrap, text_wrap_width, TextStyle::Button);
let image_rect = Rect::from_min_size(
pos2(cursor_x, rect.center().y - 0.5 - (galley.size().y / 2.0)),
galley.size(),
);
cursor_x += galley.size().x;
galley.paint_with_fallback_color(ui.painter(), image_rect.min, visuals.fg_stroke.color);
galley.paint_with_fallback_color(
ui.painter(),
image_rect.min,
visuals.fg_stroke.color,
);
}
}
}
Expand Down
1 change: 0 additions & 1 deletion core/src/egui/icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,3 @@ impl IconSize {
self.outer.y
}
}

2 changes: 1 addition & 1 deletion core/src/egui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod popup;
mod theme;

pub use collapsable::*;
pub use composite_button::{CompositeButton,Composite};
pub use composite_button::{Composite, CompositeButton};
pub use composite_icon::CompositeIcon;
pub use easy_mark::easy_mark;
pub use extensions::*;
Expand Down
4 changes: 2 additions & 2 deletions core/src/egui/theme/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl ThemeColor {
syncing_color: egui::Color32::from_rgb(255, 255, 136),
// connected_color: egui::Color32::from_rgb(144, 238, 144),
connected_color: egui::Color32::from_rgb(85, 233, 136),
icon_color_default: Color32::from_rgb(240,240,240),
icon_color_default: Color32::from_rgb(240, 240, 240),
ack_color: Color32::from_rgb(100, 200, 100),
nack_color: Color32::from_rgb(200, 100, 100),

Expand Down Expand Up @@ -141,7 +141,7 @@ impl ThemeColor {
warning_color: egui::Color32::from_rgb(77, 77, 41),
syncing_color: egui::Color32::from_rgb(76, 77, 41),
connected_color: egui::Color32::from_rgb(8, 110, 65),
icon_color_default: Color32::from_rgb(32,32,32),
icon_color_default: Color32::from_rgb(32, 32, 32),
ack_color: Color32::from_rgb(100, 200, 100),
nack_color: Color32::from_rgb(200, 100, 100),

Expand Down
1 change: 0 additions & 1 deletion core/src/egui/theme/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ pub fn apply_theme_style_by_name(ctx: &Context, theme_style_name: impl Into<Stri
}

pub fn apply_theme(ctx: &Context, theme: Theme) {

// generate_theme_icons(theme.color.icon_color_default.to_hex().as_str());

unsafe {
Expand Down
4 changes: 2 additions & 2 deletions core/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ pub use crate::modules::{Module, ModuleCaps, ModuleStyle, ModuleT};
pub use crate::network::Network;
pub use crate::notifications::{UserNotification, UserNotifyKind};
pub use crate::primitives::{
Account, AccountCollection, BlockDagGraphSettings, DaaBucket, DagBlock, Transaction,
TransactionCollection, AccountSelectorButtonExtension,
Account, AccountCollection, AccountSelectorButtonExtension, BlockDagGraphSettings, DaaBucket,
DagBlock, Transaction, TransactionCollection,
};
pub use crate::result::Result;
pub use crate::runtime::{runtime, spawn, spawn_with_result, Device, Payload, Runtime, Service};
Expand Down
32 changes: 21 additions & 11 deletions core/src/primitives/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ impl AccountContext {
pub fn uri(&self) -> String {
self.uri.clone()
}

}

struct Inner {
Expand Down Expand Up @@ -169,7 +168,6 @@ impl Account {

Ok(())
}

}

impl IdT for Account {
Expand Down Expand Up @@ -206,11 +204,21 @@ impl DescribeAccount for AccountKind {
}

pub trait AccountSelectorButtonExtension {
fn account_selector_button(&mut self, account: &Account, network_type: &NetworkType, selected : bool) -> Response;
fn account_selector_button(
&mut self,
account: &Account,
network_type: &NetworkType,
selected: bool,
) -> Response;
}

impl AccountSelectorButtonExtension for Ui {
fn account_selector_button(&mut self, account: &Account, network_type: &NetworkType, selected : bool) -> Response {
fn account_selector_button(
&mut self,
account: &Account,
network_type: &NetworkType,
selected: bool,
) -> Response {
let account_name = account.name_or_id();

let icon = if selected {
Expand All @@ -219,24 +227,26 @@ impl AccountSelectorButtonExtension for Ui {
Composite::icon(egui_phosphor::thin::LIST_DASHES)
};

let large_button_size = theme_style().large_button_size() + vec2(32.,0.);
let large_button_size = theme_style().large_button_size() + vec2(32., 0.);
if let Some(balance) = account.balance() {
let color = self.style().visuals.text_color();
self.add_sized(
large_button_size, CompositeButton::image_and_text(
large_button_size,
CompositeButton::image_and_text(
icon,
RichText::new(account_name).size(14.),
s2kws_layout_job(balance.mature, network_type, color,FontId::monospace(16.))
)
s2kws_layout_job(balance.mature, network_type, color, FontId::monospace(16.)),
),
)
} else {
self.add_sized(
large_button_size, CompositeButton::image_and_text(
large_button_size,
CompositeButton::image_and_text(
icon,
RichText::new(account_name).size(14.),
RichText::new("N/A").font(FontId::monospace(16.)),
)
),
)
}
}
}
}
1 change: 0 additions & 1 deletion core/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ impl<'core> Status<'core> {
}
});
}

});
}

Expand Down
58 changes: 46 additions & 12 deletions core/src/utils/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,43 @@ pub fn format_address(address: &Address, range: Option<usize>) -> String {
}

/// SOMPI (u64) to KASPA (string) with suffix layout job generator
pub fn s2kws_layout_job(sompi : u64, network_type: &NetworkType, color : Color32, font : FontId) -> LayoutJob {

pub fn s2kws_layout_job(
sompi: u64,
network_type: &NetworkType,
color: Color32,
font: FontId,
) -> LayoutJob {
let suffix = kaspa_suffix(network_type);
let style = Style::default();

let mut layout_job = LayoutJob::default();
if sompi == 0 {
let transparent = color.gamma_multiply(0.25);
let left = RichText::new("0.0").color(color).font(font.clone());
let right = RichText::new("0000000 ").color(transparent).font(font.clone());
let right = RichText::new("0000000 ")
.color(transparent)
.font(font.clone());
let suffix = RichText::new(suffix).color(color).font(font);
left.append_to(&mut layout_job, &style, FontSelection::Default, Align::Center);
right.append_to(&mut layout_job, &style, FontSelection::Default, Align::Center);
suffix.append_to(&mut layout_job, &style, FontSelection::Default, Align::Center);
left.append_to(
&mut layout_job,
&style,
FontSelection::Default,
Align::Center,
);
right.append_to(
&mut layout_job,
&style,
FontSelection::Default,
Align::Center,
);
suffix.append_to(
&mut layout_job,
&style,
FontSelection::Default,
Align::Center,
);
layout_job
} else {

let transparent = color.gamma_multiply(0.05);
let kas = sompi_to_kaspa_string_with_trailing_zeroes(sompi);
let mut digits = kas.chars().rev().take_while(|c| *c == '0').count();
Expand All @@ -68,10 +88,24 @@ pub fn s2kws_layout_job(sompi : u64, network_type: &NetworkType, color : Color32
let left = RichText::new(left).color(color).font(font.clone());
let right = RichText::new(right).color(transparent).font(font.clone());
let suffix = RichText::new(suffix).color(color).font(font);
left.append_to(&mut layout_job, &style, FontSelection::Default, Align::Center);
right.append_to(&mut layout_job, &style, FontSelection::Default, Align::Center);
suffix.append_to(&mut layout_job, &style, FontSelection::Default, Align::Center);
left.append_to(
&mut layout_job,
&style,
FontSelection::Default,
Align::Center,
);
right.append_to(
&mut layout_job,
&style,
FontSelection::Default,
Align::Center,
);
suffix.append_to(
&mut layout_job,
&style,
FontSelection::Default,
Align::Center,
);
layout_job
}

}

0 comments on commit a1c0c59

Please sign in to comment.