mirror of
https://github.com/danbulant/cushy
synced 2026-06-21 07:32:08 +00:00
Making it easier to draw focus correctly
This commit is contained in:
parent
0684ac59bf
commit
ce6935a7a7
5 changed files with 8 additions and 7 deletions
|
|
@ -20,7 +20,7 @@ fn main() -> gooey::Result {
|
|||
.on_accept_focus(|context| context.enabled())
|
||||
.on_redraw(|context| {
|
||||
context.fill(context.theme().secondary.color);
|
||||
if context.focused() {
|
||||
if context.focused(true) {
|
||||
context.draw_focus_ring();
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -979,7 +979,7 @@ impl<'context, 'window> WidgetContext<'context, 'window> {
|
|||
/// Widget events relating to focus changes are deferred until after the all
|
||||
/// contexts for the currently firing event are dropped.
|
||||
pub fn blur(&mut self) -> bool {
|
||||
if self.focused() {
|
||||
if self.focused(true) {
|
||||
self.clear_focus();
|
||||
true
|
||||
} else {
|
||||
|
|
@ -1052,8 +1052,9 @@ impl<'context, 'window> WidgetContext<'context, 'window> {
|
|||
|
||||
/// Returns true if this widget is currently focused for user input.
|
||||
#[must_use]
|
||||
pub fn focused(&self) -> bool {
|
||||
pub fn focused(&self, check_window: bool) -> bool {
|
||||
self.pending_state.focus == Some(self.current_node.id())
|
||||
&& (!check_window || self.window.focused().get_tracking_refresh(self))
|
||||
}
|
||||
|
||||
/// Returns true if this widget is the target to activate when the user
|
||||
|
|
|
|||
|
|
@ -343,7 +343,7 @@ impl Widget for Button {
|
|||
let two_lp_stroke = StrokeOptions::lp_wide(Lp::points(2));
|
||||
context.stroke_outline(style.outline, two_lp_stroke);
|
||||
|
||||
if context.focused() {
|
||||
if context.focused(true) {
|
||||
if current_style == ButtonKind::Transparent {
|
||||
let two_lp_stroke = two_lp_stroke.into_px(context.gfx.scale());
|
||||
let focus_color = context.get(&HighlightColor);
|
||||
|
|
|
|||
|
|
@ -1023,7 +1023,7 @@ where
|
|||
|
||||
let cache = self.layout_text(Some(size.width.into_signed()), context);
|
||||
|
||||
let highlight = if context.focused() && window_focused {
|
||||
let highlight = if context.focused(false) && window_focused {
|
||||
context.draw_focus_ring();
|
||||
context.get(&HighlightColor)
|
||||
} else {
|
||||
|
|
@ -1032,7 +1032,7 @@ where
|
|||
outline_color
|
||||
};
|
||||
|
||||
if context.focused() {
|
||||
if context.focused(false) {
|
||||
context.set_ime_allowed(true);
|
||||
context.set_ime_purpose(if cache.masked {
|
||||
ImePurpose::Password
|
||||
|
|
|
|||
|
|
@ -219,7 +219,7 @@ where
|
|||
|
||||
// Draw the knob
|
||||
if spec.knob_size > 0 {
|
||||
let focus = context.focused().then_some(self.focused_knob).flatten();
|
||||
let focus = context.focused(true).then_some(self.focused_knob).flatten();
|
||||
Self::draw_knobs(
|
||||
self.flip_pt_if_vertical(Point::new(end + spec.half_knob, spec.half_knob) + inset),
|
||||
spec.end.map(|_| {
|
||||
|
|
|
|||
Loading…
Reference in a new issue