the great orientation refactor (move to x & y UiScalars/Spans) + don't call full size in align
This commit is contained in:
@@ -32,8 +32,8 @@ impl<O> TextBuilder<O> {
|
||||
self.attrs.line_height = height;
|
||||
self
|
||||
}
|
||||
pub fn text_align(mut self, align: Align) -> Self {
|
||||
self.attrs.align = align;
|
||||
pub fn text_align(mut self, align: impl Into<RegionAlign>) -> Self {
|
||||
self.attrs.align = align.into();
|
||||
self
|
||||
}
|
||||
pub fn wrap(mut self, wrap: bool) -> Self {
|
||||
|
||||
@@ -15,10 +15,10 @@ pub struct TextEdit {
|
||||
|
||||
impl TextEdit {
|
||||
pub fn region(&self) -> UiRegion {
|
||||
UiRegion::from_size_align(
|
||||
self.tex().map(|t| t.size()).unwrap_or(Vec2::ZERO),
|
||||
self.align,
|
||||
)
|
||||
self.tex()
|
||||
.map(|t| t.size())
|
||||
.unwrap_or(Vec2::ZERO)
|
||||
.align(self.align)
|
||||
}
|
||||
|
||||
pub fn content(&self) -> String {
|
||||
@@ -44,7 +44,7 @@ impl Widget for TextEdit {
|
||||
let size = vec2(1, self.attrs.line_height);
|
||||
painter.primitive_within(
|
||||
RectPrimitive::color(Color::WHITE),
|
||||
UiRegion::from_size_align(size, Align::TopLeft)
|
||||
size.align(Align::TOP_LEFT)
|
||||
.offset(offset)
|
||||
.within(®ion),
|
||||
);
|
||||
@@ -205,7 +205,7 @@ impl<'a> TextEditCtx<'a> {
|
||||
}
|
||||
|
||||
pub fn select(&mut self, pos: Vec2, size: Vec2) {
|
||||
let pos = pos - self.text.region().top_left.to_abs(size);
|
||||
let pos = pos - self.text.region().top_left().to_abs(size);
|
||||
self.text.cursor = self.text.buf.hit(pos.x, pos.y);
|
||||
}
|
||||
|
||||
|
||||
@@ -100,11 +100,13 @@ impl Widget for Text {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn text_region(tex: &TextTexture, align: Align) -> UiRegion {
|
||||
pub fn text_region(tex: &TextTexture, align: RegionAlign) -> UiRegion {
|
||||
let tex_dims = tex.handle.size();
|
||||
let mut region = UiRegion::from_size_align(tex.size(), align);
|
||||
region.top_left.abs += tex.top_left;
|
||||
region.bot_right.abs = region.top_left.abs + tex_dims;
|
||||
let mut region = tex.size().align(align);
|
||||
region.x.start.abs += tex.top_left.x;
|
||||
region.y.start.abs += tex.top_left.y;
|
||||
region.x.end.abs = region.x.start.abs + tex_dims.x;
|
||||
region.y.end.abs = region.y.start.abs + tex_dims.y;
|
||||
region
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user