mirror of
https://github.com/danbulant/cushy
synced 2026-05-24 12:28:23 +00:00
Fixed mouse events + docs
This commit is contained in:
parent
5e5d826267
commit
ca42ecc956
5 changed files with 43 additions and 10 deletions
|
|
@ -308,6 +308,9 @@ impl<'context, 'window> EventContext<'context, 'window> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Advances the focus from this widget to the next widget in `direction`.
|
||||||
|
///
|
||||||
|
/// This widget does not need to be focused.
|
||||||
pub fn advance_focus(&mut self, direction: VisualOrder) {
|
pub fn advance_focus(&mut self, direction: VisualOrder) {
|
||||||
self.pending_state.focus = self.next_focus_after(self.current_node.clone(), direction);
|
self.pending_state.focus = self.next_focus_after(self.current_node.clone(), direction);
|
||||||
}
|
}
|
||||||
|
|
@ -430,6 +433,9 @@ impl<'context, 'window, 'clip, 'gfx, 'pass> GraphicsContext<'context, 'window, '
|
||||||
/// Invokes [`Widget::redraw()`](crate::widget::Widget::redraw) on this
|
/// Invokes [`Widget::redraw()`](crate::widget::Widget::redraw) on this
|
||||||
/// context's widget.
|
/// context's widget.
|
||||||
pub fn redraw(&mut self) {
|
pub fn redraw(&mut self) {
|
||||||
|
self.current_node
|
||||||
|
.tree
|
||||||
|
.note_widget_rendered(self.current_node.id());
|
||||||
self.current_node.clone().lock().as_widget().redraw(self);
|
self.current_node.clone().lock().as_widget().redraw(self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -908,8 +914,13 @@ impl RedrawStatus {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A type chat can convert to a [`ManagedWidget`] through a [`WidgetContext`].
|
||||||
pub trait ManageWidget {
|
pub trait ManageWidget {
|
||||||
|
/// The managed type, which can be `Option<ManagedWidget>` or
|
||||||
|
/// `ManagedWidget`.
|
||||||
type Managed: MapManagedWidget<ManagedWidget>;
|
type Managed: MapManagedWidget<ManagedWidget>;
|
||||||
|
|
||||||
|
/// Resolve `self` into a [`ManagedWidget`].
|
||||||
fn manage(&self, context: &WidgetContext<'_, '_>) -> Self::Managed;
|
fn manage(&self, context: &WidgetContext<'_, '_>) -> Self::Managed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -940,9 +951,12 @@ impl ManageWidget for ManagedWidget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A type that can produce another type when provided a [`ManagedWidget`].
|
||||||
pub trait MapManagedWidget<T> {
|
pub trait MapManagedWidget<T> {
|
||||||
|
/// The result of the mapping operation.
|
||||||
type Result;
|
type Result;
|
||||||
|
|
||||||
|
/// Call `map` with a [`ManagedWidget`].
|
||||||
fn map(self, map: impl FnOnce(ManagedWidget) -> T) -> Self::Result;
|
fn map(self, map: impl FnOnce(ManagedWidget) -> T) -> Self::Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -162,13 +162,17 @@ impl ComponentDefinition for EasingOut {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A 2d ordering configuration.
|
||||||
#[derive(Copy, Clone, Eq, PartialEq)]
|
#[derive(Copy, Clone, Eq, PartialEq)]
|
||||||
pub struct VisualOrder {
|
pub struct VisualOrder {
|
||||||
|
/// The ordering to apply horizontally.
|
||||||
pub horizontal: HorizontalOrder,
|
pub horizontal: HorizontalOrder,
|
||||||
|
/// The ordering to apply vertically.
|
||||||
pub vertical: VerticalOrder,
|
pub vertical: VerticalOrder,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VisualOrder {
|
impl VisualOrder {
|
||||||
|
/// Returns a right-to-left ordering.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn right_to_left() -> Self {
|
pub const fn right_to_left() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
|
@ -177,6 +181,7 @@ impl VisualOrder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns a left-to-right ordering.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn left_to_right() -> Self {
|
pub const fn left_to_right() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
|
@ -185,6 +190,7 @@ impl VisualOrder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the reverse ordering of `self`.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn rev(self) -> Self {
|
pub fn rev(self) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
|
@ -200,13 +206,17 @@ impl NamedComponent for VisualOrder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A horizontal direction.
|
||||||
#[derive(Copy, Clone, Eq, PartialEq)]
|
#[derive(Copy, Clone, Eq, PartialEq)]
|
||||||
pub enum HorizontalOrder {
|
pub enum HorizontalOrder {
|
||||||
|
/// Describes an order starting at the left and proceeding to the right.
|
||||||
LeftToRight,
|
LeftToRight,
|
||||||
|
/// Describes an order starting at the right and proceeding to the left.
|
||||||
RightToLeft,
|
RightToLeft,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HorizontalOrder {
|
impl HorizontalOrder {
|
||||||
|
/// Returns the reverse order of `self`.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn rev(self) -> Self {
|
pub fn rev(self) -> Self {
|
||||||
match self {
|
match self {
|
||||||
|
|
@ -215,7 +225,7 @@ impl HorizontalOrder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sort_key(self, rect: &Rect<Px>) -> Px {
|
pub(crate) fn sort_key(self, rect: &Rect<Px>) -> Px {
|
||||||
match self {
|
match self {
|
||||||
HorizontalOrder::LeftToRight => rect.origin.x,
|
HorizontalOrder::LeftToRight => rect.origin.x,
|
||||||
HorizontalOrder::RightToLeft => -(rect.origin.x + rect.size.width),
|
HorizontalOrder::RightToLeft => -(rect.origin.x + rect.size.width),
|
||||||
|
|
@ -223,13 +233,17 @@ impl HorizontalOrder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A vertical direction.
|
||||||
#[derive(Copy, Clone, Eq, PartialEq)]
|
#[derive(Copy, Clone, Eq, PartialEq)]
|
||||||
pub enum VerticalOrder {
|
pub enum VerticalOrder {
|
||||||
|
/// Describes an order starting at the top and proceeding to the bottom.
|
||||||
TopToBottom,
|
TopToBottom,
|
||||||
|
/// Describes an order starting at the bottom and proceeding to the top.
|
||||||
BottomToTop,
|
BottomToTop,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VerticalOrder {
|
impl VerticalOrder {
|
||||||
|
/// Returns the reverse order of `self`.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn rev(self) -> Self {
|
pub fn rev(self) -> Self {
|
||||||
match self {
|
match self {
|
||||||
|
|
@ -238,14 +252,14 @@ impl VerticalOrder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn max_px(self) -> Px {
|
pub(crate) fn max_px(self) -> Px {
|
||||||
match self {
|
match self {
|
||||||
VerticalOrder::TopToBottom => Px::MAX,
|
VerticalOrder::TopToBottom => Px::MAX,
|
||||||
VerticalOrder::BottomToTop => Px::MIN,
|
VerticalOrder::BottomToTop => Px::MIN,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn smallest_px(self, a: Px, b: Px) -> Px {
|
pub(crate) fn smallest_px(self, a: Px, b: Px) -> Px {
|
||||||
match self {
|
match self {
|
||||||
VerticalOrder::TopToBottom => a.min(b),
|
VerticalOrder::TopToBottom => a.min(b),
|
||||||
VerticalOrder::BottomToTop => b.max(a),
|
VerticalOrder::BottomToTop => b.max(a),
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,6 @@ impl Tree {
|
||||||
pub(crate) fn set_layout(&self, widget: WidgetId, rect: Rect<Px>) {
|
pub(crate) fn set_layout(&self, widget: WidgetId, rect: Rect<Px>) {
|
||||||
let mut data = self.data.lock().map_or_else(PoisonError::into_inner, |g| g);
|
let mut data = self.data.lock().map_or_else(PoisonError::into_inner, |g| g);
|
||||||
|
|
||||||
data.render_order.push(widget);
|
|
||||||
let node = data.nodes.get_mut(&widget).expect("missing widget");
|
let node = data.nodes.get_mut(&widget).expect("missing widget");
|
||||||
node.layout = Some(rect);
|
node.layout = Some(rect);
|
||||||
let mut children_to_offset = node.children.clone();
|
let mut children_to_offset = node.children.clone();
|
||||||
|
|
@ -79,6 +78,11 @@ impl Tree {
|
||||||
data.render_order.clear();
|
data.render_order.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn note_widget_rendered(&self, widget: WidgetId) {
|
||||||
|
let mut data = self.data.lock().map_or_else(PoisonError::into_inner, |g| g);
|
||||||
|
data.render_order.push(widget);
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn reset_child_layouts(&self, parent: WidgetId) {
|
pub(crate) fn reset_child_layouts(&self, parent: WidgetId) {
|
||||||
let mut data = self.data.lock().map_or_else(PoisonError::into_inner, |g| g);
|
let mut data = self.data.lock().map_or_else(PoisonError::into_inner, |g| g);
|
||||||
let children = data.nodes[&parent].children.clone();
|
let children = data.nodes[&parent].children.clone();
|
||||||
|
|
|
||||||
|
|
@ -388,7 +388,7 @@ impl Widget for Input {
|
||||||
);
|
);
|
||||||
(false, HANDLED)
|
(false, HANDLED)
|
||||||
}
|
}
|
||||||
(_, Some(text)) if !context.modifiers().state().primary() => {
|
(_, Some(text)) if !context.modifiers().state().primary() && text != "\t" => {
|
||||||
editor.insert_string(&text, None);
|
editor.insert_string(&text, None);
|
||||||
(true, HANDLED)
|
(true, HANDLED)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use kludgine::figures::units::UPx;
|
use kludgine::figures::units::UPx;
|
||||||
use kludgine::figures::{Fraction, IntoUnsigned, ScreenScale, Size};
|
use kludgine::figures::{Fraction, IntoSigned, IntoUnsigned, Rect, ScreenScale, Size};
|
||||||
|
|
||||||
use crate::context::{AsEventContext, GraphicsContext, LayoutContext};
|
use crate::context::{AsEventContext, GraphicsContext, LayoutContext};
|
||||||
use crate::styles::Dimension;
|
use crate::styles::Dimension;
|
||||||
|
|
@ -68,7 +68,8 @@ impl Widget for Resize {
|
||||||
available_space: Size<ConstraintLimit>,
|
available_space: Size<ConstraintLimit>,
|
||||||
context: &mut LayoutContext<'_, '_, '_, '_, '_>,
|
context: &mut LayoutContext<'_, '_, '_, '_, '_>,
|
||||||
) -> Size<UPx> {
|
) -> Size<UPx> {
|
||||||
if let (Some(width), Some(height)) = (self.width, self.height) {
|
let child = self.child.mounted(&mut context.as_event_context());
|
||||||
|
let size = if let (Some(width), Some(height)) = (self.width, self.height) {
|
||||||
Size::new(
|
Size::new(
|
||||||
width.into_px(context.graphics.scale()).into_unsigned(),
|
width.into_px(context.graphics.scale()).into_unsigned(),
|
||||||
height.into_px(context.graphics.scale()).into_unsigned(),
|
height.into_px(context.graphics.scale()).into_unsigned(),
|
||||||
|
|
@ -82,10 +83,10 @@ impl Widget for Resize {
|
||||||
context.graphics.scale(),
|
context.graphics.scale(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
let child = self.child.mounted(&mut context.as_event_context());
|
|
||||||
// TODO set_child_layout
|
|
||||||
context.for_other(&child).layout(available_space)
|
context.for_other(&child).layout(available_space)
|
||||||
}
|
};
|
||||||
|
context.set_child_layout(&child, Rect::from(size.into_signed()));
|
||||||
|
size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue