Struct pushrod::widget::box_widget::BoxWidget

source ·
pub struct BoxWidget { /* private fields */ }
Expand description

A BoxWidget is a CanvasWidget with a bounding box. Takes two additional options:

  • CONFIG_BORDER_WIDTH specifies the width of the border to be drawn in pixels.
  • CONFIG_BORDER_COLOR specifies the color of the border to be drawn.

Implementations§

source§

impl BoxWidget

source

pub fn new() -> Self

Constructor.

Examples found in repository?
examples/simple.rs (line 546)
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
    fn add_horizontal_layout(&mut self) {
        let mut base_widget: CanvasWidget = CanvasWidget::new();

        base_widget.set_point(CONFIG_ORIGIN, 20, 70);
        base_widget.set_size(CONFIG_BODY_SIZE, 760, 200);
        base_widget.set_color(CONFIG_MAIN_COLOR, [1.0, 1.0, 1.0, 1.0]);

        let base_widget_id = self.pushrod.borrow_mut().add_widget_to_parent_by_name(
            "MainContainerWidget",
            "HorizontalManagerWidget1",
            Box::new(base_widget),
        );

        let base_layout_id =
            self.pushrod
                .borrow_mut()
                .add_layout_manager(Box::new(HorizontalLayoutManager::new(
                    base_widget_id,
                    LayoutManagerPadding {
                        top: 4,
                        left: 4,
                        right: 4,
                        bottom: 4,
                        spacing: 4,
                    },
                )));

        let mut box_widget = BoxWidget::new();

        box_widget.set_point(CONFIG_ORIGIN, 250, 80);
        box_widget.set_size(CONFIG_BODY_SIZE, 200, 200);
        box_widget.set_color(CONFIG_MAIN_COLOR, [0.0, 1.0, 0.0, 1.0]);
        box_widget.set_numeric(CONFIG_BORDER_WIDTH, 4);
        box_widget.set_color(CONFIG_BORDER_COLOR, [1.0, 0.0, 0.0, 1.0]);
        let box_widget_id = self.pushrod.borrow_mut().add_widget_to_layout_manager(
            "BoxInLayoutWidget1",
            Box::new(box_widget),
            base_layout_id,
            make_origin_point(),
        );

        let mut text_widget2 = TextWidget::new(
            "assets/OpenSans-Regular.ttf".to_string(),
            "Left".to_string(),
            24,
            TextJustify::Left,
        );
        text_widget2.set_point(CONFIG_ORIGIN, 265, 100);
        text_widget2.set_size(CONFIG_BODY_SIZE, 170, 32);
        text_widget2.set_color(CONFIG_TEXT_COLOR, [0.0, 0.0, 0.0, 1.0]);
        text_widget2.set_color(CONFIG_MAIN_COLOR, [1.0, 1.0, 1.0, 0.0]);
        self.pushrod.borrow_mut().add_widget_to_parent(
            "LeftJustifiedText",
            Box::new(text_widget2),
            box_widget_id,
        );

        let mut text_widget3 = TextWidget::new(
            "assets/OpenSans-Regular.ttf".to_string(),
            "Center".to_string(),
            24,
            TextJustify::Center,
        );
        text_widget3.set_point(CONFIG_ORIGIN, 265, 166);
        text_widget3.set_size(CONFIG_BODY_SIZE, 170, 32);
        text_widget3.set_color(CONFIG_TEXT_COLOR, [0.0, 0.0, 0.0, 1.0]);
        text_widget3.set_color(CONFIG_MAIN_COLOR, [1.0, 1.0, 1.0, 0.0]);
        self.pushrod.borrow_mut().add_widget_to_parent(
            "CenterJustifiedText",
            Box::new(text_widget3),
            box_widget_id,
        );

        let mut text_widget4 = TextWidget::new(
            "assets/OpenSans-Regular.ttf".to_string(),
            "Right".to_string(),
            24,
            TextJustify::Right,
        );
        text_widget4.set_point(CONFIG_ORIGIN, 265, 230);
        text_widget4.set_size(CONFIG_BODY_SIZE, 170, 32);
        text_widget4.set_color(CONFIG_TEXT_COLOR, [0.0, 0.0, 0.0, 1.0]);
        text_widget4.set_color(CONFIG_MAIN_COLOR, [1.0, 1.0, 1.0, 0.0]);
        self.pushrod.borrow_mut().add_widget_to_parent(
            "RightJustifiedText",
            Box::new(text_widget4),
            box_widget_id,
        );

        let mut box_1 = BoxWidget::new();
        box_1.set_point(CONFIG_ORIGIN, 480, 80);
        box_1.set_size(CONFIG_BODY_SIZE, 200, 200);
        box_1.set_color(CONFIG_MAIN_COLOR, [0.5, 0.5, 1.0, 1.0]);
        box_1.set_numeric(CONFIG_BORDER_WIDTH, 2);
        box_1.set_color(CONFIG_BORDER_COLOR, [0.0, 0.0, 1.0, 1.0]);
        let box_1_id = self.pushrod.borrow_mut().add_widget_to_layout_manager(
            "BoxInLayoutWidget2",
            Box::new(box_1),
            base_layout_id,
            make_origin_point(),
        );

        let mut inner_box_1 = BoxWidget::new();
        inner_box_1.set_point(CONFIG_ORIGIN, 505, 105);
        inner_box_1.set_size(CONFIG_BODY_SIZE, 70, 60);
        inner_box_1.set_color(CONFIG_MAIN_COLOR, [0.75, 0.75, 1.0, 1.0]);
        inner_box_1.set_numeric(CONFIG_BORDER_WIDTH, 1);
        inner_box_1.set_color(CONFIG_BORDER_COLOR, [1.0, 0.0, 1.0, 1.0]);
        self.pushrod
            .borrow_mut()
            .add_widget_to_parent("MiniBox1", Box::new(inner_box_1), box_1_id);

        let mut inner_box_2 = BoxWidget::new();
        inner_box_2.set_point(CONFIG_ORIGIN, 585, 105);
        inner_box_2.set_size(CONFIG_BODY_SIZE, 70, 60);
        inner_box_2.set_color(CONFIG_MAIN_COLOR, [0.75, 0.25, 1.0, 1.0]);
        inner_box_2.set_numeric(CONFIG_BORDER_WIDTH, 1);
        inner_box_2.set_color(CONFIG_BORDER_COLOR, [1.0, 1.0, 0.0, 1.0]);
        self.pushrod
            .borrow_mut()
            .add_widget_to_parent("MiniBox2", Box::new(inner_box_2), box_1_id);

        let mut inner_box_3 = BoxWidget::new();
        inner_box_3.set_point(CONFIG_ORIGIN, 505, 190);
        inner_box_3.set_size(CONFIG_BODY_SIZE, 70, 60);
        inner_box_3.set_color(CONFIG_MAIN_COLOR, [0.25, 0.50, 0.75, 1.0]);
        inner_box_3.set_numeric(CONFIG_BORDER_WIDTH, 1);
        inner_box_3.set_color(CONFIG_BORDER_COLOR, [1.0, 0.50, 1.0, 1.0]);
        self.pushrod
            .borrow_mut()
            .add_widget_to_parent("MiniBox3", Box::new(inner_box_3), box_1_id);

        let mut inner_box_4 = BoxWidget::new();
        inner_box_4.set_point(CONFIG_ORIGIN, 585, 190);
        inner_box_4.set_size(CONFIG_BODY_SIZE, 70, 60);
        inner_box_4.set_color(CONFIG_MAIN_COLOR, [0.75, 0.50, 0.0, 1.0]);
        inner_box_4.set_numeric(CONFIG_BORDER_WIDTH, 1);
        inner_box_4.set_color(CONFIG_BORDER_COLOR, [0.50, 0.0, 0.25, 1.0]);
        self.pushrod
            .borrow_mut()
            .add_widget_to_parent("MiniBox4", Box::new(inner_box_4), box_1_id);

        let mut box_2 = BoxWidget::new();
        box_2.set_point(CONFIG_ORIGIN, 480, 80);
        box_2.set_size(CONFIG_BODY_SIZE, 200, 200);
        box_2.set_color(
            CONFIG_MAIN_COLOR,
            [
                (rand::random::<u8>() as f32 / 255.0),
                (rand::random::<u8>() as f32 / 255.0),
                (rand::random::<u8>() as f32 / 255.0),
                1.0,
            ],
        );
        box_2.set_numeric(CONFIG_BORDER_WIDTH, 1);
        box_2.set_color(CONFIG_BORDER_COLOR, [0.0, 0.0, 0.0, 1.0]);
        self.pushrod.borrow_mut().add_widget_to_layout_manager(
            "BoxInLayoutWidget3",
            Box::new(box_2),
            base_layout_id,
            make_origin_point(),
        );
    }

Trait Implementations§

source§

impl Drawable for BoxWidget

source§

fn draw(&mut self, c: Context, g: &mut GlGraphics, clip: &DrawState)

Draws the Widget’s contents. Only gets called if the Widget is in invalidated state. Provides a modified Context object that has an origin of 0x0 in drawing space for the draw routine. Also provides a mut G2d object against which to draw, and a clip, which is automatically set to provide a clipping area for the Widget. If the Widget draws outside of the clipped bounds, that will not be drawn on the screen.
source§

fn draw_disabled( &mut self, c: Context, size: Size, g: &mut GlGraphics, clip: &DrawState, )

Internal method that is used to draw a box around the Widget when in disabled state. You can override this method, should you choose to, so that the disabled state appears differently in your application. It is safe to leave this alone.
source§

fn draw_with_offset( &mut self, c: Context, g: &mut GlGraphics, clip: &DrawState, point_offset: Point, )

Draws an object at an offset on the screen. This is a convenience method that is used by other Widgets that contain multiple widgets. (See CheckboxWidget and ImageButtonWidget for good examples of this use.)
source§

impl InjectableCustomEvents for BoxWidget

source§

fn inject_custom_event(&mut self, _widget_id: i32) -> Option<CallbackEvent>

Injects an event into the run loop. This can be a timer event, a refresh event, or whatever the Widget wants to inject. These should be custom events, not system events. This method only gets called if injects_events returns true.
source§

impl InjectableSystemEvents for BoxWidget

source§

fn inject_system_event(&mut self) -> Option<CallbackEvent>

Part of the main loop that queries the Widget for any system-level events that should be injected into the PushrodCallbackEvents trait, and not handled by the top-level run loop. This sends out messages that are bypassed from being used by the Run Loop, so be very careful. Use this for sending things like custom messages (such as a Widget move or Widget resize message, which is irrelevant to the run loop.)
source§

impl Widget for BoxWidget

source§

fn config(&mut self) -> &mut Configurable

Retrieves the Configurable object for this Widget. All Widget implementations must provide this. (See the CanvasWidget implementation.)
source§

fn set_config(&mut self, config: u8, config_value: Config)

Master config setter - use convenience methods.
source§

fn set_size(&mut self, config: u8, w: i32, h: i32)

Sets a size value for a configuration key.
source§

fn set_point(&mut self, config: u8, x: i32, y: i32)

Sets a point value for a configuration key.
source§

fn set_widget_id(&mut self, widget_id: i32)

source§

fn get_widget_id(&mut self) -> i32

source§

fn injects_system_events(&mut self) -> bool

Indicates to the run loop whether or not a Widget injects system-level events.
source§

fn get_injectable_custom_events(&mut self) -> &mut dyn InjectableCustomEvents

Retrieves the InjectableCustomEvents trait of this class, which is responsible for injecting custom events when appropriate. Injecting system events is used with the InjectableSystemEvents, and things like mouse clicks and widget clicks are used with the handle_event block. This code is used to inject events that are not triggered by other events in the system.
source§

fn get_injectable_system_events(&mut self) -> &mut dyn InjectableSystemEvents

Retrieves the trait for injecting system events. Only use this if your Widget injects custom system-level events that the top-level application needs to use. Anything other than that should be ignored completely.
source§

fn get_drawable(&mut self) -> &mut dyn Drawable

Retrieves the Drawable functionality of this Widget.
source§

fn invalidate(&mut self)

Indicates that a Widget object needs to be repainted.
source§

fn clear_invalidate(&mut self)

Clears the invalidation flag. Set this when the draw function completes. Otherwise, this Widget object may be continuously repainted.
source§

fn is_invalidated(&mut self) -> bool

Indicates whether or not a Widget needs to be repainted.
source§

fn get_config(&mut self, config: u8) -> Option<&Config>

Master config getter - use convenience methods.
source§

fn set_color(&mut self, config: u8, color: Color)

Sets a color for a configuration key.
source§

fn set_numeric(&mut self, config: u8, value: u64)

Sets a numeric value for a configuration key.
source§

fn set_text(&mut self, config: u8, text: String)

Sets a text value for a configuration key.
source§

fn set_toggle(&mut self, config: u8, flag: bool)

Sets a toggle value for a configuration key.
source§

fn handle_event( &mut self, _injected: bool, _event: CallbackEvent, ) -> Option<CallbackEvent>

Custom handler to receive an event. Any Widget that implements this does so to handle top-level GUI events, such as a mouse entering or exiting the bounds of this Widget. If the injected flag is set, it indicates that the event supplied was generate by a Widget, and not by the run loop.
source§

fn handles_events(&mut self) -> bool

Indicates to the run loop whether or not the Widget handles system-generated events.
source§

fn injects_custom_events(&mut self) -> bool

If this Widget provides custom injected events that are generated outside of the handle_event loop, indicate true. Only override if necessary. (See TimerWidget for reference.)
source§

fn is_drawable(&mut self) -> bool

Describes whether or not the Widget returns a Drawable trait. This function is called each time a frame is refreshed, so if there is no Drawable available, this function could serve as a way to indicate a frame tick. Only override this to set it to false if your Widget does not draw anything on the screen.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> SetParameter for T

source§

fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result
where T: Parameter<Self>,

Sets value as a parameter of self.
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.