Class: Wads::WadsLayout

Inherits:
Object
  • Object
show all
Defined in:
lib/wads/widgets.rb

Overview

The base class for all wads layouts. It has helper methods to add different types of widgets to the layout.

Direct Known Subclasses

SectionLayout, VerticalColumnLayout

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y, width, height, parent_widget, args = {}) ⇒ WadsLayout

Returns a new instance of WadsLayout.



589
590
591
592
593
# File 'lib/wads/widgets.rb', line 589

def initialize(x, y, width, height, parent_widget, args = {})
    @border_coords = Coordinates.new(x, y, width, height)
    @parent_widget = parent_widget
    @args = args
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



587
588
589
# File 'lib/wads/widgets.rb', line 587

def args
  @args
end

#border_coordsObject

Returns the value of attribute border_coords.



585
586
587
# File 'lib/wads/widgets.rb', line 585

def border_coords
  @border_coords
end

#parent_widgetObject

Returns the value of attribute parent_widget.



586
587
588
# File 'lib/wads/widgets.rb', line 586

def parent_widget
  @parent_widget
end

Instance Method Details

#add_button(label, args = {}, &block) ⇒ Object



648
649
650
651
652
653
654
655
656
657
658
659
# File 'lib/wads/widgets.rb', line 648

def add_button(label, args = {}, &block)
    text_width = WadsConfig.instance.current_theme.pixel_width_for_string(label) + 20
    coordinates = get_coordinates(ELEMENT_BUTTON,
        { ARG_DESIRED_WIDTH => text_width}.merge(args))
    new_button = Button.new(coordinates.x, coordinates.y, label, 
                            { ARG_DESIRED_WIDTH => coordinates.width,
                              ARG_THEME => @parent_widget.gui_theme}.merge(args))
    new_button.set_action(&block)
    new_button.base_z = @parent_widget.base_z
    @parent_widget.add_child(new_button)
    new_button
end

#add_document(content, args = {}) ⇒ Object



670
671
672
673
674
675
676
677
678
679
680
681
682
# File 'lib/wads/widgets.rb', line 670

def add_document(content, args = {})
    number_of_content_lines = content.lines.count
    height = (number_of_content_lines * 26) + 4
    coordinates = get_coordinates(ELEMENT_DOCUMENT,
        { ARG_DESIRED_HEIGHT => height}.merge(args))
    new_doc = Document.new(coordinates.x, coordinates.y,
                           coordinates.width, coordinates.height,
                           content,
                           {ARG_THEME => @parent_widget.gui_theme}.merge(args))
    new_doc.base_z = @parent_widget.base_z
    @parent_widget.add_child(new_doc)
    new_doc
end

#add_graph_display(graph, display_mode = GRAPH_DISPLAY_ALL, args = {}) ⇒ Object



684
685
686
687
688
689
690
691
692
# File 'lib/wads/widgets.rb', line 684

def add_graph_display(graph, display_mode = GRAPH_DISPLAY_ALL, args = {})
    coordinates = get_coordinates(ELEMENT_GRAPH, args)
    new_graph = GraphWidget.new(coordinates.x, coordinates.y,
                                coordinates.width, coordinates.height,
                                graph, display_mode) 
    new_graph.base_z = @parent_widget.base_z
    @parent_widget.add_child(new_graph)
    new_graph
end

#add_horizontal_panel(args = {}) ⇒ Object



733
734
735
# File 'lib/wads/widgets.rb', line 733

def add_horizontal_panel(args = {})
    internal_add_panel(ELEMENT_HORIZONTAL_PANEL, args)
end

#add_image(filename, args = {}) ⇒ Object



636
637
638
639
640
641
642
643
644
645
646
# File 'lib/wads/widgets.rb', line 636

def add_image(filename, args = {})
    img = Gosu::Image.new(filename)
    coordinates = get_coordinates(ELEMENT_IMAGE,
        { ARG_DESIRED_WIDTH => img.width,
          ARG_DESIRED_HEIGHT => img.height}.merge(args))
    new_image = ImageWidget.new(coordinates.x, coordinates.y, img,
                                {ARG_THEME => @parent_widget.gui_theme}.merge(args))
    new_image.base_z = @parent_widget.base_z
    @parent_widget.add_child(new_image)
    new_image
end

#add_max_panel(args = {}) ⇒ Object



741
742
743
# File 'lib/wads/widgets.rb', line 741

def add_max_panel(args = {})
    internal_add_panel(ELEMENT_MAX_PANEL, args)
end

#add_multi_select_table(column_headers, visible_rows, args = {}) ⇒ Object



707
708
709
710
711
712
713
714
715
716
717
718
# File 'lib/wads/widgets.rb', line 707

def add_multi_select_table(column_headers, visible_rows, args = {})
    calculated_height = 30 + (visible_rows * 30)
    coordinates = get_coordinates(ELEMENT_TABLE,
        { ARG_DESIRED_HEIGHT => calculated_height}.merge(args))
    new_table = MultiSelectTable.new(coordinates.x, coordinates.y,
                                     coordinates.width, coordinates.height,
                                     column_headers, visible_rows,
                                     {ARG_THEME => @parent_widget.gui_theme}.merge(args))
    new_table.base_z = @parent_widget.base_z
    @parent_widget.add_child(new_table)
    new_table
end

#add_plot(args = {}) ⇒ Object



661
662
663
664
665
666
667
668
# File 'lib/wads/widgets.rb', line 661

def add_plot(args = {})
    coordinates = get_coordinates(ELEMENT_PLOT, args)
    new_plot = Plot.new(coordinates.x, coordinates.y,
                        coordinates.width, coordinates.height) 
    new_plot.base_z = @parent_widget.base_z
    @parent_widget.add_child(new_plot)
    new_plot
end

#add_single_select_table(column_headers, visible_rows, args = {}) ⇒ Object



694
695
696
697
698
699
700
701
702
703
704
705
# File 'lib/wads/widgets.rb', line 694

def add_single_select_table(column_headers, visible_rows, args = {})
    calculated_height = 30 + (visible_rows * 30)
    coordinates = get_coordinates(ELEMENT_TABLE,
        { ARG_DESIRED_HEIGHT => calculated_height}.merge(args))
    new_table = SingleSelectTable.new(coordinates.x, coordinates.y,
                                      coordinates.width, coordinates.height,
                                      column_headers, visible_rows,
                                      {ARG_THEME => @parent_widget.gui_theme}.merge(args))
    new_table.base_z = @parent_widget.base_z
    @parent_widget.add_child(new_table)
    new_table
end

#add_table(column_headers, visible_rows, args = {}) ⇒ Object



720
721
722
723
724
725
726
727
728
729
730
731
# File 'lib/wads/widgets.rb', line 720

def add_table(column_headers, visible_rows, args = {})
    calculated_height = 30 + (visible_rows * 30)
    coordinates = get_coordinates(ELEMENT_TABLE,
        { ARG_DESIRED_HEIGHT => calculated_height}.merge(args))
    new_table = Table.new(coordinates.x, coordinates.y,
                        coordinates.width, coordinates.height,
                        column_headers, visible_rows,
                        {ARG_THEME => @parent_widget.gui_theme}.merge(args))
    new_table.base_z = @parent_widget.base_z
    @parent_widget.add_child(new_table)
    new_table
end

#add_text(message, args = {}) ⇒ Object



609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
# File 'lib/wads/widgets.rb', line 609

def add_text(message, args = {})
    default_dimensions = WadsConfig.instance.default_dimensions(ELEMENT_TEXT)
    if args[ARG_USE_LARGE_FONT]
        text_width = WadsConfig.instance.current_theme.pixel_width_for_large_font(message)
    else
        text_width = WadsConfig.instance.current_theme.pixel_width_for_string(message)
    end
    coordinates = get_coordinates(ELEMENT_TEXT,
        { ARG_DESIRED_WIDTH => text_width,
          ARG_DESIRED_HEIGHT => default_dimensions[1]}.merge(args))
    new_text = Text.new(coordinates.x, coordinates.y, message,
        { ARG_THEME => @parent_widget.gui_theme}.merge(args))
    new_text.base_z = @parent_widget.base_z
    @parent_widget.add_child(new_text)
    new_text
end

#add_text_input(width, default_text = '', args = {}) ⇒ Object



626
627
628
629
630
631
632
633
634
# File 'lib/wads/widgets.rb', line 626

def add_text_input(width, default_text = '', args = {})
    coordinates = get_coordinates(ELEMENT_TEXT_INPUT,
        { ARG_DESIRED_WIDTH => width}.merge(args))
    new_text_input = TextField.new(coordinates.x, coordinates.y, default_text, width)
    new_text_input.base_z = @parent_widget.base_z
    @parent_widget.add_child(new_text_input)
    @parent_widget.text_input_fields << new_text_input
    new_text_input
end

#add_vertical_panel(args = {}) ⇒ Object



737
738
739
# File 'lib/wads/widgets.rb', line 737

def add_vertical_panel(args = {})
    internal_add_panel(ELEMENT_VERTICAL_PANEL, args)
end

#add_widget(widget, args = {}) ⇒ Object



599
600
601
602
603
604
605
606
607
# File 'lib/wads/widgets.rb', line 599

def add_widget(widget, args = {})
    # The widget already has an x, y position, so we need to move it
    # based on the layout
    coordinates = get_coordinates(ELEMENT_GENERIC, args)
    widget.move_recursive_absolute(coordinates.x, coordinates.y)
    widget.base_z = @parent_widget.base_z
    @parent_widget.add_child(widget)
    widget
end

#get_coordinates(element_type, args = {}) ⇒ Object



595
596
597
# File 'lib/wads/widgets.rb', line 595

def get_coordinates(element_type, args = {})
    raise "You must use a subclass of WadsLayout"
end

#internal_add_panel(orientation, args) ⇒ Object



745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
# File 'lib/wads/widgets.rb', line 745

def internal_add_panel(orientation, args)
    coordinates = get_coordinates(orientation, args)
    new_panel = Panel.new(coordinates.x, coordinates.y,
                          coordinates.width, coordinates.height)
    new_panel_layout = args[ARG_LAYOUT]
    if new_panel_layout.nil?
        new_panel_layout = LAYOUT_VERTICAL_COLUMN
    end
    new_panel.set_layout(new_panel_layout, args)

    new_panel_theme = args[ARG_THEME]
    new_panel.gui_theme = new_panel_theme unless new_panel_theme.nil?

    new_panel.base_z = @parent_widget.base_z
    @parent_widget.add_child(new_panel)
    #new_panel.disable_border
    new_panel
end