@@ -392,12 +392,20 @@ Usually a style object is connected to the application and is used for all widge
392392``` lua
393393local app = lwtk .Application {
394394 name = " example" ,
395- style = { { " *Width" , 10 },
396- { " *Width@MyWidget2" , 20 } }
395+ style = { { " *Columns" , 10 },
396+ { " *Columns@MyWidget2" , 20 },
397+ { " *Width" , 11 } }
397398}
398399local win = app :newWindow { w1 , w2 }
399- assert (w1 :getStyleParam (" FooWidth" ) == 10 )
400- assert (w2 :getStyleParam (" FooWidth" ) == 20 )
400+ assert (w1 :getStyleParam (" FooColumns" ) == 10 )
401+ assert (w2 :getStyleParam (" FooColumns" ) == 20 )
402+ ```
403+
404+ For scalable parameters (see [ lwtk.BuiltinStyleTypes] ( ../src/lwtk/BuiltinStyleTypes.lua ) )
405+ the screen scale factor is considered:
406+ ``` lua
407+ local scale = app :getScreenScale ()
408+ assert (w1 :getStyleParam (" FooWidth" ) == scale * 11 )
401409```
402410
403411If no style is specified, the application object gets the default style
@@ -409,16 +417,17 @@ local app = lwtk.Application {
409417}
410418local w1 , w2 , w4 = MyWidget1 (), MyWidget2 (), MyWidget4 ()
411419local win = app :newWindow { w1 , w2 , w4 }
412- assert (w1 :getStyleParam (" TextSize" ) == 12 )
420+ assert (w1 :getStyleParam (" TextSize" ) == app : getScreenScale () * 12 )
413421```
414422
415423Style rules can be added to existing style:
416424``` lua
417425app :addStyle { { " TextSize@MyWidget1" , 10 },
418426 { " TextSize@MyWidget2" , 20 } }
419- assert (w1 :getStyleParam (" TextSize" ) == 10 )
420- assert (w2 :getStyleParam (" TextSize" ) == 20 )
421- assert (w4 :getStyleParam (" TextSize" ) == 12 )
427+ local scale = app :getScreenScale ()
428+ assert (w1 :getStyleParam (" TextSize" ) == scale * 10 )
429+ assert (w2 :getStyleParam (" TextSize" ) == scale * 20 )
430+ assert (w4 :getStyleParam (" TextSize" ) == scale * 12 )
422431```
423432
424433
@@ -430,34 +439,34 @@ Style rules can be specified for individual widgets:
430439``` lua
431440local app = lwtk .Application {
432441 name = " example" ,
433- style = { { " *Width " , 10 },
434- { " *Height " , 15 } }
442+ style = { { " *Seconds " , 10 },
443+ { " *Columns " , 15 } }
435444}
436445local w1a = MyWidget1 {}
437446local w1b = MyWidget1 {
438- style = { { " *Width " , 20 } } -- individual style for w1b
447+ style = { { " *Seconds " , 20 } } -- individual style for w1b
439448}
440449local win = app :newWindow { w1a , w1b }
441- assert (w1a :getStyleParam (" FooWidth " ) == 10 )
442- assert (w1a :getStyleParam (" FooHeight " ) == 15 )
443- assert (w1b :getStyleParam (" FooWidth " ) == 20 )
444- assert (w1b :getStyleParam (" FooHeight " ) == 15 )
450+ assert (w1a :getStyleParam (" FooSeconds " ) == 10 )
451+ assert (w1a :getStyleParam (" FooColumns " ) == 15 )
452+ assert (w1b :getStyleParam (" FooSeconds " ) == 20 )
453+ assert (w1b :getStyleParam (" FooColumns " ) == 15 )
445454```
446455
447456<!-- ---------------------------------------------------------------------------------------- -->
448457
449458Style can be replaced:
450459``` lua
451- app :setStyle { { " *Width " , 100 },
452- { " *Height " , 200 } } -- replaces style for whole ap
453- assert (w1a :getStyleParam (" FooWidth " ) == 100 )
454- assert (w1a :getStyleParam (" FooHeight " ) == 200 )
455- assert (w1b :getStyleParam (" FooWidth " ) == 20 ) -- individual style for w1b is still active
456- assert (w1b :getStyleParam (" FooHeight " ) == 200 )
457-
458- w1b :setStyle { { " *Width " , 300 } } -- replaces individual style for w1b
459- assert (w1b :getStyleParam (" FooWidth " ) == 300 )
460- assert (w1b :getStyleParam (" FooHeight " ) == 200 )
460+ app :setStyle { { " *Seconds " , 100 },
461+ { " *Columns " , 200 } } -- replaces style for whole ap
462+ assert (w1a :getStyleParam (" FooSeconds " ) == 100 )
463+ assert (w1a :getStyleParam (" FooColumns " ) == 200 )
464+ assert (w1b :getStyleParam (" FooSeconds " ) == 20 ) -- individual style for w1b is still active
465+ assert (w1b :getStyleParam (" FooColumns " ) == 200 )
466+
467+ w1b :setStyle { { " *Seconds " , 300 } } -- replaces individual style for w1b
468+ assert (w1b :getStyleParam (" FooSeconds " ) == 300 )
469+ assert (w1b :getStyleParam (" FooColumns " ) == 200 )
461470```
462471
463472<!-- ---------------------------------------------------------------------------------------- -->
@@ -469,71 +478,71 @@ group's child widgets:
469478``` lua
470479local app = lwtk .Application {
471480 name = " example" ,
472- style = { { " *Width " , 10 },
473- { " *Height " , 15 },
474- { " *rHeight " , 16 } }
481+ style = { { " *Seconds " , 10 },
482+ { " *Columns " , 15 },
483+ { " *rColumns " , 16 } }
475484}
476485local w1a = MyWidget1 {}
477486local w1b = MyWidget1 {
478- style = { { " *oWidth " , 21 } } -- individual style rule for w1b
487+ style = { { " *oSeconds " , 21 } } -- individual style rule for w1b
479488}
480489local w2a = MyWidget2 {}
481490local w2b = MyWidget2 {
482- style = { { " *oWidth " , 22 } } -- individual style rule for w2b
491+ style = { { " *oSeconds " , 22 } } -- individual style rule for w2b
483492}
484493local g1 = lwtk .Group { w1a , w1b }
485494local g2 = lwtk .Group { w2a , w2b ,
486- style = { { " *oHeight " , 33 } } -- individual style rule for widget group g2
495+ style = { { " *oColumns " , 33 } } -- individual style rule for widget group g2
487496}
488497local win = app :newWindow { g1 , g2 }
489498
490- assert (w1a :getStyleParam (" FooWidth " ) == 10 ) -- from app
491- assert (w1a :getStyleParam (" FooHeight " ) == 15 ) -- from app
499+ assert (w1a :getStyleParam (" FooSeconds " ) == 10 ) -- from app
500+ assert (w1a :getStyleParam (" FooColumns " ) == 15 ) -- from app
492501
493- assert (w1b :getStyleParam (" FooWidth " ) == 21 ) -- from widget
494- assert (w1b :getStyleParam (" FooHeight " ) == 15 ) -- from app
502+ assert (w1b :getStyleParam (" FooSeconds " ) == 21 ) -- from widget
503+ assert (w1b :getStyleParam (" FooColumns " ) == 15 ) -- from app
495504
496- assert (w2a :getStyleParam (" FooWidth " ) == 10 ) -- from app
497- assert (w2a :getStyleParam (" FooHeight " ) == 33 ) -- from group
505+ assert (w2a :getStyleParam (" FooSeconds " ) == 10 ) -- from app
506+ assert (w2a :getStyleParam (" FooColumns " ) == 33 ) -- from group
498507
499- assert (w2b :getStyleParam (" FooWidth " ) == 22 ) -- from widget
500- assert (w2b :getStyleParam (" FooHeight " ) == 33 ) -- from group
501- assert (w2b :getStyleParam (" BarHeight " ) == 16 ) -- from app
508+ assert (w2b :getStyleParam (" FooSeconds " ) == 22 ) -- from widget
509+ assert (w2b :getStyleParam (" FooColumns " ) == 33 ) -- from group
510+ assert (w2b :getStyleParam (" BarColumns " ) == 16 ) -- from app
502511```
503512
504513<!-- ---------------------------------------------------------------------------------------- -->
505514
506515Replacing style in widget groups is also possible:
507516``` lua
508- g1 :setStyle { { " *oWidth " , 17 } }
517+ g1 :setStyle { { " *oSeconds " , 17 } }
509518
510- assert (w1a :getStyleParam (" FooWidth " ) == 17 ) -- from group
511- assert (w1a :getStyleParam (" FooHeight " ) == 15 ) -- from app
519+ assert (w1a :getStyleParam (" FooSeconds " ) == 17 ) -- from group
520+ assert (w1a :getStyleParam (" FooColumns " ) == 15 ) -- from app
512521
513- assert (w1b :getStyleParam (" FooWidth " ) == 21 ) -- from widget
514- assert (w1b :getStyleParam (" FooHeight " ) == 15 ) -- from app
522+ assert (w1b :getStyleParam (" FooSeconds " ) == 21 ) -- from widget
523+ assert (w1b :getStyleParam (" FooColumns " ) == 15 ) -- from app
515524
516- g2 :setStyle { { " BarHeight " , 34 },
517- { " *oHeight " , 36 } }
525+ g2 :setStyle { { " BarColumns " , 34 },
526+ { " *oColumns " , 36 } }
518527
519- assert (w2a :getStyleParam (" FooWidth " ) == 10 ) -- from app
520- assert (w2a :getStyleParam (" FooHeight " ) == 36 ) -- from group
528+ assert (w2a :getStyleParam (" FooSeconds " ) == 10 ) -- from app
529+ assert (w2a :getStyleParam (" FooColumns " ) == 36 ) -- from group
521530
522- assert (w2b :getStyleParam (" FooWidth " ) == 22 ) -- from widget
523- assert (w2b :getStyleParam (" FooHeight " ) == 36 ) -- from group
524- assert (w2b :getStyleParam (" BarHeight " ) == 34 ) -- from group
525- assert (w2b :getStyleParam (" FarHeight " ) == 16 ) -- from app
531+ assert (w2b :getStyleParam (" FooSeconds " ) == 22 ) -- from widget
532+ assert (w2b :getStyleParam (" FooColumns " ) == 36 ) -- from group
533+ assert (w2b :getStyleParam (" BarColumns " ) == 34 ) -- from group
534+ assert (w2b :getStyleParam (" FarColumns " ) == 16 ) -- from app
526535
527- app :setStyle { { " *Width " , 18 },
528- { " *rHeight " , 19 } }
536+ app :setStyle { { " *Seconds " , 18 },
537+ { " *rColumns " , 19 } }
529538
530- assert (w2a :getStyleParam (" FooWidth " ) == 18 ) -- from app
531- assert (w2a :getStyleParam (" FooHeight " ) == 36 ) -- from group
539+ assert (w2a :getStyleParam (" FooSeconds " ) == 18 ) -- from app
540+ assert (w2a :getStyleParam (" FooColumns " ) == 36 ) -- from group
532541
533- assert (w2b :getStyleParam (" FooWidth " ) == 22 ) -- from widget
534- assert (w2b :getStyleParam (" FooHeight " ) == 36 ) -- from group
535- assert (w2b :getStyleParam (" BarHeight " ) == 34 ) -- from group
536- assert (w2b :getStyleParam (" FarHeight " ) == 19 ) -- from app
542+ assert (w2b :getStyleParam (" FooSeconds " ) == 22 ) -- from widget
543+ assert (w2b :getStyleParam (" FooColumns " ) == 36 ) -- from group
544+ assert (w2b :getStyleParam (" BarColumns " ) == 34 ) -- from group
545+ assert (w2b :getStyleParam (" FarColumns " ) == 19 ) -- from app
537546```
538547
539548<!-- ---------------------------------------------------------------------------------------- -->
@@ -547,31 +556,31 @@ to the group's child widgets:
547556``` lua
548557local app = lwtk .Application {
549558 name = " example" ,
550- style = { { " *Width " , 10 },
551- { " *Height " , 15 } }
559+ style = { { " *Seconds " , 10 },
560+ { " *Columns " , 15 } }
552561}
553562local w1a = MyWidget1 {}
554563local w1b = MyWidget1 {
555- style = { FooWidth = 22 } -- individual style for w1b
564+ style = { FooSeconds = 22 } -- individual style for w1b
556565}
557566local g1 = lwtk .Group {
558567 style = {
559- FooWidth = 23 , -- individual style parameter for g1
560- { " *Width " , 33 } -- individual style rule for g1
568+ FooSeconds = 23 , -- individual style parameter for g1
569+ { " *Seconds " , 33 } -- individual style rule for g1
561570 },
562571 w1a ,
563572 w1b
564573}
565574
566575local win = app :newWindow { g1 }
567576
568- assert (g1 :getStyleParam (" FooWidth " ) == 23 ) -- from group
577+ assert (g1 :getStyleParam (" FooSeconds " ) == 23 ) -- from group
569578
570- assert (w1a :getStyleParam (" FooHeight " ) == 15 ) -- from app
571- assert (w1a :getStyleParam (" FooWidth " ) == 33 ) -- from group
579+ assert (w1a :getStyleParam (" FooColumns " ) == 15 ) -- from app
580+ assert (w1a :getStyleParam (" FooSeconds " ) == 33 ) -- from group
572581
573- assert (w1b :getStyleParam (" FooHeight " ) == 15 ) -- from app
574- assert (w1b :getStyleParam (" FooWidth " ) == 22 ) -- from widget
582+ assert (w1b :getStyleParam (" FooColumns " ) == 15 ) -- from app
583+ assert (w1b :getStyleParam (" FooSeconds " ) == 22 ) -- from widget
575584```
576585
577586TODO
0 commit comments