stuff for ime positioning
This commit is contained in:
@@ -272,8 +272,8 @@ impl UiRegion {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn to_screen(&self, size: Vec2) -> ScreenRegion {
|
||||
ScreenRegion {
|
||||
pub fn to_screen(&self, size: Vec2) -> PixelRegion {
|
||||
PixelRegion {
|
||||
top_left: self.top_left.rel * size + self.top_left.abs,
|
||||
bot_right: self.bot_right.rel * size + self.bot_right.abs,
|
||||
}
|
||||
@@ -329,17 +329,22 @@ impl Display for UiRegion {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ScreenRegion {
|
||||
pub struct PixelRegion {
|
||||
pub top_left: Vec2,
|
||||
pub bot_right: Vec2,
|
||||
}
|
||||
impl ScreenRegion {
|
||||
|
||||
impl PixelRegion {
|
||||
pub fn contains(&self, pos: Vec2) -> bool {
|
||||
pos.x >= self.top_left.x
|
||||
&& pos.x <= self.bot_right.x
|
||||
&& pos.y >= self.top_left.y
|
||||
&& pos.y <= self.bot_right.y
|
||||
}
|
||||
|
||||
pub fn size(&self) -> Vec2 {
|
||||
self.bot_right - self.top_left
|
||||
}
|
||||
}
|
||||
|
||||
pub struct UIRegionAxisView<'a> {
|
||||
|
||||
@@ -3,8 +3,8 @@ use image::DynamicImage;
|
||||
use crate::{
|
||||
core::{TextEdit, TextEditCtx},
|
||||
layout::{
|
||||
IdLike, PainterCtx, PainterData, StaticWidgetId, TextureHandle, Vec2, Widget, WidgetId,
|
||||
WidgetLike,
|
||||
IdLike, PainterCtx, PainterData, PixelRegion, StaticWidgetId, TextureHandle, Vec2, Widget,
|
||||
WidgetId, WidgetLike,
|
||||
},
|
||||
util::Id,
|
||||
};
|
||||
@@ -179,6 +179,11 @@ impl Ui {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn window_region<W>(&self, id: &impl IdLike<W>) -> Option<PixelRegion> {
|
||||
let region = self.data.active.get(&id.id())?.region;
|
||||
Some(region.to_screen(self.data.output_size))
|
||||
}
|
||||
|
||||
pub fn debug(&self, label: &str) {
|
||||
for (id, inst) in &self.data.active {
|
||||
let l = &self.data.widgets.data(id).unwrap().label;
|
||||
|
||||
@@ -43,6 +43,10 @@ impl Vec2 {
|
||||
y: self.y.ceil(),
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn tuple(&self) -> (f32, f32) {
|
||||
(self.x, self.y)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: const UiNum + Copy> const From<T> for Vec2 {
|
||||
|
||||
Reference in New Issue
Block a user