001package arez.dom; 002 003import akasha.Window; 004import javax.annotation.Nonnull; 005 006/** 007 * Factory for getting observable models that sizing of windows. 008 * 009 * <p>A very simple example</p> 010 * <pre>{@code 011 * import arez.Arez; 012 * import arez.dom.EventDrivenValue; 013 * import arez.dom.WindowSize; 014 * import com.google.gwt.core.client.EntryPoint; 015 * import akasha.Global; 016 * import akasha.Window; 017 * 018 * public class WindowSizeExample 019 * implements EntryPoint 020 * { 021 * public void onModuleLoad() 022 * { 023 * final EventDrivenValue<Window, Integer> innerHeight = WindowSize.innerHeight( Global.window() ); 024 * final EventDrivenValue<Window, Integer> innerWidth = WindowSize.innerWidth( Global.window() ); 025 * 026 * Arez.context().observer( () -> Global.document().querySelector( "#status" ).textContent = 027 * "Screen size: " + innerWidth.getValue() + " x " + innerHeight.getValue() ); 028 * } 029 * } 030 * }</pre> 031 */ 032public final class WindowSize 033{ 034 private WindowSize() 035 { 036 } 037 038 /** 039 * Create an event driven observable component for window.innerWidth and window.innerHeight wrapped in dimension object. 040 * 041 * @param window the window. 042 * @return the event driven observable component. 043 */ 044 @Nonnull 045 public static EventDrivenValue<Window, Dimension> inner( @Nonnull final Window window ) 046 { 047 return EventDrivenValue.create( window, "resize", w -> new Dimension( w.innerWidth(), w.innerHeight() ) ); 048 } 049 050 /** 051 * Create an event driven observable component for window.innerHeight. 052 * 053 * @param window the window. 054 * @return the event driven observable component. 055 */ 056 @Nonnull 057 public static EventDrivenValue<Window, Integer> innerHeight( @Nonnull final Window window ) 058 { 059 return EventDrivenValue.create( window, "resize", Window::innerHeight ); 060 } 061 062 /** 063 * Create an event driven observable component for window.innerWidth. 064 * 065 * @param window the window. 066 * @return the event driven observable component. 067 */ 068 @Nonnull 069 public static EventDrivenValue<Window, Integer> innerWidth( @Nonnull final Window window ) 070 { 071 return EventDrivenValue.create( window, "resize", Window::innerWidth ); 072 } 073 074 /** 075 * Create an event driven observable component for window.outerHeight. 076 * 077 * @param window the window. 078 * @return the event driven observable component. 079 */ 080 @Nonnull 081 public static EventDrivenValue<Window, Integer> outerHeight( @Nonnull final Window window ) 082 { 083 return EventDrivenValue.create( window, "resize", Window::outerHeight ); 084 } 085 086 /** 087 * Create an event driven observable component for window.outerWidth. 088 * 089 * @param window the window. 090 * @return the event driven observable component. 091 */ 092 @Nonnull 093 public static EventDrivenValue<Window, Integer> outerWidth( @Nonnull final Window window ) 094 { 095 return EventDrivenValue.create( window, "resize", Window::outerWidth ); 096 } 097}