Fix use of Rect in SAO UI script

This commit is contained in:
mars 2022-11-05 15:03:30 -06:00
parent 75e0aca668
commit ab50a8e130
6 changed files with 25 additions and 25 deletions

View File

@ -154,7 +154,7 @@ impl RectButton {
label: Option<LabelText>,
icon: Option<LabelText>,
) -> Self {
let mut label_left = rect.bl.x;
let mut label_left = rect.tl.x;
let mut alignment = HorizontalAlignment::Center;
let icon = icon.map(|text| {
@ -163,8 +163,8 @@ impl RectButton {
alignment = HorizontalAlignment::Left;
let scale = rect.height() * style.icon_scale_factor;
let color = Color::BLACK;
let cx = rect.bl.x + margin / 2.0;
let cy = rect.bl.y + rect.height() / 2.0;
let cx = rect.tl.x + margin / 2.0;
let cy = rect.tl.y + rect.height() / 2.0;
let center = Vec2::new(cx, cy);
Icon::new(text, scale, color, center)
@ -173,8 +173,8 @@ impl RectButton {
let label = label.map(|text| {
let scale = rect.height() * style.label_scale_factor;
let left = label_left;
let right = rect.tr.x;
let baseline = rect.bl.y;
let right = rect.br.x;
let baseline = rect.tl.y;
let baseline = (rect.height() * style.label_baseline) + baseline;
let color = Color::BLACK;

View File

@ -226,8 +226,8 @@ impl Container for Dialog {
let body_tr = Vec2::new(width2, style.body.height / 2.0);
let body_rect = Rect {
bl: -body_tr,
tr: body_tr,
tl: -body_tr,
br: body_tr,
};
let footer_xy = Vec2::new(-width2, -style.body.height / 2.0 - style.footer.height);

View File

@ -295,8 +295,8 @@ impl TabMenu {
let scroll_bar = Offset::new(scroll_bar, Vec2::new(scroll_x, -tab_list_height));
let separator_rect = Rect {
bl: Vec2::new(Self::TAB_WIDTH, -tab_list_height),
tr: Vec2::new(Self::TAB_WIDTH + Self::SEPARATOR_WIDTH, 0.0),
tl: Vec2::new(Self::TAB_WIDTH, -tab_list_height),
br: Vec2::new(Self::TAB_WIDTH + Self::SEPARATOR_WIDTH, 0.0),
};
let head_width = Self::TAB_WIDTH
@ -306,13 +306,13 @@ impl TabMenu {
+ scroll_bar.style.margin.x * 2.0;
let head_rect = Rect {
bl: Vec2::ZERO,
tr: Vec2::new(head_width, Self::HEAD_HEIGHT),
tl: Vec2::ZERO,
br: Vec2::new(head_width, Self::HEAD_HEIGHT),
};
let view_rect = Rect {
bl: Vec2::new(Self::TAB_WIDTH + Self::SEPARATOR_WIDTH, -tab_list_height),
tr: Vec2::new(head_rect.tr.x, 0.0),
tl: Vec2::new(Self::TAB_WIDTH + Self::SEPARATOR_WIDTH, -tab_list_height),
br: Vec2::new(head_rect.br.x, 0.0),
};
let view = ScrollView::new(
@ -322,7 +322,7 @@ impl TabMenu {
|available_width: f32| Inventory::new(available_width),
);
let view = Offset::new(view, view_rect.bl);
let view = Offset::new(view, view_rect.tl);
Self {
pop_out,

View File

@ -50,8 +50,8 @@ impl ScrollBar {
pub fn new(height: f32, content_height: f32, style: ScrollBarStyle) -> Self {
let center_x = style.body_width / 2.0 + style.margin.x;
let rail_rect = Rect {
bl: Vec2::new(center_x - style.rail_width / 2.0, style.margin.y),
tr: Vec2::new(center_x + style.rail_width / 2.0, height - style.margin.y),
tl: Vec2::new(center_x - style.rail_width / 2.0, style.margin.y),
br: Vec2::new(center_x + style.rail_width / 2.0, height - style.margin.y),
};
let body_color_anim = Animation::new(

View File

@ -132,8 +132,8 @@ impl<T: RectBounds> Offset<T> {
vert_align: OffsetAlignment,
) -> Self {
let bounds = inner.get_bounds();
let x = hori_align.align(bounds.bl.x, bounds.tr.x);
let y = vert_align.align(bounds.tr.y, bounds.bl.y);
let x = hori_align.align(bounds.tl.x, bounds.br.x);
let y = vert_align.align(bounds.br.y, bounds.tl.y);
let offset = anchor - Vec2::new(x, y);
Self { inner, offset }
}
@ -180,8 +180,8 @@ impl<T: RectBounds> Popup<T> {
vert_align: OffsetAlignment,
) -> Self {
let bounds = inner.get_bounds();
let x = hori_align.align(bounds.bl.x, bounds.tr.x);
let y = vert_align.align(bounds.tr.y, bounds.bl.y);
let x = hori_align.align(bounds.tl.x, bounds.br.x);
let y = vert_align.align(bounds.br.y, bounds.tl.y);
let offset = anchor - Vec2::new(x, y);
Self { inner, offset }
}

View File

@ -62,14 +62,14 @@ impl Widget for Label {
let bounds = Rect::from(layout.get_bounds()).scale(self.scale);
self.bounds = bounds;
let xoff = match self.alignment {
HorizontalAlignment::Left => self.left - bounds.bl.x,
HorizontalAlignment::Right => self.right - bounds.tr.x,
HorizontalAlignment::Left => self.left - bounds.tl.x,
HorizontalAlignment::Right => self.right - bounds.br.x,
HorizontalAlignment::Center => {
let available = self.right - self.left;
let halfway = available / 2.0 + self.left;
let width = bounds.tr.x - bounds.bl.x;
let width = bounds.br.x - bounds.tl.x;
let left = halfway - width / 2.0;
left - bounds.bl.x
left - bounds.tl.x
}
};
@ -117,7 +117,7 @@ impl Widget for Icon {
let bounds = Rect::from(layout.get_bounds()).scale(self.scale);
self.bounds = bounds;
self.offset = self.center - bounds.size() / 2.0;
self.offset.y -= bounds.bl.y;
self.offset.y -= bounds.tl.y;
self.dirty = false;
self.layout = Some(layout);
}