Skip to content

Commit

Permalink
editor: fix cursed CardTable scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
barsoosayque committed Dec 22, 2024
1 parent 36b70eb commit 2868eba
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions crates/opensi-editor/src/element/card.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use opensi_core::prelude::*;
use std::borrow::Cow;
use std::{borrow::Cow, fmt::Debug};

use super::{
node_context::PackageNodeContextMenu, question_name, round_name, theme_name, unselectable_label,
Expand Down Expand Up @@ -161,17 +161,18 @@ impl<'a> egui::Widget for Card<'a> {

/// Builder for a signle row inside [`CardTable`].
pub struct CardTableRow<'a, 'b> {
row: egui_extras::TableRow<'a, 'b>,
strip: egui_extras::Strip<'a, 'b>,
index: usize,
}

impl CardTableRow<'_, '_> {
pub fn index(&self) -> usize {
self.row.index()
self.index
}

fn row(&mut self, mut add: impl FnMut(&mut egui::Ui) -> egui::Response) -> egui::Response {
let mut response = std::mem::MaybeUninit::uninit();
self.row.col(|ui| {
self.strip.cell(|ui| {
response.write(add(ui));
});
unsafe { response.assume_init() }
Expand Down Expand Up @@ -234,21 +235,25 @@ impl CardTable {
// FIXME: this fixes always present horizontal scroll, but kinda yucky fix
.min_scrolled_width(ui.available_width() + 1.0)
.show(ui, |ui| {
let table = egui_extras::TableBuilder::new(ui)
.id_salt(self.id.with("table"))
.columns(egui_extras::Column::remainder(), count.0)
.vscroll(false)
.cell_layout(egui::Layout::centered_and_justified(
egui::Direction::LeftToRight,
));

table.reset();

table.body(|body| {
body.rows(120.0, count.1, |row| {
let row = CardTableRow { row };
builder(row);
});
ui.set_min_height(ui.available_height());
ui.with_layout(egui::Layout::top_down_justified(egui::Align::Center), |ui| {
egui_extras::StripBuilder::new(ui)
.sizes(egui_extras::Size::initial(120.0), count.1)
.vertical(|mut vertical| {
for row in 0..count.1 {
vertical.strip(|horizontal| {
horizontal
.sizes(egui_extras::Size::remainder(), count.0)
.cell_layout(egui::Layout::centered_and_justified(
egui::Direction::LeftToRight,
))
.horizontal(|strip| {
let row = CardTableRow { strip, index: row };
builder(row);
});
});
}
});
});
});
}
Expand Down

0 comments on commit 2868eba

Please sign in to comment.