Skip to content

Commit

Permalink
Add max entries displayed for tracker tables
Browse files Browse the repository at this point in the history
  • Loading branch information
Zerthox committed May 8, 2023
1 parent 425c87c commit 59abc74
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "arcdps_food_reminder"
version = "0.6.1"
version = "0.6.2"
edition = "2021"
authors = ["Zerthox"]
repository = "https://github.com/zerthox/arcdps-food-reminder"
Expand Down
4 changes: 4 additions & 0 deletions src/tracking/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ pub struct TrackerSettings {
/// Whether to show the subgroup column.
pub show_sub: bool,

/// Amount of entries displayed before scrolling.
pub max_entries_displayed: usize,

/// Color for subgroup numbers.
pub color_sub: Color,

Expand All @@ -41,6 +44,7 @@ impl TrackerSettings {
hotkey: Some(Tracker::DEFAULT_HOTKEY),
show_icons: true,
show_sub: true,
max_entries_displayed: 10,
color_sub: Color::Sub,
color_name: Color::Prof,
}
Expand Down
36 changes: 31 additions & 5 deletions src/tracking/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ use arcdps::{
pub type Props<'p> = (&'p Definitions, &'p [CustomReminder]);

impl Tracker {
/// Calculates height for a table.
fn table_height(&self, ui: &Ui, row_count: usize) -> f32 {
let max = self.settings.max_entries_displayed;
if max > 0 {
let [_, pad] = ui.clone_style().cell_padding;
let row_size = ui.text_line_height() + 2.0 * pad;
(max.min(row_count) + 1) as f32 * row_size
} else {
0.0
}
}

/// Renders reset buttons for squad & characters.
pub fn render_reset_buttons(&mut self, ui: &Ui, same_line: bool) {
const SPACING: f32 = 5.0;
Expand Down Expand Up @@ -259,13 +271,19 @@ impl Tracker {
TableColumnFlags::NO_SORT,
),
];
let columns = if show_sub { &columns } else { &columns[1..] };

if let Some(_table) = render::table_with_icons(
if let Some(_table) = render::table_with_icons_sizing(
ui,
"##squad-table",
if show_sub { &columns } else { &columns[1..] },
TableFlags::SIZING_STRETCH_PROP | TableFlags::PAD_OUTER_X | TableFlags::SORTABLE,
columns,
TableFlags::SIZING_STRETCH_PROP
| TableFlags::PAD_OUTER_X
| TableFlags::SORTABLE
| TableFlags::SCROLL_Y,
self.settings.show_icons,
[0.0, self.table_height(ui, self.players.len())],
0.0,
) {
// update sorting if necessary
if let Some(sort_specs) = ui.table_sort_specs_mut() {
Expand Down Expand Up @@ -312,10 +330,11 @@ impl Tracker {
/// Renders the tracker tab for own characters.
fn render_characters_tab(&mut self, ui: &Ui, props: Props) {
let current = self.players.get_self();
let count = self.players.cache_len() + if current.is_some() { 1 } else { 0 };

if current.is_none() && !self.players.cached() {
ui.text("No characters found");
} else if let Some(_table) = render::table_with_icons(
} else if let Some(_table) = render::table_with_icons_sizing(
ui,
"##self-table",
&[
Expand All @@ -324,8 +343,10 @@ impl Tracker {
TableIconColumn::new("Util", UTIL_ICON.as_ref()),
TableIconColumn::new("Buffs", UNKNOWN_ICON.as_ref()),
],
TableFlags::SIZING_STRETCH_PROP | TableFlags::PAD_OUTER_X,
TableFlags::SIZING_STRETCH_PROP | TableFlags::PAD_OUTER_X | TableFlags::SCROLL_Y,
self.settings.show_icons,
[0.0, self.table_height(ui, count)],
0.0,
) {
// render table content
let colors = exports::colors();
Expand Down Expand Up @@ -421,6 +442,11 @@ impl Windowable<Props<'_>> for Tracker {
ui.checkbox("Show subgroup", &mut self.settings.show_sub);
ui.checkbox("Show build notes", &mut self.builds.display_notes);

let mut displayed = self.settings.max_entries_displayed as i32;
if ui.input_int("Max displayed", &mut displayed).build() {
self.settings.max_entries_displayed = displayed.try_into().unwrap_or_default();
}

let input_width = render::ch_width(ui, 16);

ui.set_next_item_width(input_width);
Expand Down

0 comments on commit 59abc74

Please sign in to comment.