initial text impl
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use crate::{Painter, UiNum, UiRegion, Widget, WidgetId};
|
||||
use crate::prelude::*;
|
||||
|
||||
pub struct Regioned {
|
||||
pub region: UiRegion,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use crate::prelude::*;
|
||||
use image::DynamicImage;
|
||||
|
||||
use crate::{Color, Painter, TextureHandle, Widget, WidgetFnRet, render::RectPrimitive};
|
||||
|
||||
pub struct Image {
|
||||
handle: Option<TextureHandle>,
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
mod frame;
|
||||
mod image;
|
||||
mod num;
|
||||
mod rect;
|
||||
mod sense;
|
||||
mod span;
|
||||
mod stack;
|
||||
mod text;
|
||||
mod trait_fns;
|
||||
|
||||
pub use frame::*;
|
||||
pub use image::*;
|
||||
pub use num::*;
|
||||
pub use rect::*;
|
||||
pub use sense::*;
|
||||
pub use span::*;
|
||||
pub use stack::*;
|
||||
pub use text::*;
|
||||
pub use trait_fns::*;
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
pub trait UiNum {
|
||||
fn to_f32(self) -> f32;
|
||||
}
|
||||
|
||||
impl UiNum for f32 {
|
||||
fn to_f32(self) -> f32 {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl UiNum for u32 {
|
||||
fn to_f32(self) -> f32 {
|
||||
self as f32
|
||||
}
|
||||
}
|
||||
|
||||
impl UiNum for i32 {
|
||||
fn to_f32(self) -> f32 {
|
||||
self as f32
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Eq, PartialEq)]
|
||||
pub enum Axis {
|
||||
X,
|
||||
Y,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Eq, PartialEq)]
|
||||
pub struct Dir {
|
||||
pub axis: Axis,
|
||||
pub sign: Sign,
|
||||
}
|
||||
|
||||
impl Dir {
|
||||
pub const fn new(axis: Axis, dir: Sign) -> Self {
|
||||
Self { axis, sign: dir }
|
||||
}
|
||||
|
||||
pub const LEFT: Self = Self::new(Axis::X, Sign::Neg);
|
||||
pub const RIGHT: Self = Self::new(Axis::X, Sign::Pos);
|
||||
pub const UP: Self = Self::new(Axis::Y, Sign::Neg);
|
||||
pub const DOWN: Self = Self::new(Axis::Y, Sign::Pos);
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Eq, PartialEq)]
|
||||
pub enum Sign {
|
||||
Neg,
|
||||
Pos,
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::{Painter, UiColor, UiNum, Widget, render::RectPrimitive};
|
||||
use crate::prelude::*;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct Rect {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::{Sense, SenseCtx, SenseFn, Sensor, Widget, WidgetId, WidgetIdFnRet, WidgetLike};
|
||||
use crate::prelude::*;
|
||||
|
||||
pub trait Sensable<W, Ctx, Tag> {
|
||||
fn on(self, sense: Sense, f: impl SenseFn<Ctx>) -> WidgetIdFnRet!(W, Ctx);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::{Dir, Painter, Sign, UIScalar, UiNum, UiRegion, Widget, WidgetId};
|
||||
use crate::prelude::*;
|
||||
|
||||
pub struct Span {
|
||||
pub children: Vec<(WidgetId, SpanLen)>,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::{Painter, Widget, WidgetId};
|
||||
use crate::prelude::*;
|
||||
|
||||
pub struct Stack {
|
||||
pub children: Vec<WidgetId>,
|
||||
|
||||
17
src/core/text.rs
Normal file
17
src/core/text.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
use crate::prelude::*;
|
||||
|
||||
pub struct Text {
|
||||
content: String,
|
||||
}
|
||||
|
||||
impl<Ctx> Widget<Ctx> for Text {
|
||||
fn draw(&self, painter: &mut Painter<Ctx>) {
|
||||
painter.draw_text(&self.content);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn text(text: impl Into<String>) -> Text {
|
||||
Text {
|
||||
content: text.into(),
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::*;
|
||||
use crate::{UiRegion, Vec2, WidgetArrLike, WidgetFnRet, WidgetLike};
|
||||
use crate::layout::{Dir, UiPos, UiRegion, Vec2, WidgetArrLike, WidgetFnRet, WidgetLike};
|
||||
|
||||
pub trait CoreWidget<W: 'static, Ctx: 'static, Tag> {
|
||||
fn pad(self, padding: impl Into<Padding>) -> WidgetFnRet!(Regioned, Ctx);
|
||||
@@ -17,7 +17,7 @@ impl<W: WidgetLike<Ctx, Tag>, Ctx: 'static, Tag> CoreWidget<W::Widget, Ctx, Tag>
|
||||
|
||||
fn center(self, size: impl Into<Vec2>) -> WidgetFnRet!(Regioned, Ctx) {
|
||||
|ui| Regioned {
|
||||
region: UiRegion::center().size(size.into()),
|
||||
region: UiPos::center().expand(size.into()),
|
||||
inner: self.add(ui).erase_type(),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user