WIP: text_system

This commit is contained in:
Mikayla 2024-01-22 09:35:01 -08:00
parent 0c3fb449f0
commit a99d5b87e8
No known key found for this signature in database
5 changed files with 106 additions and 36 deletions

View file

@ -1,3 +1,17 @@
//! The element context is the main interface for interacting with the frame during a paint.
//!
//! Elements are hierarchical and with a few exceptions the context accumulates state in a stack
//! as it processes all of the elements in the frame. The methods that interact with this stack
//! are generally marked with `with_*`, and take a callback to denote the region of code that
//! should be executed with that state.
//!
//! The other main interface is the `paint_*` family of methods, which push basic drawing commands
//! to the GPU. Everything in a GPUI app is drawn with these methods.
//!
//! There are also several internal methds that GPUI uses, such as [`ElementContext::with_element_state`]
//! to call the paint and layout methods on elements. These have been included as they're often useful
//! for taking manual control of the layouting or painting of specialized elements.
use std::{
any::{Any, TypeId},
borrow::{Borrow, BorrowMut, Cow},
@ -153,6 +167,9 @@ pub struct ElementContext<'a> {
}
impl<'a> WindowContext<'a> {
/// Convert this window context into an ElementContext in this callback.
/// If you need to use this method, you're probably intermixing the imperative
/// and declarative APIs, which is not recommended.
pub fn with_element_context<R>(&mut self, f: impl FnOnce(&mut ElementContext) -> R) -> R {
f(&mut ElementContext {
cx: WindowContext::new(self.app, self.window),
@ -338,6 +355,8 @@ impl<'a> ElementContext<'a> {
self.window.next_frame.next_stacking_order_id = next_stacking_order_id;
}
/// Push a text style onto the stack, and call a function with that style active.
/// Use [`AppContext::text_style`] to get the current, combined text style.
pub fn with_text_style<F, R>(&mut self, style: Option<TextStyleRefinement>, f: F) -> R
where
F: FnOnce(&mut Self) -> R,
@ -979,9 +998,8 @@ impl<'a> ElementContext<'a> {
self.window.layout_engine = Some(layout_engine);
}
/// Obtain the bounds computed for the given LayoutId relative to the window. This method should not
/// be invoked until the paint phase begins, and will usually be invoked by GPUI itself automatically
/// in order to pass your element its `Bounds` automatically.
/// Obtain the bounds computed for the given LayoutId relative to the window. This method will usually be invoked by
/// GPUI itself automatically in order to pass your element its `Bounds` automatically.
pub fn layout_bounds(&mut self, layout_id: LayoutId) -> Bounds<Pixels> {
let mut bounds = self
.window