...
 
Commits (3)
[package]
name = "orbtk"
version = "0.2.27"
version = "0.2.29"
authors = ["Jeremy Soller <jackpot51@gmail.com>"]
description = "The Orbital Widget Toolkit"
documentation = "https://docs.rs/orbtk"
......
......@@ -132,6 +132,8 @@ impl Grid {
rect.height = rows[row].height;
}
entry.rect().set(rect);
entry.arrange();
}
}
}
......@@ -175,15 +177,24 @@ impl Widget for Grid {
}
fn draw(&self, renderer: &mut Renderer, _focused: bool, theme: &Theme) {
fn draw_widget(widget: &Arc<Widget>, renderer: &mut Renderer, focused: bool, theme: &Theme) {
widget.update();
widget.draw(renderer, focused, theme);
for child in widget.children().borrow().iter() {
draw_widget(child, renderer, focused, theme);
}
}
for (&(col, row), entry) in self.entries.borrow().iter() {
entry.draw(renderer, self.focused.get() == Some((col, row)), theme);
draw_widget(entry, renderer, self.focused.get() == Some((col, row)), theme);
}
}
fn event(&self, event: Event, mut focused: bool, redraw: &mut bool) -> bool {
fn event(&self, event: Event, mut focused: bool, redraw: &mut bool, caught: &mut bool) -> bool {
for (&(col, row), entry) in self.entries.borrow().iter() {
let is_focused = self.focused.get() == Some((col, row));
if entry.event(event, focused && is_focused, redraw) {
if entry.event(event, focused && is_focused, redraw, caught) {
if self.focused.check_set(Some((col, row))) || ! focused {
focused = true;
*redraw = true;
......@@ -191,6 +202,10 @@ impl Widget for Grid {
} else if is_focused {
self.focused.set(None);
}
if *caught {
break;
}
}
focused
......
......@@ -96,14 +96,17 @@ impl Widget for Image {
renderer.image(rect.x, rect.y, image.width(), image.height(), image.data());
}
fn event(&self, event: Event, focused: bool, redraw: &mut bool) -> bool {
fn event(&self, event: Event, focused: bool, redraw: &mut bool, caught: &mut bool) -> bool {
match event {
Event::Mouse { point, left_button, .. } => {
let rect = self.rect.get();
if rect.contains(point) && left_button {
let click_point: Point = point - rect.point();
self.emit_click(click_point);
*redraw = true;
if rect.contains(point) {
if left_button {
let click_point: Point = point - rect.point();
self.emit_click(click_point);
*redraw = true;
}
*caught = true;
}
}
_ => (),
......@@ -111,7 +114,7 @@ impl Widget for Image {
focused
}
fn children(&self) -> &RefCell<Vec<Arc<Widget>>> {
&self.children
}
......
......@@ -120,7 +120,7 @@ impl Widget for TextWidget {
}
}
fn event(&self, _event: Event, _focused: bool, _redraw: &mut bool) -> bool {
fn event(&self, _event: Event, _focused: bool, _redraw: &mut bool, _caught: &mut bool) -> bool {
_focused
}
......
......@@ -68,6 +68,10 @@ text-box :focus {
border-color: #5294E2;
}
combo-box :focus {
border-color: #5294E2;
}
combo-box-toggle :active {
background: #5294E2;
}
......
......@@ -145,7 +145,7 @@ impl Widget for Button {
self.selector().set(selector);
}
fn event(&self, event: Event, focused: bool, redraw: &mut bool) -> bool {
fn event(&self, event: Event, focused: bool, redraw: &mut bool, caught: &mut bool) -> bool {
match event {
Event::Mouse {
point, left_button, ..
......@@ -168,6 +168,8 @@ impl Widget for Button {
*redraw = true;
}
}
*caught = true;
} else {
if self.hover.check_set(false) {
*redraw = true;
......
......@@ -121,11 +121,10 @@ impl Widget for Entry {
point.x += 8;
}
}
fn event(&self, event: Event, _focused: bool, redraw: &mut bool) -> bool {
fn event(&self, event: Event, _focused: bool, redraw: &mut bool, caught: &mut bool) -> bool {
match event {
Event::Mouse {
point, left_button, ..
} => {
Event::Mouse { point, left_button, .. } => {
let mut click = false;
let rect = self.rect.get();
......@@ -141,9 +140,12 @@ impl Widget for Entry {
} else {
if self.pressed.check_set(false) {
click = true;
self.hover.set(false);
*redraw = true;
}
}
*caught = true;
} else {
if self.hover.check_set(false) {
*redraw = true;
......@@ -163,7 +165,7 @@ impl Widget for Entry {
_ => (),
}
_focused
false
}
fn name(&self) -> &str {
......@@ -313,7 +315,7 @@ impl Widget for ComboBox {
&self.margin
}
fn draw(&self, renderer: &mut Renderer, _focused: bool, theme: &Theme) {
fn draw(&self, renderer: &mut Renderer, focused: bool, theme: &Theme) {
let rect = self.rect.get();
let activated = self.activated.get();
let offset = self.offset.get();
......@@ -338,7 +340,7 @@ impl Widget for ComboBox {
if point.y >= rect.y
&& point.y + rect.height as i32 <= flyout_rect.y + flyout_rect.height as i32
{
entry.draw(renderer, _focused, theme);
entry.draw(renderer, focused, theme);
}
}
}
......@@ -350,6 +352,10 @@ impl Widget for ComboBox {
selector = selector.with_pseudo_class("active");
}
if focused {
selector = selector.with_pseudo_class("focus");
}
draw_box(renderer, rect, theme, &selector);
// draw toggle indicator
......@@ -375,12 +381,12 @@ impl Widget for ComboBox {
if activated {
if let Some(ref icon) = *self.toggle_icon_active.borrow() {
icon.position(toggle_rect.x, toggle_rect.y);
icon.draw(renderer, _focused, theme)
icon.draw(renderer, focused, theme)
}
} else {
if let Some(ref icon) = *self.toggle_icon.borrow() {
icon.position(toggle_rect.x, toggle_rect.y);
icon.draw(renderer, _focused, theme)
icon.draw(renderer, focused, theme)
}
}
......@@ -399,40 +405,45 @@ impl Widget for ComboBox {
}
}
fn event(&self, event: Event, focused: bool, redraw: &mut bool) -> bool {
match event {
Event::Mouse {
point, left_button, ..
} => {
let mut ignore_event = false;
if self.activated.get() {
for entry in self.entries.borrow().iter() {
if entry.event(event, focused, redraw) {
ignore_event = true;
self.change_selection(entry.index);
if self.activated.check_set(false) {
*redraw = true;
}
}
fn event(&self, event: Event, mut focused: bool, redraw: &mut bool, caught: &mut bool) -> bool {
let mut ignore_event = false;
if self.activated.get() {
for entry in self.entries.borrow().iter() {
if entry.event(event, focused, redraw, caught) {
ignore_event = true;
self.change_selection(entry.index);
if self.activated.check_set(false) {
*redraw = true;
}
}
if *caught {
break;
}
}
}
match event {
Event::Mouse { point, left_button, .. } => {
let rect = self.rect.get();
if rect.contains(point) {
if left_button {
self.pressed.set(!self.pressed.get());
if self.activated.check_set(true) {
focused = true;
*redraw = true;
}
} else {
if !self.pressed.get() {
if self.activated.check_set(false) {
focused = true;
*redraw = true;
}
}
}
*caught = true;
} else {
if !ignore_event {
if left_button {
......@@ -447,7 +458,7 @@ impl Widget for ComboBox {
}
}
}
Event::KeyPressed(key_event) => match key_event.scancode {
Event::KeyPressed(key_event) if focused => match key_event.scancode {
orbclient::K_UP => match self.selected.get() {
None => {
self.change_selection(0);
......
......@@ -129,7 +129,7 @@ impl Widget for Label {
&self.margin
}
fn event(&self, event: Event, focused: bool, redraw: &mut bool) -> bool {
fn event(&self, event: Event, focused: bool, redraw: &mut bool, caught: &mut bool) -> bool {
match event {
Event::Mouse { point, left_button, .. } => {
let mut click = false;
......@@ -146,6 +146,8 @@ impl Widget for Label {
*redraw = true;
}
}
*caught = true;
} else {
if !left_button {
if self.pressed.check_set(false) {
......
......@@ -267,7 +267,7 @@ impl Widget for List {
&self.local_position
}
fn event(&self, event: Event, focused: bool, redraw: &mut bool) -> bool {
fn event(&self, event: Event, focused: bool, redraw: &mut bool, caught: &mut bool) -> bool {
match event {
Event::Mouse {
point, left_button, ..
......@@ -286,6 +286,8 @@ impl Widget for List {
*redraw = true;
}
}
*caught = true;
} else {
if !left_button {
if self.pressed.check_set(false) {
......
......@@ -193,14 +193,18 @@ impl Widget for Menu {
}
}
fn event(&self, event: Event, focused: bool, redraw: &mut bool) -> bool {
fn event(&self, event: Event, focused: bool, redraw: &mut bool, caught: &mut bool) -> bool {
let mut ignore_event = false;
if self.activated.get() {
for entry in self.entries.borrow().iter() {
if entry.event(event, focused, redraw) {
if entry.event(event, focused, redraw, caught) {
ignore_event = true;
self.pressed.set(true);
}
if *caught {
break;
}
}
}
......@@ -225,6 +229,8 @@ impl Widget for Menu {
}
}
}
*caught = true;
} else {
if !ignore_event {
if left_button {
......@@ -367,7 +373,7 @@ impl Widget for Action {
}
}
fn event(&self, event: Event, _focused: bool, redraw: &mut bool) -> bool {
fn event(&self, event: Event, _focused: bool, redraw: &mut bool, caught: &mut bool) -> bool {
match event {
Event::Mouse { point, left_button, .. } => {
let mut click = false;
......@@ -389,6 +395,8 @@ impl Widget for Action {
*redraw = true;
}
}
*caught = true;
} else {
if self.hover.check_set(false) {
*redraw = true;
......@@ -477,13 +485,14 @@ impl Widget for Separator {
renderer.rect(rect.x, line_y, rect.width, 1, theme.color("color", selector));
}
fn event(&self, event: Event, _focused: bool, _redraw: &mut bool) -> bool {
fn event(&self, event: Event, _focused: bool, _redraw: &mut bool, caught: &mut bool) -> bool {
let mut ignore_event = false;
match event {
Event::Mouse { point, .. } => {
let rect = self.rect.get();
if rect.contains(point) {
ignore_event = true;
*caught = true;
}
}
_ => (),
......
......@@ -76,10 +76,10 @@ pub trait Widget: Any {
_focused
}
/// Handle the incoming events by bubbling from child to parent.
/// Handle the incoming events by bubbling from child to parent.
/// Must have overwritten to create a custom bubbling event handling.
fn event(&self, _event: Event, _focused: bool, _redraw: &mut bool) -> bool {
_focused
fn event(&self, _event: Event, _focused: bool, _redraw: &mut bool, _caught: &mut bool) -> bool {
false
}
/// Return the name of the widget.
......
......@@ -121,7 +121,7 @@ impl Widget for ProgressBar {
}
}
fn event(&self, event: Event, focused: bool, redraw: &mut bool) -> bool {
fn event(&self, event: Event, focused: bool, redraw: &mut bool, caught: &mut bool) -> bool {
match event {
Event::Mouse { point, left_button, .. } => {
let mut click = false;
......@@ -138,6 +138,8 @@ impl Widget for ProgressBar {
*redraw = true;
}
}
*caught = true;
} else {
if !left_button {
if self.pressed.check_set(false) {
......
......@@ -274,7 +274,7 @@ impl Widget for TextBox {
}
}
fn event(&self, event: Event, mut focused: bool, redraw: &mut bool) -> bool {
fn event(&self, event: Event, mut focused: bool, redraw: &mut bool, caught: &mut bool) -> bool {
// If the event wasn't handled by the custom handler.
if let Some(event) = self.handle_event(event, &mut focused, redraw) {
let mut new_text_i = None;
......@@ -296,6 +296,8 @@ impl Widget for TextBox {
*redraw = true;
}
}
*caught = true;
} else {
if !left_button {
if self.pressed.check_set(false) {
......
......@@ -46,7 +46,7 @@ impl<'a> Renderer for WindowRenderer<'a> {
fn sync(&mut self) -> bool {
self.inner.sync()
}
fn mode(&self) -> &Cell<Mode> {
&self.inner.mode()
}
......@@ -225,30 +225,20 @@ impl Window {
_ => (),
}
for widget in self.widgets.borrow().iter() {
self.redraw = self.drain_event(event, self.redraw, widget);
}
}
}
fn drain_event(&self, event: Event, redraw: bool, widget: &Arc<Widget>) -> bool {
let mut redraw = redraw;
//let mut children_redraw = false;
let mut caught = false;
for widget in self.widgets.borrow().iter().rev() {
if widget.event(event, self.focus_manager.focused(&widget), &mut self.redraw, &mut caught) {
if !self.focus_manager.focused(&widget) {
self.focus_manager.request_focus(&widget);
self.redraw = true;
}
}
if widget.event(event, self.focus_manager.focused(&widget), &mut redraw) {
if !self.focus_manager.focused(&widget) {
self.focus_manager.request_focus(&widget);
redraw = true;
if caught {
break;
}
}
}
redraw
// for child in &*widget.children().borrow_mut() {
// children_redraw = self.drain_event(event, redraw, child);
// }
// redraw || children_redraw
}
pub fn drain_orbital_events(&mut self) {
......