Debian Codegraph @

src/canvas/widgets/battery_display.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().;
2
3 use ratatuirust-analyzer cargo ratatui 0.30.2 crate/::{
4 Framerust-analyzer cargo ratatui-core 0.1.2 terminal/frame/Frame#,
5 layoutrust-analyzer cargo ratatui-core 0.1.2 layout/::{Constraintrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#, Directionrust-analyzer cargo ratatui-core 0.1.2 layout/direction/Direction#, Layoutrust-analyzer cargo ratatui-core 0.1.2 layout/layout/Layout#, Rectrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#},
6 symbolsrust-analyzer cargo ratatui-core 0.1.2 symbols/::{selfrust-analyzer cargo ratatui-core 0.1.2 symbols/, linerust-analyzer cargo ratatui-core 0.1.2 symbols/line/},
7 textrust-analyzer cargo ratatui-core 0.1.2 text/::{Linerust-analyzer cargo ratatui-core 0.1.2 text/line/Line#, Spanrust-analyzer cargo ratatui-core 0.1.2 text/span/Span#},
8 widgetsrust-analyzer cargo ratatui 0.30.2 widgets/::{Cellrust-analyzer cargo ratatui-widgets 0.3.2 table/cell/Cell#, Paragraphrust-analyzer cargo ratatui-widgets 0.3.2 paragraph/Paragraph#, Rowrust-analyzer cargo ratatui-widgets 0.3.2 table/row/Row#, Tablerust-analyzer cargo ratatui-widgets 0.3.2 table/Table#, Tabsrust-analyzer cargo ratatui-widgets 0.3.2 tabs/Tabs#},
9 };
10 use unicode_widthrust-analyzer cargo unicode-width 0.2.2 crate/::UnicodeWidthStrrust-analyzer cargo unicode-width 0.2.2 UnicodeWidthStr#;
11
12 use craterust-analyzer cargo bottom 0.14.9 crate/::{
13 apprust-analyzer cargo bottom 0.14.9 app/::Apprust-analyzer cargo bottom 0.14.9 app/App#,
14 canvasrust-analyzer cargo bottom 0.14.9 canvas/::{Painterrust-analyzer cargo bottom 0.14.9 canvas/Painter#, drawing_utilsrust-analyzer cargo bottom 0.14.9 canvas/drawing_utils/::widget_blockrust-analyzer cargo bottom 0.14.9 canvas/drawing_utils/widget_block().},
15 collectionrust-analyzer cargo bottom 0.14.9 collection/::batteriesrust-analyzer cargo bottom 0.14.9 collection/batteries/::BatteryStaterust-analyzer cargo bottom 0.14.9 collection/batteries/BatteryState#,
16 constantsrust-analyzer cargo bottom 0.14.9 constants/::*,
17 optionsrust-analyzer cargo bottom 0.14.9 options/::configrust-analyzer cargo bottom 0.14.9 options/config/::flagsrust-analyzer cargo bottom 0.14.9 options/config/flags/::TableGaprust-analyzer cargo bottom 0.14.9 options/config/flags/TableGap#,
18 };
19
20 /// Calculate how many bars are to be drawn within basic mode's components.
21 fn calculate_basic_use_barsrust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/calculate_basic_use_bars().(use_percentage: f64, num_bars_available: usize) -> usize {
22 minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().(
23 (num_bars_available as f64 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().use_percentage rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div().100.0).roundrust-analyzer cargo std https://github.com/rust-lang/rust/library/std f64/impl#[f64]round().() as usize,
24 num_bars_available,
25 )
26 }
27
28 impl Painterrust-analyzer cargo bottom 0.14.9 canvas/Painter# {
29 pub fn draw_batteryrust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/impl#[Painter]draw_battery().(
30 &self, f: &mut Framerust-analyzer cargo ratatui-core 0.1.2 terminal/frame/Frame#<'_>, app_state: &mut Apprust-analyzer cargo bottom 0.14.9 app/App#, draw_loc: Rectrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#, widget_id: u64,
31 ) {
32 let should_get_widget_bounds = app_state.should_get_widget_boundsrust-analyzer cargo bottom 0.14.9 app/impl#[App]should_get_widget_bounds().();
33 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(battery_widget_state) = app_state
34 .statesrust-analyzer cargo bottom 0.14.9 app/App#states.
35 .battery_staterust-analyzer cargo bottom 0.14.9 app/states/AppWidgetStates#battery_state.
36 .widget_statesrust-analyzer cargo bottom 0.14.9 app/states/AppBatteryState#widget_states.
37 .get_mutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get_mut().(&widget_id)
38 {
39 let is_selected = widget_id rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq().app_state.current_widgetrust-analyzer cargo bottom 0.14.9 app/App#current_widget..widget_idrust-analyzer cargo bottom 0.14.9 app/layout_manager/BottomWidget#widget_id.;
40 let border_style = if is_selected {
41 self.stylesrust-analyzer cargo bottom 0.14.9 canvas/Painter#styles..highlighted_border_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#highlighted_border_style.
42 } else {
43 self.stylesrust-analyzer cargo bottom 0.14.9 canvas/Painter#styles..border_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#border_style.
44 };
45 let table_gap_setting = app_state.app_config_fieldsrust-analyzer cargo bottom 0.14.9 app/App#app_config_fields..table_gaprust-analyzer cargo bottom 0.14.9 app/AppConfigFields#table_gap.;
46 let table_gap = if draw_loc.heightrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#height. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]lt().TABLE_GAP_HEIGHT_LIMITrust-analyzer cargo bottom 0.14.9 constants/TABLE_GAP_HEIGHT_LIMIT. {
47 0
48 } else {
49 table_gap_setting.heightrust-analyzer cargo bottom 0.14.9 options/config/flags/impl#[TableGap]height().()
50 };
51
52 let block = {
53 let mut block = widget_blockrust-analyzer cargo bottom 0.14.9 canvas/drawing_utils/widget_block().(
54 app_state.app_config_fieldsrust-analyzer cargo bottom 0.14.9 app/App#app_config_fields..use_basic_moderust-analyzer cargo bottom 0.14.9 app/AppConfigFields#use_basic_mode.,
55 is_selected,
56 self.stylesrust-analyzer cargo bottom 0.14.9 canvas/Painter#styles..border_typerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#border_type.,
57 self.stylesrust-analyzer cargo bottom 0.14.9 canvas/Painter#styles..general_widget_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#general_widget_style.,
58 )
59 .border_stylerust-analyzer cargo ratatui-widgets 0.3.2 block/impl#[`Block<'a>`]border_style().(border_style)
60 .title_toprust-analyzer cargo ratatui-widgets 0.3.2 block/impl#[`Block<'a>`]title_top().(Linerust-analyzer cargo ratatui-core 0.1.2 text/line/Line#::styledrust-analyzer cargo ratatui-core 0.1.2 text/line/impl#[`Line<'a>`]styled().(" Battery ", self.stylesrust-analyzer cargo bottom 0.14.9 canvas/Painter#styles..widget_title_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#widget_title_style.));
61
62 if app_state.is_expandedrust-analyzer cargo bottom 0.14.9 app/App#is_expanded. {
63 block = block.title_toprust-analyzer cargo ratatui-widgets 0.3.2 block/impl#[`Block<'a>`]title_top().(
64 Linerust-analyzer cargo ratatui-core 0.1.2 text/line/Line#::styledrust-analyzer cargo ratatui-core 0.1.2 text/line/impl#[`Line<'a>`]styled().(" Esc to go back ", self.stylesrust-analyzer cargo bottom 0.14.9 canvas/Painter#styles..widget_title_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#widget_title_style.)
65 .right_alignedrust-analyzer cargo ratatui-core 0.1.2 text/line/impl#[`Line<'a>`]right_aligned().(),
66 )
67 }
68
69 block
70 };
71
72 let battery_harvest = &(app_state.data_storerust-analyzer cargo bottom 0.14.9 app/App#data_store..get_datarust-analyzer cargo bottom 0.14.9 app/data/store/impl#[DataStore]get_data().().battery_harvestrust-analyzer cargo bottom 0.14.9 app/data/store/InnerData#battery_harvest.);
73 if battery_harvest.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().1 {
74 let battery_names = battery_harvest
75 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
76 .enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().()
77 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(itx, _)| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Battery {itx}"))
78 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>();
79
80 let tab_draw_loc = Layoutrust-analyzer cargo ratatui-core 0.1.2 layout/layout/Layout#::defaultrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout][Default]default().()
81 .constraintsrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout]constraints().([
82 Constraintrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#::Lengthrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#Length#(1),
83 Constraintrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#::Lengthrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#Length#(2),
84 Constraintrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#::Minrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#Min#(0),
85 ])
86 .directionrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout]direction().(Directionrust-analyzer cargo ratatui-core 0.1.2 layout/direction/Direction#::Verticalrust-analyzer cargo ratatui-core 0.1.2 layout/direction/Direction#Vertical#)
87 .splitrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout]split().(draw_loc)[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().;
88
89 f.render_widgetrust-analyzer cargo ratatui-core 0.1.2 terminal/frame/impl#[`Frame<'_>`]render_widget().(
90 Tabsrust-analyzer cargo ratatui-widgets 0.3.2 tabs/Tabs#::newrust-analyzer cargo ratatui-widgets 0.3.2 tabs/impl#[`Tabs<'a>`]new().(
91 battery_names
92 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
93 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|name| Linerust-analyzer cargo ratatui-core 0.1.2 text/line/Line#::fromrust-analyzer cargo ratatui-core 0.1.2 text/line/impl#[`Line<'_>`][`From<String>`]from().((*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().name).clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().()))
94 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(),
95 )
96 .dividerrust-analyzer cargo ratatui-widgets 0.3.2 tabs/impl#[`Tabs<'a>`]divider().(symbolsrust-analyzer cargo ratatui-core 0.1.2 symbols/::linerust-analyzer cargo ratatui-core 0.1.2 symbols/line/::VERTICALrust-analyzer cargo ratatui-core 0.1.2 symbols/line/VERTICAL.)
97 .stylerust-analyzer cargo ratatui-widgets 0.3.2 tabs/impl#[`Tabs<'a>`]style().(self.stylesrust-analyzer cargo bottom 0.14.9 canvas/Painter#styles..text_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#text_style.)
98 .highlight_stylerust-analyzer cargo ratatui-widgets 0.3.2 tabs/impl#[`Tabs<'a>`]highlight_style().(self.stylesrust-analyzer cargo bottom 0.14.9 canvas/Painter#styles..selected_text_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#selected_text_style.)
99 .selectrust-analyzer cargo ratatui-widgets 0.3.2 tabs/impl#[`Tabs<'a>`]select().(battery_widget_state.currently_selected_battery_indexrust-analyzer cargo bottom 0.14.9 widgets/battery_info/BatteryWidgetState#currently_selected_battery_index.),
100 tab_draw_loc,
101 );
102
103 if should_get_widget_bounds {
104 let mut current_x = tab_draw_loc.xrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#x.;
105 let current_y = tab_draw_loc.yrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#y.;
106 let mut tab_click_locs: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<((u16, u16), (u16, u16))> = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![];
107 for battery in battery_names {
108 // +1 because there's a space after the tab label.
109 let width = UnicodeWidthStrrust-analyzer cargo unicode-width 0.2.2 UnicodeWidthStr#::widthrust-analyzer cargo unicode-width 0.2.2 impl#[str][UnicodeWidthStr]width().(battery.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().()) as u16;
110 tab_click_locs
111 .pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(((current_x, current_y), (current_x rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().width, current_y)));
112
113 // +4 because we want to go one space, then one space past to get to the
114 // '|', then 2 more to start at the blank space
115 // before the tab label.
116 current_x rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`AddAssign<Self>`]add_assign().width rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().4;
117 }
118 battery_widget_state.tab_click_locsrust-analyzer cargo bottom 0.14.9 widgets/battery_info/BatteryWidgetState#tab_click_locs. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(tab_click_locs);
119 }
120 }
121
122 let is_basic = app_state.app_config_fieldsrust-analyzer cargo bottom 0.14.9 app/App#app_config_fields..use_basic_moderust-analyzer cargo bottom 0.14.9 app/AppConfigFields#use_basic_mode.;
123
124 let [margined_draw_loc] = Layoutrust-analyzer cargo ratatui-core 0.1.2 layout/layout/Layout#::defaultrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout][Default]default().()
125 .constraintsrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout]constraints().([Constraintrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#::Percentagerust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#Percentage#(100)])
126 .horizontal_marginrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout]horizontal_margin().(u16::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u16][`From<bool>`]from().(is_basic && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_selected))
127 .directionrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout]direction().(Directionrust-analyzer cargo ratatui-core 0.1.2 layout/direction/Direction#::Horizontalrust-analyzer cargo ratatui-core 0.1.2 layout/direction/Direction#Horizontal#)
128 .areasrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout]areas().(draw_loc);
129
130 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(battery_details) =
131 battery_harvest.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(battery_widget_state.currently_selected_battery_indexrust-analyzer cargo bottom 0.14.9 widgets/battery_info/BatteryWidgetState#currently_selected_battery_index.)
132 {
133 let full_width = draw_loc.widthrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#width..saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]saturating_sub().(2);
134 let bar_length = usize::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`From<u16>`]from().(full_width.saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]saturating_sub().(6));
135 let charge_percent = battery_details.charge_percentrust-analyzer cargo bottom 0.14.9 collection/batteries/BatteryData#charge_percent.;
136
137 let num_bars = calculate_basic_use_barsrust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/calculate_basic_use_bars().(charge_percent, bar_length);
138 let bars = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
139 "[{}{}{:3.0}%]",
140 "|".repeatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]repeat().(num_bars),
141 " ".repeatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]repeat().(bar_length -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). num_bars),
142 charge_percent,
143 );
144
145 let mut battery_charge_rows = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(2);
146 battery_charge_rows.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Rowrust-analyzer cargo ratatui-widgets 0.3.2 table/row/Row#::newrust-analyzer cargo ratatui-widgets 0.3.2 table/row/impl#[`Row<'a>`]new().([
147 Cellrust-analyzer cargo ratatui-widgets 0.3.2 table/cell/Cell#::fromrust-analyzer cargo ratatui-widgets 0.3.2 table/cell/impl#[`Cell<'a>`][`From<T>`]from().("Charge").stylerust-analyzer cargo ratatui-widgets 0.3.2 table/cell/impl#[`Cell<'a>`]style().(self.stylesrust-analyzer cargo bottom 0.14.9 canvas/Painter#styles..text_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#text_style.)
148 ]));
149 battery_charge_rows.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Rowrust-analyzer cargo ratatui-widgets 0.3.2 table/row/Row#::newrust-analyzer cargo ratatui-widgets 0.3.2 table/row/impl#[`Row<'a>`]new().([Cellrust-analyzer cargo ratatui-widgets 0.3.2 table/cell/Cell#::fromrust-analyzer cargo ratatui-widgets 0.3.2 table/cell/impl#[`Cell<'a>`][`From<T>`]from().(bars).stylerust-analyzer cargo ratatui-widgets 0.3.2 table/cell/impl#[`Cell<'a>`]style().(
150 if charge_percent rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]lt().10.0 {
151 self.stylesrust-analyzer cargo bottom 0.14.9 canvas/Painter#styles..low_batteryrust-analyzer cargo bottom 0.14.9 options/config/style/Styles#low_battery.
152 } else if charge_percent rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]lt().50.0 {
153 self.stylesrust-analyzer cargo bottom 0.14.9 canvas/Painter#styles..medium_batteryrust-analyzer cargo bottom 0.14.9 options/config/style/Styles#medium_battery.
154 } else {
155 self.stylesrust-analyzer cargo bottom 0.14.9 canvas/Painter#styles..high_batteryrust-analyzer cargo bottom 0.14.9 options/config/style/Styles#high_battery.
156 },
157 )]));
158
159 let mut battery_rows = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(3);
160 let watt_consumption = battery_details.watt_consumptionrust-analyzer cargo bottom 0.14.9 collection/batteries/impl#[BatteryData]watt_consumption().();
161 let health = battery_details.healthrust-analyzer cargo bottom 0.14.9 collection/batteries/impl#[BatteryData]health().();
162
163 battery_rows.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Rowrust-analyzer cargo ratatui-widgets 0.3.2 table/row/Row#::newrust-analyzer cargo ratatui-widgets 0.3.2 table/row/impl#[`Row<'a>`]new().([""]).bottom_marginrust-analyzer cargo ratatui-widgets 0.3.2 table/row/impl#[`Row<'a>`]bottom_margin().(table_gap rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().1));
164 battery_rows
165 .pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Rowrust-analyzer cargo ratatui-widgets 0.3.2 table/row/Row#::newrust-analyzer cargo ratatui-widgets 0.3.2 table/row/impl#[`Row<'a>`]new().(["Rate", &watt_consumption]).stylerust-analyzer cargo ratatui-widgets 0.3.2 table/row/impl#[`Row<'a>`]style().(self.stylesrust-analyzer cargo bottom 0.14.9 canvas/Painter#styles..text_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#text_style.));
166
167 battery_rows.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(
168 Rowrust-analyzer cargo ratatui-widgets 0.3.2 table/row/Row#::newrust-analyzer cargo ratatui-widgets 0.3.2 table/row/impl#[`Row<'a>`]new().(["State", battery_details.staterust-analyzer cargo bottom 0.14.9 collection/batteries/BatteryData#state..as_strrust-analyzer cargo bottom 0.14.9 collection/batteries/impl#[BatteryState]as_str().()])
169 .stylerust-analyzer cargo ratatui-widgets 0.3.2 table/row/impl#[`Row<'a>`]style().(self.stylesrust-analyzer cargo bottom 0.14.9 canvas/Painter#styles..text_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#text_style.),
170 );
171
172 let mut time: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#; // Keep string lifetime in scope.
173 {
174 let style = self.stylesrust-analyzer cargo bottom 0.14.9 canvas/Painter#styles..text_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#text_style.;
175 let time_width = (full_width rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Div<Self>`]div().2) as usize;
176
177 match &battery_details.staterust-analyzer cargo bottom 0.14.9 collection/batteries/BatteryData#state. {
178 BatteryStaterust-analyzer cargo bottom 0.14.9 collection/batteries/BatteryState#::Chargingrust-analyzer cargo bottom 0.14.9 collection/batteries/BatteryState#Charging# {
179 time_to_fullrust-analyzer cargo bottom 0.14.9 collection/batteries/BatteryState#Charging#time_to_full.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(secs),
180 } => {
181 time = long_timerust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/long_time().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().secs);
182
183 if time_width rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().time.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]len().() {
184 battery_rows.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Rowrust-analyzer cargo ratatui-widgets 0.3.2 table/row/Row#::newrust-analyzer cargo ratatui-widgets 0.3.2 table/row/impl#[`Row<'a>`]new().(["Time to full", &time]).stylerust-analyzer cargo ratatui-widgets 0.3.2 table/row/impl#[`Row<'a>`]style().(style));
185 } else {
186 time = short_timerust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/short_time().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().secs);
187 battery_rows.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Rowrust-analyzer cargo ratatui-widgets 0.3.2 table/row/Row#::newrust-analyzer cargo ratatui-widgets 0.3.2 table/row/impl#[`Row<'a>`]new().(["To full", &time]).stylerust-analyzer cargo ratatui-widgets 0.3.2 table/row/impl#[`Row<'a>`]style().(style));
188 }
189 }
190 BatteryStaterust-analyzer cargo bottom 0.14.9 collection/batteries/BatteryState#::Dischargingrust-analyzer cargo bottom 0.14.9 collection/batteries/BatteryState#Discharging# {
191 time_to_emptyrust-analyzer cargo bottom 0.14.9 collection/batteries/BatteryState#Discharging#time_to_empty.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(secs),
192 } => {
193 time = long_timerust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/long_time().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().secs);
194
195 if time_width rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().time.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]len().() {
196 battery_rows.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Rowrust-analyzer cargo ratatui-widgets 0.3.2 table/row/Row#::newrust-analyzer cargo ratatui-widgets 0.3.2 table/row/impl#[`Row<'a>`]new().(["Time to empty", &time]).stylerust-analyzer cargo ratatui-widgets 0.3.2 table/row/impl#[`Row<'a>`]style().(style));
197 } else {
198 time = short_timerust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/short_time().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().secs);
199 battery_rows.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Rowrust-analyzer cargo ratatui-widgets 0.3.2 table/row/Row#::newrust-analyzer cargo ratatui-widgets 0.3.2 table/row/impl#[`Row<'a>`]new().(["To empty", &time]).stylerust-analyzer cargo ratatui-widgets 0.3.2 table/row/impl#[`Row<'a>`]style().(style));
200 }
201 }
202 _ => {}
203 }
204 }
205
206 battery_rows.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Rowrust-analyzer cargo ratatui-widgets 0.3.2 table/row/Row#::newrust-analyzer cargo ratatui-widgets 0.3.2 table/row/impl#[`Row<'a>`]new().(["Health", &health]).stylerust-analyzer cargo ratatui-widgets 0.3.2 table/row/impl#[`Row<'a>`]style().(self.stylesrust-analyzer cargo bottom 0.14.9 canvas/Painter#styles..text_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#text_style.));
207
208 let header = if battery_harvest.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().1 {
209 Rowrust-analyzer cargo ratatui-widgets 0.3.2 table/row/Row#::newrust-analyzer cargo ratatui-widgets 0.3.2 table/row/impl#[`Row<'a>`]new().([""]).bottom_marginrust-analyzer cargo ratatui-widgets 0.3.2 table/row/impl#[`Row<'a>`]bottom_margin().(table_gap)
210 } else {
211 Rowrust-analyzer cargo ratatui-widgets 0.3.2 table/row/Row#::defaultrust-analyzer cargo ratatui-widgets 0.3.2 table/row/impl#[`Row<'a>`][Default]default().()
212 };
213
214 let block_inner = block.innerrust-analyzer cargo ratatui-widgets 0.3.2 block/impl#[`Block<'a>`]inner().(margined_draw_loc);
215
216 // Draw bar
217 f.render_widgetrust-analyzer cargo ratatui-core 0.1.2 terminal/frame/impl#[`Frame<'_>`]render_widget().(
218 Tablerust-analyzer cargo ratatui-widgets 0.3.2 table/Table#::newrust-analyzer cargo ratatui-widgets 0.3.2 table/impl#[`Table<'a>`]new().(battery_charge_rows, [Constraintrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#::Percentagerust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#Percentage#(100)])
219 .blockrust-analyzer cargo ratatui-widgets 0.3.2 table/impl#[`Table<'a>`]block().(block.clonerust-analyzer cargo ratatui-widgets 0.3.2 block/impl#[`Block<'a>`][Clone]clone().())
220 .headerrust-analyzer cargo ratatui-widgets 0.3.2 table/impl#[`Table<'a>`]header().(header.clonerust-analyzer cargo ratatui-widgets 0.3.2 table/row/impl#[`Row<'a>`][Clone]clone().()),
221 margined_draw_loc,
222 );
223
224 // Draw info
225 f.render_widgetrust-analyzer cargo ratatui-core 0.1.2 terminal/frame/impl#[`Frame<'_>`]render_widget().(
226 Tablerust-analyzer cargo ratatui-widgets 0.3.2 table/Table#::newrust-analyzer cargo ratatui-widgets 0.3.2 table/impl#[`Table<'a>`]new().(
227 battery_rows,
228 [Constraintrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#::Percentagerust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#Percentage#(50), Constraintrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#::Percentagerust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#Percentage#(50)],
229 )
230 .blockrust-analyzer cargo ratatui-widgets 0.3.2 table/impl#[`Table<'a>`]block().(block)
231 .headerrust-analyzer cargo ratatui-widgets 0.3.2 table/impl#[`Table<'a>`]header().(header),
232 margined_draw_loc,
233 );
234
235 if table_gap rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]gt().0 && table_gap_setting rust-analyzer cargo bottom 0.14.9 options/config/flags/impl#[TableGap][`PartialEq<Self>`]eq().==rust-analyzer cargo bottom 0.14.9 options/config/flags/impl#[TableGap][`PartialEq<Self>`]eq(). rust-analyzer cargo bottom 0.14.9 options/config/flags/impl#[TableGap][`PartialEq<Self>`]eq().TableGaprust-analyzer cargo bottom 0.14.9 options/config/flags/TableGap#::Linerust-analyzer cargo bottom 0.14.9 options/config/flags/TableGap#Line# && battery_harvest.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().1
236 {
237 let y = block_inner.yrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#y. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().1;
238 let buf = f.buffer_mutrust-analyzer cargo ratatui-core 0.1.2 terminal/frame/impl#[`Frame<'_>`]buffer_mut().();
239
240 for x in (margined_draw_loc.xrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#x. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().1)
241 ..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#(margined_draw_loc.xrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#x. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().margined_draw_loc.widthrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#width. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Sub<Self>`]sub().1)
242 {
243 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(cell) = buf.cell_mutrust-analyzer cargo ratatui-core 0.1.2 buffer/buffer/impl#[Buffer]cell_mut().((x, y)) {
244 cell.set_symbolrust-analyzer cargo ratatui-core 0.1.2 buffer/cell/impl#[Cell]set_symbol().(linerust-analyzer cargo ratatui-core 0.1.2 symbols/line/::NORMALrust-analyzer cargo ratatui-core 0.1.2 symbols/line/NORMAL..horizontalrust-analyzer cargo ratatui-core 0.1.2 symbols/line/Set#horizontal.);
245 cell.set_stylerust-analyzer cargo ratatui-core 0.1.2 buffer/cell/impl#[Cell]set_style().(border_style);
246 }
247 }
248
249 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_basic || is_selected {
250 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(cell) = buf.cell_mutrust-analyzer cargo ratatui-core 0.1.2 buffer/buffer/impl#[Buffer]cell_mut().((margined_draw_loc.xrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#x., y)) {
251 cell.set_symbolrust-analyzer cargo ratatui-core 0.1.2 buffer/cell/impl#[Cell]set_symbol().(linerust-analyzer cargo ratatui-core 0.1.2 symbols/line/::NORMALrust-analyzer cargo ratatui-core 0.1.2 symbols/line/NORMAL..vertical_rightrust-analyzer cargo ratatui-core 0.1.2 symbols/line/Set#vertical_right.);
252 cell.set_stylerust-analyzer cargo ratatui-core 0.1.2 buffer/cell/impl#[Cell]set_style().(border_style);
253 }
254
255 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(cell) =
256 buf.cell_mutrust-analyzer cargo ratatui-core 0.1.2 buffer/buffer/impl#[Buffer]cell_mut().((margined_draw_loc.xrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#x. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().margined_draw_loc.widthrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#width. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Sub<Self>`]sub().1, y))
257 {
258 cell.set_symbolrust-analyzer cargo ratatui-core 0.1.2 buffer/cell/impl#[Cell]set_symbol().(linerust-analyzer cargo ratatui-core 0.1.2 symbols/line/::NORMALrust-analyzer cargo ratatui-core 0.1.2 symbols/line/NORMAL..vertical_leftrust-analyzer cargo ratatui-core 0.1.2 symbols/line/Set#vertical_left.);
259 cell.set_stylerust-analyzer cargo ratatui-core 0.1.2 buffer/cell/impl#[Cell]set_style().(border_style);
260 }
261 }
262 }
263 } else {
264 let mut contents = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Linerust-analyzer cargo ratatui-core 0.1.2 text/line/Line#::defaultrust-analyzer cargo ratatui-core 0.1.2 text/line/impl#[`Line<'a>`][Default]default().(); table_gap.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()];
265
266 contents.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Linerust-analyzer cargo ratatui-core 0.1.2 text/line/Line#::fromrust-analyzer cargo ratatui-core 0.1.2 text/line/impl#[`Line<'a>`][`From<Span<'a>>`]from().(Spanrust-analyzer cargo ratatui-core 0.1.2 text/span/Span#::styledrust-analyzer cargo ratatui-core 0.1.2 text/span/impl#[`Span<'a>`]styled().(
267 "No data found for this battery",
268 self.stylesrust-analyzer cargo bottom 0.14.9 canvas/Painter#styles..text_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#text_style.,
269 )));
270
271 f.render_widgetrust-analyzer cargo ratatui-core 0.1.2 terminal/frame/impl#[`Frame<'_>`]render_widget().(Paragraphrust-analyzer cargo ratatui-widgets 0.3.2 paragraph/Paragraph#::newrust-analyzer cargo ratatui-widgets 0.3.2 paragraph/impl#[`Paragraph<'a>`]new().(contents).blockrust-analyzer cargo ratatui-widgets 0.3.2 paragraph/impl#[`Paragraph<'a>`]block().(block), margined_draw_loc);
272 }
273
274 if should_get_widget_bounds {
275 // Update draw loc in widget map
276 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(widget) = app_state.widget_maprust-analyzer cargo bottom 0.14.9 app/App#widget_map..get_mutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get_mut().(&widget_id) {
277 widget.top_left_cornerrust-analyzer cargo bottom 0.14.9 app/layout_manager/BottomWidget#top_left_corner. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((margined_draw_loc.xrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#x., margined_draw_loc.yrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#y.));
278 widget.bottom_right_cornerrust-analyzer cargo bottom 0.14.9 app/layout_manager/BottomWidget#bottom_right_corner. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((
279 margined_draw_loc.xrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#x. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().margined_draw_loc.widthrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#width.,
280 margined_draw_loc.yrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#y. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().margined_draw_loc.heightrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#height.,
281 ));
282 }
283 }
284 }
285 }
286 }
287
288 fn get_hmsrust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/get_hms().(secs: u32) -> (u32, u32, u32) {
289 let hours = secs rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div().(60 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().60);
290 let minutes = (secs rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div().60) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().hours rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().60;
291 let seconds = secs rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().minutes rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().60 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().hours rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().60 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().60;
292
293 (hours, minutes, seconds)
294 }
295
296 fn long_timerust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/long_time().(secs: u32) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
297 let (hours, minutes, seconds) = get_hmsrust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/get_hms().(secs);
298
299 if hours rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt().0 {
300 let h = if hours rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().1 { "hour" } else { "hours" };
301 let m = if minutes rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().1 { "minute" } else { "minutes" };
302 let s = if seconds rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().1 { "second" } else { "seconds" };
303
304 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{hours} {h}, {minutes} {m}, {seconds} {s}")
305 } else {
306 let m = if minutes rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().1 { "minute" } else { "minutes" };
307 let s = if seconds rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().1 { "second" } else { "seconds" };
308
309 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{minutes} {m}, {seconds} {s}")
310 }
311 }
312
313 fn short_timerust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/short_time().(secs: u32) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
314 let (hours, minutes, seconds) = get_hmsrust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/get_hms().(secs);
315
316 if hours rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt().0 {
317 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{hours}h {minutes}m {seconds}s")
318 } else {
319 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{minutes}m {seconds}s")
320 }
321 }
322
323 #[cfg(test)]
324 mod testsrust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/tests/ {
325 use superrust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/::*;
326
327 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
328 fn test_get_hmsrust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/tests/test_get_hms().() {
329 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(get_hmsrust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/get_hms().(10), (0, 0, 10));
330 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(get_hmsrust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/get_hms().(60), (0, 1, 0));
331 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(get_hmsrust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/get_hms().(61), (0, 1, 1));
332 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(get_hmsrust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/get_hms().(3600), (1, 0, 0));
333 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(get_hmsrust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/get_hms().(3601), (1, 0, 1));
334 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(get_hmsrust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/get_hms().(3661), (1, 1, 1));
335 }
336
337 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
338 fn test_long_timerust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/tests/test_long_time().() {
339 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(long_timerust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/long_time().(1), "0 minutes, 1 second".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
340 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(long_timerust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/long_time().(10), "0 minutes, 10 seconds".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
341 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(long_timerust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/long_time().(60), "1 minute, 0 seconds".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
342 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(long_timerust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/long_time().(61), "1 minute, 1 second".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
343 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(long_timerust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/long_time().(3600), "1 hour, 0 minutes, 0 seconds".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
344 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(long_timerust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/long_time().(3601), "1 hour, 0 minutes, 1 second".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
345 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(long_timerust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/long_time().(3661), "1 hour, 1 minute, 1 second".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
346 }
347
348 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
349 fn test_short_timerust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/tests/test_short_time().() {
350 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(short_timerust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/short_time().(1), "0m 1s".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
351 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(short_timerust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/short_time().(10), "0m 10s".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
352 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(short_timerust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/short_time().(60), "1m 0s".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
353 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(short_timerust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/short_time().(61), "1m 1s".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
354 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(short_timerust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/short_time().(3600), "1h 0m 0s".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
355 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(short_timerust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/short_time().(3601), "1h 0m 1s".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
356 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(short_timerust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/short_time().(3661), "1h 1m 1s".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
357 }
358
359 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
360 fn test_calculate_basic_use_barsrust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/tests/test_calculate_basic_use_bars().() {
361 // Testing various breakpoints and edge cases.
362 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(calculate_basic_use_barsrust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/calculate_basic_use_bars().(0.0, 15), 0);
363 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(calculate_basic_use_barsrust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/calculate_basic_use_bars().(1.0, 15), 0);
364 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(calculate_basic_use_barsrust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/calculate_basic_use_bars().(5.0, 15), 1);
365 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(calculate_basic_use_barsrust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/calculate_basic_use_bars().(10.0, 15), 2);
366 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(calculate_basic_use_barsrust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/calculate_basic_use_bars().(40.0, 15), 6);
367 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(calculate_basic_use_barsrust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/calculate_basic_use_bars().(45.0, 15), 7);
368 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(calculate_basic_use_barsrust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/calculate_basic_use_bars().(50.0, 15), 8);
369 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(calculate_basic_use_barsrust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/calculate_basic_use_bars().(100.0, 15), 15);
370 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(calculate_basic_use_barsrust-analyzer cargo bottom 0.14.9 canvas/widgets/battery_display/calculate_basic_use_bars().(150.0, 15), 15);
371 }
372 }