@@ -76,11 +76,23 @@ public function form(Form $form): Form
7676 ->label ('Label Height (inches) ' )
7777 ->numeric ()
7878 ->required ()
79- ->default ($ this ->cardHeight ),
79+ ->default ($ this ->cardHeight )
80+ ->rules (['required ' , 'numeric ' , 'min:0.1 ' , function ($ attribute , $ value , $ fail ) {
81+ $ availableHeight = $ this ->pageHeight - $ this ->pageTopPadding - $ this ->pageBottomPadding ;
82+ if ($ value > $ availableHeight ) {
83+ $ fail ("The card height must not exceed the available page height. " );
84+ }
85+ }]),
8086 TextInput::make ('cardWidth ' )
8187 ->label ('Label Width (inches) ' )
8288 ->numeric ()
8389 ->required ()
90+ ->rules (['required ' , 'numeric ' , 'min:0.1 ' , function ($ attribute , $ value , $ fail ) {
91+ $ availableWidth = $ this ->pageWidth - $ this ->pageLeftPadding - $ this ->pageRightPadding ;
92+ if ($ value > $ availableWidth ) {
93+ $ fail ("The card width must not exceed the available page width. " );
94+ }
95+ }])
8496 ->default ($ this ->cardWidth ),
8597 TextInput::make ('pageWidth ' )
8698 ->label ('Page Width (inches) ' )
@@ -124,7 +136,7 @@ public function form(Form $form): Form
124136 ])->columns (2 );
125137 }
126138
127- public function generatePages ($ showNotification = true )
139+ public function generatePages ($ showNotification = true ): void
128140 {
129141 $ this ->validate ();
130142 $ this ->init ();
@@ -181,11 +193,10 @@ private function calculateGridData()
181193 ];
182194 }
183195
184- $ cols = floor ($ availablePageWidth / $ this ->cardWidth );
185- $ rows = floor ($ availablePageHeight / $ this ->cardHeight );
186- $ gapX = ($ availablePageWidth - $ cols * $ this ->cardWidth ) / ($ cols - 1 );
187- $ gapY = ($ this ->pageHeight - $ rows * $ this ->cardHeight ) / ($ rows - 1 );
188-
196+ $ cols = max (1 , floor ($ availablePageWidth / $ this ->cardWidth ));
197+ $ rows = max (1 , floor ($ availablePageHeight / $ this ->cardHeight ));
198+ $ gapX = $ cols > 1 ? ($ availablePageWidth - $ cols * $ this ->cardWidth ) / ($ cols - 1 ) : 0 ;
199+ $ gapY = $ rows > 1 ? ($ availablePageHeight - $ rows * $ this ->cardHeight ) / ($ rows - 1 ) : 0 ;
189200 return [
190201 'cols ' => $ cols ,
191202 'rows ' => $ rows ,
0 commit comments