mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Add mouse support to radio view
This commit is contained in:
parent
1b67c3eceb
commit
13059dae0b
@ -1,6 +1,6 @@
|
||||
use {Printer, With};
|
||||
use direction::Direction;
|
||||
use event::{Event, EventResult, Key};
|
||||
use event::{Event, EventResult, Key, MouseButton, MouseEvent};
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use theme::ColorStyle;
|
||||
@ -144,16 +144,20 @@ impl<T> RadioButton<T> {
|
||||
printer.print((4, 0), &self.label);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> View for RadioButton<T> {
|
||||
fn required_size(&mut self, _: Vec2) -> Vec2 {
|
||||
fn req_size(&self) -> Vec2 {
|
||||
if self.label.is_empty() {
|
||||
Vec2::new(3, 1)
|
||||
} else {
|
||||
Vec2::new(3 + 1 + self.label.len(), 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> View for RadioButton<T> {
|
||||
fn required_size(&mut self, _: Vec2) -> Vec2 {
|
||||
self.req_size()
|
||||
}
|
||||
|
||||
fn take_focus(&mut self, _: Direction) -> bool {
|
||||
self.enabled
|
||||
@ -179,6 +183,15 @@ impl<T> View for RadioButton<T> {
|
||||
self.select();
|
||||
EventResult::Consumed(None)
|
||||
}
|
||||
Event::Mouse {
|
||||
event: MouseEvent::Release(MouseButton::Left),
|
||||
position,
|
||||
offset,
|
||||
} if position.fits_in_rect(offset, self.req_size()) =>
|
||||
{
|
||||
self.select();
|
||||
EventResult::Consumed(None)
|
||||
}
|
||||
_ => EventResult::Ignored,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user