From a46cd7856bd25243afb6f37288c353eca1e09249 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Tue, 12 Mar 2024 01:38:11 +0100 Subject: [PATCH] add br element, update docs --- hui/src/element/builtin.rs | 3 +++ hui/src/element/builtin/br.rs | 22 ++++++++++++++++++++++ hui/src/element/builtin/container.rs | 8 ++++++-- hui/src/measure.rs | 2 ++ 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 hui/src/element/builtin/br.rs diff --git a/hui/src/element/builtin.rs b/hui/src/element/builtin.rs index f650d65..db0e26b 100644 --- a/hui/src/element/builtin.rs +++ b/hui/src/element/builtin.rs @@ -9,6 +9,9 @@ pub mod fill_rect; #[cfg(feature = "builtin_elements")] pub mod spacer; +#[cfg(feature = "builtin_elements")] +pub mod br; + // "The basics": #[cfg(feature = "builtin_elements")] diff --git a/hui/src/element/builtin/br.rs b/hui/src/element/builtin/br.rs new file mode 100644 index 0000000..4858582 --- /dev/null +++ b/hui/src/element/builtin/br.rs @@ -0,0 +1,22 @@ +use crate::{ + element::{MeasureContext, ProcessContext, UiElement}, + measure::Response +}; + +#[derive(Clone, Copy, Debug, Default)] +pub struct Br; + +impl UiElement for Br { + fn name(&self) -> &'static str { + "Br" + } + + fn measure(&self, _: MeasureContext) -> Response { + Response { + should_wrap: true, + ..Default::default() + } + } + + fn process(&self, _: ProcessContext) {} +} diff --git a/hui/src/element/builtin/container.rs b/hui/src/element/builtin/container.rs index 65084c6..f97ca87 100644 --- a/hui/src/element/builtin/container.rs +++ b/hui/src/element/builtin/container.rs @@ -76,7 +76,11 @@ pub struct Container { #[setters(into)] pub corner_radius: Corners, - /// Set this to `true` to allow the elements wrap automatically\ + /// Set this to `true` to allow the elements wrap automatically + /// + /// Disabling/enabling this does not affect explicit wrapping\ + /// (for example, `Br`, or any other element with `should_wrap` set to `true`) + /// /// This is an experimental feature and may not work as expected pub wrap: bool, @@ -206,7 +210,7 @@ impl UiElement for Container { }; //Wrap the element if it exceeds container's size and is not the first element in the line - if self.wrap && (end_pos_pri > max_line_pri) && (line_element_count > 0) { + if ((self.wrap && (end_pos_pri > max_line_pri)) || measure.should_wrap) && (line_element_count > 0) { // >>>>>>> WRAP THAT B*TCH! //Negate the leftover gap from the previous element diff --git a/hui/src/measure.rs b/hui/src/measure.rs index 17607f2..6f8ebbb 100644 --- a/hui/src/measure.rs +++ b/hui/src/measure.rs @@ -26,6 +26,8 @@ pub struct Response { /// (the element itself gets wrapped to the next line too) /// /// You should almost never set this, and the exact behavior may change in the future + /// + /// Currently, this forces wrapping even if Container::wrap is set to false pub should_wrap: bool, }