Add option to isolate an element
This commit is contained in:
parent
bd9cca5f11
commit
7a40050799
3 changed files with 44 additions and 1 deletions
|
@ -72,6 +72,7 @@ pub struct ButtonInfo {
|
||||||
|
|
||||||
// the chosen element for controller input
|
// the chosen element for controller input
|
||||||
pub select: bool,
|
pub select: bool,
|
||||||
|
pub isolate: bool,
|
||||||
|
|
||||||
pub parent: Weak<GridInfo>,
|
pub parent: Weak<GridInfo>,
|
||||||
}
|
}
|
||||||
|
@ -120,6 +121,7 @@ impl ButtonInfo {
|
||||||
neighbour_infos: Vec::new(),
|
neighbour_infos: Vec::new(),
|
||||||
|
|
||||||
select: false,
|
select: false,
|
||||||
|
isolate: false,
|
||||||
|
|
||||||
parent: Arc::downgrade(grid),
|
parent: Arc::downgrade(grid),
|
||||||
};
|
};
|
||||||
|
@ -168,6 +170,7 @@ impl ButtonInfo {
|
||||||
.add_neighbour(NeighbourDirection::North, cow_to_str(attribute.value)),
|
.add_neighbour(NeighbourDirection::North, cow_to_str(attribute.value)),
|
||||||
b"south_neighbour" => button_info
|
b"south_neighbour" => button_info
|
||||||
.add_neighbour(NeighbourDirection::South, cow_to_str(attribute.value)),
|
.add_neighbour(NeighbourDirection::South, cow_to_str(attribute.value)),
|
||||||
|
b"isolate" => button_info.isolate = str_into(attribute.value)?,
|
||||||
_ => {
|
_ => {
|
||||||
return Err(anyhow::Error::msg(format!(
|
return Err(anyhow::Error::msg(format!(
|
||||||
"Unsupported attribute in Button: {}",
|
"Unsupported attribute in Button: {}",
|
||||||
|
|
|
@ -24,6 +24,8 @@ pub struct ButtonBuilder {
|
||||||
icon: Option<Arc<Image>>,
|
icon: Option<Arc<Image>>,
|
||||||
margin: u32,
|
margin: u32,
|
||||||
|
|
||||||
|
isolate: bool,
|
||||||
|
|
||||||
text: String,
|
text: String,
|
||||||
text_color: Color,
|
text_color: Color,
|
||||||
ratio: f32,
|
ratio: f32,
|
||||||
|
@ -42,6 +44,12 @@ pub struct ButtonBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ButtonBuilder {
|
impl ButtonBuilder {
|
||||||
|
pub fn set_isolate(mut self, isolate: bool) -> Self {
|
||||||
|
self.isolate = isolate;
|
||||||
|
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_select_mode(mut self, select_mode: ButtonSelectMode) -> Self {
|
pub fn set_select_mode(mut self, select_mode: ButtonSelectMode) -> Self {
|
||||||
self.button_select_mode = select_mode;
|
self.button_select_mode = select_mode;
|
||||||
|
|
||||||
|
@ -147,6 +155,7 @@ impl ButtonBuilder {
|
||||||
click_executable.clone(),
|
click_executable.clone(),
|
||||||
select_executable.clone(),
|
select_executable.clone(),
|
||||||
on_select_executable.clone(),
|
on_select_executable.clone(),
|
||||||
|
self.isolate,
|
||||||
);
|
);
|
||||||
|
|
||||||
let hoverable = Hoverable::new(
|
let hoverable = Hoverable::new(
|
||||||
|
@ -278,6 +287,8 @@ impl Button {
|
||||||
icon: None,
|
icon: None,
|
||||||
margin: 0,
|
margin: 0,
|
||||||
|
|
||||||
|
isolate: false,
|
||||||
|
|
||||||
text: String::new(),
|
text: String::new(),
|
||||||
text_color: Color::Black,
|
text_color: Color::Black,
|
||||||
ratio: 0.7,
|
ratio: 0.7,
|
||||||
|
@ -357,7 +368,9 @@ impl Button {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn try_from(button_info: &ButtonInfo, gui_handler: &Arc<GuiHandler>) -> Result<Arc<Self>> {
|
pub fn try_from(button_info: &ButtonInfo, gui_handler: &Arc<GuiHandler>) -> Result<Arc<Self>> {
|
||||||
let mut button_builder = Button::builder().set_select_mode(button_info.select_mode);
|
let mut button_builder = Button::builder()
|
||||||
|
.set_select_mode(button_info.select_mode)
|
||||||
|
.set_isolate(button_info.isolate);
|
||||||
|
|
||||||
if let Some(normal) = button_info.normal.clone() {
|
if let Some(normal) = button_info.normal.clone() {
|
||||||
button_builder = button_builder.set_normal(normal);
|
button_builder = button_builder.set_normal(normal);
|
||||||
|
|
|
@ -29,6 +29,7 @@ pub struct Selectable {
|
||||||
click_audible: RwLock<Option<Arc<Audible>>>,
|
click_audible: RwLock<Option<Arc<Audible>>>,
|
||||||
|
|
||||||
ui_layer: AtomicI32,
|
ui_layer: AtomicI32,
|
||||||
|
isolate: bool,
|
||||||
|
|
||||||
// used when clicked
|
// used when clicked
|
||||||
executable: Arc<Executable<()>>,
|
executable: Arc<Executable<()>>,
|
||||||
|
@ -54,6 +55,7 @@ impl Selectable {
|
||||||
executable: Arc<Executable<()>>,
|
executable: Arc<Executable<()>>,
|
||||||
selected_changed_executable: Arc<Executable<bool>>,
|
selected_changed_executable: Arc<Executable<bool>>,
|
||||||
on_select_executable: Arc<Executable<bool>>,
|
on_select_executable: Arc<Executable<bool>>,
|
||||||
|
isolate: bool,
|
||||||
) -> Arc<Self> {
|
) -> Arc<Self> {
|
||||||
Arc::new(Selectable {
|
Arc::new(Selectable {
|
||||||
gui_handler,
|
gui_handler,
|
||||||
|
@ -78,6 +80,7 @@ impl Selectable {
|
||||||
custom_callback: RwLock::new(None),
|
custom_callback: RwLock::new(None),
|
||||||
|
|
||||||
ui_layer: AtomicI32::new(0),
|
ui_layer: AtomicI32::new(0),
|
||||||
|
isolate,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,6 +218,10 @@ impl Selectable {
|
||||||
///
|
///
|
||||||
/// * `selectable` the new east neighbour
|
/// * `selectable` the new east neighbour
|
||||||
pub fn set_east_neighbour(&self, selectable: Option<&Arc<Selectable>>) {
|
pub fn set_east_neighbour(&self, selectable: Option<&Arc<Selectable>>) {
|
||||||
|
if self.isolate {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let mut east_neighbour = self.east_neighbour.write().unwrap();
|
let mut east_neighbour = self.east_neighbour.write().unwrap();
|
||||||
|
|
||||||
match selectable {
|
match selectable {
|
||||||
|
@ -240,6 +247,10 @@ impl Selectable {
|
||||||
///
|
///
|
||||||
/// * `selectable` the new west neighbour
|
/// * `selectable` the new west neighbour
|
||||||
pub fn set_west_neighbour(&self, selectable: Option<&Arc<Selectable>>) {
|
pub fn set_west_neighbour(&self, selectable: Option<&Arc<Selectable>>) {
|
||||||
|
if self.isolate {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let mut west_neighbour = self.west_neighbour.write().unwrap();
|
let mut west_neighbour = self.west_neighbour.write().unwrap();
|
||||||
|
|
||||||
match selectable {
|
match selectable {
|
||||||
|
@ -265,6 +276,10 @@ impl Selectable {
|
||||||
///
|
///
|
||||||
/// * `selectable` the new north neighbour
|
/// * `selectable` the new north neighbour
|
||||||
pub fn set_north_neighbour(&self, selectable: Option<&Arc<Selectable>>) {
|
pub fn set_north_neighbour(&self, selectable: Option<&Arc<Selectable>>) {
|
||||||
|
if self.isolate {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let mut north_neighbour = self.north_neighbour.write().unwrap();
|
let mut north_neighbour = self.north_neighbour.write().unwrap();
|
||||||
|
|
||||||
match selectable {
|
match selectable {
|
||||||
|
@ -290,6 +305,10 @@ impl Selectable {
|
||||||
///
|
///
|
||||||
/// * `selectable` the new south neighbour
|
/// * `selectable` the new south neighbour
|
||||||
pub fn set_south_neighbour(&self, selectable: Option<&Arc<Selectable>>) {
|
pub fn set_south_neighbour(&self, selectable: Option<&Arc<Selectable>>) {
|
||||||
|
if self.isolate {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let mut south_neighbour = self.south_neighbour.write().unwrap();
|
let mut south_neighbour = self.south_neighbour.write().unwrap();
|
||||||
|
|
||||||
match selectable {
|
match selectable {
|
||||||
|
@ -299,11 +318,19 @@ impl Selectable {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn connect_vertically(upper: &Arc<Selectable>, lower: &Arc<Selectable>) {
|
pub fn connect_vertically(upper: &Arc<Selectable>, lower: &Arc<Selectable>) {
|
||||||
|
if upper.isolate || lower.isolate {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
*upper.south_neighbour.write().unwrap() = Some(Arc::downgrade(lower));
|
*upper.south_neighbour.write().unwrap() = Some(Arc::downgrade(lower));
|
||||||
*lower.north_neighbour.write().unwrap() = Some(Arc::downgrade(upper));
|
*lower.north_neighbour.write().unwrap() = Some(Arc::downgrade(upper));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn connect_horizontally(left: &Arc<Selectable>, right: &Arc<Selectable>) {
|
pub fn connect_horizontally(left: &Arc<Selectable>, right: &Arc<Selectable>) {
|
||||||
|
if left.isolate || right.isolate {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
*left.east_neighbour.write().unwrap() = Some(Arc::downgrade(right));
|
*left.east_neighbour.write().unwrap() = Some(Arc::downgrade(right));
|
||||||
*right.west_neighbour.write().unwrap() = Some(Arc::downgrade(left));
|
*right.west_neighbour.write().unwrap() = Some(Arc::downgrade(left));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue