mirror of
https://github.com/danbulant/cushy
synced 2026-06-20 06:51:07 +00:00
TileMap focus, Style helpers
This commit is contained in:
parent
22fb955dca
commit
a818cc41fd
4 changed files with 35 additions and 5 deletions
|
|
@ -1,18 +1,17 @@
|
|||
use gooey::styles::components::TextColor;
|
||||
use gooey::styles::Styles;
|
||||
use gooey::widget::{MakeWidget, Widget};
|
||||
use gooey::widgets::stack::Stack;
|
||||
use gooey::widgets::{Button, Style};
|
||||
use gooey::{styles, Run};
|
||||
use gooey::Run;
|
||||
use kludgine::Color;
|
||||
|
||||
fn main() -> gooey::Result {
|
||||
Stack::rows(Button::new("Green").and(red_text(Button::new("Red"))))
|
||||
.with_styles(Styles::new().with(&TextColor, Color::GREEN))
|
||||
.with(&TextColor, Color::GREEN)
|
||||
.run()
|
||||
}
|
||||
|
||||
/// Creating reusable style helpers that work with any Widget is straightfoward
|
||||
fn red_text(w: impl Widget) -> Style {
|
||||
Style::new(styles!(TextColor => Color::RED), w)
|
||||
w.with(&TextColor, Color::RED)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -451,6 +451,11 @@ impl<'context, 'window, 'clip, 'gfx, 'pass> GraphicsContext<'context, 'window, '
|
|||
/// To ensure the correct color is used, include [`HighlightColor`] in the
|
||||
/// styles request.
|
||||
pub fn draw_focus_ring_using(&mut self, styles: &Styles) {
|
||||
// If this is the root widget, don't draw a focus ring. It's redundant.
|
||||
if !self.current_node.has_parent() {
|
||||
return;
|
||||
}
|
||||
|
||||
let visible_rect = Rect::from(self.graphics.region().size - (Px(1), Px(1)));
|
||||
let focus_ring = Shape::stroked_rect(
|
||||
visible_rect,
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ use kludgine::figures::{IntoSigned, IntoUnsigned, Point, Rect, Size};
|
|||
|
||||
use crate::context::{AsEventContext, EventContext, GraphicsContext, LayoutContext};
|
||||
use crate::styles::components::VisualOrder;
|
||||
use crate::styles::Styles;
|
||||
use crate::styles::{Component, NamedComponent, Styles};
|
||||
use crate::tree::Tree;
|
||||
use crate::value::{IntoValue, Value};
|
||||
use crate::widgets::{Align, Expand, Scroll, Style};
|
||||
|
|
@ -444,6 +444,13 @@ pub trait MakeWidget: Sized {
|
|||
Style::new(styles, self)
|
||||
}
|
||||
|
||||
/// Associates a style component with `self`.
|
||||
fn with(self, name: &impl NamedComponent, component: impl Into<Component>) -> Style {
|
||||
let mut styles = Styles::new();
|
||||
styles.insert(name, component);
|
||||
Style::new(styles, self)
|
||||
}
|
||||
|
||||
/// Sets the widget that should be focused next.
|
||||
///
|
||||
/// Gooey automatically determines reverse tab order by using this same
|
||||
|
|
@ -897,6 +904,12 @@ impl ManagedWidget {
|
|||
.and_then(|id| self.tree.widget(id))
|
||||
}
|
||||
|
||||
/// Returns true if this node has a parent.
|
||||
#[must_use]
|
||||
pub fn has_parent(&self) -> bool {
|
||||
self.tree.parent(self.id()).is_some()
|
||||
}
|
||||
|
||||
pub(crate) fn attach_styles(&self, styles: Styles) {
|
||||
self.tree.attach_styles(self.id(), styles);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ where
|
|||
self.layers.map(|layers| {
|
||||
tilemap::draw(layers, focus, self.zoom, context.graphics.inner_graphics());
|
||||
});
|
||||
context.draw_focus_ring();
|
||||
|
||||
if let Some(tick) = &self.tick {
|
||||
tick.rendered(context);
|
||||
|
|
@ -78,6 +79,18 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
fn accept_focus(&mut self, _context: &mut EventContext<'_, '_>) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn hit_test(
|
||||
&mut self,
|
||||
_location: kludgine::figures::Point<kludgine::figures::units::Px>,
|
||||
_context: &mut EventContext<'_, '_>,
|
||||
) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn layout(
|
||||
&mut self,
|
||||
available_space: Size<ConstraintLimit>,
|
||||
|
|
|
|||
Loading…
Reference in a new issue