Apply cursor styles during paint

This makes the editor's cursor an IBeam and properly deals with nested cursor styles.

Co-Authored-By: Antonio Scandurra <me@as-cii.com>
This commit is contained in:
Nathan Sobo
2022-04-22 10:54:18 -06:00
co-authored by Antonio Scandurra
parent 53bf7b61c0
commit 92f040df00
16 changed files with 124 additions and 96 deletions
+15 -4
View File
@@ -1,17 +1,17 @@
use pathfinder_geometry::rect::RectF;
use serde::Deserialize;
use serde_json::json;
use crate::{
color::Color,
geometry::{
deserialize_vec2f,
rect::RectF,
vector::{vec2f, Vector2F},
},
json::ToJson,
platform::CursorStyle,
scene::{self, Border, Quad},
Element, ElementBox, Event, EventContext, LayoutContext, PaintContext, SizeConstraint,
};
use serde::Deserialize;
use serde_json::json;
#[derive(Clone, Copy, Debug, Default, Deserialize)]
pub struct ContainerStyle {
@@ -27,6 +27,8 @@ pub struct ContainerStyle {
pub corner_radius: f32,
#[serde(default)]
pub shadow: Option<Shadow>,
#[serde(default)]
pub cursor: Option<CursorStyle>,
}
pub struct Container {
@@ -128,6 +130,11 @@ impl Container {
self
}
pub fn with_cursor(mut self, style: CursorStyle) -> Self {
self.style.cursor = Some(style);
self
}
fn margin_size(&self) -> Vector2F {
vec2f(
self.style.margin.left + self.style.margin.right,
@@ -205,6 +212,10 @@ impl Element for Container {
});
}
if let Some(style) = self.style.cursor {
cx.scene.push_cursor_style(quad_bounds, style);
}
let child_origin =
quad_bounds.origin() + vec2f(self.style.padding.left, self.style.padding.top);