layout: Put all button state into active_buttons

Ths gets rid of Rc<RefCell<>> sharing of state, which can be hard to keep track of.
In addition, there's no longer any duplication of button state.
This commit is contained in:
Dorota Czaplejewicz
2022-10-01 12:48:52 +00:00
parent 74c5ef4a51
commit 952ec805ed
4 changed files with 188 additions and 218 deletions

View File

@ -1,11 +1,10 @@
/*! Drawing the UI */
use cairo;
use std::cell::RefCell;
use ::action::{ Action, Modifier };
use ::keyboard;
use ::layout::{ Button, Label, LatchedState, Layout };
use crate::layout::{ Button, ButtonPosition, Label, LatchedState, Layout };
use ::layout::c::{ Bounds, EekGtkKeyboard, Point };
use ::submission::c::Submission as CSubmission;
@ -84,8 +83,15 @@ mod c {
let cr = unsafe { cairo::Context::from_raw_none(cr) };
let active_modifiers = submission.get_active_modifiers();
layout.foreach_visible_button(|offset, button| {
let state = RefCell::borrow(&button.state).clone();
layout.foreach_visible_button(|offset, button, (row, position_in_row)| {
// TODO: this iterator copies string indices way too much.
// For efficiency, it would be better to draw pressed buttons from the list first,
// and then iterate the rest without having to look up their indices.
let state = layout.state.active_buttons.get(&ButtonPosition {
view: layout.state.current_view.clone(),
row,
position_in_row,
});
let locked = LockedStyle::from_action(
&button.action,
@ -116,7 +122,7 @@ mod c {
let layout = unsafe { &mut *layout };
let cr = unsafe { cairo::Context::from_raw_none(cr) };
layout.foreach_visible_button(|offset, button| {
layout.foreach_visible_button(|offset, button, _index| {
render_button_at_position(
renderer, &cr,
offset,